IsElementInWater: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added OOP variable)
m (fix oop syntax)
Line 5: Line 5:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool isElementInWater ( element theElement )</syntaxhighlight>
<syntaxhighlight lang="lua">bool isElementInWater ( element theElement )</syntaxhighlight>
{{OOP|This function is also a static function underneath the Element class.|[[element]]:isInWater|inWater}}
{{OOP||[[element]]:isInWater|inWater}}


===Required Arguments===
===Required Arguments===

Revision as of 14:38, 1 January 2015

This function checks whether an element is submerged in water.

Syntax

bool isElementInWater ( element theElement )

OOP Syntax Help! I don't understand this!

Method: element:isInWater(...)
Variable: .inWater


Required Arguments

  • theElement: The element to check.

Returns

Returns true if the passed element is in water, false if it isn't, or if the element is invalid.

Example

Creates a command that checks if the player is in water or not.

Click to collapse [-]
Server

function waterCheck(thePlayer)
    if isElementInWater(thePlayer) then
        outputChatBox("Wet.", thePlayer)
    else
        outputChatBox("Dry.", thePlayer)
    end
end

addCommandHandler("check", waterCheck)

Function which checks if player is in water, which is triggered when player dies.

Click to collapse [-]
Client
function diedInWater()
   if isElementInWater(source) then
       local name = source == localPlayer and "You are" or getPlayerName(source).." is"
       outputChatBox(name.." sleeping with the fishies!")
   end
end
addEventHandler("onClientPlayerWasted", root, diedInWater)

See Also