Community Forum

Liftaxle Script

Forum Overview >> Scripting

CategoryScripting
Created30.06.2022 00:43


Jonas Graulund Hansen (Traktorjonas) 30.06.2022 00:43
Hello there, Back in FS19 we had the perfect liftaxle script which we could use in mods so the trailer could lift axle/s whenever it had a preset fill level - But if i try to use it, alot of Lua call stacks come up - Can anyone reright the script?

LiftingAxles = {};
LiftingAxles.MOD_NAME = g_currentModName;

function LiftingAxles.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(FillUnit, specializations);
end;

function LiftingAxles.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, "loadLiftingAxle", LiftingAxles.loadLiftingAxle);
end;

function LiftingAxles.registerEventListeners(vehicleType)
SpecializationUtil.registerEventListener(vehicleType, "onLoad", LiftingAxles);
SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", LiftingAxles);
SpecializationUtil.registerEventListener(vehicleType, "onFillUnitFillLevelChanged", LiftingAxles);
end

function LiftingAxles:onLoad(savegame)
self.spec_LiftingAxles = self[string.format("spec_%s.liftingAxles", LiftingAxles.MOD_NAME)]
local spec = self.spec_LiftingAxles

spec.liftingAxles = {};
local i = 0;
while true do
local key = string.format("vehicle.liftingAxles.liftingAxle(%d)", i);
if not hasXMLProperty(self.xmlFile, key) then
break;
end;
local liftingAxle = {}
if self:loadLiftingAxle(self.xmlFile, key, liftingAxle) then
table.insert(spec.liftingAxles, liftingAxle);
end;
i = i + 1;
end;
end;

function LiftingAxles:onPostLoad(savegame)
local spec = self.spec_LiftingAxles;
for _, liftingAxle in ipairs(spec.liftingAxles) do
self:playAnimation(liftingAxle.animationName, 1, nil, true);
AnimatedVehicle.updateAnimationByName(self, liftingAxle.animationName, 9999999);
end;
end;

function LiftingAxles:loadLiftingAxle(xmlFile, key, liftingAxle)
local fillUnitIndex = getXMLInt(self.xmlFile, key.."#fillUnitIndex");
if fillUnitIndex ~= nil then
liftingAxle.fillUnitIndex = fillUnitIndex;
liftingAxle.animationName = getXMLString(xmlFile, key.."#animationName");
liftingAxle.liftAtFillLevel = Utils.getNoNil(getXMLFloat(xmlFile, key.."#liftAtFillLevel"), 1.0);
end;
return liftingAxle.animationName ~= nil;
end;

function LiftingAxles:onFillUnitFillLevelChanged(fillUnitIndex, fillLevelDelta, fillTypeIndex, toolType, fillPositionData, appliedDelta)
local spec = self.spec_LiftingAxles;
for _, liftingAxle in pairs(spec.liftingAxles) do
if liftingAxle.fillUnitIndex == fillUnitIndex then
local fillLevel = self:getFillUnitFillLevel(fillUnitIndex);
local direction = 0;
local stopTime = 0.0;
if fillLevel >= liftingAxle.liftAtFillLevel then
direction = -1;
else
direction = 1;
stopTime = 1.0
end;
if direction ~= 0 and not self:getIsAnimationPlaying(liftingAxle.animationName) then
self:playAnimation(liftingAxle.animationName, direction, nil, true);
self:setAnimationStopTime(liftingAxle.animationName, stopTime);
end;
end;
end;
end;


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