IsElementInAir: Difference between revisions
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 | ||
return not (isPedOnGround(element) or getPedContact(element)) | |||
return | elseif getElementType(element) == 'vehicle' then | ||
return not isVehicleOnGround(element) | |||
end | end | ||
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 [-]
ClientThis 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