Jump to content

attempt to compare number with nil


roaddog

Recommended Posts

Hai I got a lil problem with this custom wanted level.

error says attempt to compare number with nil

  
function handleVehicleDamage(attacker, weapon, loss, x, y, z, tyre) 
    -- Protect law and staff from getting wanted 
    local hasWantedPlayersInside = false 
    local occupants = getVehicleOccupants( source ) 
    local vx,vy,vz = getElementPosition( source ) 
    local px,py,pz = getElementPosition( localPlayer ) 
    local dist = getDistanceBetweenPoints3D( vx,vy,vz, px,py,pz ) 
    if occupants then 
        for seat, occupant in pairs(occupants) do 
            if getElementType(occupant) == "player" then 
                if tonumber(getElementData(occupant,"Wanted")) > 0 then   ----- this line gives error 
                    hasWantedPlayersInside = true 
                end 
            end 
        end 
    end 

Link to comment

getElementData can return nil if no is set.

try

  
function handleVehicleDamage(attacker, weapon, loss, x, y, z, tyre) 
    -- Protect law and staff from getting wanted 
    local hasWantedPlayersInside = false 
    local occupants = getVehicleOccupants( source ) 
    local vx,vy,vz = getElementPosition( source ) 
    local px,py,pz = getElementPosition( localPlayer ) 
    local dist = getDistanceBetweenPoints3D( vx,vy,vz, px,py,pz ) 
    if occupants then 
        for seat, occupant in pairs(occupants) do 
            if getElementType(occupant) == "player" then 
                if (tonumber(getElementData(occupant,"Wanted")) or 0) > 0 then   ----- this line gives error 
                    hasWantedPlayersInside = true 
                   else 
                  outputChatBox("No data, or data<0",root) 
                end 
            end 
        end 
    end 

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