Lephisto/dat/missions/cargo.lua

60 lines
1.8 KiB
Lua

-- Create the mission.
function create()
-- Target destination.
local i = 0
repeat
planet = space.getPlanet(misn.factions())
i = i + 1
until planet ~= space.landName() or i > 10
-- Protect agains inf loop.
if i > 10 then
misn.finish()
end
-- Missions generic.
misn_type = "Rush"
misn.setTitle("Rush Delivery to " .. planet)
-- More mission specifics.
carg_mass = rnd.int(10, 30)
carg_type = "Food"
misn.setDesc(string.format(
"%s needs a rush delivery of %d tons of %s by %s.",
planet, carg_mass, carg_type, "SOMEDAY"))
misn_reward = carg_mass * 1000 + rnd.int(0, 5000)
misn.setReward(string.format("%d Scred", misn_reward))
end
function accept()
if player.freeCargo() < carg_mass then
tk.msg("Ship is full",
string.format(
"Your ship is too full, You need to make room for %d more tons if you want to be able to accept the mission.",
carg_mass-player.freeCargo()))
elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
carg_id = player.addCargo(carg_type, carg_mass)
tk.msg("Mission Accepted",
string.format("The workers load the %d tons of %s onto your ship.",
carg_mass, carg_type))
hook.land("land"); -- Only hook after accepting.
else
tk.msg("Too many missions", "You have too many active missions.")
end
end
function land()
if space.landName() == planet then
if player.rmCargo(carg_id) then
player.pay(misn_reward)
tk.msg("Mission Accomplished",
string.format("The workers unload the %s at the docks.", carg_type))
misn_finish()
else
tk.msg("Where is the cargo?",
string.format("You are missing the %d tons of %s!.",
carg_mass, carg_type))
end
end
end