Jump to content

[MOD] Goods Hauler (Automatically buy/sell/move goods!)


Splutty

Recommended Posts

After testing it a while on our server it seems there is an increase in server load when multiple ships are hauling goods in multiple sectors. It came to mind after jumping around trying to narrow down the cause but all I could find were 3 afk players hauling goods in their sectors that could have a significant load.

It might have more to do with how the game handles updates as one laggy sector slows down everything else and the cause might also lie somewhere else as we use many more mods tho.

 

Would it be possible to somehow limit the amount of ships a player can use to haul goods?

The few players I found were using 3-6 ships so that might have something to do with it.

 

It must be some other mod interfering with mine, since there's no way my mod uses up any sort of significant CPU even with 100 haulers. (And yes, I've tried that :)

 

So not sure what's affecting it. But each sector only has 1 ship building the actual list, and if it fails that it'll try to rebuild it in increments of 5 seconds, and the rest basically does nothing and will also increase their polling interval by 5 seconds up to 60 seconds.

 

So the most impact you can possibly have is one goods rebuild every 5 seconds if there's nothing to haul (and with my system with 50 stations that takes a very short time), and one inter-object call for each of the haulers doing nothing every 60 seconds.

 

If they actually *are* doing something, they do a check every 5 seconds if the previous step has finished, and kick off a new flying or docking step. That's about it. I can't see how any of that has any impact.

 

I'll build some timings in my next version, though. Always interesting to see what might be causing this sort of stuff :)

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 116
  • Created
  • Last Reply

Top Posters In This Topic

 

Hello,

 

your mod is a great idea and really hope it will be added in the game in a way.

 

Right now I have a bit of a problem, when entering a sector that was set as a regenerative

I end up having a couple of issues with the ship commands in Keyboard-mouse playing.

 

Like for example the inability to toggle on-off the turrets groups

 

or suddenly having the 'invert speed' getting all crazy and unable to be stopped

 

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

I love your mod.  It doesnt seem to work with Complex3s mod though.  Is there a way to make it work.

 

If you use the / commands to control your ships, the mod shouldn't interfere with any other mods at all, since it doesn't modify any source files.

 

Not sure which mod you mean that gives problems, though :)

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

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..

   

Link to comment
Share on other sites

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. 

 

Link to comment
Share on other sites

  • 4 weeks later...

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.

Link to comment
Share on other sites

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.

 

 

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

 

 

 

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 5 weeks later...

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:

 

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>

Link to comment
Share on other sites

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:

 

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?

Link to comment
Share on other sites

There is something new that happens after using your file. I get the following error message, as well as the ones I already reported:

 

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...