I've taken a look into this mod, because I wanted to make it work, even if I'm not in the same sector as the ship.
The first thing I found out, was that this script was always started anew when a game was loaded. I took a look at the station scripts and found out that they save their state and restore it afterwards. So I added this to the haulgoods script.
function restore(values)
haulGoodsStage = values.haulGoodsStage
haulGoodsList = values.haulGoodsList
haulGoods = values.haulGoods
haulGoodsDispatcher = values.haulGoodsDispatcher
haulGoodsRoute = values.haulGoodsRoute
end
function secure()
local route = {}
return
{
haulGoodsStage = haulGoodsStage,
haulGoodsList = haulGoodsList,
haulGoods = haulGoods,
haulGoodsDispatcher = haulGoodsDispatcher,
haulGoodsRoute = haulGoodsRoute,
}
end
Another thing I had to change for this to work was the haulGoodsRoute, in the original version the stations are saved there, for this save and restore to work I needed to change this to the index of the stations, so I changed the return value of the requestGoodsRoute function to:
return from.index, to.index, good, amount
In response to this, I also had to change all calls of
haulGoodsRoute[1]
to
Entity(haulGoodsRoute[1])
, same for index 2.
That gave me another error, in fact it seems like the docking positions of a station can not be determined, as
station:getDockingPositions()
in dock.lua returned nil, nil when out of sector.
Replacing line 12 in dock.lua with
local pos, dir = station:getDockingPositions()
if (dir == nil) then
dir = station.up;
end
if (pos == nil) then
pos = station.translationf;
end
solved the problem and gives the ship a faint idea of the docking positions.
A last error thrown in haulgoods_cmd.lua in line 12
player:sendChatMessage("HaulGoods", 0, errorMessage .. help)
can be simply solved by surrounding it with a test:
if (help ~= nil) then
player:sendChatMessage("HaulGoods", 0, errorMessage .. help)
end
I hope my explanations are somewhat understandable ::)
I really like the idea of this mod and would love some other opinions on my changes. And for what I can say, it works out of sector.
:o well that post got bigger than I thought :D