Jump to content

arithmetic help


K4stic

Recommended Posts

  
function blablabla (hitPlayer) 
local vehicle = getPedOccupiedVehicle(hitPlayer) 
local speed = getElementSpeed(vehicle,1) 
if speed < 30 then 
  
function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        return false 
    end 
end 

on first 5 lines is the one part of all code so i just no add end to this 5 lines

the error at line 5: attempt to compare boolean with number

Edited by Guest
Link to comment

You need to add 'end's. And it's giving that error because "hitPlayer" is either not an element (but that would give the error 'Bad ped pointer' @ 'getPedOccupiedVehicle' function) or "hitPlayer" is not inside a vehicle, so you're comparing a boolean value with a number.

Edited by Guest
Link to comment
  
addEventHandler("onClientVehicleEnter",root, 
function ()      
addEventHandler ( "onClientRender", getRootElement(), getPlayerSpeed ) 
end 
)    
addEventHandler("onClientVehicleExit",root, 
function ()      
removeEventHandler ( "onClientRender", getRootElement(), getPlayerSpeed ) 
end 
) 
function getPlayerSpeed ( ) 
local sx, sy, sz = getElementVelocity (getPedOccupiedVehicle(localPlayer)) 
return (sx^2 + sy^2 + sz^2)^0.5*180 
end      
  

Now u can get the speed example :

  
if(tonumber( math.floor( getPlayerSpeed() ) ) < 30 ) then 
  

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