Community Forum

Wearable.getWearMultiplier override not working as expected

Forum Overview >> Scripting

CategoryScripting
Created15.12.2021 19:48


Rob Jones (kaosfere) 15.12.2021 19:48
Hi there.

I'm trying to create a small mod to reduce the rate of wear in FS22. After looking at the SDK docs, it seemed like the best place to do this would be by overwriting Wearable.getWearMultiplier. I have a basic mod working that is configured that way, and I know that the basic hook is working because if I put a print statement in my replacement function I see output in the logs.

However, even if I simply replace the wear multiplier with 0, which should, based on the docs for Wearable.updateWearAmount*, mean that no wear ever gets added, I still see the damage counter on my vehicles going up, verified by examination of both debug messages and save files.

What I am doing effectively boils down to something like:

function init()
Wearable.getWearMultiplier = Utils.overwrittenFunction(Wearable.getWearMultiplier, getWearMultiplier)
end

function getWearMultiplier(node, superFunc)
local mult = 0
local origVal = superFunc(node)
local newVal= origVal * mult
print ("newVal is" .. newVal)
return newVal
end


...

Anyone have any idea what I might be doing wrong? TIA.

* https://gdn.giants-software.com/documentation_scripting_fs19.php?version=script&category=32&class=410#updateWearAmount5833

Marc Ewelt (Sweetwater) 17.12.2021 04:15
So i am just getting started on scripting in fs and was trying to do the same thing as you. I wasnt able to do it until now but i managed to do a different thing, which may still be interesting to you. By overwriting the function getVehicleDamage() and returning 0 i basically removed all bad effects of wear /damage. So a combine with 95% damage still gets you the full yield and full working speed. I modified the mod reducedMaintenanceCosts.

function ReduceMaintenanceCosts.registerOverwrittenFunctions(vehicleType)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getVehicleDamage", ReduceMaintenanceCosts.getVehicleDamage);
end

function ReduceMaintenanceCosts:getVehicleDamage(superFunc)
return 0;
end;

If you manage to "properly" sort out giants very poor balancing by decreasing wear to a realistic rate it would be nice to post your solution here or even think about releasing the mod.


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