IsElementInAir: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Fixed the function)
m (Changed syntax a little)
Line 15: Line 15:
function isElementInAir(element)
function isElementInAir(element)
     assert(type(element) == 'userdata',('Expected element at argument 1, got %s!'):format(type(element)))
     assert(type(element) == 'userdata',('Expected element at argument 1, got %s!'):format(type(element)))
    assert(getElementType(element) == 'ped' or getElementType(element) == 'vehicle',
        ('Expected element at argument 1, got %s!'):format(type(element))
    )
     if getElementType(element) == 'ped' then
     if getElementType(element) == 'ped' then
         if isPedOnGround(element) or getPedContact(element) then return false end
         return not (isPedOnGround(element) or getPedContact(element))
         return true
    elseif getElementType(element) == 'vehicle' then
         return not isVehicleOnGround(element)
     end
     end
    if getElementType(element) == 'vehicle' then
        if isVehicleOnGround(element) then return false end
    end
    return true
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 07:18, 7 June 2022


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)))
    assert(getElementType(element) == 'ped' or getElementType(element) == 'vehicle',
        ('Expected element at argument 1, got %s!'):format(type(element))
    )
    if getElementType(element) == 'ped' then
        return not (isPedOnGround(element) or getPedContact(element))
    elseif getElementType(element) == 'vehicle' then
        return not isVehicleOnGround(element)
    end
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