Jump to content

getElementVelocity Script


Sasu

Recommended Posts

Posted

The script works perfectly but in debugscript appears errors:

WARNING: velocidad\panel.lua:23: Bad 'element' pointer @ 'getElementVelocity'(1)

ERROR: velocidad\panel.lua:24: attempt to perform arithmetic on local 'speedx' (a boolean value)

The script is client side:

local x,y = guiGetScreenSize() 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        velocity = guiCreateLabel(x*0.6984375, y*0.74609375, x*0.23359375, y*0.1276041666666667, "KM/H: 0", false) 
        Font = guiCreateFont( "Pricedown.ttf", 70 ) 
        guiSetFont(velocity, Font) 
        guiSetVisible(velocity, false) 
    end 
) 
  
function math.round(number, decimals, method) 
    decimals = decimals or 0 
    local factor = 10 ^ decimals 
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor 
    else return tonumber(("%."..decimals.."f"):format(number)) end 
end 
  
function mostrar(vehicle) 
guiSetVisible(velocity, true) 
local timer = setTimer(function( vehicle ) 
if (not getPedOccupiedVehicle(localPlayer) ) then guiSetVisible(velocity, false) return end 
local speedx, speedy, speedz = getElementVelocity ( vehicle ) 
actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) 
kmh = actualspeed * 180 
guiSetText(velocity, "KM/H: "..math.round(kmh)) 
end 
, 50, 0, vehicle) 
end 
addEventHandler("onClientPlayerVehicleEnter", root, mostrar) 
  
function desaparecer(vehicle) 
guiSetVisible(velocity, false) 
if isTimer(timer) then 
killTimer(timer) 
end 
end 
addEventHandler("onClientPlayerVehicleExit", root, desaparecer) 

Can you help me?

Posted

Try this ;

local x,y = guiGetScreenSize() 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        velocity = guiCreateLabel(x*0.6984375, y*0.74609375, x*0.23359375, y*0.1276041666666667, "KM/H: 0", false) 
        guiSetVisible(velocity, false) 
        Font = guiCreateFont( "Pricedown.ttf", 70 ) 
        guiSetFont(velocity, Font) 
        guiSetVisible(velocity, false) 
    end 
) 
  
function math.round(number, decimals, method) 
    decimals = decimals or 0 
    local factor = 10 ^ decimals 
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor 
    else return tonumber(("%."..decimals.."f"):format(number)) end 
end 
  
function mostrar(vehicle) 
guiSetVisible(velocity, true) 
local timer = setTimer(function( vehicle ) 
if (not getPedOccupiedVehicle(localPlayer) ) then return guiSetVisible(velocity, false) end 
local speedx, speedy, speedz = getElementVelocity ( vehicle ) 
actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5) 
kmh = actualspeed * 180 
guiSetText(velocity, "KM/H: "..math.round(kmh)) 
end 
, 50, 0, vehicle) 
end 
addEventHandler("onClientPlayerVehicleEnter", root, mostrar) 
  
function desaparecer(vehicle) 
guiSetVisible(velocity, false) 
if isTimer(timer) then 
killTimer(timer) 
end 
end 
addEventHandler("onClientPlayerVehicleExit", root, desaparecer) 

Posted (edited)

Nothing :/ . Its happen when I spawn a vehicle with admin panel "P".

EDIT: I solved.

Edited by Guest
Posted

It won't work if you give yourself the vehicle via the admin panel that is because you got event that only gets triggered when a person enters a vehicle and exits, you could use a timer instead that checks when a person is in vehicle or not.

Posted

Now, I created a variable.

local vehicle = getPedOccupiedVehicle(localPlayer) 

And works perfectly.

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