44 lines
874 B
Lua
44 lines
874 B
Lua
-- Required control rate.
|
|
control_rate = 2
|
|
|
|
-- Required "control" function.
|
|
function control()
|
|
if taskname() == "none" then
|
|
pushtask(0, "fly")
|
|
end
|
|
end
|
|
|
|
-- Required "attacked" function.
|
|
function attacked(attacker)
|
|
if taskname() ~= "runaway" then
|
|
-- Let's have some messages.
|
|
if attacker == player then
|
|
msg = rng(0,4)
|
|
if msg == 0 then say("ARGH! Please don't hurt me.")
|
|
elseif msg == 1 then say("HEY! We are simply a merchant vessle.")
|
|
elseif msg == 2 then say("LEAVE! ME! ALONE!")
|
|
end
|
|
end
|
|
-- So bravely run away!
|
|
pushtask(0, "runaway", attacker)
|
|
end
|
|
end
|
|
|
|
-- Runs away.
|
|
function runaway()
|
|
target = gettargetid()
|
|
dir = face(target, 1)
|
|
accel()
|
|
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
|
|
|