IsElementInAir: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Fixed the function)
Line 2: Line 2:
<lowercasetitle/>
<lowercasetitle/>
__NOTOC__
__NOTOC__
{{Needs_Checking|This function may return a ''true'' value if you are at a very high point (Z > 10) on the map.}}


{{Needs_Checking|This function may return a ''true'' value if you are at a very high point (Z > ZPos) on the map.}}
This function checks if an element is in air.
 
This function checks if an element is in air. Function made by Hydra


==Syntax==
==Syntax==
<syntaxhighlight lang="lua"> bool isElementInAir ( element theElement ) </syntaxhighlight>
<syntaxhighlight lang="lua"> bool isElementInAir ( element theElement ) </syntaxhighlight>
<syntaxhighlight lang="lua"> bool isElementInAir ( element theElement float ZPos ) </syntaxhighlight>


===Returns===
===Returns===
Line 18: Line 14:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function isElementInAir(element)
function isElementInAir(element)
     local x, y, z = getElementPosition(element)
     assert(type(element) == 'userdata',('Expected element at argument 1, got %s!'):format(type(element)))
     if element then  
     if getElementType(element) == 'ped' then
         if z >= 10 then
         if isPedOnGround(element) or getPedContact(element) then return false end
          return z
         return true
         end
     end
     end
end
    if getElementType(element) == 'vehicle' then
</syntaxhighlight>
         if isVehicleOnGround(element) then return false end
 
<syntaxhighlight lang="lua">
function isElementInAir(element, ZPos)
    local x, y, z = getElementPosition(element)
    if element then  
         if z >= tonumber(ZPos) then
          return z
        end
     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 cAir()
addCommandHandler('air', function()
  if isElementInAir(localPlayer) then
    iprint(isElementInAir(localPlayer) and 'Indeed it is' or "Nope it's not")
      iprint("Indeed it is")
end)
  else
      iprint("Nope it's not")
  end
end
addCommandHandler("air", cAir)
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="lua">
function cAir2()
  if isElementInAir(localPlayer, 20) then
      iprint("Indeed it is")
  else
      iprint("Nope it's not")
  end
end
addCommandHandler("air2", cAir2)
</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 [-]
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