3dTextLabel colors
#1

Hello everyone i did a label command it works fine but i have problems sitting the color

i want it to be like example : /label {00FF00}This is green\n{FF0000}This is red

so if i entered this command the label should be like :

This is green
This is red

it works this way if i do it manually in gamemodint like this:

Код:
Create3DTextLabel("{00FF00}This is green\n{FF0000}This is red", 0xFFFFFFFF, 1350.1772,-1645.8958,13.5969, 15.0, 0, 0);
but it wont work when i enter same text with color codes with the command below:

Код:
CMD:label(playerid, params[])
{
	new string[49], Float:x, Float:y, Float:z;
	if(sscanf(params, "s[90]", string)) return SendClientMessage(playerid, -1, "/label text");

	GetPlayerPos(playerid, x, y, z);
	Create3DTextLabel(string, 0xFFFFFFFF, x, y, z, 40.0, 0, 0);
	return 1;
}
Reply
#2

Hex codes are automatically removed from player input in SA-MP 0.3(e?)+. If you try entering a hex code in SA-MP using the chatbox or a dialog, it will be automatically removed. You need to find an alternative that will replace your input with a hex code.

Example:
/label {red}This is red. {yellow}This is yellow.

Then you simply replace {red} with {FF0000} and {yellow} with {FFFF00}.
Reply
#3

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Hex codes are automatically removed from player input in SA-MP 0.3(e?)+. If you try entering a hex code in SA-MP using the chatbox or a dialog, it will be automatically removed. You need to find an alternative that will replace your input with a hex code.

Example:
/label {red}This is red. {yellow}This is yellow.

Then you simply replace {red} with {FF0000} and {yellow} with {FFFF00}.
i have tried to do what you said and did this:

Код:
#define RED {FF0000}
#define GREEN {00FF00}
but when i try to use command

/label GREENThis is green\nREDThis is red

then it shows as text
Reply
#4

guys i am still waiting for help
Reply
#5

any help guys i am stuck with this one its been long
Reply
#6

Код:
/label {GREEN}This is green{RED}This is red
is what he said... You still need the { }
Reply
#7

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Код:
/label {GREEN}This is green{RED}This is red
is what he said... You still need the { }
it does not compile when i add {} gives me error:
Код:
error 074: #define pattern must start with an alphabetic character
PHP код:
#define {RED} {FF0000}
#define {GREEN} {00FF00} 
Reply
#8

READ what was put up...


Код:
#define RED {FF0000}
#define GREEN {00FF00}
Quote:
Originally Posted by Threshold
Посмотреть сообщение
Example:
/label {RED}This is red. {YELLOW}This is yellow.
Reply
#9

Its still the same:

Reply
#10

Okay, first of all, use this function by Slice to replace the strings.

pawn Код:
stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) {
    // No need to do anything if the limit is 0.
    if (limit == 0)
        return 0;
   
    new
             sublen = strlen(search),
             replen = strlen(replacement),
        bool:packed = ispacked(string),
             maxlen = maxlength,
             len = strlen(string),
             count = 0
    ;
   
   
    // "maxlen" holds the max string length (not to be confused with "maxlength", which holds the max. array size).
    // Since packed strings hold 4 characters per array slot, we multiply "maxlen" by 4.
    if (packed)
        maxlen *= 4;
   
    // If the length of the substring is 0, we have nothing to look for..
    if (!sublen)
        return 0;
   
    // In this line we both assign the return value from "strfind" to "pos" then check if it's -1.
    while (-1 != (pos = strfind(string, search, ignorecase, pos))) {
        // Delete the string we found
        strdel(string, pos, pos + sublen);
       
        len -= sublen;
       
        // If there's anything to put as replacement, insert it. Make sure there's enough room first.
        if (replen && len + replen < maxlen) {
            strins(string, replacement, pos, maxlength);
           
            pos += replen;
            len += replen;
        }
       
        // Is there a limit of number of replacements, if so, did we break it?
        if (limit != -1 && ++count >= limit)
            break;
    }
   
    return count;
}
This should be placed on top of your script somewhere, above any callbacks.

Once you've done that, you can create your color conversion function, which will convert text like "{RED}", "{BLUE}", "{YELLOW}" etc. to their respective hex codes: "{FF0000}", "{0000FF}" etc.

Unfortunately, there is no way to do this using SA-MP native functions, but we can make our own.
pawn Код:
ConvertColors(input[144])
{
    strreplace(input, "{RED}", "{FF0000}", true);
    strreplace(input, "{GREEN}", "{00FF00}", true);
    strreplace(input, "{YELLOW}", "{FFFF00}", true);
    strreplace(input, "{BLUE}", "{0000FF}", true);
    strreplace(input, "{WHITE}", "{FFFFFF}", true);
    return input;
}
This is the simplest way of doing it.
This function will basically replace every instance of {RED} with {FF0000}. Why do we use {RED} instead of RED? Well, if a player wants to create a label that says: "My favourite color is red.", then the string will end up saying "My favourite color is .". By adding the parenthesis, we can safely assume that they definitely want the color to be changed to red.

Now our /label command:
pawn Код:
CMD:label(playerid, params[])
{
    if(!strlen(params)) return SendClientMessage(playerid, -1, "/label text");
    new Float:x, Float:y, Float:z, string[144];
    strcat(string, params);
    format(string, sizeof(string), "%s", ConvertColors(string));
    GetPlayerPos(playerid, x, y, z);
    Create3DTextLabel(string, 0xFFFFFFFF, x, y, z, 40.0, 0, 0);
    return 1;
}
This doesn't require sscanf for this part, because you only want a string parameter, for which you can just use the 'params' given to you by zcmd.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)