Community Forum

Print fill type when selling

Forum Overview >> Scripting

Created04.08.2020 12:32

Brian Thompson (tommert) 04.08.2020 12:32

I'm trying to determine fill types when selling at stations. I have a mod that sets pricePerLitre of different filltypes, but when I sell, some don't seem to use the set value. For example, wrapped silage bales ignore the pricePerLitre I've set.

Is there a way that when a sell trigger is activated (like selling bales), that the log could be updated with the filltype of what is being sold, and the priceperlitre?

Bilbo Beutlin (BBeutlin) 04.08.2020 13:32
What you have set by this mod is the basic price per fillType.
The sellingStations have additionally individual prices for each fillType. In the xml <fillType name=".." priceScale=".." (price multiplier).
Besides the prices are dynamic, dependent on supply/demand balance.

It is possible to add a custom LUA function to a sellTrigger, however requires some experience in FS LUA scripting.

Brian Thompson (tommert) 09.08.2020 14:00
For reference, I'm using Marwell Manor map. In the sellingStations XML, for the bale sell point the priceScale="1". There are currently no great demands active

For a square bale of straw, I expect ~€25. Bale capacity set to 2,500 litres via FS19_VariableBaleCapacity mod, and the pricePerLitre is set to €0.01c (g_currentMission.fillTypeManager.fillTypes[41].pricePerLiter = 0.01)

Yet when I sell the bale, I get €96 - 4 times approx what I expect

I just can't figure out the discrepancy

Brian Thompson (tommert) 09.08.2020 14:20
For reference, I'm using Marwell Manor map. In the sellingStations XML, for the bale sell point the priceScale="1". There are currently no great demands active

For a square bale of straw, I expect ~€25. Bale capacity set to 2,500 litres via FS19_VariableBaleCapacity mod, and the pricePerLitre is set to €0.01c (g_currentMission.fillTypeManager.fillTypes[41].pricePerLiter = 0.01)

Yet when I sell the bale, I get €96 - 4 times approx what I expect

I just can't figure out the discrepancy

Bilbo Beutlin (BBeutlin) 09.08.2020 21:46
Changing the prices by LUA script is a little tricky. You must do that very early before most other stuff is loaded. If the economyManager has been setup, it's too late.

Why changing by LUA script at all? Simply change the prices in the map's fillTypes.xml - that's easier and safe.

Brian Thompson (tommert) 09.08.2020 22:14
I'm doing it so that the prices are consistent across different maps. And this way I don't have to edit maps. I'm basing my changes on the RealLifeNumbers mod, but very mush scaled down.

I have the lua updates running in :loadMap(), and it used to work but I think since patch 1.6 it has stopped. Something changed somewhere!

Any idea why it prints as the right value when I query the table, but not then use that value?
What would I add in the stations XML? pricePerLitre? Could you give an example?

Bilbo Beutlin (BBeutlin) 10.08.2020 11:41
The economyManager uses its own price table. If this has been setup, changes on the global fillType.pricePerLiter don't take effect anymore.

In the station.xml you can add only relative prices/factors 'priceScale'.

Brian Thompson (tommert) 10.08.2020 13:21
Is there a way to check the Economy manager has been setup? Or can it be manipulated post setup via lua?

Bilbo Beutlin (BBeutlin) 11.08.2020 12:47
Of course there will be a way. But I don't know exactly, since the economy aspect is barely documented in the official docs.
And as usual: all what isn't documented, one has to find out oneself. *g*
Dig through the economy datas and functions, perhaps beginning with 'g_currentMission.economyManager'.

Gtx | Andy (GtX_Andy) 12.08.2020 07:41
Hey Brian,
Happy to help out here so I will just clarify what you want as an end goal.

Are you hoping to make the sale price static or do you still want it to be dynamic but at a reduced value?
The selling stations do still use the 'fillType.pricePerLiter' but you need to remember that there is other multipliers added to this, not much has changed here for many game versions.


Bilbo Beutlin (BBeutlin) 12.08.2020 10:36
The sellingStations don't use the 'fillType.pricePerLiter' directly. Instead they have their own price tables, probably calculated by the economyManager.

In opposite to earlier FS it is more tricky to manipulate the pricePerLiter by LUA script. If you do it too early, it will be overwritten by the map's "fillTypes.xml". If you do it too late, the price tables of sellingStations have been setup already.

Gtx | Andy (GtX_Andy) 12.08.2020 12:26
I am not sure how you worked this out @Bilbo but you are incorrect that the 'pricePerLiter' is not used.
It is an integral part of setting up the SellingStations :-)

I am also not sure why you needed to comment as I was not addressing you anyhow and your comment is not helpfull at all.
It is very easy to change prices so I am not sure where your confusion comes from about 19 sell points in lua.

Some simple debugging on the second parameter of 'SellingStation.addAcceptedFillType' shows the 'pricePerLiter + sellingStation.priceScale' just like in 17 and this sets the starting point.

And just like in 17 also this is stored in sellingStation.fillTypePrices table and sellingStation.originalFillTypePrices and used along with 'EconomyManager.PRICE_MULTIPLIER and sellingStation.fillTypePriceRandomDelta' to calculate the dynamic price to be paid when selling.

Anyhow I am still happy to help solve your issue or explain the code as needed @Brian when you read these as I do not come here to be right or wrong but to help when I have time. ;-)

Bilbo Beutlin (BBeutlin) 12.08.2020 13:20
Surely the 'fillType.pricePerLiter' is used. But only once at setup of the stations' price tables.
Scan the sellingStation tables and you'll see each station has its individual tables anyPrice[fillTypeId]. There are 3 (or more) different tables.
It's clear that afterwards changing the global 'fillType.pricePerLiter' doesn't effect these tables anymore.

Gtx | Andy (GtX_Andy) 12.08.2020 13:41
Look, I only came to solve the requested problem so I will not waste the little time I have arguing over who is right.
The problem can be fixed and I have the ability to do this so that is all that matters to the OP right?

Bilbo Beutlin (BBeutlin) 12.08.2020 13:53
*sigh* no need to moan.
I just wanted to explain the TO why changing the selling prices by script is more tricky as in earlier FS and what he must consider.

Brian Thompson (tommert) 12.08.2020 17:02
Hi @Andy,
Yes please, I need help :-)
So far I've managed as part of :loadMap() to set the pricePerLitre for different fill types. For example, a straw bale. In my script I have a straw bale price set to 25, and I calculate the pricePerLitre by dividing the 25 by the bale volume (using square bales, I've the volume set to 2560l). So:
local strawBalePrice = 25;
local pricePerLitre[fillType] = strawBalePrice / baleVolume;
This should give me €0.01c per litre and when I print in the log that's exactly what I get. Then I sell a bale I get €96, and not the €25 I was expecting.

I don't mind if the sell price stays static, or fluctuates with supply/demand as long as the fluctuation isn't in the order of 10s

Bilbo Beutlin (BBeutlin) 12.08.2020 17:32
You don't get it?
If you place the code in the loadMap() section, your changes will be overwritten by the map's individual "fillTypes.xml".
I've run into the same problem, but didn't follow furtheron since using specific "fillTypes.xml" is in my eyes much more safer, flexible and compatible way.

I didn't try yet, but maybe it works if you append/prepend the code around the loadMapFinished() function.
If you're lucky, the station price tables are not yet setup.

Brian Thompson (tommert) 12.08.2020 17:40
I understand what you are saying. I was detailing what I'd tried. Funny thing, this used to work this way but I think patch 1.6 changed something and now it doesn't work. Can't say for sure though as I've the patch auto installed since it came out and I only just went to sell bales :-)

I didn't know there was a loadMapFinished() function.

Gtx | Andy (GtX_Andy) 13.08.2020 10:37
Hey Brian,

As the 'modEventListener - loadMap()' function is called from 'loadMapFinished' function and by this stage all map fillTypes are added and none of the placeables have been loaded there is no need to worry about the function not working. :-)

I actually think the reason your prices are wrong maybe due to the 'Economic Difficulty' multiplier + market fluctuation (See below), but I may be wrong without seeing all of your code.

Now the best place to change fillType data would be by tagging on to the end of the 'FillTypeManager.loadMapData' function for example unless you were changing custom fillTypes that are added by a mod and not the map.

If you were adjusting custom fillTypes it would be better to prepend the 'FillTypeManager.addFillType' function as you could adjust the numbers before it is even created. But this does not sound like what you require.

You do need to keep in mind that the sell point prices have many multipliers on top of the PricingDynamics, so the sale price will change for example when playing on different Economic Difficulty levels.

Easy = x3
Normal = x1.8
Hard = x1

So you would need to also divide your 'pricePerLitre' by the 'economicDifficulty' to offset this if you do not play on Hard and want it consistant for all levels of difficulty. Example: pricePerLitre = 0.01 / 1.8 or pricePerLitre = 0.01 / 3

To avoid the above in the example I just removed the economicDifficulty multiplier from the overwritten 'SellingStation.getEffectiveFillTypePrice' function if 'removeEconomicMultiplier' is true as you will see.

The market prices will still fluctuate but it will be around your new price you wanted.

See the below link is a working example mod, I made some notes in the lua file and tried to explain what is going on. This could be done in other ways or with less changes but I tried to keep it clear and show different options.

I hope this helps,

Brian Thompson (tommert) 13.08.2020 22:13
Thanks Andy. I'll give it a try.
Is there a way to log the filltype when the trigger is activated?

Gtx | Andy (GtX_Andy) 14.08.2020 04:47
When did you want to print? The whole time it is tipping or only once at the end when the bale or all the product has been sold.

What information did you want also, anything is possible but depends how many functions you want to append and how necessary it is or is it only for debugging etc

Brian Thompson (tommert) 14.08.2020 10:08
Ideally as each item is sold, I'd like to see the fillType and the pricePerLitre.

I did a quick test of your changes and I'm not sure they worked OK. Certainly for square bales of straw (forget if it's barley or wheat) it wasn't giving the correct price per bale based on the pricePerLitre value set in the script.

Gtx | Andy (GtX_Andy) 14.08.2020 10:34
The price will not be static remeber, it will adjust up and down with the economy so it may be 6 > 14 per 1000 litres if you were using the script as it is set in the mod I sent you as it is set to 0.01 per litre so '€ 10'

What does the price say in the `esc` menu?
When I did my tests it works fine so I am confused. If you want exactly the same price all the time no change it needs to be a static overwrite otherwise it will move a little with the market to keep the price table interesting.

Sell a bale with no mod added and then the same with the mod I sent added, what is the difference?

Note: Log in to post. Create a new account here.