Jump to content

[HELP] Works but something is wrong


LabiVila

Recommended Posts

function speed () 
    if isPedInVehicle (localPlayer) then 
        speedX, speedY, speedZ = getElementVelocity (getPedOccupiedVehicle (localPlayer)) 
        speed = math.ceil (((speedX^2 + speedY^2 + speedZ^2)^(0.5))*180) 
        dxDrawText (speed.." km/h", x/1.20, y/2.8, x, y, tocolor (255, 255, 255)) 
    end 
end 
addEventHandler ("onClientRender", root, speed) 

WARNING: test\client:73: Bad argument @ 'getElementVelocity'

ERROR: test\client:74: attempt to perform arithmetic on global "speedX" (a boolean value)

It works but why do these message appear? and how can I fix them?

Link to comment
  • Moderators

I have no idea why the getPedOccupiedVehicle or isPedInVehicle function failed, very strange.

I hardly use the isPedInVehicle function, because I always need to know the vehicle element userdata.

But this is how I would write it.

  
function speed () 
    local vehicle = getPedOccupiedVehicle (localPlayer) 
    if vehicle then 
        local speedX, speedY, speedZ = getElementVelocity (vehicle) 
        local speed = math.ceil (((speedX^2 + speedY^2 + speedZ^2)^(0.5))*180) 
        dxDrawText (speed.." km/h", x/1.20, y/2.8, x, y, tocolor (255, 255, 255)) 
    end 
end 
addEventHandler ("onClientRender", root, speed) 

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