Avorion Forum

General => Mods => Topic started by: Splutty on March 17, 2017, 01:52:50 AM

Title: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on March 17, 2017, 01:52:50 AM
So I have a new ship design now that doesn't crash into stations, I still think the calculations are off, but at least my mod still works.

A version for the latest version by Evil33: http://www.avorion.net/forum/index.php/topic,2896.msg22268.html#msg22268 (http://www.avorion.net/forum/index.php/topic,2896.msg22268.html#msg22268)

Short description: After you've done all the adjusting in this post, you'll have a 'Haul Goods' order on your ship, which will automatically try to figure out what needs to be transported and what can make a profit in the sector you're in. Obviously you need a ship with a captain and some cargo space.

If you want to easy install with commands instead of changing the orders list for ships, then the first part is enough. This gives you a /haulgoods command instead of an entry in the Orders menu. I actually prefer this option myself :)

You can give multiple ships the 'Haul Goods' order, and they will all work together so they don't start doing the same thing. You can see all that at work if you open your console window, quote-key by default.

It only works in your current sector. I mainly use it to run all the supply lines of my factories (0 profit is considered a valid traderoute for my AI :), but I've tested a bit on trade runs in NPC sectors as well, which seems to work.

It produces a fair amount of debug logging, which you can disable at the following place (if you run into problems, turn this back on):
Code: [Select]
function debug_msg(message)
-- if (true) then return end

Easy installation with commands:
The haulgoods_cmd-v0.9.2.zip file contains 3 files:
commands\haulgoods.lua
entity\ai\haulgoods.lua
entity\ai\haulgood_cmd.lua

If you unzip the zip file into the data\scripts directory of your Avorion install directory (generally with an 'extract to..' option), these will be put where they belong. These are all server side, but can be installed on your client side as well for single player.

Usage: Target a ship you want to use as a hauler (needs a captain), open your chat input (enter by default) and type /haulgoods start

The commands are:
/haulgoods start
/haulgoods stop
/haulgoods status

Always make sure you have the right ship targeted (you can do this from your fleet list)

By default debugging is on, and you can follow what's going on in the console window (quote key by default), which should show you exactly what your ship is doing (or more than one if you give more than one orders)

If you want a button in the Orders list of your ship, then follow these instructions:

Installation of a menu entry for 'Orders' on a ship:
Spoiler: show

As always, make a backup before making changes!

Changes to be made to data\scripts\entity\craftorders.lua.

In InitUI(), around line 119 and below make the following changes:

At the end of these lines there might already be some entries extra (from for example the salvage mod) but this is how it should look by default without changes:
Code: [Select]
local splitter = UIHorizontalMultiSplitter(Rect(window.size), 10, 10, 6)

    window:createButton(splitter:partition(0), "Idle"%_t, "onIdleButtonPressed")
    window:createButton(splitter:partition(1), "Passive"%_t, "onPassiveButtonPressed")
    window:createButton(splitter:partition(2), "Guard This Position"%_t, "onGuardButtonPressed")
    window:createButton(splitter:partition(3), "Patrol Sector"%_t, "onPatrolButtonPressed")
    window:createButton(splitter:partition(4), "Escort Me"%_t, "onEscortMeButtonPressed")
    window:createButton(splitter:partition(5), "Attack Enemies"%_t, "onAttackEnemiesButtonPressed")
    window:createButton(splitter:partition(6), "Mine"%_t, "onMineButtonPressed")

Add the following line to the list and change the 6 in the first line to a 7 as well.
Code: [Select]
window:createButton(splitter:partition(7), "Haul Goods"%_t, "onHaulGoodsButtonPressed")
The 7 can be a different number if there are already more entries than the first 6. If that is the case, you need to change the last number 6 in the first line to something other than 7 as well.

For example, the list looks like this in my file:
Code: [Select]
    local splitter = UIHorizontalMultiSplitter(Rect(window.size), 10, 10, 9)

    window:createButton(splitter:partition(0), "Idle"%_t, "onIdleButtonPressed")
    window:createButton(splitter:partition(1), "Passive"%_t, "onPassiveButtonPressed")
    window:createButton(splitter:partition(2), "Guard This Position"%_t, "onGuardButtonPressed")
    window:createButton(splitter:partition(3), "Patrol Sector"%_t, "onPatrolButtonPressed")
    window:createButton(splitter:partition(4), "Escort Me"%_t, "onEscortMeButtonPressed")
    window:createButton(splitter:partition(5), "Attack Enemies"%_t, "onAttackEnemiesButtonPressed")
    window:createButton(splitter:partition(6), "Mine"%_t, "onMineButtonPressed")
window:createButton(splitter:partition(7), "Salvage"%_t, "onSalvageButtonPressed")
window:createButton(splitter:partition(8), "Clean Sector"%_t, "onSalvageAllButtonPressed")
window:createButton(splitter:partition(9), "Haul Goods"%_t, "onHaulGoodsButtonPressed")

Then at this spot:
Code: [Select]
end

function checkCaptain()

copy the following code between the 'end' and 'function'

Code: [Select]
function onHaulGoodsButtonPressed()
    if onClient() then
        invokeServerFunction("onHaulGoodsButtonPressed")
        ScriptUI():stopInteraction()
        return
    end

    if checkCaptain() then
        removeSpecialOrders()
        Entity():addScript("ai/haulgoods.lua")
    end
end

There doesn't seem to be a nice way yet to add commands to a ship from other scripts. If anyone knows how to do this nicely, please let me know.
Title: Re: [MOD] Player factory goods haulers
Post by: Mutiegenesis on March 17, 2017, 02:31:04 AM
Sounds like something my players may enjoy. ServerSide? ClientSide? Do you modify the existing trade AI to prefer player stations for their own routes (if that is how that works), or whole new scripts being processed?
Title: Re: [MOD] Player factory goods haulers
Post by: Devious on March 17, 2017, 03:01:40 AM
Looking forward to test it out :)
Title: Re: [MOD] Player factory goods haulers
Post by: Pob on March 17, 2017, 03:50:35 AM
Nice this is much needed.
Title: Re: [MOD] Player factory goods haulers
Post by: Splutty on March 17, 2017, 04:07:25 AM
Sounds like something my players may enjoy. ServerSide? ClientSide? Do you modify the existing trade AI to prefer player stations for their own routes (if that is how that works), or whole new scripts being processed?

Completely new scripts for player ships. And for now it only works on your own factories.

I use tiny bits of the trader mechanic (mainly the docking sequencing), but everything else is completely AI ship driven.

So you're going to need at least a hauler with a captain for it to work.

I'm currently experimenting with where I want to run it, but it's designed to run server side.
Title: Re: [MOD] Goods Hauler
Post by: Splutty on March 17, 2017, 10:29:44 PM
Modified the original post and released version 0.9, please let me know if you have issues, whether it works, if it does what you hoped it would do, if things need to be added, if you want me to sacrifice a chicken in your name, or whatever you can come up with.

It's been ages since I've coded any LUA, and this is my first foray into the Avorion API, so any comments on what I could've done better are very welcome!

If some things look a bit Perl/Python/C ish... Then that's because that's what I normally code in..  ;D
Title: Re: [MOD] Goods Hauler
Post by: Splutty on March 18, 2017, 04:14:41 PM
Uploaded version 0.9.1 which has a fix to recognize all factories. My need for clarity caused the factory check to not always succeed :)
Title: Re: [MOD] Goods Hauler
Post by: Splutty on March 18, 2017, 10:53:27 PM
I guess no one has any comments. Haha.

I've found an issue which I'm currently running some debugs on to see if I can fix it at all, in that if I run this in a busy system with a number of haulers going at the same time, they kinda crush into each other at some docking ports :)

So I'm going to see if I can make some sort of queueing mechanism for docking ports (at first only for my haulers, but it might be useful to have that in dock.lua by default)

Title: Re: [MOD] Goods Hauler
Post by: weedworm31 on March 19, 2017, 01:14:15 AM
well i have a question. could you make the install instructions slightly more concise i would like to use this mod as it is exactly what ive been looking for but im not entirely sure what i need to do to get it to work correctly. drag a drop edit files what?
Title: Re: [MOD] Goods Hauler
Post by: Wilponderoci on March 19, 2017, 01:24:00 AM
Yes better and clearer instructions boioh ;)

I assume it goes into the data/scripts/entity folder?

Also it should be made clear as to if it works on single player as well.
Title: Re: [MOD] Goods Hauler
Post by: Splutty on March 19, 2017, 01:32:07 AM
I have no idea how to make better instructions. I could just pack up both files and you can extract them, but that would mess with other mods.

I'll give it a try tomorrow.
Title: Re: [MOD] Goods Hauler (v0.9.2 now with commands)
Post by: Splutty on March 19, 2017, 10:39:52 AM
I have created a set of commands to control your ships, and have made an attempt at making the install instructions for changing the orders list of your ship somewhat easier..

If you get the commands installed, it will all work fine, though.
Title: Re: [MOD] Goods Hauler (v0.9.2 now with commands)
Post by: Splutty on March 21, 2017, 02:11:42 AM
Disabled this for now, with the new upgrades ships keep ramming into docks at full speed  ::)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on March 22, 2017, 12:12:32 PM
I have some working haulers again, so I guess the mod is fine. Still some weird behaviour on certain ships :) Use at your own risk!  ;D
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Devious on March 30, 2017, 11:01:06 PM
Loving your mod so far!

I'm curious towards the performance usage when a lot of players are using this at the same time, as the debug output is quite extensive.
I've also added it on the client so they can use the UI assuming there is not extra going on, but I could be mistaken ofcourse.

This spam is what concerned me:
Code: [Select]
Assert: Trading route reset, no viable trading route found in object
v0.9.2 Thu Mar 30 23:02:59 2017 (Lemming) data/scripts/entity/ai/haulgoods.lua: Empty list received, no queue left.
v0.9.2 Thu Mar 30 23:02:59 2017 (Lemming) data/scripts/entity/ai/haulgoods.lua: Found a dispatcher. (J_C 1)

Looking forward to your answer! :)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on March 31, 2017, 12:55:43 AM
Loving your mod so far!

I'm curious towards the performance usage when a lot of players are using this at the same time, as the debug output is quite extensive.
I've also added it on the client so they can use the UI assuming there is not extra going on, but I could be mistaken ofcourse.

This spam is what concerned me:
Code: [Select]
Assert: Trading route reset, no viable trading route found in object
v0.9.2 Thu Mar 30 23:02:59 2017 (Lemming) data/scripts/entity/ai/haulgoods.lua: Empty list received, no queue left.
v0.9.2 Thu Mar 30 23:02:59 2017 (Lemming) data/scripts/entity/ai/haulgoods.lua: Found a dispatcher. (J_C 1)

Looking forward to your answer! :)

There's pretty much no impact from those messages.

I'm not sure if I already had the time delays in 0.9.2, but those checks happen at most once every 5 seconds. And when the ship can't find a useable trading route, it'll increase the wait time 5 seconds every time to a max of 60 seconds.

The only thing that costs any cycles at all is the initial building of the list, and even that's only minimal. I might put timings around some stuff to see how long it actually takes.

As for the client side, if you want people to be able to use the Orders -> Haul Goods command, you're going to have to do that yes. Otherwise it can be fully run on the server side, as long as you add the command to the right permissions group.

0.9.3 also has a change in debugging, where you can set some levels.

If you don't want debug messages at all, just change the debug_msg function.

Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: tangowrangler on March 31, 2017, 10:26:01 PM
Thanks for the mod. Was hoping for something like this to improve the station building aspect of the game. I can test it out cause I am playing in Rustys Galaxy and we recently got it there. I tried it out a little (for like 20 to 15 mins on  the server) and i have a suggestion: a command that forces trade with only player owned stations (or non-npc stations). I built liquor chain in a sector with tradepost that bought wheat. The little bugger was always selling it to the tradepost.

I found 2 issues:
1. The haulers tend to collide with ai ships already docked at stations. sad for rep.
2. One of the hauler had a cargo bay filled with lots of power cells that *I THINK* it wasnt selling. but that maybe due to the fact that it had bought it and there was a server restart in between. not sure.

Anywho, thanks for your work and your effort. It was great seeing the ship do its thing. It makes a great addition to the game. i am looking forward to playing with it more in an empty sector :)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on April 01, 2017, 02:05:58 PM
Thanks for the mod. Was hoping for something like this to improve the station building aspect of the game. I can test it out cause I am playing in Rustys Galaxy and we recently got it there. I tried it out a little (for like 20 to 15 mins on  the server) and i have a suggestion: a command that forces trade with only player owned stations (or non-npc stations). I built liquor chain in a sector with tradepost that bought wheat. The little bugger was always selling it to the tradepost.

Of course! That's where it can actually earn money  ;D

I also built in a check where it only transfers the largest amount possible. So if 1000 is needed somewhere, and a station sells 500 and another 100, it'll always pick the 500.

I'll have to think about how to implement a limitation on what stations it's allowed to visit.

I found 2 issues:
1. The haulers tend to collide with ai ships already docked at stations. sad for rep.
2. One of the hauler had a cargo bay filled with lots of power cells that *I THINK* it wasnt selling. but that maybe due to the fact that it had bought it and there was a server restart in between. not sure.

As to 1: There's not much I can do about that :( I've had NPC haulers squish my ships as well, and when I'm running 3 of them at once, they squish each other. The 'get a docking port' routine seems to always pick the same one, so everything piles up there.

I've been messing around a bit with the dock code, but I'm not sure if I can fix it in such a way that it doesn't affect a lot of other things. And I can't fix the 'playership getting crushed' issue at all.

For number 2, yes. If it's bought things and gets interrupted, then depending on who's the actual dispatcher and at what point it picks up again, it won't sell it. I've tried to alleviate this problem somewhat by making it so the hauler tries to sell everything if there's more in the cargo bay than what was originally planned, but that doesn't always work either.

For those things, there's still some manual intervention required, unfortunately.

Thanks for using it and posting the issues :)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: tangowrangler on April 05, 2017, 09:42:04 AM
Have been playing around more with your mod and have an idea regarding point 2.

Quote from: Splutty
For number 2, yes. If it's bought things and gets interrupted, then depending on who's the actual dispatcher and at what point it picks up again, it won't sell it. I've tried to alleviate this problem somewhat by making it so the hauler tries to sell everything if there's more in the cargo bay than what was originally planned, but that doesn't always work either.

Might an if check which looks for what the hauler has in its cargo and all the things it can sell in the sector before it starts doing trade routes alleviate the problem?

I must confess, i havent looked at your script yet. And after i am done doing these trade runs, i will have a look  8). if i have better ideas, i will let you know.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on April 05, 2017, 01:07:02 PM
Have been playing around more with your mod and have an idea regarding point 2.

Quote from: Splutty
For number 2, yes. If it's bought things and gets interrupted, then depending on who's the actual dispatcher and at what point it picks up again, it won't sell it. I've tried to alleviate this problem somewhat by making it so the hauler tries to sell everything if there's more in the cargo bay than what was originally planned, but that doesn't always work either.

Might an if check which looks for what the hauler has in its cargo and all the things it can sell in the sector before it starts doing trade routes alleviate the problem?

I must confess, i havent looked at your script yet. And after i am done doing these trade runs, i will have a look  8). if i have better ideas, i will let you know.

It might, but that's not really what the mod was for :)

I've thought about building in a 'recovery' mode, which saves and loads what it was doing last and tries to continue doing that, but haven't gotten around to that yet.

I mainly built all this for my own sector with my own factories, so it's not really very multi purpose. It will work in a sector where you can do trade between NPC stations as well, since that was only a small adjustment to make.

A bigger problem is ships getting stuck on each other when they're at the same docking port. Since getting a 'random' docking port doesn't seem to be random at all :)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: tangowrangler on April 05, 2017, 02:28:47 PM
Had a skim of the script. The relative complexity and my lack of knowledge of lua led to very shallow understanding. Thankfully, i found the /haulgoods status command while re-reading your title post.

I mainly built all this for my own sector with my own factories


It might, but that's not really what the mod was for :)

I mainly built all this for my own sector with my own factories, so it's not really very multi purpose. It will work in a sector where you can do trade between NPC stations as well, since that was only a small adjustment to make.

This is what I am hoping to use it for. the problem is I built my things in a neutral zone where there are trade posts. So it sometimes makes those trades. Thats why I was thinking maybe when u populate your table in your "buildGoodsList" function, there can be column which stores the owner of the station. Later that information maybe used to restrict the hauler to only the players station.

I've thought about building in a 'recovery' mode, which saves and loads what it was doing last and tries to continue doing that, but haven't gotten around to that yet.

Regarding the recovery mode, it can be useful even when building in an empty sector because of servers crashes. I do not know what is easier, checking the cargo, or periodically writing the state. I am gonna see if there is any way to give captain commands to the ship i am commanding. Sth I would really like to be able to do. Also gonna play around with the haulgoods status command.

P.S  I myself imagine/assume many things are possible (modwise), but my lack of programming experience makes me overzealous. so excuse me if i sound thick.  :)

Cheerio
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Spacefaring_Guy on April 10, 2017, 06:35:16 PM
I do not know what is easier, checking the cargo, or periodically writing the state.

I know I certainly don't know the answer to that for scripting, but if we look at it in terms of how it might work in the real world... you know what cargo you have, but you may have forgotten your route.  So since you KNOW what cargo you have, and your job is to sell whatever you can... start from scratch.  It's a long chain query, though, because there's probably a nasty, nasty web of possibilities to choose from.

I'd do something like:

List of all stations that will buy my cargo
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: tangowrangler on April 10, 2017, 10:04:48 PM
From the metadata of your quote i thought u were talking to Splutty. hehe

List of all stations that will buy my cargo

Anywho, the code already makes a list of the goods being bought and sold in the sector. It is done using the buildGoodsList function in the haulgoods.lua file. incase you feel inspired to have a look at the script and change it for the rest of us ;)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Spacefaring_Guy on April 11, 2017, 03:48:08 PM

Anywho, the code already makes a list of the goods being bought and sold in the sector. It is done using the buildGoodsList function in the haulgoods.lua file. incase you feel inspired to have a look at the script and change it for the rest of us ;)

I have no idea what happened, but that post stopped about 1/4 of the way through what I recall having typed up... and now I can't remember any of it.  It probably seemed brilliant at the time, too.  Developers around the world will mourn the loss of my genius. :)

In future, I will attempt to post less frequently while running on caffeine instead of sleep.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Devious on April 11, 2017, 05:37:02 PM
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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on April 13, 2017, 05:16:58 PM
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 :)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Stavinsky on April 29, 2017, 05:41:14 PM

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
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Tridi on May 10, 2017, 01:36:15 AM
I love your mod.  It doesnt seem to work with Complex3s mod though.  Is there a way to make it work.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on May 27, 2017, 06:57:37 PM
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 :)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Devious on May 27, 2017, 07:00:28 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Pirat 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Valshala 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..
   
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Dinoff 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. 
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Kryptos 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Valhar2000 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>
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw 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?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Valhar2000 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?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Valhar2000 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Valhar2000 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?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Valhar2000 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Yuisan 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Valhar2000 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!
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: solyxx 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
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Myrre 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>
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: thrasher779 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?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Azerik 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Azerik 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)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Azerik 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Evil33 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
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: albert0015 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
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Evil33 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
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Kryptos 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.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Laserzwei on November 22, 2017, 08:18:56 AM
Does this still work in the .15 beta? I've been trying to see what's changed, and the cargo shuttles are...underwhelming.
http://www.avorion.net/forum/index.php/topic,4015.0.html
If something changes correct it in the topic
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Evil33 on November 29, 2017, 05:13:34 PM
As far as I can see, it still works.
But as I checked the script I got the feeling, that after a server restart a player must visit the sector once, because the docking sequence doesn't finish. After a first visit they can be left alone again.  :-\
Maybe the lazy update in the server config can change that behavior.
Edit: I've added another debug message for the first server update after startup and made some minor fixes to the secure and restore functions. It works after server restarts, if the sector was visited once after script/game update, at least it worked like that for me.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Maxx4u on December 05, 2017, 11:20:45 PM
Like i see, the mod does not work with the beta branch
he try do use the "old" docking mechanism.

he dont use docking stages.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: zgrillo2004 on December 07, 2017, 12:14:50 AM
I can confirm it doesnt work

Code: [Select]
data/scripts/entity/ai/haulgoods.lua:370: in function 'haulGoodsMoveToSeller'
data/scripts/entity/ai/haulgoods.lua:457: in function <data/scripts/entity/ai/haulgoods.lua:428>

If you say that this is using the old docking mechanism then what does 0.15 use as it's replacement?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Azerik on December 07, 2017, 05:07:16 AM
I'd be eternally in your debt if some intrepid soul could make this work again.

I need to have the ability to run routes at a loss and this is the perfect mechanism for me.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Evil33 on December 09, 2017, 06:15:38 PM
I missed that you were looking for an update for the beta ^^" sry
I fixed the script (as far as I see) for the 0.15.6 update released yesterday.
Might be that I missed something, so tell me about your results :)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Azerik on December 10, 2017, 03:23:45 AM
Thank you.  I've spent most of this week scrambling to get things updated and fixed and such for our reset today.  I didn't even find out until Friday that cargo shuttles only take 1 cargo at a time.  There is *no* way I will sustain my production lines with that.  Unless we can suddenly have a couple thousand cargo shuttles at a time.

I won't be able to fully test things for a bit, but I'll let you know if there are any problems.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Samjam on December 29, 2017, 09:26:30 PM
Really useful looking mod. Im pretty new to the avorion forums, and i cant seem to find the place to download the .zip file... could someone point it out to me?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on January 02, 2018, 11:11:38 PM
Good to see people provide updates for my mod while I was AWOL :)

I'm not sure if I'm coming back to Avorion any time soon. This mod was the thing I wrote while I was stuck sick at home, just to see if I still could. It was mainly meant to be used by myself, but I decided to post it.

Good to see people have been using it and thanks from everyone for those who modified it to make things work with newer versions!
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on January 02, 2018, 11:15:04 PM
I missed that you were looking for an update for the beta ^^" sry
I fixed the script (as far as I see) for the 0.15.6 update released yesterday.
Might be that I missed something, so tell me about your results :)

I've added your message to the original post for now. Thanks for updating things in my absence!
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Shrooblord on January 11, 2018, 07:54:03 PM
Hey, I installed this mod, but whenever I click on "Haul Goods", the ship just sits there and does nothing. I made sure to be in a system where there's trade happening, and checked with the Trade Module to see if there was anything to be traded profitably (there was). Does anyone have any idea why this is happening?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Evil33 on January 12, 2018, 03:04:40 PM
Try it with the chat command /haulgoods start
I didn't use the UI very much, perhaps it's only a problem in this part.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Shrooblord on January 12, 2018, 04:54:20 PM
That doesn't seem to do anything either. I was outside of my captained craft with my mining drone, selected it, and used "/haulgoods start" but nothing happened. Am I doing it right?

EDIT: Nevermind, it works now! After trying to activate this again, I decided to manually trade with a station, but as I approached the docking port, I was pulled towards it with light beams while I was still pilotting (I gotta say, being beamed up by a tractor beam while immobilised is freaking scary), automatically attained 50 displays and was immediately expelled from the docking port. When I hopped into my mining drone, the ship lay still doing nothing, but then I gave it the UI order to Haul Goods, and off it went! Very cool. I'm now watching my little ship zoom around the Sector making trades. Very cool.

Not sure what I did to "fix" the issue though; maybe you just need to try a couple of times before it works?

EDIT II: This is fantastic. One of my favourite new things now is editing a ship in Building Mode while it's in the process of hauling goods. It's a nice change of background, and also I'm making money while doing something else: excellent! :D

EDIT III: I figured out how this works:
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Shrooblord on January 15, 2018, 03:43:49 PM
Hey there. Not a big fan of double-posting, but with lack of a delete button, I can't delete-edit-update my post like I'd do everywhere else and I'd like this to be seen.

I found a "bug" of sorts while using this mod. Although I'm not sure if that's at the mod's fault or simply due to the nature of how Avorion works with the player not being present in a Sector, I've noticed that while I'm away, the Captained ships that are hauling goods don't move assets or make me any money. In fact, when I return to the Sector they are in, they're in the exact state and position they were in, carrying the goods they had, as when I left. The Sector, apparently, is literally frozen in time until my return.

Is there any way to simulate the Captained ships still moving assets around while out of Sector? Like with the Out of Sector Production Mod (https://www.avorion.net/forum/index.php/topic,1322.0.html)? I've seen in the Documentation that there's a whole bunch of functions for teleporting entities around, adding and removing their cargo and so forth. So while the "simulation part" could be just that: a faking of them moving goods around, upon re-entry, you might find them in another place you expected them, teleported by the script to some location that makes sense based on the time you've been away and the number of goods they've been simulated to have hauled.

I don't know how easy it is to register the haulers in a list of entities you can keep track of, though I must admit I haven't taken a look at whether Goods Hauler already does that or not. In my view, if it does, that's already a large part of the heavy lifting underway. My mind is already racing with possibilities on how to "fix" the other parts of this idea. Just to sum up what's on my mind:

These additions would be a little bit of work to be sure, but would make the galaxy feel that much more alive. Moreover, it would allow players to set up little trading routes and trading convoys that actually function, which would be super cool.

Anyway, if anyone has any insights into how this could be done, please do contact me. I'm very interested in trying to set this up.

P.S.
And after writing all of that, now my mind is racing with the possibilities of adding multi-sector trading convoys going out to trade with Stations elsewhere than the current Station. I guess I'm starting to try and make the galaxy into a persistent universe-type deal. xD
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw on January 15, 2018, 06:17:43 PM
P.S.
And after writing all of that, now my mind is racing with the possibilities of adding multi-sector trading convoys going out to trade with Stations elsewhere than the current Station. I guess I'm starting to try and make the galaxy into a persistent universe-type deal. xD


Already thought about that, but never had time to do this. Also I think it should be a completely new mod instead of changing this one. Very great idea though.


I thought about Anno-like trading routes, wich can be configured. There is only one problem when you use out of sector production mod: An AI controlled ship would not trigger the oosp production, cause oosp mod is only attached to the player.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Shrooblord on January 15, 2018, 06:34:48 PM
There is only one problem when you use out of sector production mod: An AI controlled ship would not trigger the oosp production, cause oosp mod is only attached to the player.
Do AI controlled ships even touch anything while the player is not around? I thought Sectors weren't loaded without player or player-owned ship presence.

But, good of you to mention this; I didn't realise that OoSP only activates player-owned production chains. Off to researching how to make OoSP universal across the board, it is!
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Hammelpilaw on January 15, 2018, 07:13:37 PM
Every player can keep up a specified amount of sectors. How much sectors is defined in server config. In offline games default setting is 500, on servers default setting is 5, but always can be changed by the admin.


Wich sectors are alive is depending on what you have in these sectors. A ships counts 1, a station 3. The sectors with most points are kept up (up to the maximum sectors per player setting). Thats why you even could have galaxy wide trading routes. But when you send your ship into an offline sector, it will stop. Doing anything.


I would like to have access to sector activation in Script API  ;D
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Valshala on February 02, 2018, 08:05:45 AM
I missed that you were looking for an update for the beta ^^" sry
I fixed the script (as far as I see) for the 0.15.6 update released yesterday.
Might be that I missed something, so tell me about your results :)

The mod works fine while in sector, but the haulers do nothing when you leave the sector...  After the oos update last year I used the mod and it worked fine oos...  What has changed  or am I missing something?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Shrooblord on February 02, 2018, 12:39:29 PM
I have a bug report. Not entirely sure what triggers it, but I'll tell you the outcome.

Sometimes Goods Haulers try to do one or both of the following problematic things:

Whenever they decide they want to do either, they don't let up and continue to try and perform this behaviour somewhere between 5 and 10 times in a row, which spams both the Console and the main game screen itself full of error messages (Console says something along the lines of "Expected to buy 5 goods but bought only 4", while the game screen shows an error in the typical red "You can't do that" message with a red cross, on the right) every second or so. With multiple Goods Haulers at work in one Sector, this gets very spammy very quickly, but more importantly, your Goods Haulers aren't doing anything, because they load up their Cargo Bays with goods they can now no longer push, because the receiving Station doesn't accept more goods of that type anymore.

Is there anything you can do to include some sort of check that wouldn't trigger this behaviour anymore? It's made me steer clear of giving my craft the Goods Hauler orders inside my own Sector, because they keep trying to push Aluminium from my Alu Mine to my Shipyard, which doesn't want it anymore, instead of acting as my handy cargo shuttle between production chains as I intended for them to do.

Furthermore, Goods Haulers with cargo already with them will never try and push these items for profit, which I think isn't in the spirit of how this mod operates.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Rilgar on July 22, 2018, 04:49:18 AM
Fantastic mod!

After attempting to set up a supply chain with cargo shuttles and bringing my server to it's knees long before the shuttles (using more shuttles mod) were able to move enough goods I gave this mod a try. Works wonderfully on 0.17.1.

Thank You!

 ;D ;D ;D ;)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Rilgar on July 24, 2018, 10:03:27 AM
Unfortunately my haulers also just "doing nothing..." from time totime when I know they have loads of trades they could make. Sometimes /haulgoods stop;/haulgoods startfixes this but not always. Hopefully this can be resolved?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Rilgar on July 24, 2018, 08:57:50 PM
I get the following in the log when the hauler "stops working":

2018-07-24 20-21-17| error constructing Entity: Entity with index Uuid doesn't exist at
2018-07-24 20-21-17| stack traceback:
2018-07-24 20-21-17|     [C]:-1: in function Entity
2018-07-24 20-21-17|     data/scripts/entity/ai/haulgoods.lua:456: in function haulGoodsMoveToSeller
2018-07-24 20-21-17|     data/scripts/entity/ai/haulgoods.lua:583: in function ?
2018-07-24 20-21-17|
2018-07-24 20-21-17| Execution Context (inner to outer):
2018-07-24 20-21-17| #0: updateServer data/scripts/entity/ai/haulgoods.lua
2018-07-24 20-21-17|
2018-07-24 20-21-17| could not execute function 'updateServer' in '"data/scripts/entity/ai/haulgoods.lua"':
2018-07-24 20-21-17|
2018-07-24 20-21-17| data/scripts/entity/ai/haulgoods.lua:456: attempt to index a nil value
2018-07-24 20-21-17| stack traceback:
2018-07-24 20-21-17|     data/scripts/entity/ai/haulgoods.lua:456: in function 'haulGoodsMoveToSeller'
2018-07-24 20-21-17|     data/scripts/entity/ai/haulgoods.lua:583: in function <data/scripts/entity/ai/haulgoods.lua:547>
2018-07-24 20-21-17|
2018-07-24 20-21-17| Starting thread [Stacktrace Sender]...
2018-07-24 20-21-17| Started thread [Stacktrace Sender] with id 643
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on July 26, 2018, 06:33:31 AM
Hi Rilgar,

Unfortunately my haulers also just "doing nothing..." from time totime when I know they have loads of trades they could make. Sometimes /haulgoods stop;/haulgoods startfixes this but not always. Hopefully this can be resolved?
while you are in the sector? It happens when your station is moved, I have had a look at the scripts and might be able to fix that soon (tm). Seems like the code causing the problem is copy&paste from a game-script...

I also found some unintended behaviour: The Mod doesn't know how to deal with player-owned trade-stations, semms like buy/sell have to be swapped. I don't know if and how other consumer-stations work.

EDIT: Except for that, it also works with the current beta-branch version 0.18.1
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Rilgar on July 26, 2018, 10:14:19 PM
Quote
while you are in the sector? It happens when your station is moved, I have had a look at the scripts and might be able to fix that soon (tm). Seems like the code causing the problem is copy&paste from a game-script...
Both while I am in the sector and out. I think. Could just be that they stop shortly after I get back in too though. Haven't tried to compare timestamps on the logs to see at exactly what moment it happens. Happy to  check if it'll help...

I can believe the station moved... I tend to bump into the stations quite a bit, esp. when flying the big 15 slot ship. I believe it may also be when their docking get's "interrupted" by NPC traders. I have upwards of 30 NPC traders in the system at any given point. I have a couple times seen them "stuck" on a NPC trader ship... generally have to move them manually, let the trader pass and then restart the haulgoods process.

Looking forward to an update. Thanks :)
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on July 28, 2018, 02:44:50 PM
Hi Rilgar,

I did some extensive testing... Something put one of my stations 1500 km away from its normal position, pushing it back @ 500 m/s a goodshauler-ship still tried docking... -> Movement doesn't break goodshauler.

Oosp seems to be broken to me. Restoring the sector from disk stops your goodshaulers (broken, too).

The errorlog you posted seems to be a one in a million chance, goodshauler didn't restore any routes. I think that's because it didn't store any routes - sector was saved to disk exactly when there was nothing to save.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on July 31, 2018, 10:39:58 AM
Hi,

the new Beta 0.18.2 broke stuff, my freighters have problems to dock with stations.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Devious on August 02, 2018, 07:56:00 PM
The braking behaviour changed, I will try to find if there's changed code about this.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on August 02, 2018, 08:05:22 PM
Hi Devious,

The braking behaviour changed, I will try to find if there's changed code about this.
not needed anymore. I reported the problems in the 0.18.2 Release-Notes, Martin found a Bug (or more) on their end, it's working again now.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: jmattspartacus on August 05, 2018, 07:43:15 AM
It's throwing an error when trying to concatenate the help and error messages on intialization for some reason, I've been thinking about learning LUA for ages, I guess this is an excuse to monkey with it some and see if I can figure it out.
Spoiler: show
2018-08-05 01-14-01| #0: initialize data/scripts/entity/ai/haulgoods_cmd.lua
2018-08-05 01-14-01|
2018-08-05 01-14-01| could not execute function 'initialize' in '"data/scripts/entity/ai/haulgoods_cmd.lua"':
2018-08-05 01-14-01|
2018-08-05 01-14-01| data/scripts/entity/ai/haulgoods_cmd.lua:12: attempt to concatenate local 'help' (a nil value)
2018-08-05 01-14-01| stack traceback:
2018-08-05 01-14-01|     data/scripts/entity/ai/haulgoods_cmd.lua:12: in function 'haulGoodsCmdSendError'
2018-08-05 01-14-01|     data/scripts/entity/ai/haulgoods_cmd.lua:41: in function <data/scripts/entity/ai/haulgoods_cmd.lua:27>
2018-08-05 01-14-01|

Edit: Fixed this by adding an empty string into the argument of the call of haulGoodsCmdSendError at line 4,
Code: [Select]
then
haulGoodsCmdSendError(player, "Error: No ship selected.\n","")
return terminate()
end
And now getting the following error, trying to figure it out, but if anyone has any suggestions, I'd love the help. I've been trying to isolate what about 'flyToDock' that isn't working.
Spoiler: show

2018-08-05 04-44-43| #0: updateServer data/scripts/entity/ai/haulgoods.lua
2018-08-05 04-44-43|
2018-08-05 04-44-43| could not execute function 'updateServer' in '"data/scripts/entity/ai/haulgoods.lua"':
2018-08-05 04-44-43|
2018-08-05 04-44-43| data/scripts/entity/ai/haulgoods.lua:370: attempt to call global 'flyToDock' (a nil value)
2018-08-05 04-44-43| stack traceback:
2018-08-05 04-44-43|     data/scripts/entity/ai/haulgoods.lua:370: in function 'haulGoodsMoveToSeller'
2018-08-05 04-44-43|     data/scripts/entity/ai/haulgoods.lua:457: in function <data/scripts/entity/ai/haulgoods.lua:428>
2018-08-05 04-44-43|

Edit 2: So I downloaded the OOS version, and was getting the same error, and fixed it, it was a namespacing error. ANYWAYS, here's a functioning version for you all
Edit 3: It has trouble with stations that don't always buy/sell the same goods, but I'm happy with it for managing my hub sector's so I don't have to manually move all the stuffs
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Splutty on August 31, 2018, 06:44:18 PM
Thank you guys for keeping this alive. I've been otherwise busy on a lot of things, and don't actively play Avorion at the moment, although I'm sure that will change again in the future :)

Glad to see people are still using my mod, even though it's mostly been rewritten by now it looks like.  ;D
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: bit on September 18, 2018, 04:01:40 AM
I too am having some trouble finding the latest (or any) copy of the mod. Is  it hosted separately?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Devious on September 19, 2018, 06:02:41 PM
https://www.avorion.net/forum/index.php/topic,2896.msg27645.html#msg27645
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: bit on September 21, 2018, 01:55:09 AM
Thanks! Just turned out I wasn't logged in while I was looking.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: kirknay on September 24, 2018, 09:10:50 AM
I'm trying to run this on a server, and I keep getting an error saying I don't have permission to use this command. Any hope on fixing that? The files that are used have been completely reorganized for modifying files compared to what I'm seeing in the original post, as well, so I don't know if I'm installing it correctly or not.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Devious on September 30, 2018, 01:22:52 PM
I'm trying to run this on a server, and I keep getting an error saying I don't have permission to use this command. Any hope on fixing that? The files that are used have been completely reorganized for modifying files compared to what I'm seeing in the original post, as well, so I don't know if I'm installing it correctly or not.

To use this on a server the permission to use the command needs to be added to the default group in the admin.xml
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: kirknay on October 01, 2018, 12:07:22 AM
Hm... I have been trying that, but the command isn't showing up in my admin list, and adding it manually ends up with it being removed when I bring the server back up. Is it possibly an issue with my install of shipscript loader?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: nutcase840 on November 04, 2018, 08:43:53 PM
for version 18.3 if your haulers are getting to stage 3 in the console and just sitting still and not dropping off the goods here a fixed version

for those who dont want the haulers to be undocked by the stations
Spoiler: show

got to data\scripts\entity\ai\haulgoods.lua and add -- or comment out the 2 lines starting with DockAI.flyAwayFromDock
Code: [Select]
at line 390 --DockAI.flyAwayFromDock(ship, haulGoodsRoute[1])
and line 423 --DockAI.flyAwayFromDock(ship, haulGoodsRoute[2])




Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on January 11, 2019, 02:26:21 PM
Hi,

Goods Hauler is still working in the current beta-branch versions 0.20.x. At least, if some updates didn't break stuff, my Goods Hauler still says
Code: [Select]
local VERSION = "v0.9.2"in entity/ai/haulgoods.lua
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Salminar on January 24, 2019, 10:49:53 AM
Not working at all for me (Using the beta branch).

In 1.82 it's stuck in stage 3 .
In 1.83 it's stuck in stage 1, saying he should trade something getting close to the station that sells the goods and never docks. But he is nice and move his ass to let other traders dock when they are close to him lol.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Salminar on January 26, 2019, 04:21:29 AM
If someone can assure it still works then i'll try to make an update on it to change the version number and put the files inside a mod directory so it do not mess with the rest of the file and don't interfere with future game update.

But it dont seem to work on my game so i don't know if it's worth updating now. If someone can notify me.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 04, 2019, 04:07:12 PM
Hi,

Beam me up, Scotty...

Patch-Notes:
- Bumped Version to v0.9.3
- simplified/cleaned code
- Added Feature: Docking using Transporters (code feels a little quick'n'dirty)
  - fixes "ships with Transporters are unable to do any business"

Requires Avorion 0.20.2 or later

LLAP
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 05, 2019, 10:00:01 AM
Hi,

I've been thinking about further improvements of Goods Hauler. What would you think about some kind of priority queue instead of the current list of traderoutes?
Well, since that requires some kind of sorting, it would need a little more CPU-time, compared to the current system.

Have you got other ideas for the Mod?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Salminar on February 05, 2019, 03:39:47 PM
Lovely, it fixed my bug
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 12, 2019, 10:58:27 PM
Hi,

spoiler-alert :)
Spoiler: show

Code: [Select]
2019-02-12 22-15-20| Goodshauler v0.10.0-alpha1 12.02.2019 22:15:20 (Frachter 2) : haulGoodsGetRoute (Stage 1) finished. Starting to transport 420 Platinum from Goldgrube 1 to Prozessorfabrik
2019-02-12 22-17-58| Goodshauler v0.10.0-alpha1 12.02.2019 22:17:58 (Frachter 2) : BuyGoods Data: 420 Platinum size 0.5 requested, 97 in the cargobay, room for 2939 more. Decided to buy 323 more.
2019-02-12 22-21-06| Goodshauler v0.10.0-alpha1 12.02.2019 22:21:06 (Frachter 2) : Finished trade from Goldgrube 1 to Prozessorfabrik
Well, that's all the default-level logging of the current development-version (of a successful trade-run)... Server-Admins will love it :)

If anybody is interested, I could share the latest dev-version.
Disclaimer: This is experimental software, you can expect some unintended behavior.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 13, 2019, 09:50:38 PM
Hi,

Shrooblord had to wait more then a year for a reply now...
Sometimes Goods Haulers try to do one or both of the following problematic things:
  • Buy more goods than the Cargo Hauler has stock for, usually as simple as 1 over the total amount they could carry.
  • Push more goods to the receiving Station than that Station has space for.

Whenever they decide they want to do either, they don't let up and continue to try and perform this behaviour somewhere between 5 and 10 times in a row, which spams both the Console and the main game screen itself full of error messages (Console says something along the lines of "Expected to buy 5 goods but bought only 4", while the game screen shows an error in the typical red "You can't do that" message with a red cross, on the right) every second or so. With multiple Goods Haulers at work in one Sector, this gets very spammy very quickly, but more importantly, your Goods Haulers aren't doing anything, because they load up their Cargo Bays with goods they can now no longer push, because the receiving Station doesn't accept more goods of that type anymore.

Is there anything you can do to include some sort of check that wouldn't trigger this behaviour anymore? It's made me steer clear of giving my craft the Goods Hauler orders inside my own Sector, because they keep trying to push Aluminium from my Alu Mine to my Shipyard, which doesn't want it anymore, instead of acting as my handy cargo shuttle between production chains as I intended for them to do.

Furthermore, Goods Haulers with cargo already with them will never try and push these items for profit, which I think isn't in the spirit of how this mod operates.

"Buys more then fits into the cargobay"
The dispatcher decided in 0.9.x versions of Goods Hauler how much to buy. That data is simply old at some point.

"Push more goods to the receiving Station than that Station has space for."
Goods Hauler always tries to sell as much as possible. That's not a bug, it was the only way for the 0.9.x versions to try to keep the cargobay free. Well, I'm not going to change that.

"Whenever they decide they want to do either, they don't let up and continue to try and perform this behaviour somewhere between 5 and 10 times in a row, ..."
That's actually a bug, the 0.9.x versions were missing 2 "undocking" stages - one after buying and one after selling stuff - , so the updateServer-function ran the same code again and again.

"...your Goods Haulers aren't doing anything, because they load up their Cargo Bays with goods they can now no longer push, because the receiving Station doesn't accept more goods of that type anymore."
Well, 0.10.0-alpha1 took a look at the cargobay before buying anything, so it should maximize free cargospace over time. Problem is: It still relied on old (inaccurate) data.
0.10.0-alpha2 now updates the amount of goods in the cargobays of your ship, selling station and buying station and decides then how much to transport.

So, now I'm talking about 0.10.0 again... alpha2 is still missing features I'd like in the final 0.10.0, but in hours of testing I didn't come across a single bug, it works much better then the old 0.9.x versions. What has changed? - Spoiler :)
Spoiler: show

These changes should slowly free your cargospace - or at least keep the cargobay free as good as possible:
 Ships don't buy stuff that's already in the cargobay
 Amount of goods to transport is determined just before buying - previous versions used the dispatcher-information (old data - very likely wrong)
 
Added limitation to transporterrange (35km range should be enough - or do people equip ships with 10 legendary Transporter-Software now?)
Changed docking distance calculation for ships with transporters

Introduced Log-Levels, haulGoodsLogThreshold (default 2):
 5 and higher values should suppress all messages,
 choose 4 for Errors,
 choose 3 for Errors and Warnings,
 choose 2 for Errors, Warnings and Notifications,
 choose 1 for all the beauty of console- and log-spamming that you know from previous versions: Errors, Warnings, Notifications and the rest of the Spam.
Also changed Log-Entry format.
 
Ships without transporters: Properly resetting DockAI.dockStage and .undockStage, and waiting until ships are fully undocked
 Fixes: Ships without transporters are sometimes going mad and fly thousands of kilometers away
 
Added additional stages for undocking - this reduces spamming of buy- and sell-stages


EDIT: Removed old 0.10.0-alpha2 version of the Mod.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Uchiki on February 15, 2019, 06:50:01 AM
Thanks for the mod.
I tested 0.10.0-alpha2. And in the case without Transporters it did a nice operation.
Improved dispatchers are great.
However, it seems that the ship with Transporters is stuck when leaving the station.

The part considered to be the log at that time is below.
Code: [Select]
Execution Context (inner to outer):
#0: updateServer data/scripts/entity/ai/haulgoods.lua

 could not execute function 'updateServer' in '"data/scripts/entity/ai/haulgoods.lua"':
 
data/scripts/entity/ai/haulgoods.lua:425: attempt to concatenate local 'station' (a userdata value)
 stack traceback:
     data/scripts/entity/ai/haulgoods.lua:425: in function 'haulGoodsMoveToStation'
     data/scripts/entity/ai/haulgoods.lua:576: in function <data/scripts/entity/ai/haulgoods.lua:548>
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 15, 2019, 10:17:23 AM
Hi,

Thanks for the mod.
I tested 0.10.0-alpha2. And in the case without Transporters it did a nice operation.
Improved dispatchers are great.
However, it seems that the ship with Transporters is stuck when leaving the station.

The part considered to be the log at that time is below.
Code: [Select]
Execution Context (inner to outer):
#0: updateServer data/scripts/entity/ai/haulgoods.lua

 could not execute function 'updateServer' in '"data/scripts/entity/ai/haulgoods.lua"':
 
data/scripts/entity/ai/haulgoods.lua:425: attempt to concatenate local 'station' (a userdata value)
 stack traceback:
     data/scripts/entity/ai/haulgoods.lua:425: in function 'haulGoodsMoveToStation'
     data/scripts/entity/ai/haulgoods.lua:576: in function <data/scripts/entity/ai/haulgoods.lua:548>

I didn't touch the dispatcher so far, I just updated the data (amount) before buying anything.

Well, the Error you found is a bug in one of the only Error-Messages at the moment. In line 425 the variable station needs to be replaced with station.name. If you changed that, you would get the following output:
Quote
ERROR: Can't dock to <Enter station-name here> using Transporters. Calculated Distance is <some negative value here> meters.
The Transporter-Software is limiting the range, in your case the Freighter would need to park somewhere inside the station - and I dislike crashing your ships into stations.

During my tests with transporters, I saw that 500m range are not sufficient, even on smaller stations.  However, the transporter-code in 0.9.3 is even worse, it needs about twice the range to work (compared to 0.10.0alpha2).

I'm currently working on 0.10.0alpha4, so I can't release a fixed alpha2 version at the moment.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Uchiki on February 15, 2019, 12:41:29 PM
I fixed station.name and tested it with a 2.5 km transporter.
The ship was ported to Uenhzauz and stacked after selling the goods.
The ship has not moved from Uenhzauz.

It is the error code at that time.
Code: [Select]
: BuyGoods Data: 214 Steel size 1 requested. Updated to 214 and 0 in the cargobay, room for 526 more. Decided to buy 214 more.
 : Sold 214 Steel
 : Finished trade from Yi'now to Uenhzauz
 : haulGoodsGetRoute (Stage 1) finished. Starting to transport 11900 Oxygen from Moyouwua to Nouwrie
 : ERROR: Can't dock to Moyouwua using Transporters. Calculated Distance is -2257.4322414398 meters.
 : ERROR: Can't dock to Moyouwua using Transporters. Calculated Distance is -2257.4322414398 meters.
 : ERROR: Can't dock to Moyouwua using Transporters. Calculated Distance is -2257.4322414398 meters.

I am looking forward to 0.10.0alpha4.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 15, 2019, 01:17:57 PM
Hi,

Code: [Select]
: ERROR: Can't dock to Moyouwua using Transporters. Calculated Distance is -2257.4322414398 meters.
hmm, how big are the ships and stations? Since the ship was able to "dock" at the other stations, I'd guess Moyouwua is big (compared to the other stations).

In alpha2 I calculated the possible distance in line 416:
Code: [Select]
local Distance = (range - ((ship.radius + station.radius)/2))I don't see how to further reduce that... (And if it's radius even that formula is wrong, the radius-values shouldn't be divided by 2)

If you could find the sector-file, compress it to a zip and upload it here, so I could take a look myself, it would be a great help.
Quote
I am looking forward to 0.10.0alpha4.
Well, first I need to finish it, then I'll need to run tests for hours... And after that I'll think about releasing it.

I didn't release alpha3, the reason is: It didn't change a lot for the players. I introduced shortcuts - if a ship receives a route and has got the needed goods in the cargobay, it can skip flying to the selling station. The result was:
Code: [Select]
torsten@debian:~/.avorion/galaxies/avorion_galaxy$ cat serverlog\ 2019-02-14\ 17-00-59.txt | grep directly
2019-02-14 17-21-37| Goods Hauler v0.10.0-alpha3 17:21:37 (Frachter 1) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 18-05-37| Goods Hauler v0.10.0-alpha3 18:05:37 (Frachter 3) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 18-57-37| Goods Hauler v0.10.0-alpha3 18:57:37 (Allianz-Frachter 1) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 20-26-45| Goods Hauler v0.10.0-alpha3 20:26:45 (Frachter 3) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 20-51-20| Goods Hauler v0.10.0-alpha3 20:51:20 (Allianz-Frachter 2) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 21-10-09| Goods Hauler v0.10.0-alpha3 21:10:09 (Frachter 1) : Amount is in the cargobay, directly moving to buyer.
torsten@debian:~/.avorion/galaxies/avorion_galaxy$
The shortcut was used 6 times during 4 hours of testing in a sector with 20 stations and 5 Goods Hauler controlled freighters - as I said before, it didn't change a lot for the players.

There was also another shortcut: If a route is received and the updated amount of goods is 0, then the route is reset. That didn't happen at all during the test.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Uchiki on February 15, 2019, 01:59:21 PM
The ship is small with 6 slots.

Upload the sector I tested.
Thanks for the effort.

Since the file was large, I could not upload it here, so I will put a link destination uploaded to a different location.
Please tell me when downloading because I will erase the link.

Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 15, 2019, 05:23:34 PM
Hi,

The ship is small with 6 slots.

Upload the sector I tested.
thank you. Well, I was unable to run tests in that sector (becoming a friend of that pirate-faction would have taken some time), but I think I've got a working formula now...
Code: [Select]
local Distance = range + station.radius - ship.radiusIf you put that formula into line 416 of your haulgoods.lua, your ship shouldn't try to crash into the stations, but it should be able to dock and do business then.
BTW: That's the formula I'm using in 0.10.0alpha4 now...

My tests with the formula above were successful:
Code: [Select]
2019-02-15 17-07-52| Goods Hauler v0.10.0-alpha4 17:07:52 (Longrange) : Trying to dock with Transporters to Chemiefabrik. Calculated Distance is 4513.9723396301 meters.
2019-02-15 17-08-32| Goods Hauler v0.10.0-alpha4 17:08:32 (Longrange) : Trying to dock with Transporters to Siliziummine. Calculated Distance is 4439.3046760559 meters.
That ship has got a legendary Transporter-Software (3.5 km range).
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Uchiki on February 15, 2019, 06:22:23 PM

Code: [Select]
local Distance = range + station.radius - ship.radiusIf you put that formula into line 416 of your haulgoods.lua, your ship shouldn't try to crash into the stations, but it should be able to dock and do business then.
BTW: That's the formula I'm using in 0.10.0alpha4 now...


Although it worked better than before, if the station is very long, it stopped short of approaching the station.

So I tested the formula as follows.
Code: [Select]
local Distance = range - ship.radius
In this case, as far as I tested a little, the problems such as stopping and colliding on the way did not occur.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 15, 2019, 07:41:44 PM
Hi,

So I tested the formula as follows.
Code: [Select]
local Distance = range - ship.radius
In this case, as far as I tested a little, the problems such as stopping and colliding on the way did not occur.
in my tests, the distance exceeded the 3.5km range of the Transporter Software, so you won't need to reduce it further.

I've got a stupid idea:  Line 422 looks like this:
Code: [Select]
ShipAI(ship):setFly(target, 0)The 0 in the end is the distance from the target-coordinates, so we could try to change it to:
Code: [Select]
ShipAI(ship):setFly(target, range)but the target would need to be changed, line 417 could be changed to:
Code: [Select]
local target = station.translationfthe ship-AI should avoid collisions.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Uchiki on February 15, 2019, 10:05:10 PM
OK. I tested it as unbekannt1984 said.

Code: [Select]
Line416:  local Distance = range + station.radius - ship.radius
Line417:  local target = station.translationf

Line422:  ShipAI(ship):setFly(target, range)

It worked fine. Even at the station where the problem occurred because it was too long.
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 17, 2019, 07:39:16 PM
Hi,

I know you like my Patchnotes (collected since 0.9.3):
Spoiler: show

These changes should slowly free your cargospace - or at least keep the cargobay free as good as possible:
    Ships don't buy stuff that's already in the cargobay
    Amount of goods to transport is determined just before buying - previous versions used the dispatcher-information (old data - very likely wrong)
    alpha3: Introduced shortcuts:
          If a route with amount 0 is received, it won't be excuted
          If a route is received and the required amount of goods are in the cargobay "Buy"-Stages are skipped
          alpha4: If a route updates to the amount 0 during the buy-stage, we ask for a new route.
 
Added limitation to transporterrange (35km range should be enough - or do people equip ships with 10 legendary Transporter-Software now?)
Changed docking distance calculation for ships with transporters (alpha4: twice now)

Introduced Log-Levels, haulGoodsLogThreshold (default 2):
      5 and higher values should suppress all messages,
      choose 4 for Errors,
      choose 3 for Errors and Warnings,
      choose 2 for Errors, Warnings and Notifications,
      choose 1 for all the beauty of console- and log-spamming that you know from previous versions: Errors, Warnings, Notifications and the rest of the Spam.
  Also changed Log-Entry format.
  alpha3: Dropped date from messages - it will be added in the logs and shouldn't matter that much while playing
 
Ships without transporters: Properly resetting DockAI.dockStage and .undockStage, and waiting until ships are fully undocked
    Fixes: Ships without transporters are sometimes going mad and fly thousands of kilometers away
 
Added additional stages for undocking - this reduces spamming of buy- and sell-stages
      alpha3: Added additional stages to haulGoodsStatus (/goodshauler status)- Oops
          fixes: Wrong status-messages in alpha2

alpha5: Added a shitload of patches from Hammelpilaw (33 lines of code imported from his version)
      Changed filestructure - most files are in the mods-directory now
      Made Mod compatible with Custom Craft Orders (by Hammelpilaw), includes config-files and a Readme.txt.

When upgrading to this version, active Goodshaulers won't find their scripts - don't worry about a few weird errors.

Custom Craft Orders (by Hammelpilaw) can be found here (https://www.avorion.net/forum/index.php/topic,5467.msg29657.html#msg29657).
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: Bocephus666 on February 20, 2019, 03:52:58 AM
I assume this mod only works if you're physically in the sector with the ship you've designated as a hauler?
Title: Re: [MOD] Goods Hauler (Automatically buy/sell/move goods!)
Post by: unbekannt1984 on February 20, 2019, 09:33:16 AM
Hi,

I assume this mod only works if you're physically in the sector with the ship you've designated as a hauler?
the script keeps running, when you leave the sector.

The problem is: Ship movement and docking/undocking aren't simulated in weak-loaded sectors - and that causes the script to be stuck.