66 lines
1.3 KiB
Lua
66 lines
1.3 KiB
Lua
-- Required control rate.
|
|
control_rate = 2
|
|
|
|
-- Required "control" function.
|
|
function control()
|
|
if taskname() == "none" then
|
|
local planet = getrndplanet()
|
|
pushtask(0, "go", planet)
|
|
end
|
|
end
|
|
|
|
-- Required "attacked" function.
|
|
function attacked(attacker)
|
|
if taskname() ~= "runaway" then
|
|
-- Let's have some messages.
|
|
if attacker == player then
|
|
local 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()
|
|
local target = gettargetid()
|
|
local dir = face(target, 1)
|
|
accel()
|
|
end
|
|
|
|
-- Fly to the target.
|
|
function go()
|
|
local target = gettarget()
|
|
local dir = face(target)
|
|
local dist = getdist(target)
|
|
local bdist = minbrakedist()
|
|
if dir < 10 and dist > bdist then
|
|
accel()
|
|
elseif dir < 10 and dist < bdist then
|
|
poptask()
|
|
pushtask(0, "stop")
|
|
end
|
|
end
|
|
|
|
-- Backthrust.
|
|
function stop()
|
|
brake()
|
|
if isstopped() then
|
|
poptask()
|
|
settimer(0, rng(3000, 5000))
|
|
pushtask(0, "land")
|
|
end
|
|
end
|
|
|
|
--Waits.
|
|
function land()
|
|
if timeup(0) then
|
|
pushtask(0, "runaway", player)
|
|
end
|
|
end
|
|
|