Community Forum

update/modify PricePerLiter for any Friut

Forum Overview >> Farming Simulator 17

CategoryFarming Simulator 17
Created24.08.2018 21:11


Bio Medical Extetion (Unknown) 24.08.2018 21:11
Hello,

I need to modify the PricePerLiter base in my mod script, I'm using this script:

local wheat = FillUtil.fillTypeIndexToDesc[FillUtil.FILLTYPE_WHEAT];
wheat.pricePerLiter = wheat.pricePerLiter * 1.5;

but this code work only on my mod "inizialize" event

Instead I need to change the prices mainly on my mod "update" event, but wont work
the log is clear and nothing happens (no changes occures)

Please and thank you for help

Bilbo Beutlin (BBeutlin) 25.08.2018 12:52
After the map was initialized, the sell prices are held by the "EconomyManager".
To get the price use "g_currentMission.economyManager:getPricePerLiter(FillUtil.FILLTYPE_xxx)"

I didn't examine so far, but there should? exist the appropriate function "setPricePerLiter(..)".
Best was, you examine (dump) the "g_currentMission.economyManager" to get the name of valid functions. Perhaps you'll find also other interesting functions or variables.

Bio Medical Extetion (Unknown) 25.08.2018 14:40
Bilbo thank you for the reply,

i found nothing about "EconomyManager" documentation or examples

do you have some links? thx

Bilbo Beutlin (BBeutlin) 26.08.2018 01:22
No surprise. Giants is very reserved publishing docs which go deeper into the game mechanics. *g*
Also I don't know about external tutorials.
You must make it like all others: trial and error. Examine the "g_currentMission.economyManager" table and probably you'll find useful stuff.
Write an own function to dump the table or use the DebugUtil "printTableRecursively".

Bio Medical Extetion (Unknown) 26.08.2018 20:09
Hi Bilbo,

I examinated the "g_currentMission.economyManager" table, but it isnt useful for my problem, instead I need to "override" the TipTrigger object

Then I wrote this code:

local oldTipTriggerPrice = TipTrigger.getEffectiveFillTypePrice;
TipTrigger.getEffectiveFillTypePrice = function(self)
local updateTipTriggerPrice = oldTipTriggerPrice(self, FillUtil.FILLTYPE_WHEAT);
return updateTipTriggerPrice * mymod.adjustPriceFactor
end;

but ocured this error:

Error: Running LUA method 'update'.
dataS/scripts/triggers/TipTrigger.lua(521) : attempt to perform arithmetic on a nil value

in TipTrigger.lua (line 521) there is this code:

function TipTrigger:getEffectiveFillTypePrice(fillType)
if self.isServer then
return ((self.fillTypePrices[fillType] + self.fillTypePriceRandomDelta[fillType]) * self.priceMultipliers[fillType])
else
return self.fillTypePrices[fillType]
end
end

I cant figure out solve it.... can u help me?


Bilbo Beutlin (BBeutlin) 26.08.2018 20:55
Directly overriding a function entry is never a good idea - and sometimes dangerous. *g*
And your assignment " = function(self)" will not work.
Instead use the FS functions "functionEntry = Utils.XXXFunction(oldFunction, newFunction)" where XXX may be "overridden", "appended" or "prepended". Best place is outside your mod's functions, but in the base code.
In your case I'd suggest eg.:
----------
TipTrigger.getEffectiveFillTypePrice = Utils.overriddenFunction(TipTrigger.getEffectiveFillTypePrice, myMod.getPrice)
----------
In your code of "myMod" is then the "function myMod.getPrice(fillType)". There you can examine the fillType and decide to use the original code or branch to your own.

Bio Medical Extetion (Unknown) 26.08.2018 23:24
Bilbo,

ok works, but the original func "TipTrigger.getEffectiveFillTypePrice" returns a value, and I dont know how return my value with "myMod.getPrice()"

This is my code:
function myMod.getPrice(self, superFunc, fillType)
if superFunc ~= nil then
superFunc(self, fillType) --- <---- How change the "superFunc" value with my value???
end
end
TipTrigger.getEffectiveFillTypePrice = Utils.overwrittenFunction(TipTrigger.getEffectiveFillTypePrice, myMod.getPrice)

pls hlp...thank you so much for yr support :)

PS:
I dont want to change the values of the original object
I want to change only the returned value of the original func

Bilbo Beutlin (BBeutlin) 26.08.2018 23:50
You don't need superFunc.
Simply copy the original code into your getPrice function.
Example:
----------
function myMod.getPrice(fillType)
-- at first examine fillType
if (fillType is of kind I want to change) then
-- calculate myPrice
return myPrice
else
-- here you insert the original code
end
end
----------


And yes - of course it is "overwrittenFunction" and not "overriddenFunction" .. *sigh* long ago I used this stuff. ;)

Bio Medical Extetion (Unknown) 28.08.2018 11:50
thank you Bilbo, Now WORKS!!

just a little question:

how can i format a value with thousands saparator?

my code:
function mymod.reformatMoney(value)
return tostring(value):reverse():gsub("%d%d%d", "%1,"):reverse():gsub("^,", "")
end

Unfortunately I cant change "," with "."

Current Output for value=1000000:
1,000,000

But I need this Output:
1.000.000

thank you for the support :)

Bilbo Beutlin (BBeutlin) 28.08.2018 13:01
This worked at least in earlier FS:
textToDisplay = tostring(g_i18n:formatNumber(value, decimals))
It requires the game language is set properly.
The "tostring" is for safety when for some reason the g_i18n result is nil.

The g_i18n has/had also a direct conversion "g_i18n:formatMoney(..)"

Bio Medical Extetion (Unknown) 29.08.2018 16:54
Bilbo, thank you again :)


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