Jump to content

Function for isElementOnGround


Jaysds1

Recommended Posts

Hi,

I was thinking, instead of using isVehicleOnGround or isPedOnGround,

why don't we make isElementOnGround and remove these function, plus it could check if an object is on the ground...

What about it guyz/girlz?

veh's and ped's are the main two things that use phys engine. rest doesn't. just compare the Z coordinate.

Link to comment
  
--Returns true if the given element is on the ground, false otherwise. 
--Note: this may return incorrect values if the element is not streamed in. 
function isElementOnGround(element) 
    if not isEntity(element) then 
        error("Invalid arguments to isElementOnGround (expected entity at argument 1)!") 
        return false 
    end 
  
    local oZ = getElementDistanceFromCentreOfMassToBaseOfModel(element) 
    local x, y, z = getElementPosition(element) 
    if x and y and z then --Check if for some reason the position is not available (this shouldn't happen) 
        local ground = getGroundPosition(x, y) 
        return (z-oZ == ground and true) or false 
    else 
        return false 
    end  
end 
  
--Returns true if the given value is an entity, false otherwise. 
local validTypes = {    "ped" = true, "player" = true, "vehicle"= true,"object" = true, 
            "vehicle" = true, "pickup" = true, "marker" = true, "blip" = true, "radararea" = true} 
function isEntity(element) 
    if not isElement(element) then return false end 
     
    local elementType = getElementType(element) 
  
    if validType[elementType] then 
        return true 
    else 
        return false 
    end 
end 
  

Clientside only, though it would be pretty easy to implement serverside.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...