Category | Scripting |
Created | 06.09.2020 22:11 |
Kirill Teltevskoy (Atrides) | 06.09.2020 22:11 |
---|---|
Hello. How can I change "updateVehiclePhysics" function in FS19? I want switch "axisSideIsAnalog" to "true" |
Bilbo Beutlin (BBeutlin) | 06.09.2020 23:44 |
---|---|
You can change default functions by using 'Utils.prependedFunction()' or 'Utils.appendedFunction()' or 'Utils.overwrittenFunction()' - the syntax is "oldFunction = Utils.*Function(oldFunction, newFunction)". If using overwrittenFunction() you must be aware that another mod could do the same. So it's better to use prepended|appendedFunction whenever possible, since these are queued. |
Kirill Teltevskoy (Atrides) | 07.09.2020 11:19 |
---|---|
Thank. I will try |
Kirill Teltevskoy (Atrides) | 07.09.2020 11:51 |
---|---|
Error: Running LUA method 'update'. dataS/scripts/vehicles/specializations/Locomotive.lua(359) : bad argument #1 to 'abs' (number expected, got nil) |
Bilbo Beutlin (BBeutlin) | 07.09.2020 14:58 |
---|---|
*sigh* What do you expect? Here are no clairvoyants. We need at least a description which function method you have used and what you have changed vs. original. If you want to use the 'overwritten' method, test at first with a clone of the original function. Only when everything is running fine make your changes. |
Kirill Teltevskoy (Atrides) | 07.09.2020 19:03 |
---|---|
This register file: g_specializationManager:addSpecialization("camBlock", "camBlock", g_currentModDirectory.."camBlock.lua") camBlockRegister = {} function camBlockRegister:register(name) for _, vehicle in pairs(g_vehicleTypeManager:getVehicleTypes()) do local drivable = false; local camBlock = false; for _, spec in pairs(vehicle.specializationNames) do if spec == "drivable" then drivable = true; end; if spec == "camBlock" then camBlock = true; end; end; if drivable and not camBlock then g_vehicleTypeManager:addSpecialization(vehicle.name, "FS19_CAM_BLOCK.camBlock"); end; end; end; VehicleTypeManager.finalizeVehicleTypes = Utils.prependedFunction(VehicleTypeManager.finalizeVehicleTypes, camBlockRegister.register); |
Kirill Teltevskoy (Atrides) | 07.09.2020 19:04 |
---|---|
This functions file: camBlock = {}; function camBlock.prerequisitesPresent(specializations) return true; end; function camBlock.registerEventListeners(vehicleType) SpecializationUtil.registerEventListener(vehicleType, "onUpdate", camBlock); end; function camBlock:onUpdate(dt) if self.spec_enterable ~= nil then if self.spec_enterable.isEntered then if Input.isKeyPressed(Input.KEY_lshift) then self.spec_enterable.activeCamera.isRotatable = true; else self.spec_enterable.activeCamera.isRotatable = false; end; end; end; end; function camBlock:updateVehiclePhysics(self, axisForward, axisForwardIsAnalog, axisSide, axisSideIsAnalog, doHandbrake, dt) axisSideIsAnalog = true; axisSide = 0; end; Drivable.updateVehiclePhysics = Utils.overwrittenFunction(Drivable.updateVehiclePhysics, camBlock.updateVehiclePhysics); |
Kirill Teltevskoy (Atrides) | 07.09.2020 19:05 |
---|---|
If remove "function camBlock:updateVehiclePhysics" and "Drivable.updateVehiclePhysics", then there are no errors |
Bilbo Beutlin (BBeutlin) | 07.09.2020 21:14 |
---|---|
Forget it! Do you really think your poor two lines can replace the original code? It is perhaps suitable for appending/prepending, but not for overwritten function. What did I say? For overwritten function at first begin with the original function code. If you're unsure change and test it stepwise. |
Kirill Teltevskoy (Atrides) | 08.09.2020 09:48 |
---|---|
I took the original function: camBlock = {}; function camBlock.prerequisitesPresent(specializations) return true; end; function camBlock.registerEventListeners(vehicleType) SpecializationUtil.registerEventListener(vehicleType, "onUpdate", camBlock); end; function camBlock:onUpdate(dt) if self.spec_enterable ~= nil then if self.spec_enterable.isEntered then if Input.isKeyPressed(Input.KEY_lshift) then self.spec_enterable.activeCamera.isRotatable = true; else self.spec_enterable.activeCamera.isRotatable = false; end; end; end; end; function camBlock:updateVehiclePhysics(axisForward, axisForwardIsAnalog, axisSide, axisSideIsAnalog, doHandbrake, dt) local spec = self.spec_drivable axisForward = axisForward axisSide = self:getSteeringDirection() * axisSide local acceleration = 0 if self:getIsMotorStarted() and self:getMotorStartTime() <= g_currentMission.time then acceleration = axisForward if math.abs(acceleration) > 0 then self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF) end if spec.cruiseControl.state ~= Drivable.CRUISECONTROL_STATE_OFF then acceleration = 1.0 end end if not self:getCanMotorRun() then acceleration = 0 if self:getIsMotorStarted() then self:stopMotor() end end if self.getIsControlled ~= nil and self:getIsControlled() then local targetRotatedTime = 0 if self.maxRotTime ~= nil and self.minRotTime ~= nil then if axisSide < 0 then -- 0 to maxRotTime targetRotatedTime = math.min(-self.maxRotTime * axisSide, self.maxRotTime) else -- 0 to minRotTime targetRotatedTime = math.max(self.minRotTime * axisSide, self.minRotTime) end end self.rotatedTime = targetRotatedTime end if self.firstTimeRun then if self.spec_wheels ~= nil then WheelsUtil.updateWheelsPhysics(self, dt, self.lastSpeedReal*self.movingDirection, acceleration, doHandbrake, g_currentMission.missionInfo.stopAndGoBraking) end end return acceleration end; Drivable.updateVehiclePhysics = Utils.overwrittenFunction(Drivable.updateVehiclePhysics, camBlock.updateVehiclePhysics); |
Kirill Teltevskoy (Atrides) | 08.09.2020 09:48 |
---|---|
Result in the log: 2020-09-08 10:47 Error: Running LUA method 'update'. 2020-09-08 10:47 dataS/scripts/vehicles/VehicleMotor.lua(872) : attempt to perform arithmetic on local 'dt' (a nil value) |
Bilbo Beutlin (BBeutlin) | 08.09.2020 18:36 |
---|---|
You can read, can't you? I said "at first begin with the original function code". So start with the UNCHANGED function with the parameters "updateVehiclePhysics(axisForward, axisSide, doHandbrake, dt)" Though there are additional parameters documented, may have a reason that they are not used in original code. |
Kirill Teltevskoy (Atrides) | 08.09.2020 20:21 |
---|---|
Ok. Now in the log: 2020-09-08 21:18 Error: Running LUA method 'update'. 2020-09-08 21:18 C:/Users/Admin/Documents/My Games/FarmingSimulator2019/mods/FS19_CAM_BLOCK/camBlock.lua:30: bad argument #1 to 'abs' (number expected, got function) Code: camBlock = {}; function camBlock.prerequisitesPresent(specializations) return true; end; function camBlock.registerEventListeners(vehicleType) SpecializationUtil.registerEventListener(vehicleType, "onUpdate", camBlock); end; function camBlock:onUpdate(dt) if self.spec_enterable ~= nil then if self.spec_enterable.isEntered then if Input.isKeyPressed(Input.KEY_lshift) then self.spec_enterable.activeCamera.isRotatable = true; else self.spec_enterable.activeCamera.isRotatable = false; end; end; end; end; function camBlock:updateVehiclePhysics(axisForward, axisSide, doHandbrake, dt) local spec = self.spec_drivable axisForward = axisForward axisSide = self:getSteeringDirection() * axisSide local acceleration = 0 if self:getIsMotorStarted() and self:getMotorStartTime() <= g_currentMission.time then acceleration = axisForward if math.abs(acceleration) > 0 then self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF) end if spec.cruiseControl.state ~= Drivable.CRUISECONTROL_STATE_OFF then acceleration = 1.0 end end if not self:getCanMotorRun() then acceleration = 0 if self:getIsMotorStarted() then self:stopMotor() end end if self.getIsControlled ~= nil and self:getIsControlled() then local targetRotatedTime = 0 if self.maxRotTime ~= nil and self.minRotTime ~= nil then if axisSide < 0 then -- 0 to maxRotTime targetRotatedTime = math.min(-self.maxRotTime * axisSide, self.maxRotTime) else -- 0 to minRotTime targetRotatedTime = math.max(self.minRotTime * axisSide, self.minRotTime) end end self.rotatedTime = targetRotatedTime end if self.firstTimeRun then if self.spec_wheels ~= nil then WheelsUtil.updateWheelsPhysics(self, dt, self.lastSpeedReal*self.movingDirection, acceleration, doHandbrake, g_currentMission.missionInfo.stopAndGoBraking) end end return acceleration end; Drivable.updateVehiclePhysics = Utils.overwrittenFunction(Drivable.updateVehiclePhysics, camBlock.updateVehiclePhysics); |
Bilbo Beutlin (BBeutlin) | 09.09.2020 01:03 |
---|---|
The error comes most probably if "acceleration = axisForward" was assigned. That might be caused by the special handling of the Utils.XFunction(). Try with the parameters "updateVehiclePhysics(superFunc, axisForward, axisSide, doHandbrake, dt)" You could also try a "dirty hack" (for personal use only, not recommanded for publishing): Instead the Utils.overwrittenFunction() use Drivable.updateVehiclePhysics = camBlock.updateVehiclePhysics; |
Kirill Teltevskoy (Atrides) | 09.09.2020 08:42 |
---|---|
Thank. Works with "superFunc". Log clean |
Kirill Teltevskoy (Atrides) | 09.09.2020 10:20 |
---|---|
Can you explain to me how to look for functions? For example, I want to find how to count the movement of the mouse along the X axis. How do I find how to write a function? |
Bilbo Beutlin (BBeutlin) | 10.09.2020 00:35 |
---|---|
For finding certain functions you must be a little creative and a good analyst. Try to imagine in which category the issue is used and search in the LUADOCs in appropriate section. It can be helpful to DL and install the Giants Remote Debugger. This comes with a zip archive of most used LUA codes and is a good supplement to the LUADOCs here on GDN. Very comfortable if you unpack the zip - this enables extensive search, eg. with Notepad++ "search in files". |
Kirill Teltevskoy (Atrides) | 10.09.2020 10:02 |
---|---|
Thanks |
Kirill Teltevskoy (Atrides) | 10.09.2020 19:53 |
---|---|
I cannot find the amount of movement of the mouse on the X axis. Can you help me? I remember that in previous FS versions it was "InputBinding.mouseMovementX". And in FS19 I can't understand |
Bilbo Beutlin (BBeutlin) | 11.09.2020 05:06 |
---|---|
See above my recommendation: install the Giants Remote Debugger, unpack the "gameSources/Farming_Simulator_19-1.5.1.0.zip" to a separate folder. Here you do with Notepad++ a "search in files" for "mouse". You'll get lots of examples how mouse related values are used in game. |
Kirill Teltevskoy (Atrides) | 11.09.2020 07:37 |
---|---|
I did it all. Found "VehicleCamera: actionEventLookLeftRight". I understand that this is a left-right mouse view of the camera. And "inputValue" is the variable I need. But how do I use it in my script? There is also "self.lastInputValues.leftRight". But I cannot use this either. Error in the log "nill value" |
Bilbo Beutlin (BBeutlin) | 11.09.2020 11:41 |
---|---|
If you look through the LUAs, most time is used something with "mouseEvent(posX, posY, isDown, isUp, button)" There are also mouse values in the table "g_currentMission.inputManager" which could be interesting: .inputMouseXAxisValue .inputMouseYAxisValue .mouseMovementX .mouseMovementY Perhaps try out these. |
Kirill Teltevskoy (Atrides) | 11.09.2020 12:03 |
---|---|
Thank. I'm going to try |
Kirill Teltevskoy (Atrides) | 11.09.2020 12:27 |
---|---|
Everything is working! I got what I wanted! Thank! |
Kirill Teltevskoy (Atrides) | 11.09.2020 12:30 |
---|---|
Everything is working! I got what I wanted! Thank! |
Note: Log in to post. Create a new account here.