| Category | Farming Simulator 25 |
| Created | 02.03.2025 17:46 |
| letmecook | 02.03.2025 17:46 |
|---|---|
| Hi, would love to get some help. Trying to create mod responsibile for tipping trailer, by pressing specific buttons trailer should start tipping and when player unpress those bind trailer will stop in specific "angle". So far i got this code but cant handle stoping trailer at specific angle, infact trailer is going back to initial state like using normal ingame ctrl+i. ManualTipping = {} ManualTipping.MOD_NAME = g_currentModName function ManualTipping.prerequisitesPresent(specializations) return SpecializationUtil.hasSpecialization(Dischargeable, specializations) end function ManualTipping.registerFunctions(vehicleType) SpecializationUtil.registerFunction(vehicleType, "startManualTipping", ManualTipping.startManualTipping) SpecializationUtil.registerFunction(vehicleType, "stopManualTipping", ManualTipping.stopManualTipping) end function ManualTipping.registerEventListeners(vehicleType) SpecializationUtil.registerEventListener(vehicleType, "onLoad", ManualTipping) SpecializationUtil.registerEventListener(vehicleType, "onUpdate", ManualTipping) SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", ManualTipping) end function ManualTipping:onLoad() self.spec_manualTipping = { currentAngle = 0, tippingActive = false, tippingDirection = 1, -- 1 = podnoszenie, -1 = opuszczanie actionEvents = {} } if self.spec_dischargeable == nil then print("Error: Trailer does not have Dischargeable specialization!") else print("Success: Trailer has Dischargeable specialization!") print("Number of discharge nodes: " .. tostring(#self.spec_dischargeable.dischargeNodes)) end end function ManualTipping:onRegisterActionEvents(isActiveForInput) local spec = self.spec_manualTipping if self.isClient then self:clearActionEventsTable(spec.actionEvents) local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.MANUAL_TIPPING_TOGGLE, self, ManualTipping.onManualTippingToggle, true, true, false, true) g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL) end end function ManualTipping:onManualTippingToggle(actionName, inputValue) print("ManualTipping toggled") local spec = self.spec_manualTipping if inputValue > 0 then spec.tippingActive = true print("Tipping true") else spec.tippingActive = false print("Tipping false") end end function ManualTipping:onUpdate(dt) local spec = self.spec_manualTipping if not spec.tippingActive then return end local dischargeSpec = self.spec_dischargeable if dischargeSpec == nil then print("Error: dischargeSpec is nil!") return end -- Jeśli nie ma ustawionego węzła rozładunku, ustaw domyślnie pierwszy if dischargeSpec.currentDischargeNodeIndex == nil or dischargeSpec.currentDischargeNodeIndex == 0 then if #dischargeSpec.dischargeNodes > 0 then dischargeSpec.currentDischargeNodeIndex = 1 print("[INFO] Ustawiono currentDischargeNodeIndex na 1") else print("[WARNING] Brak dostępnych dischargeNodes!") return end end local nodeIndex = dischargeSpec.currentDischargeNodeIndex local dischargeNode = dischargeSpec.dischargeNodes[nodeIndex] -- Sprawdzenie, czy dischargeNode istnieje if dischargeNode == nil then print("Error: dischargeNode is nil!") return end -- Maksymalny kąt przechyłu local maxAngle = math.rad(50) -- Można zmienić na wartość z modelu -- Zwiększanie kąta przechyłu if spec.tippingActive and spec.currentAngle < maxAngle then spec.currentAngle = math.min(spec.currentAngle + dt * 0.001, maxAngle) -- dt * 0.001 dla płynnego przechylania end -- Ustawienie kąta przechyłu setRotation(dischargeNode.node, spec.currentAngle, 0, 0) -- Rozpoczęcie rozładunku self:setDischargeState(Dischargeable.DISCHARGE_STATE_OBJECT, true) end function ManualTipping:startManualTipping() local spec = self.spec_manualTipping spec.tippingActive = true end function ManualTipping:stopManualTipping() local spec = self.spec_manualTipping spec.tippingActive = false end |
|
| Earl Bush (ProQuasar) | 26.04.2025 19:05 |
|---|---|
| Hello. I think this would conflict with the tipping animation for the trailer. Looks like it would potentially work. Alternatively, you could set up the trailer's tipping to be controlled by the cylindered section for a specific axis. Then model the tipping nodes after what you see in buckets. Those tip nodes depend on the angle of the bucket and the discharge rate is depending on what angle. Just and alternative suggestion, but I think your code would be cool if you can get it to stop at a specific angle. |
|
Note: Log in to post. Create a new account here.