Jump to content

question about setElementVelocity


matito6

Recommended Posts

Posted

Hey.

I do not know how to do the "setElementVelocity" was speeding to the front of the "0.30". Please help can there another way to speed up? Please help :)

Posted

Use:

function getElementSpeed ( element , unit ) 
    if not element or not isElement ( element ) then 
        return false 
    end 
    if unit == "kph" then 
        unit = 1.61 
    else 
        unit = 1 
    end 
    local velX , velY , velZ = getElementVelocity ( element ) 
    return ( velX ^ 2 + velY ^ 2 + velZ ^ 2 ) ^ 0.5 * unit * 100 
end 
     
function setElementSpeed ( element , unit , speed ) 
    if not element or not isElement ( element ) then 
        return false 
    end 
    if not speed then 
        speed = 0 
    end 
    local acSpeed = getElementSpeed ( element , unit ) 
    local diff = speed / acSpeed 
    local velX , velY , velZ = getElementVelocity ( element ) 
    setElementVelocity ( element , velX * diff , velY * diff , velZ * diff ) 
    return true 
end 

Posted
addCommandHandler("speed", 
function (thePlayer, cmd, theSpeed) 
    local theSpeed = tonumber(theSpeed) 
    local vehicle = getPedOccupiedVehicle(thePlayer) 
    if (theSpeed and vehicle) 
        setElementSpeed(vehicle, "kph", theSpeed) 
    end 
end) 
  
function getElementSpeed ( element , unit ) 
    if not element or not isElement ( element ) then 
        return false 
    end 
    if unit == "kph" then 
        unit = 1.61 
    else 
        unit = 1 
    end 
    local velX , velY , velZ = getElementVelocity ( element ) 
    return ( velX ^ 2 + velY ^ 2 + velZ ^ 2 ) ^ 0.5 * unit * 100 
end 
    
function setElementSpeed ( element, unit , speed ) 
    if not element or not isElement ( element ) then 
        return false 
    end 
    if not speed then 
        speed = 0 
    end 
    local acSpeed = getElementSpeed ( element , unit ) 
    local diff = speed / acSpeed 
    local velX , velY , velZ = getElementVelocity ( element ) 
    setElementVelocity ( element , velX * diff , velY * diff , velZ * diff ) 
    return true 
end 

That should add a command: /speed .

Posted

it does not work. I would like to, if you type "/ speed Euro" I got the speed right away

such that the car accelerated (DM maps) It can be done?

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