GetMarkerColor: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(15 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function returns three [[int]]s corresponding to the amount of red, green and blue (respectively) in the marker's color. It can be useful for coloring objectives text to the same color as the marker.
{{Server client function}}
This function returns the color and transparency for a marker element.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">int int int getMarkerColor ( marker myMarker )</syntaxhighlight>
<syntaxhighlight lang="lua">
 
int, int, int, int getMarkerColor ( marker theMarker )
This function also has three variants that allow you to retrieve data from just one of the three axes.
</syntaxhighlight>
 
{{OOP||[[Marker]]:getColor||setMarkerColor}}
<syntaxhighlight lang="lua">int getMarkerColor|getMarkerColorRed ( marker myMarker )</syntaxhighlight>
 
<syntaxhighlight lang="lua">int getMarkerColor|getMarkerColorGreen ( marker myMarker )</syntaxhighlight>
 
<syntaxhighlight lang="lua">int getMarkerColor|getMarkerColorBlue ( marker myMarker )</syntaxhighlight>
 
===Required Arguments===
===Required Arguments===
*'''marker''': The [[marker]] that you wish to retrieve the color of.
*'''theMarker''': The [[marker]] that you wish to retrieve the color of.


===Returns===
===Returns===
Returns three [[int]]s corresponding to the amount of red, green and blue (respectively) in the marker's color.
Returns four [[int]]s corresponding to the amount of ''red'', ''green'', ''blue'' and ''alpha'' (respectively) of the marker, ''false'' if invalid arguments were passed.


==Example==
==Example==
<syntaxhighlight lang="lua">newMarker = createMarker ( 1, 1000, 1000, 1000, 1,0,0 )
<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.
r,g,b = getMarkerColor ( newmarker )
<syntaxhighlight lang="lua">
if (r) then
-- we define the function that will determine if the player is to be healed or killed
  OutputChatBox ( ("Current marker color: ",r,",",g,",",b,"."), player )
function healOrKill ( hitMarker, matchingDimension )
end</syntaxhighlight>
-- 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
setElementHealth( 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
killPed( source )
end
end
-- add our function as a handler to "onPlayerMarkerHit"
addEventHandler( "onPlayerMarkerHit", root, healOrKill )
</syntaxhighlight>
</section>
 
==See Also==
{{Marker functions}}

Latest revision as of 19:22, 15 July 2024

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

Syntax

int, int, int, int getMarkerColor ( marker theMarker )

OOP Syntax Help! I don't understand this!

Method: Marker:getColor(...)
Counterpart: setMarkerColor


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
		setElementHealth( 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
		killPed( source )
	end
end
-- add our function as a handler to "onPlayerMarkerHit"
addEventHandler( "onPlayerMarkerHit", root, healOrKill )

See Also