Jump to content

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


Splutty

Recommended Posts

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:

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>

Link to comment
Share on other sites

  • Replies 116
  • Created
  • Last Reply

Top Posters In This Topic

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?

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

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:

 

    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

 

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

Link to comment
Share on other sites

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)

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

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

require ("utility")

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

function haulGoodsCmdSendError(player, errorMessage, help)

Link to comment
Share on other sites

I've taken a look into this mod, because I wanted to make it work, even if I'm not in the same sector as the ship.

The first thing I found out, was that this script was always started anew when a game was loaded. I took a look at the station scripts and found out that they save their state and restore it afterwards. So I added this to the haulgoods script.

function restore(values)
    haulGoodsStage = values.haulGoodsStage
    haulGoodsList = values.haulGoodsList
    haulGoods = values.haulGoods
    haulGoodsDispatcher = values.haulGoodsDispatcher
    haulGoodsRoute = values.haulGoodsRoute
end

function secure()
local route = {}

    return
    {
        haulGoodsStage = haulGoodsStage,
        haulGoodsList = haulGoodsList,
        haulGoods = haulGoods,
        haulGoodsDispatcher = haulGoodsDispatcher,
        haulGoodsRoute = haulGoodsRoute,
    }
end

Another thing I had to change for this to work was the haulGoodsRoute, in the original version the stations are saved there, for this save and restore to work I needed to change this to the index of the stations, so I changed the return value of the requestGoodsRoute function to:

return from.index, to.index, good, amount

In response to this, I also had to change all calls of

haulGoodsRoute[1]

to

Entity(haulGoodsRoute[1])

, same for index 2.

That gave me another error, in fact it seems like the docking positions of a station can not be determined, as

station:getDockingPositions()

in dock.lua returned nil, nil when out of sector.

Replacing line 12 in dock.lua with

local pos, dir = station:getDockingPositions()
if (dir == nil) then
	dir = station.up;
end
if (pos == nil) then
	pos = station.translationf;
end

solved the problem and gives the ship a faint idea of the docking positions.

 

A last error thrown in haulgoods_cmd.lua in line 12

player:sendChatMessage("HaulGoods", 0, errorMessage .. help)

can be simply solved by surrounding it with a test:

	if (help ~= nil) then
	player:sendChatMessage("HaulGoods", 0, errorMessage .. help)
end

 

I hope my explanations are somewhat understandable  ::)

I really like the idea of this mod and would love some other opinions on my changes. And for what I can say, it works out of sector.

 

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

Link to comment
Share on other sites

 

: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

Link to comment
Share on other sites

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

haulgoods-oos.zip

haulgoods-oos-fixed.zip

Link to comment
Share on other sites

  • 4 weeks later...

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.

haulgoods-oos.zip

Link to comment
Share on other sites

I can confirm it doesnt work

 

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 2 weeks later...

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?

Link to comment
Share on other sites

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:

[*]have a Captained Ship with a Cargo Hold, and either be in a Sector with profitable trade routes, or have cargo you can sell;

[*]use the command /haulgoods start. From this moment on, that ship is considered a "hauler";

[*]now you can enter and leave the ship as you will, piloting itself or letting it do its hauling duty. When you are not piloting it, you can give the Haul Goods command through the UI Orders interface. This doesn't work as the ship isn't considered a "hauler" before you use /haulgoods start (as evidenced by the error message response /haulgoods status gives you if you have not called /haulgoods start on that ship yet).

Link to comment
Share on other sites

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? 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:

[*]We need to gather a list of the Stations that exist in the Sector. Documentation shows there's a "get all entities" function with an option to filter for a specific type, such as Traders, or Factories.

 

 

 

[*]We need to know what these places regularly have in stock. I'm not sure how this is determined in-game, but surely there's some way to determine their regular production ticks, how much storage they have, and roundabout estimate how much of that product gets stored, and how much is used up by other factories in the system, or traded away to other people (or AI) than the player. I.e. how much cargo is actually available for us when we are in the Sector? Our simulated amount should be around the same amounts, or things will be very fishy and obviously fudged (and more exploitable).

 

 

 

[*]During regular or random intervals, the Haulers are marked for "picking up goods", "in transit" or "delivering goods". These are three separate states they can exist in, and these states are tracked for each Hauler individually.

 

 

 

[*]In the "picking up goods" state, if the player warps in at that time, the Hauler is teleported to the Station they were assigned to be "picking up goods" from, then buy the amount of goods from that Station as per normal with this mod installed while inside the Sector.

 

 

 

[*]In the "in transit" state, if the player warps in at that time, the Hauler is teleported to some point in the Sector along the expected travel path between the Station where it was "picking up goods" just before, and the Station where it's set to be "delivering goods". This point along the travel path is determined by the measure of time between the completion of the "picking up goods" state, the player warping in on them, the Hauler's maximum velocity and the distance of the Station where it's meant to be "delivering goods" from the Station where it was "picking up goods".

At the same time, the Hauler's cargo bay is stocked up with the goods in question.

 

 

 

[*]In the "delivering goods" state, if the player warps in at that time, the Hauler is teleported to the Station they were assigned to be "delivering goods" to, then sell the goods they're carrying.

 

 

 

[*]In each of these states, if the player does not warp in, a number of things happen to simulate the Haulers performing the work they're not actually performing (due to how the game unloads Sectors, apparently):

  • At the end of the "picking up goods" state, which lasts for some predetermined amount of time, money is deducted from the player's total,
    and a message is posted in the Economy chatlog to indicate that money was spent to buy goods.
  • During the "in transit" state, a non-arbitrary timer is going off that is determining when the Hauler transitions into the "delivering goods" state.
  • At the end of the "delivering goods" state, which lasts for some predetermined amount of time, money is added to the player's total, and a message is posted in the Economy chatlog to indicate that the player received money for selling goods.
  • No cargo changes or teleporting around of entities is actually performed if the player does not warp in, save for some "virtual cargo"
    that tries to keep track of how much the Stations in the Sector currently have in stock; this should follow the method of how the OoSP mod does this; perhaps these changes I propose are a new mod unto themselves, which hybridises the Goods Hauler and OoSP mods together.

 

 

 

[*]We can fudge most of the points on this list, as long as it's in a realm of reasonable possibilities. For example, Diamond Factories don't suddenly sell Clothes, and the Energy Cell Factory that's always out of Energy Cells doesn't suddenly have them in stock while we're away. And goods sell and are bought for realistic prices, as if normal transactions are actually taking place.

 

 

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...