Jump to content

surf vehicle


Apo

Recommended Posts

  • Moderators

I'm not at home actually so here is a draft of what you can use:

Client side script:

-- You can modify below: 
local speedUnit = "km/h" -- Possible values: "km/h", "mph" or "m/s" 
local minSpeed = 5 -- minimum speed before falling 
local exceptionList = { 
    -- Boats: 
    472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 
    -- add other vehicles here if needed 
} 
  
-- Function responsible for the "fall animation" 
-- fromSpeed is the speed the player is falling from 
function makeLocalPlayerFall( fromSpeed ) 
    -- ultra basic fall animation (edit for more complex one): 
    setElementVelocity( localPlayer, 0, 0, 1 ) 
end 
  
-- !! DO NOT MODIFY BELOW !! -- 
-- Maybe an infinite timer of 1 second won't make any difference but would reduce hardware consumption 
addEventHandler("onClientRender", root, function () 
    local veh = getPedContactElement( localPlayer ) 
    if not veh or isVehicleInExceptionList( veh ) then return end 
     
    local speed = getElementSpeed( veh, speedUnit ) 
    if speed >= minSpeed then 
        makeLocalPlayerFall( speed ) 
    end 
end) 
  
function isVehicleInExceptionList( veh ) 
    if not exceptionList then return false end 
    local model = getElementModel( veh ) 
    for k, m in ipairs ( exceptionList ) do 
        if model == m then return true end 
    end 
    return false 
end 
  
-- Taken from: [url=https://wiki.multitheftauto.com/wiki/GetElementSpeed]https://wiki.multitheftauto.com/wiki/GetElementSpeed[/url] 
function getElementSpeed(theElement, unit) 
    -- Check arguments for errors 
    assert(isElement(theElement), "Bad argument 1 @ getElementSpeed (element expected, got " .. type(theElement) .. ")") 
    assert(getElementType(theElement) == "player" or getElementType(theElement) == "ped" or getElementType(theElement) == "object" or getElementType(theElement) == "vehicle", "Invalid element type @ getElementSpeed (player/ped/object/vehicle expected, got " .. getElementType(theElement) .. ")") 
    assert((unit == nil or type(unit) == "string" or type(unit) == "number") and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == "m/s" or unit == "km/h" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)") 
    -- Default to m/s if no unit specified and 'ignore' argument type if the string contains a number 
    unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit)) 
    -- Setup our multiplier to convert the velocity to the specified unit 
    local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456) 
    -- Return the speed by calculating the length of the velocity vector, after converting the velocity to the specified unit 
    return (Vector3(getElementVelocity(theElement)) * mult).length 
end 
  

Test it for me please (errors/warnings will be visible with /debugscript 3).

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...