OnColShapeHit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(17 intermediate revisions by 12 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This event is triggered when the player hits a [[colshape]].
{{Server event}}
{{Note|The hit won't be detected if the [[element]] that entered the colshape is a colshape.}}
This event is triggered when a physical [[element]] hits a [[colshape]].


==Syntax==  
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onColShapeHit ( element hitElement, bool matchingDimension
element hitElement, bool matchingDimension
</syntaxhighlight>  
</syntaxhighlight>  


==Parameters==
*The '''source''' of this event refers to the [[colshape]] which was hit by the player.
*'''hitElement''': the [[element]] that entered the colshape.
*'''hitElement''': the [[element]] that entered the colshape.
*'''matchingDimension''': a boolean referring to whether the hit collision shape was in the same dimension as the player.
*'''matchingDimension''': a [[boolean]] referring to whether the hit collision shape was in the same [[dimension]] as the element.
 
==Source==
The [[event system#Event source|source]] of this event is the [[colshape]] that got hit by a player or vehicle.


==Example==  
==Example==  
Line 16: Line 19:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- create our hill area for our gamemode
-- create our hill area for our gamemode
local hillArea = createColSquare ( -2171.0678710938, 678.17950439453, 0, 15, 15 )
local hillArea = createColRectangle ( -2171.0678710938, 678.17950439453, 15, 15 )


-- add hill_Enter as a handler for when a player enters the hill area
-- add hill_Enter as a handler for when a player enters the hill area
addEventHandler ( "onColShapeHit", hillArea, "hill_Enter" )
function hill_Enter ( thePlayer, matchingDimension )
function hill_Enter ( thePlayer, matchingDimension )
--announce to everyone that the player entered the hill
        if getElementType ( thePlayer ) == "player" then --if the element that entered was player
outputChatBox( getClientName(thePlayer).." entered the zone!", getRootElement(),255, 255, 109, )
                --let's get the name of the player
                local nameOfThePlayer = getPlayerName ( thePlayer )
        --announce to everyone that the player entered the hill
        outputChatBox ( nameOfThePlayer.." entered the zone!", getRootElement(), 255, 255, 109 )
        end
end
end
addEventHandler ( "onColShapeHit", hillArea, hill_Enter )


-- add hill_Enter as a handler for when a player leaves the hill area
-- add hill_Enter as a handler for when a player leaves the hill area
addEventHandler ( "onColShapeLeave", hillArea, "hill_Exit" )
function hill_Exit ( thePlayer, matchingDimension )
function hill_Exit ( thePlayer, matchingDimension )
--check if the player is not dead
        if getElementType ( thePlayer ) == "player" then --if the element that left was player
if isPlayerDead ( thePlayer ) ~= true then
        --check if the player is not dead
--if he was alive, announce to everyone that the player has left the hill
        if isPlayerDead ( thePlayer ) ~= true then
outputChatBox ( getClientName(thePlayer).." left the zone!", getRootElement(), 255, 255, 109 )
                        --let's get the name of the player
end
                        local nameOfThePlayer = getPlayerName ( thePlayer )
        --if he was alive, announce to everyone that the player has left the hill
        outputChatBox ( nameOfThePlayer.." left the zone!", getRootElement(), 255, 255, 109 )
        end
        end
end
end
addEventHandler ( "onColShapeLeave", hillArea, hill_Exit )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
{{See also/Server event|Colshape events}}
{{Event_functions}}

Revision as of 17:55, 30 September 2018

[[{{{image}}}|link=|]] Note: The hit won't be detected if the element that entered the colshape is a colshape.

This event is triggered when a physical element hits a colshape.

Parameters

element hitElement, bool matchingDimension
  • hitElement: the element that entered the colshape.
  • matchingDimension: a boolean referring to whether the hit collision shape was in the same dimension as the element.

Source

The source of this event is the colshape that got hit by a player or vehicle.

Example

This example creates a hill area for a King of the hill gamemode. When a player enters or leaves the area, it's announced in the chatbox.

-- create our hill area for our gamemode
local hillArea = createColRectangle ( -2171.0678710938, 678.17950439453, 15, 15 )

-- add hill_Enter as a handler for when a player enters the hill area
function hill_Enter ( thePlayer, matchingDimension )
        if getElementType ( thePlayer ) == "player" then --if the element that entered was player
                --let's get the name of the player
                local nameOfThePlayer = getPlayerName ( thePlayer )
	        --announce to everyone that the player entered the hill
	        outputChatBox ( nameOfThePlayer.." entered the zone!", getRootElement(), 255, 255, 109 )
        end
end
addEventHandler ( "onColShapeHit", hillArea, hill_Enter )

-- add hill_Enter as a handler for when a player leaves the hill area
function hill_Exit ( thePlayer, matchingDimension )
        if getElementType ( thePlayer ) == "player" then --if the element that left was player
	        --check if the player is not dead
	        if isPlayerDead ( thePlayer ) ~= true then
                        --let's get the name of the player
                        local nameOfThePlayer = getPlayerName ( thePlayer )
	        	--if he was alive, announce to everyone that the player has left the hill
	        	outputChatBox ( nameOfThePlayer.." left the zone!", getRootElement(), 255, 255, 109 )
	        end
        end
end
addEventHandler ( "onColShapeLeave", hillArea, hill_Exit )

See Also

Colshape events


Event functions