IsElementInWater: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| m (Dedicated to Talidan. <3) | No edit summary | ||
| (11 intermediate revisions by 8 users not shown) | |||
| Line 4: | Line 4: | ||
| ==Syntax== | ==Syntax== | ||
| <syntaxhighlight lang="lua">bool isElementInWater ( element theElement )</syntaxhighlight> | <syntaxhighlight lang="lua">bool isElementInWater ( element theElement )</syntaxhighlight> | ||
| {{OOP||[[element]]:isInWater|inWater}} | |||
| ===Required Arguments=== | ===Required Arguments=== | ||
| Line 12: | Line 12: | ||
| ===Returns=== | ===Returns=== | ||
| Returns ''true'' if the passed element is in water, ''false'' if it isn't, or if the element is invalid. | Returns ''true'' if the passed element is in water, ''false'' if it isn't, or if the element is invalid. | ||
| ==Example== | ==Example== | ||
| Line 19: | Line 18: | ||
| <syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
| function waterCheck( | function waterCheck(thePlayer) | ||
|      if isElementInWater( |      if isElementInWater(thePlayer) then | ||
|          outputChatBox("Wet.",  |          outputChatBox("Wet.", thePlayer) | ||
|      else |      else | ||
|          outputChatBox("Dry.",  |          outputChatBox("Dry.", thePlayer) | ||
|      end |      end | ||
| end | end | ||
| addCommandHandler("check", waterCheck) | addCommandHandler("check", waterCheck) | ||
| </syntaxhighlight> | |||
| </section> | |||
| Function which checks if player is in water, which is triggered when player dies. | |||
| <section name="Client" class="client" show="true"> | |||
| <syntaxhighlight lang="lua"> | |||
| 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) | |||
| </syntaxhighlight> | |||
| </section> | |||
| Function which checks if player is in water and then kills the player after 3 seconds. | |||
| <section name="Client" class="client" show="true"> | |||
| <syntaxhighlight lang="lua"> | |||
| addEventHandler ("onClientResourceStart", resourceRoot, | |||
| function() | |||
|     setTimer(function() | |||
|                 if isElementInWater( localPlayer ) then | |||
|                     setElementHealth( localPlayer, 0 ) | |||
|                  end | |||
|              end, | |||
|              3000, 0 ) | |||
| end | |||
| ) | |||
| </syntaxhighlight> | </syntaxhighlight> | ||
| </section> | </section> | ||
Latest revision as of 00:23, 18 April 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 [-]
Clientfunction 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)
Function which checks if player is in water and then kills the player after 3 seconds.
Click to collapse [-]
ClientaddEventHandler ("onClientResourceStart", resourceRoot,
function()
    setTimer(function()
                if isElementInWater( localPlayer ) then
                    setElementHealth( localPlayer, 0 )
                 end
             end,
             3000, 0 )
end
)
See Also
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement