IsElementInWater: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by 6 users not shown)
Line 4: Line 4:


==Syntax==
==Syntax==
<section name="Server and client" class="both" show="true">
<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.
</section>


==Example==
==Example==
Line 31: Line 30:
</section>
</section>


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


<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local deathMessage = { "Man over Board", "Wooops he failed into the water ?", "Wow im getting wet Honey", "He died in tha deep water" }
function diedInWater()
 
   if isElementInWater(source) then
function p_Water(playa)
       local name = source == localPlayer and "You are" or getPlayerName(source).." is"
   if isElementInWater(thePlayer) then
      outputChatBox(name.." sleeping with the fishies!")
       local ped_X, ped_Y, ped_Z = getElementPosition()
      if ped_Z then
            outputChatBox(math.random(1, #deathMessage), 194, 84, 68)
            outputChatBox("#FF0000"..getPlayerName(playa).."#FFFFFF you died "..ped_Z.." feet´s under the Water", 255, 255, 255, true)
      end
   end
   end
end
end
addEventHandler("onClientPlayerWasted", root, diedInWater)
</syntaxhighlight>
</section>
Function which checks if player is in water and then kills the player after 3 seconds.


addEventHandler("onClientPlayerWasted", getRootElement(), p_Water)
<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 [-]
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)

Function which checks if player is in water and then kills the player after 3 seconds.

Click to collapse [-]
Client
addEventHandler ("onClientResourceStart", resourceRoot,
function()
    setTimer(function()
                if isElementInWater( localPlayer ) then
                    setElementHealth( localPlayer, 0 )
                 end
             end,
             3000, 0 )
end
)

See Also