Category | Scripting |
Created | 10.03.2021 12:31 |
Dellorian | 10.03.2021 12:31 |
---|---|
This script from fs 17 I want to move it to fs 19. Pls help Lua: First script: newExhaustEffects = {}; function newExhaustEffects.prerequisitesPresent(specializations) return true; end; function newExhaustEffects:load(savegame) self.nrep = {}; -- all variables will be stored in this table to prevent interference with other scripts self.nrep.maxMotorLoad = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.motorized.newExhaustEffects#maxMotorLoad"), 20); self.nrep.psThreshold = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.motorized.newExhaustEffects#psThreshold"), 0.85); self.nrep.ps = {}; ParticleUtil.loadParticleSystem(self.xmlFile, self.nrep.ps, "vehicle.motorized.newExhaustEffects.particle", self.components, false, nil, self.baseDirectory) end; function newExhaustEffects:update(dt) if self:getIsActive() and self.spec_motorized.isMotorStarted then local mLoad = self.spec_motorized.getMotorLoadPercentage / self.nrep.maxMotorLoad; -- converting the individual motor load to 0-1 range value if mLoad > self.nrep.psThreshold then Utils.setEmittingState(self.nrep.ps, true); else Utils.setEmittingState(self.nrep.ps, false) end; end; end; function newExhaustEffects:delete() if self.nrep.ps ~= nil then ParticleUtil.deleteParticleSystem(self.nrep.ps); end; end; function newExhaustEffects:onLeave() if self.nrep.ps then Utils.setEmittingState(self.nrep.ps, false); end; end; function newExhaustEffects:mouseEvent(posX, posY, isDown, isUp, button) end; function newExhaustEffects:keyEvent(unicode, sym, modifier, isDown) end; function newExhaustEffects:draw() end; Second script: noSmokeNoFun = {}; function noSmokeNoFun.prerequisitesPresent(specializations) return true; end; function noSmokeNoFun:load(savegame) self.LSF = {}; self.LSF.emittTime = 0; self.LSF.threshingStartPS = {}; noSmokeNoFun.LSF = self.LSF; noSmokeNoFun.LSF.emittTime = self.LSF.emittTime; noSmokeNoFun.LSF.threshingStartPS = self.LSF.threshingStartPS; ParticleUtil.loadParticleSystem(self.xmlFile, self.LSF.threshingStartPS, "vehicle.motorized.threshingStartParticleSystem", self.components, false, nil, self.baseDirectory); self.LSF.allowedEmittTime = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.motorized.threshingStartParticleSystem#startOffset"),0.1)*1000; end; function noSmokeNoFun:delete() ParticleUtil.deleteParticleSystem(self.LSF.threshingStartPS); end; function noSmokeNoFun:writeStream(streamId, connection) end; function noSmokeNoFun:readStream(streamId, connection) end; function noSmokeNoFun:mouseEvent(posX, posY, isDown, isUp, button) end; function noSmokeNoFun:keyEvent(unicode, sym, modifier, isDown) end; function noSmokeNoFun:update(dt) end; function noSmokeNoFun:updateTick(dt) if self:getIsActive() then if self.isClient then if self.LSF.emitting then if self.LSF.emittTime >= self.LSF.allowedEmittTime then Utils.setEmittingState(self.LSF.threshingStartPS, false); self.LSF.emittTime = 0; else self.LSF.emittTime = self.LSF.emittTime + dt; end; end; end; end; end; function noSmokeNoFun:startMotor() if self:getIsActive() then if self.isClient then Utils.setEmittingState(self.LSF.threshingStartPS, true); self.LSF.emitting = true; end; end; end; function noSmokeNoFun:onTurnedOn() if self:getIsActive() then if self.isClient then Utils.setEmittingState(noSmokeNoFun.LSF.threshingStartPS, true); noSmokeNoFun.LSF.emitting = true; end; end; end; function noSmokeNoFun:draw() end; function noSmokeNoFun:onAttachImplement(implement) if SpecializationUtil.hasSpecialization(Mower, implement.object.specializations) then Mower.onTurnedOn = Utils.overwrittenFunction(Mower.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(Baler, implement.object.specializations) then Baler.onTurnedOn = Utils.overwrittenFunction(Baler.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(Cultivator, implement.object.specializations) then Cultivator.onAiTurnOn = Utils.overwrittenFunction(Cultivator.onAiTurnOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(MixerWagon, implement.object.specializations) then MixerWagon.onTurnedOn = Utils.overwrittenFunction(MixerWagon.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(RotorSpreader, implement.object.specializations) then RotorSpreader.onTurnedOn = Utils.overwrittenFunction(RotorSpreader.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(SowingMachine, implement.object.specializations) then SowingMachine.onTurnedOn = Utils.overwrittenFunction(SowingMachine.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(Sprayer, implement.object.specializations) then Sprayer.onTurnedOn = Utils.overwrittenFunction(Sprayer.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(StumpCutter, implement.object.specializations) then StumpCutter.onTurnedOn = Utils.overwrittenFunction(StumpCutter.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(Cultivator, implement.object.specializations) then Cultivator.onTurnedOn = Utils.overwrittenFunction(Cultivator.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(Windrower, implement.object.specializations) then Windrower.onTurnedOn = Utils.overwrittenFunction(Windrower.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(Tedder, implement.object.specializations) then Tedder.onTurnedOn = Utils.overwrittenFunction(Tedder.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(ForageWagon, implement.object.specializations) then ForageWagon.onTurnedOn = Utils.overwrittenFunction(ForageWagon.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(ManureBarrel, implement.object.specializations) then ManureBarrel.onTurnedOn = Utils.overwrittenFunction(ManureBarrel.onTurnedOn, noSmokeNoFun.onTurnedOn); end; if SpecializationUtil.hasSpecialization(ManureSpreader, implement.object.specializations) then ManureSpreader.onTurnedOn = Utils.overwrittenFunction(ManureSpreader.onTurnedOn, noSmokeNoFun.onTurnedOn); end; end; XML: <exhaustEffects> <exhaustEffect node="0>4|1" filename="$data/particleSystems/shared/exhaust.i3d" minRpmColor="0.2 0.2 0.2 0.1" maxRpmColor="0.2 0.2 0.2 0.4" minRpmScale="0.05" maxRpmScale="0.3" xzRotationsOffset="0 0" xzRotationsForward="-250 0" xzRotationsBackward="50 0" xzRotationsLeft="0 100" xzRotationsRight="0 -100" /> </exhaustEffects> <newExhaustEffects maxMotorLoad="0.2" count="2"> <particle node="0>4|3" position="0 0 0" rotation="0 0 0" file="shared/newRealParticles1.i3d"/> </newExhaustEffects> <StartParticleSystem node="0>4|3" file="shared/exhaust.i3d" startOffset="1"/> <threshingStartParticleSystem node="0>4|3" file="shared/exhaust.i3d" startOffset="1"/> |
Bilbo Beutlin (BBeutlin) | 10.03.2021 16:32 |
---|---|
This LUA script will not work since methods in spec function calls have changed. In opposite to earlier FS versions you must now specify the functions which should be processed. This is usually done in an initializing function 'registerEventListeners()'. For reference and examples see default spec codes. |
Dellorian | 10.03.2021 19:50 |
---|---|
Hello, thank you for the feedback, I looked at how to call spec, I prescribed it at my place, but nothing changed. I give you the code below:function noSmokeNoFun.registerEventListeners(vehicleType) for _, n in pairs( { "onUpdate", "onDelete", "onDraw", "onLoad", "onWriteStream", "onReadStream", "onUpdateTick", "onkeyEvent", "onmouseEvent" } ) do SpecializationUtil.registerEventListener(vehicleType, n, noSmokeNoFun) end end function noSmokeNoFun.registerOverwrittenFunctions(vehicleType) SpecializationUtil.registerOverwrittenFunction(vehicleType, "onTurnedOn", noSmokeNoFun.onTurnedOn) end No error again, I’d appreciate you pointing to the error in the code again |
Bilbo Beutlin (BBeutlin) | 10.03.2021 21:31 |
---|---|
The function 'registerEventListeners()' is not executed automatically. You must at least run it once, preferably from where you have setup the custom specialization. AFAIK the raw input 'keyEvent' and 'mouseEvent' is not handled anymore by the spec function dispatcher. If you need key/mouse input, use the actual method with ActionEvents instead. What else I noticed in your code, "Utils.setEmittingState()" is deprecated. Actual is "ParticleUtil.setEmittingState()". Maybe there's some more obsolete code, I didn't check in detail. |
Dellorian | 10.03.2021 22:47 |
---|---|
Thanks for the answer, I’m grateful, but the situation hasn’t changed, there have been mistakes, I’ve fixed them, the same situation. |
Note: Log in to post. Create a new account here.