72 lines
1.4 KiB
Lua
72 lines
1.4 KiB
Lua
--Required control rate.
|
|
control_rate = 2
|
|
|
|
-- Required "control" function.
|
|
function control()
|
|
if taskname() ~= "attack" then
|
|
enemy = getenemy()
|
|
if enemy ~= -1 then
|
|
pushtask(0, "attack", enemy)
|
|
else
|
|
pushtask(0, "fly")
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Required "attacked" function
|
|
function attacked(attacker)
|
|
task = taskname()
|
|
if task ~= "attack" and task ~= "runaway" then
|
|
taunt()
|
|
pushtask(0, "attack", attacker)
|
|
elseif task == "attack" then
|
|
if gettargetid() ~= attacker then
|
|
pushtask(0, "attack", attacker)
|
|
end
|
|
end
|
|
end
|
|
|
|
function taunt()
|
|
num = rng(0,4)
|
|
if num == 0 then msg = "How dare you attack me?!"
|
|
elseif num == 1 then msg = "Aha! You think you can best ME?!"
|
|
elseif num == 2 then msg = "JUST! DIE!"
|
|
elseif num == 3 then msg = "Ohh, You're not going to enjoy this!"
|
|
end
|
|
if msg then comm(attacker, msg) end
|
|
end
|
|
|
|
-- Run away.
|
|
function runaway()
|
|
target = gettargerid()
|
|
dir = face(target, 1)
|
|
accel()
|
|
end
|
|
|
|
-- Attack.
|
|
function attack()
|
|
target = gettargetid()
|
|
dir = face(target)
|
|
dist = getdist(getpos(target))
|
|
|
|
if parmor() < 70 then
|
|
poptask()
|
|
pushtask(0, "runaway", target)
|
|
elseif dir < 10 and dist > 300 then
|
|
accel()
|
|
elseif dir < 10 and dist < 300 then
|
|
shoot()
|
|
end
|
|
end
|
|
|
|
-- Fly to the player.
|
|
function fly()
|
|
target = 0
|
|
dir = face(target)
|
|
dist = getdist(getpos(target))
|
|
if dir < 10 and dist > 300 then
|
|
accel()
|
|
end
|
|
end
|
|
|