Author Topic: [MOD] Goods Hauler (Automatically buy/sell/move goods!)  (Read 40552 times)

Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    534
    • View Profile
    • Scrap Yard - Avofactory
on: September 11, 2017, 09:08:07 PM
Yes it works on new ships. We got no issues with this mod on our server. At least with our modified version, wich does not fix issues, but does only some improvements.
« Last Edit: September 11, 2017, 09:10:37 PM by Hammelpilaw »
Scrap Yard Galaxy
My mods and tools
My Workshop

If you find a bug in my mods please contact me.



Yuisan

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    6
    • View Profile
on: September 13, 2017, 01:33:19 AM
I was wondering if this mod is still being updated/worked on and whatnot. I wasn't sure where to post this question so I apologize if this isn't the right location for this. also does the mod still only work with player made factories? it may be why its not really working for me because I only have a turret factory and was attempting to use a hauler to buy/transfer goods to the turret factory for me, but I guess the turret factory is more of a 'store/shop' than a station that can buy/trade/produce goods. anywho if I could get some feedback that would be awesome. Thanks for the cool mod, I cant wait until I can fully utilize it.



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    534
    • View Profile
    • Scrap Yard - Avofactory
on: September 13, 2017, 08:24:46 AM
I did not use it on 0.14 patch, but it is running on our server and should work fine.
Scrap Yard Galaxy
My mods and tools
My Workshop

If you find a bug in my mods please contact me.



Valhar2000

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    11
    • View Profile
on: September 14, 2017, 11:31:53 AM
Yesterday I did the obvious thing: I uninstalled the mod, had Steam check the integrity of Avorion's local files loaded up a save game to make sure nothing was broken, and then installed the mod again. After that, everything worked as expected, and I was able to command 3 cargo ships to haul goods.

Strangely enough, I do get the same messages I was getting before, but the cargo ships work.

Thanks for the help!



solyxx

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    1
    • View Profile
on: September 16, 2017, 10:10:06 PM
Great mod now only if I can find a trade mode that shows me trade routes around my home sector



Myrre

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    2
    • View Profile
on: September 27, 2017, 01:19:31 AM
Great mod now only if I can find a trade mode that shows me trade routes around my home sector

There is an in-game inte already for that...


Anyway..
In 0.14.3 I got this error.

 Log entries:
Code: [Select]
2017-09-27 01-09-17| could not execute function 'initialize' in '"data/scripts/entity/ai/haulgoods_cmd.lua"':
2017-09-27 01-09-17| data/scripts/entity/ai/haulgoods_cmd.lua:12: attempt to concatenate local 'help' (a nil value)
2017-09-27 01-09-17| stack traceback:
2017-09-27 01-09-17| data/scripts/entity/ai/haulgoods_cmd.lua:12: in function 'haulGoodsCmdSendError'
2017-09-27 01-09-17| data/scripts/entity/ai/haulgoods_cmd.lua:41: in function <data/scripts/entity/ai/haulgoods_cmd.lua:27>



thrasher779

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    1
    • View Profile
on: October 02, 2017, 07:37:47 PM
Is there any way this could get updated so haulers can move stuff between sectors?
Maybe give the hauler some kind of home sector (the sector where you "/haulgoods start" it) and make it trade within any (visited) sector within hyperdrive range of its home sector?

Maybe add some other requirement to inter-sector-trade, like having to put a High-Tech Trading System (yellow rarity) or higher into the hauler?



Azerik

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    47
    • View Profile
on: October 20, 2017, 01:19:53 PM
Is there any way to make it run at a loss?

I'm trying to run supply chains that are a mix of my stations, a friend's stations, and alliance stations.  I'd like to be able to change the code or something to let it buy at a real price and "sell" at 0 to my own stations.  I just do not possess sufficient programming skills to make this change on my own.



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    534
    • View Profile
    • Scrap Yard - Avofactory
on: October 20, 2017, 04:59:10 PM
Is there any way to make it run at a loss?

I'm trying to run supply chains that are a mix of my stations, a friend's stations, and alliance stations.  I'd like to be able to change the code or something to let it buy at a real price and "sell" at 0 to my own stations.  I just do not possess sufficient programming skills to make this change on my own.

You can do this easily. Open file /entity/ai/haulgoods.lua in any text editor (f.e. notepad++). You should change lines 326-330:

Code: [Select]
    if (stock["fromprice"] > stock["toprice"])
    then -- Would run a loss (this takes into account 0 prices for player factories)
        debug_msg("Route is not profitable for buying at " .. stock["fromprice"] .. " and selling at " .. stock["toprice"])
        return
    end

Change this to

Code: [Select]
    --if (stock["fromprice"] > stock["toprice"])
    --then -- Would run a loss (this takes into account 0 prices for player factories)
        --debug_msg("Route is not profitable for buying at " .. stock["fromprice"] .. " and selling at " .. stock["toprice"])
        --return
    --end

Then the mod does not skip routes that give a negative profit. Be aware that it also sells every of your stuff to all npc stations in the sector.
I did not test it, if you get any issues just answere here.
« Last Edit: October 20, 2017, 05:03:47 PM by Hammelpilaw »
Scrap Yard Galaxy
My mods and tools
My Workshop

If you find a bug in my mods please contact me.



Azerik

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    47
    • View Profile
on: October 20, 2017, 08:21:13 PM
Thank you.  It is working brilliantly so far.

What I mostly needed it for was supplying Ore to my steel factory from the alliance owned mine.  Since I'm footing the bills for the alliance it is all technically me so this will work.

Another Q: If I were to say, copy and rename the files to "haul" instead of "haulgoods" and have "haul" be the one running w/o profit, but "haulgoods" still had the profit check, would that work to add two commands?

I don't care if I am making a profit in my home sector w/o npc stations, but other people on the server might not have the same setup.


Answered my own question.  I'd need to go through the scripts and change all the references to "haulgoods.lua" to the different name at the very least.

New Q: Would it be sufficient to just change those references (assuming I could do it), or would there be deeper things that would need changing?

Edit: Apparently I might be smarter than I give myself credit for.  I think I've implemented it as two different commands.  I found only a couple references to the original scripts and changed those (as well as the haulgoods_cmd.lua) and it seems to be operating as intended.  The only thing I haven't done is change the dispatcher name from HaulGoods, but I think that's minor enough nobody will notice.

I wouldn't mind a more educated opinion on what I've done though, just to make sure I'm not going to set fire to something.

in the haulgoods.lua in the command folder (now autotrade)
Code: [Select]
function execute(sender, commandName, action, ...)
Player(sender):addScriptOnce("data/scripts/entity/ai/autotrade_cmd.lua", getHelp(), sender, action, ...)

in the haulgoods.lua in the ai folder
Code: [Select]
local VERSION = "v0.9.2"
local ME = "data/scripts/entity/ai/autotrade.lua"
local factory = "data/scripts/entity/merchants/factory.lua"

in the haulgoods_cmd.lua in the ai folder
Code: [Select]
require ("utility")

local haulscript = "data/scripts/entity/ai/autotrade.lua"

function haulGoodsCmdSendError(player, errorMessage, help)
« Last Edit: October 20, 2017, 09:22:23 PM by Azerik »



Azerik

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    47
    • View Profile
on: October 22, 2017, 12:52:42 AM
Looks like it works.  After a few other bumps in the road, my players are happily trading away.

Brilliant mod.



Evil33

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    6
    • View Profile
on: October 25, 2017, 09:48:15 PM
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.
Code: [Select]
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:
Code: [Select]
return from.index, to.index, good, amountIn response to this, I also had to change all calls of
Code: [Select]
haulGoodsRoute[1] to
Code: [Select]
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
Code: [Select]
station:getDockingPositions() in dock.lua returned nil, nil when out of sector.
Replacing line 12 in dock.lua with
Code: [Select]
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
Code: [Select]
player:sendChatMessage("HaulGoods", 0, errorMessage .. help)can be simply solved by surrounding it with a test:
Code: [Select]
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



albert0015

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    9
    • View Profile
on: October 26, 2017, 04:55:34 AM
Quote

 :o well that post got bigger than I thought :D

i have no clue in anything above. would love to try this out if someone can continue developing this mod. been reading all the post and seem like this mod have been abandon by the person that developed it



Evil33

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    6
    • View Profile
on: October 26, 2017, 12:23:13 PM
I've packed the files I touched together, so you can give it a try, might be a better explanation than my wall of text above ^^"
I've changed some parts of my modification, so I'm closer to the original code now.

Edit: Seems I broke some things trying to save the data to the database, now it should work ^^"
I can't save entities directly but need to save the indices.

Edit2: Seems like the secure and restore functions don't like me, they give me tons of errors, that the entities can't be created but I definitely wrote them in correctly... at least I hope so...

Edit3: I finally found it :D As it seems, I can't call Entity(uuid) in the restore function, so the script fails to restore the references, I changed all calls on the tables to Entity(tableContent) so the only thing restored and saved are UUIDs, so far it's looking good.


Edit4: After some more debugging I found out that the missing docking positions must have been an inconsistent state of my server. I added a test for this case and a workaround, but was able to remove my changes to the dock.lua
« Last Edit: October 26, 2017, 10:06:08 PM by Evil33 »



Kryptos

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    8
    • View Profile
on: November 22, 2017, 06:31:58 AM
Does this still work in the .15 beta? I've been trying to see what's changed, and the cargo shuttles are...underwhelming.