Community Forum

Bale Price Script

Forum Overview >> Scripting

Created20.02.2019 16:44

Dominic S (dominiczeth) 20.02.2019 16:44

I'm new to scripting and wanted to try something easy which i also would use.
So i tried to create a script which adjusts the Bale Price.

I used this:

function Bale:getValue()
local pricePerLiter = g_currentMission.economyManager:getPricePerLiter(self.fillType);
return self.fillLevel * pricePerLiter * self.baleValueScale;

From the FS19 Script Docu. but the function Bale:getValue doesn't seem to work?
I don't get any Values with it when i try to print something.

The following script someone gave to me and i tried to work with it.

local baleAdjustments = {
straw = 4,
grass_windrow = 4,
silage = 4,
dryGrass_windrow = 4,
others = 4,

print("BalePrices adjustment factors:");
print("straw: " .. baleAdjustments["straw"]);
print("grass_windrow: " .. baleAdjustments["grass_windrow"]);
print("silage: " .. baleAdjustments["silage"]);
print("dryGrass_windrow: " .. baleAdjustments["dryGrass_windrow"]);
print("others: " .. baleAdjustments["others"]);

local oldBaleGetValue = Bale.getValue;

Bale.getValue = function(self)
local updatedBalePrice = oldBaleGetValue(self);

local fillType = FillUtil.fillTypeIntToName[self.fillType]
local adjustmentFactor = 2
if fillType ~= nil and baleAdjustments[fillType] ~= nil then
adjustmentFactor = baleAdjustments[fillType]
adjustmentFactor = baleAdjustments[others]

return updatedBalePrice * adjustmentFactor


But when i try for example to print "updated Bale price" it says error because it's a nil value or it's a not specified global variable... Any Help?
I wanted to learn with this easy script but it's a nightmare now ^^

Bilbo Beutlin (BBeutlin) 20.02.2019 18:48
Why such efford? Since FS19 you can easily adapt the fillType prices in the "fillTypes.xml".

If you really want to change by script use something like
local ftName = "wheat";
local ftDesc = FillUtil.fillTypeNameToDesc[ftName];
if ftDesc ~= nil then
ftDesc.pricePerLiter = newPrice;
You must insert the code in a very early stage where the map isn't loaded yet, eg. already in the startup code.

Dominic S (dominiczeth) 20.02.2019 19:31
Oh ok didn't know that. Now i have to figure out to

A) adapt that to Bales only for Straw and Hay/Grass (maybe Silage)

and B) how to load it on startup.

Thanks :)

is it the ...:loadMap(name) variable?

Bilbo Beutlin (BBeutlin) 20.02.2019 19:50
The bales are NOT handled separately, they have no 'special bale price'. The effective price is simply calculated about fillType and quantity.

For FS19 I didn't try yet the best time for changing fillType price by script.
It must be BEFORE the map is loaded completely and the EconomyManager has been setup.
Otherwise must be probably AFTER the map specific "fillType.xml" is evaluated.

Dominic S (dominiczeth) 20.02.2019 20:02
Yeah i understand. Sounds very hard for a beginner like me :)
I already saw that bales are just calculated with the price from there filltype (4000L in bales or loose doesn't make any difference).
And that's the point for me - if you want to produce bales to sell them there is no point. More Realistic in FS17 had this with higher bale prices.

Maybe i should try something easy first but don't know what.

There must be a way though to see if it's a bale or not, but i really can't figure that out yet. I also don't know what all those bale types are in the fillType.xml

Edit: Another idea: Is it somehow possible to change the fillLevel from a bale at the moment of selling it? Didn't found something yet.

Bilbo Beutlin (BBeutlin) 20.02.2019 20:22
You'll need to 'hack' the UnloadTrigger (see LUADOC -> Triggers)
The function "updateBales()" seems suitable.

Dominic S (dominiczeth) 20.02.2019 20:27
Thank you that should help!

Edit: It works!! Thank you soo much, my first script :D

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