OnColShapeHit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 8: Line 8:


==Parameters==
==Parameters==
* The source of this event refers to the col shape which was hit by a player
*The '''source''' of this event refers to the [[colshape]] which was hit by the player.
*'''thePlayer''': A player element referring to the player who entered the col shape.
*'''thePlayer''': a [[player]] element referring to the player who entered the colshape.
*'''matchingDimension''': A boolean referring to whether the collision shape was hit in the correct dimension.
*'''matchingDimension''': a boolean referring to whether the hit collision shape was in the same dimension as the player.


==Example==  
==Example==  
This example creates a hill area for a king of the hill gamemode.  When a player enters the area, it announces it in the chatbox.
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.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
hillArea = createColSquare ( -2171.0678710938, 678.17950439453, 0, 15, 15 ) --create our hill area for our gamemode
-- create our hill area for our gamemode
local hillArea = createColSquare ( -2171.0678710938, 678.17950439453, 0, 15, 15 )


addEventHandler ( "onColShapeHit", hillArea, "hill_Enter" ) -- add an event handler for onConsole
-- add hill_Enter as a handler for when a player enters the hill area
function hill_Enter ( thePlayer, matchingDimension )   --when a player enters the hill area
addEventHandler ( "onColShapeHit", hillArea, "hill_Enter" )
    outputChatBox( getClientName(thePlayer).." entered the zone!", getRootElement(),255, 255, 109, ) --announce to everyone that the player entered the hill
function hill_Enter ( thePlayer, matchingDimension )
--announce to everyone that the player entered the hill
outputChatBox( getClientName(thePlayer).." entered the zone!", getRootElement(),255, 255, 109, )
end
end


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

Revision as of 19:40, 22 April 2007

This event is triggered when the player hits a colshape.

Syntax

void onColShapeHit ( player thePlayer, bool matchingDimension )  

Parameters

  • The source of this event refers to the colshape which was hit by the player.
  • thePlayer: a player element referring to the player who entered the colshape.
  • matchingDimension: a boolean referring to whether the hit collision shape was in the same dimension as the player.

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 = createColSquare ( -2171.0678710938, 678.17950439453, 0, 15, 15 )

-- add hill_Enter as a handler for when a player enters the hill area
addEventHandler ( "onColShapeHit", hillArea, "hill_Enter" )
function hill_Enter ( thePlayer, matchingDimension )
	--announce to everyone that the player entered the hill
	outputChatBox( getClientName(thePlayer).." entered the zone!", getRootElement(),255, 255, 109, )
end

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

See Also