IsElementWithinColShape: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Corrected addEventHandler call)
Line 15: Line 15:
This small script is an example of detecting if a player is within a certain defined colshape. This could serve as a base to perform many functions, rather than just an output.
This small script is an example of detecting if a player is within a certain defined colshape. This could serve as a base to perform many functions, rather than just an output.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onColShapeHit", getRootElement(), "ColShapeHit" )
function ColShapeHit ( player, matchingDimension )
function ColShapeHit ( player, matchingDimension )
detection = isElementWithinColShape ( player, circlearea )
detection = isElementWithinColShape ( player, circlearea )
--A varible called 'detection' stores the result of asking if the player
--A variable called 'detection' stores the result of asking if the player
--who entered a colshape is within the specific colshape called 'circlearea'.
--who entered a colshape is within the specific colshape called 'circlearea'.
--The result is either true or false.
--The result is either true or false.
if detection == true then
if detection == true then
outputChatBox ( "Player is in the 'circle area' col shape" )
outputChatBox ( "Player is in the 'circle area' col shape" )
end
end
--if detection was true then the player is in the col shape. Output a
--if detection was true then the player is in the col shape. Output a
--message to confirm this
--message to confirm this
end
end
addEventHandler ( "onColShapeHit", getRootElement(), ColShapeHit )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{element functions}}
{{element functions}}

Revision as of 15:05, 15 August 2007

This function is used to tell if an element is within a collision shape.

Syntax

bool isElementWithinColShape ( element theElement, colshape theShape )

Required Arguments

  • theElement: The element you're checking.
  • theShape: The colshape you're checking

Returns

Returns true if the element is within the colshape, false otherwise

Example

This small script is an example of detecting if a player is within a certain defined colshape. This could serve as a base to perform many functions, rather than just an output.

function ColShapeHit ( player, matchingDimension )
	detection = isElementWithinColShape ( player, circlearea )
	--A variable called 'detection' stores the result of asking if the player
	--who entered a colshape is within the specific colshape called 'circlearea'.
	--The result is either true or false.
	if detection == true then
		outputChatBox ( "Player is in the 'circle area' col shape" )
	end
	--if detection was true then the player is in the col shape. Output a
	--message to confirm this
end
addEventHandler ( "onColShapeHit", getRootElement(), ColShapeHit )

See Also