GetMarkerColor: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Fixed syntax, added templates and sections, removed broken example)
(Added useful example)
Line 17: Line 17:


==Example==
==Example==
This example does
<section name="Serverside example" class="server" show="true">
This example script fully heals players who hit a white marker, and kills players who hit a red one.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
...
-- we define the function that will determine if the player is to be healed or killed
function healOrKill ( hitMarker, matchingDimension )
-- if the marker was in a different dimension, stop here to ignore the event
if not matchingDimension then
return
end
-- get the marker's color
local R, G, B, A = getMarkerColor( hitMarker )
-- if its RGB color is 255,255,255 (white),
if R == 255 and G == 255 and B == 255 then
-- heal the player
setPlayerHealth( source, 100 )
-- if it isn't white, but 255,0,0 (red),
elseif R == 255 and G == 0 and B == 0 then
-- kill the player
killPlayer( source )
end
end
-- add our function as a handler to "onPlayerMarkerHit"
addEventHandler( "onPlayerMarkerHit", getRootElement(), healOrKill )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Marker functions}}
{{Marker functions}}

Revision as of 22:43, 4 August 2007

This function returns the color and transparency for a marker element.

Syntax

Click to collapse [-]
Server and Client
int int int int getMarkerColor ( marker theMarker )

Required Arguments

  • theMarker: The marker that you wish to retrieve the color of.

Returns

Returns four ints corresponding to the amount of red, green, blue and alpha (respectively) of the marker, false if invalid arguments were passed.

Example

Click to collapse [-]
Serverside example

This example script fully heals players who hit a white marker, and kills players who hit a red one.

-- we define the function that will determine if the player is to be healed or killed
function healOrKill ( hitMarker, matchingDimension )
	-- if the marker was in a different dimension, stop here to ignore the event
	if not matchingDimension then
		return
	end
	-- get the marker's color
	local R, G, B, A = getMarkerColor( hitMarker )
	-- if its RGB color is 255,255,255 (white),
	if R == 255 and G == 255 and B == 255 then
		-- heal the player
		setPlayerHealth( source, 100 )
	-- if it isn't white, but 255,0,0 (red),
	elseif R == 255 and G == 0 and B == 0 then
		-- kill the player
		killPlayer( source )
	end
end
-- add our function as a handler to "onPlayerMarkerHit"
addEventHandler( "onPlayerMarkerHit", getRootElement(), healOrKill )

See Also