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

Splutty

  • Sr. Member
  • ****
  • Status:
    Offline
    Posts:
    258
    • View Profile
on: June 01, 2017, 04:53:54 PM
I think he means that it doesn't work with a factory complex, which is a mod that merges stations together into one (made by Laserzwei). That's probably why it isn't working, as it's no longer a normal station.

There's a list of all the stationscripts used in determining what's a station, so that should be easy to do, as long as Laser has a script that defines the combined station as an actual station.



Pirat

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    10
    • View Profile
on: June 13, 2017, 01:20:46 AM
Wow, good job.
There is only one thing left to see with this mod: Playerless system simulation.



Valshala

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    17
    • View Profile
on: July 02, 2017, 05:31:26 PM
I have been using this mod for pretty much the whole time I have been playing Avorion, it works pretty flawlessly for me thankyou so much for adding a vital feature to the game.

I have a few suggestions to improve it you may consider to make it perfect and worthy of the devs implementing it..

1)  When picking up a resource make a quick recheck of the factory/station you are delivering too to
     reduce  the chance an npc trader has delivered to the station.. Meaning less chance of having
    access cargo left over.

2) With beta branch allowing several sectors active to the player/faction how about working on a system
    where the trader can move between sectors, like setting a certain factory or sector as its base and
    allowing it to move x amount of sectors away to sell etc maybe dependent on the quality of trading
    artifact installed.

3) Have the requirement of a trade ship be changed to require a pilot and trading artifact rather than a
    captain.  Why I request this is simple, I have a sector with 10 stations who require 4 mechanics each.
    The small trade ship I use has 500 cargo without any modifications and only requires 2 mechanics to
    function....    The single captain attached to this ship In salary is paid more than the 10 stations and
    the crew + the ships worth combined and I find this absolutely insane.  There is no way the galaxy
   would last more than a couple of hours with these kind of wages..
   



Dinoff

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    1
    • View Profile
on: July 09, 2017, 12:19:23 PM
I am new to modding in this game.  I am not sure i understand where those text lines need to be inserted or what they should look like when finished.    could someone post a screenshot.  currently playing an unmodded game. 
« Last Edit: July 09, 2017, 12:26:18 PM by Dinoff »



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    549
    • View Profile
    • Scrap Yard - Avofactory
on: August 05, 2017, 04:37:49 PM
I am new to modding in this game.  I am not sure i understand where those text lines need to be inserted or what they should look like when finished.    could someone post a screenshot.  currently playing an unmodded game.

A little late, but maybe it still helps anybody... Use the attached file for Avorion 0.12.7. For other versions you should verify the compatibilty though.

The file is outdated since 0.13, I removed it from this post.
« Last Edit: September 11, 2017, 07:13:19 PM by Hammelpilaw »
Scrap Yard Galaxy
My mods and tools
My Workshop

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



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    549
    • View Profile
    • Scrap Yard - Avofactory
on: August 06, 2017, 02:23:41 PM
Thanks Splutty for the great mod.
I got some ideas to improve its ai without lot of trouble:

When I watched people on our server using this mod, I noticed some problems when the mod is handling many stations (about 30 in this case).

Ships often transport a few goods (about 100 or even less) while other stations stuck at 25k produced goods or are low on required goods. The first thing I did is to set a minimum of 1000 traded goods to be a valid route. This improved things a little, but did not solve it at all.

The only solution would be to add a priority to all valid routes, calculated by the relation of available and max goods of both stations of each route. So I started to implement this into .../entity/ai/haulgoods.lua.

Spoiler: show
Code: [Select]
for _, good in pairs(soldgoods)
do
-- Don't bother doing anything if there isn't anything to actually sell
local numGoods
local maxgoods
local priority

--retval, numGoods = station:invokeFunction(stationscript, "getNumGoods", good)
retval, numGoods, maxgoods = station:invokeFunction(stationscript, "getStock", good)
-- debug_msg(station.name .. " is selling " .. numGoods .. " " .. good)

if (retval == 0 and numGoods > 1000)
then
if maxgoods > 0 then
priority = numGoods / maxgoods
else
priority = 0
end
if (haulGoodsList[good]) -- Already initialized?
then
table.insert(haulGoodsList[good]["from"], station)

if priority > haulGoodsList[good]["fpriority"] then
haulGoodsList[good]["fpriority"] = priority
end
else -- Initialize good
haulGoodsList[good] = {from = {station}, to = {}, amount = numGoods, fpriority = priority, tpriority = 0, priority = 0}
end
end
end


Spoiler: show
Code: [Select]
for _, good in pairs(boughtgoods)
do
-- Don't bother if the station's already full
local available, maxgoods
local priority
retval, available, maxgoods = station:invokeFunction(stationscript, "getStock", good)

-- debug_msg(station.name .. " is buying " .. good .. " available/max " .. available .. "/" .. maxgoods)

if (retval == 0 and (maxgoods - available) > 1000)
then
if maxgoods > 0 then
priority = (maxgoods - available) / maxgoods
else
priority = 0
end
if (haulGoodsList[good])
then
table.insert(haulGoodsList[good]["to"], station)

if priority > haulGoodsList[good]["tpriority"] then
haulGoodsList[good]["tpriority"] = priority
-- *2 because bought goods are more important to keep productions running
haulGoodsList[good]["priority"] = priority * 2 + haulGoodsList[good]["fpriority"]
end
else
haulGoodsList[good] = {from = {}, to = {station}, amount = 0, fpriority = 0, tpriority = priority, priority = priority * 2}
end
end
end


After assigning the priority I just had to sort the haulgoods table by the priority. Only tested this with ~5 stations yet, but it seemed to work great, so I will try this on our server soon. But no warrenty yet, i need more testing until I really know if it helps.

Mybe you'd like to add these ideas to the mod when my tests are finished? Imo it could be a great improvement for using this mod with many stations, if it works like I expect.
Scrap Yard Galaxy
My mods and tools
My Workshop

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



Kryptos

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    8
    • View Profile
on: August 11, 2017, 11:30:15 PM
This mod is great! However, it doesn't seem to recognize Habitats or Biotopes as valid selling stations. I have a cargo hauler running water from my water factory to the cattle farm at 29 per, whereas the biotope literally along the way sits empty buying water at ~60. Similar in another system I started building in. I'm gonna try to find a solo biotope/habitat system and build a supply complex to confirm.



Valhar2000

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    11
    • View Profile
on: September 11, 2017, 02:32:33 AM
I was able to use this mod to automate one cargo ship, but it will not work with a second cargo ship I created. When I try to run the command "/haulgoods start" with the second ship selected, I get the following in the console:

Code: [Select]
could not execute function 'Traders.update' in '"data/scripts/sector/traders.lua"':
data/scripts/sector/traders.lua:128 attempt to index local 'g' (a nil value)
stack traceback:
       data/scripts/sector/traders.lua:128: in function <data/scripts/sector/traders.lua:39>



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    549
    • View Profile
    • Scrap Yard - Avofactory
on: September 11, 2017, 08:00:38 AM
I was able to use this mod to automate one cargo ship, but it will not work with a second cargo ship I created. When I try to run the command "/haulgoods start" with the second ship selected, I get the following in the console:

Code: [Select]
could not execute function 'Traders.update' in '"data/scripts/sector/traders.lua"':
data/scripts/sector/traders.lua:128 attempt to index local 'g' (a nil value)
stack traceback:
       data/scripts/sector/traders.lua:128: in function <data/scripts/sector/traders.lua:39>

Did you use the modified version I published or the original mod?
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 11, 2017, 10:21:58 AM
Did you use the modified version I published or the original mod?

Thanks for replying.

I used the original mod. Did you make your version available for download somewhere, or were you referring to the code snippets you published in your posts on this thread?



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    549
    • View Profile
    • Scrap Yard - Avofactory
on: September 11, 2017, 04:04:57 PM
I used the original mod. Did you make your version available for download somewhere, or were you referring to the code snippets you published in your posts on this thread?

Download a fixed version at reply #34.
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 11, 2017, 06:32:26 PM
Download a fixed version at reply #34.

Thanks for that. Unfortunately, it doesn't make any difference. I get the exact same error messages.



Valhar2000

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    11
    • View Profile
on: September 11, 2017, 06:45:37 PM
There is something new that happens after using your file. I get the following error message, as well as the ones I already reported:

Code: [Select]
could not execute function 'CraftOrders.onHaulGoodsButtonPressed' in '"data/scripts/entity/craftorders"':
data/scripts/entity/craftorders.lua: 146: attempt tp call global 'checkCaptain' (a nil value)
stack traceback
       data/scripts/entity/craftorders.lua:146: in function <data/scripts/entity/craftorders.lua:139>

Perhaps I should mention that I am using version 0.13 r9105 of Avorion. Maybe this is the update that changes Entity Indeces to UUIDs?
« Last Edit: September 11, 2017, 07:04:13 PM by Valhar2000 »



Hammelpilaw

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    549
    • View Profile
    • Scrap Yard - Avofactory
on: September 11, 2017, 07:11:35 PM
My fault sorry, please delete the file craftorders.lua. It seems to be outdated since 0.13. Replace it by original file.

However i could not reproduce this error... using a modified version of this mod though. Maybe I will find some time soon to test it with original mod.
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 11, 2017, 08:19:12 PM
However i could not reproduce this error... using a modified version of this mod though. Maybe I will find some time soon to test it with original mod.

Are you also on version 0.13? If you are, have you tried creating a new ship, and then ordering it to haul goods? The ship I have that works was created in a previous version, whereas the one that doesn't was created in v0.13.