IsElementInAir: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Fixed the function) |
||
Line 2: | Line 2: | ||
<lowercasetitle/> | <lowercasetitle/> | ||
__NOTOC__ | __NOTOC__ | ||
This function checks if an element is in air. | |||
This function checks if an element is in air. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> bool isElementInAir ( element theElement ) </syntaxhighlight> | <syntaxhighlight lang="lua"> bool isElementInAir ( element theElement ) </syntaxhighlight> | ||
===Returns=== | ===Returns=== | ||
Line 18: | Line 14: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function isElementInAir(element) | function isElementInAir(element) | ||
assert(type(element) == 'userdata',('Expected element at argument 1, got %s!'):format(type(element))) | |||
if element then | if getElementType(element) == 'ped' then | ||
if | if isPedOnGround(element) or getPedContact(element) then return false end | ||
return true | |||
end | end | ||
if getElementType(element) == 'vehicle' then | |||
if isVehicleOnGround(element) then return false end | |||
if | |||
end | end | ||
return true | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 42: | Line 30: | ||
This script tells if the player is in air or not. | This script tells if the player is in air or not. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | addCommandHandler('air', function() | ||
iprint(isElementInAir(localPlayer) and 'Indeed it is' or "Nope it's not") | |||
end) | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
Author: Hydra, Tracer | |||
<!-- | |||
==See Also== | ==See Also== | ||
{{Useful_Functions}} | {{Useful_Functions}} | ||
[[Category:Needs Checking]] | [[Category:Needs Checking]] | ||
--> |
Revision as of 07:15, 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))) 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 [-]
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