Jump to content

help creating a shift drift script.


Recommended Posts

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

Here is an example of how you could achieve this:

  1. Detecting the shift key press:
  2. function onClientKey ( button, press )
        if ( button == "lshift" and press ) then
            -- Change the car handling
        end
    end
    addEventHandler ( "onClientKey", root, onClientKey )

     

  3. Changing the car handling:
  4. 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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...