Color Embedding

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 22:06, 5 August 2012
Drebin (Talk | contribs)
(Examples)
← Previous diff
Revision as of 22:06, 5 August 2012
Drebin (Talk | contribs)
(Examples)
Next diff →
Line 42: Line 42:
</pawn> </pawn>
-A similar system can be used with [[TextDrawCreate|textdraws]], however is limited to only a few pre-set colors. See [[Colors|this page]] for more information.+A similar system can be used with [[TextDrawCreate|textdraws]].
== Using GetPlayerColor== == Using GetPlayerColor==

Revision as of 22:06, 5 August 2012

Image:32px-Ambox_warning_orange.png It has been suggested that this page or section be merged into Colors List. Discuss.

Color embedding was introduced in SA:MP 0.3c. It allows text in various features such as client messages and 3D text labels to use multiple colors with the use of hex codes enclosed in curly brackets. The format, {RRGGBB}, is similar to that of ordinary hexadecimal color values, but there is no alpha (transparency) value. You may use a color picker to easily find a color you like.


Contents


Color embedding is currently supported in:


Examples

SendClientMessage(playerid, -1, "Hello, and welcome to {00FF00}ASDASDFASFAS{FFFFFF}!");

'ASDASDFASFAS' will be green (00FF00) and the rest white (-1 and FFFFFF).


Another example:

SendClientMessage(playerid, -1, "Welcome to {00FF00}M{FFFFFF}a{FF0000}r{FFFFFF}c{00FF00}o{FFFFFF}'{FF0000}s\
{FFFFFF}B{00FF00}i{FFFFFF}s{FF0000}t{FFFFFF}r{00FF00}o{FFFFFF}!");

Turns into Image:cembed.png


You can also define colours on top of your script and then use them inside messages:

#define RED_EMBED "{FF0000}"
 
 
SendClientMessage(playerid, -1, "This is white"RED_EMBED" and this is red.");

A similar system can be used with textdraws.

Using GetPlayerColor

To use a player's color as an embedded color, you must first remove the alpha value. To do this, perform a logical right shift.

new msg[128];
format(msg, sizeof(msg), "{ffffff}This is white and {%06x}this is the player's color!", GetPlayerColor(playerid) >>> 8);
SendClientMessage(playerid, 0xffffffff, msg);

The %x is the placeholder for hexadecimal values, the 6 ensures that the output string will always be six characters long and the 0 will pad it with zeros if it's not. Note that GetPlayerColor only works properly if SetPlayerColor has been used beforehand.

See Also

Personal tools