weverton gabriel Posted April 6, 2023 Share Posted April 6, 2023 Can anyone help me make a system that changes the handler of the current car when I press shift? The goal is to create a drift shift system. But I'm a layman and I don't know where to start. Link to comment
FLUSHBICEPS Posted April 7, 2023 Share Posted April 7, 2023 local default = {} local drift = { -- ur drift handling properties } function applydrift() local veh = getPedOccupiedVehicle(localPlayer) if veh and getVehicleController(veh) == localPlayer then sethandling(veh, drift) end end function revertdefault() local veh = getPedOccupiedVehicle(localPlayer) if veh and getVehicleController(veh) == localPlayer then local model = getElementModel(veh) sethandling(veh, default[model]) end end function sethandling(veh, handlingData) for prop, val in pairs(handlingData) do setVehicleHandling(veh, prop, val) end end function onEnter(_, seat) if source and seat == 0 then local vehModel = getElementModel(source) if not default[vehModel] then default[vehModel] = getVehicleHandling(source) end end end addEventHandler("onClientPlayerVehicleEnter", localPlayer, onEnter) bindKey("lshift", "down", applydrift) bindKey("lshift", "up", revertdefault) so basically it’s drifting with shift by holding it, u need to change the drift handling properties local drift = { ["mass"] = 1400, ["turnMass"] = 4000, ["dragCoeff"] = 2.2, ["tractionMultiplier"] = 0.65, ["tractionLoss"] = 0.85, ["tractionBias"] = 0.52, ["brakeDeceleration"] = 8.17, ["brakeBias"] = 0.52, ["suspensionForceLevel"] = 1.2, ["suspensionDamping"] = 0.08, ["suspensionHighSpeedDamping"] = 0.0, ["suspensionUpperLimit"] = 0.28, ["suspensionLowerLimit"] = -0.16, ["suspensionFrontRearBias"] = 0.45, ["suspensionAntidiveMultiplier"] = 0.0, ["steeringLock"] = 40.0 } Didn’t try but they might do the job but still ya need to adjust them Link to comment
P[ow]er Posted April 13, 2023 Share Posted April 13, 2023 Here is an example of how you could achieve this: Detecting the shift key press: function onClientKey ( button, press ) if ( button == "lshift" and press ) then -- Change the car handling end end addEventHandler ( "onClientKey", root, onClientKey ) Changing the car handling: function changeHandling () local handlingTable = getVehicleHandling ( getPedOccupiedVehicle ( localPlayer ) ) -- Modify the handling table to make the car more suitable for drifting setVehicleHandling ( getPedOccupiedVehicle ( localPlayer ), handlingTable ) end You would need to modify the changeHandling function to adjust the handling table to make the car more suitable for drifting. You could increase the car's rear-wheel grip, reduce its weight, or increase its acceleration, for example. You can find more information on MTA scripting in the official MTA wiki: https://wiki.multitheftauto.com/ Link to comment
weverton gabriel Posted April 15, 2023 Author Share Posted April 15, 2023 On 07/04/2023 at 03:01, FLUSHBICEPS said: local default = {} local drift = { -- ur drift handling properties } function applydrift() local veh = getPedOccupiedVehicle(localPlayer) if veh and getVehicleController(veh) == localPlayer then sethandling(veh, drift) end end function revertdefault() local veh = getPedOccupiedVehicle(localPlayer) if veh and getVehicleController(veh) == localPlayer then local model = getElementModel(veh) sethandling(veh, default[model]) end end function sethandling(veh, handlingData) for prop, val in pairs(handlingData) do setVehicleHandling(veh, prop, val) end end function onEnter(_, seat) if source and seat == 0 then local vehModel = getElementModel(source) if not default[vehModel] then default[vehModel] = getVehicleHandling(source) end end end addEventHandler("onClientPlayerVehicleEnter", localPlayer, onEnter) bindKey("lshift", "down", applydrift) bindKey("lshift", "up", revertdefault) so basically it’s drifting with shift by holding it, u need to change the drift handling properties local drift = { ["mass"] = 1400, ["turnMass"] = 4000, ["dragCoeff"] = 2.2, ["tractionMultiplier"] = 0.65, ["tractionLoss"] = 0.85, ["tractionBias"] = 0.52, ["brakeDeceleration"] = 8.17, ["brakeBias"] = 0.52, ["suspensionForceLevel"] = 1.2, ["suspensionDamping"] = 0.08, ["suspensionHighSpeedDamping"] = 0.0, ["suspensionUpperLimit"] = 0.28, ["suspensionLowerLimit"] = -0.16, ["suspensionFrontRearBias"] = 0.45, ["suspensionAntidiveMultiplier"] = 0.0, ["steeringLock"] = 40.0 } Não tentou, mas eles podem fazer o trabalho, mas ainda assim você precisa ajustá-los Como eu disse, sou muito novo no assunto, então recebi um erro que diz que em "default[model]" o argumento é nulo, você sabe o que poderia ser? Link to comment
weverton gabriel Posted April 15, 2023 Author Share Posted April 15, 2023 6 hours ago, weverton gabriel said: Como eu disse, sou muito novo no assunto, então recebi um erro que diz que em "default[model]" o argumento é nulo, você sabe o que poderia ser? I ended up managing to resolve the issue of nil but still the code does not return anything. Link to comment
FLUSHBICEPS Posted April 15, 2023 Share Posted April 15, 2023 You can use the isPlayerActuallyInVehicle useful function to check if a player is fully inside a vehicle, onEnter function is being called before the vehicle is fully loaded Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now