IsElementInAir

From Multi Theft Auto: Wiki
Revision as of 07:15, 7 June 2022 by Tracer (talk | contribs) (Fixed the function)
Jump to navigation Jump to search


This function checks if an element is in air.

Syntax

 bool isElementInAir ( element theElement ) 

Returns

Returns true if the element is in air, false otherwise.

Code

function isElementInAir(element)
    assert(type(element) == 'userdata',('Expected element at argument 1, got %s!'):format(type(element)))
    if getElementType(element) == 'ped' then
        if isPedOnGround(element) or getPedContact(element) then return false end
        return true
    end
    if getElementType(element) == 'vehicle' then
        if isVehicleOnGround(element) then return false end
    end
    return true
end

Example

Click to collapse [-]
Client

This script tells if the player is in air or not.

addCommandHandler('air', function()
    iprint(isElementInAir(localPlayer) and 'Indeed it is' or "Nope it's not")
end)

</syntaxhighlight>

Author: Hydra, Tracer