Color help
#1

So I have a string like: clanInfo[clanid][clanColor] = "FF0000"

and I want to make something like this:

PHP код:
SendClientMessage(playerid0xFF0000FF"This is the clan color"); 
But i don't know how to make the color in the variable to be something like this: 0xFF0000FF

I've tried something like this, but it doesn't work

pawn Код:
stock getClanColor(clanid) {
    new str[10];
    format(str, sizeof str, "0x%sFF", clanInfo[clanid][clanColor]);
    return str;
}

// using:

SendClientMessage(playerid, getClanColor(player_clan), "This is the clan color!");
Can someone help me?
Reply
#2

Код:
new string[64];
format(string, sizeof(string), "This is a {%06x}clan color", clanInfo[clanid][clanColor] >>> 8);
SendClientMessage(playerid, -1, string);
Reply
#3

pawn Код:
stock GetClanColor(clanid)
{
    new color;
    color = clanInfo[clanid][clanColor];
    color <<= 8;
    color |= 0xFF;
    return color;
}
try this, not sure if it works.
Reply
#4

Do not use strings for storing colors. Colors ARE integers!

When a player types the desired clan color: FF0000
Use sscanf and "x" specifier to retrieve integer and store it in the integer clanColor (get rid of the array size). You can limit text to 6 characters if you want to.

Then you can use partially what ConnorW posted but without `>>> 8` as the color will not have an alpha value.
Reply
#5

Quote:
Originally Posted by ConnorW
Посмотреть сообщение
Код:
new string[64];
format(string, sizeof(string), "This is a {%06x}clan color", clanInfo[clanid][clanColor] >>> 8);
SendClientMessage(playerid, -1, string);
I didn't ask that. I want to put the color instead of -1, like SendClientMessage(playerid, getClanColor(clanid), string);

Quote:
Originally Posted by ReD_HunTeR
Посмотреть сообщение
pawn Код:
stock GetClanColor(clanid)
{
    new color;
    color = clanInfo[clanid][clanColor];
    color <<= 8;
    color |= 0xFF;
    return color;
}
try this, not sure if it works.
it doesn't work, the color is black always....

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
Do not use strings for storing colors. Colors ARE integers!

When a player types the desired clan color: FF0000
Use sscanf and "x" specifier to retrieve integer and store it in the integer clanColor (get rid of the array size). You can limit text to 6 characters if you want to.

Then you can use partially what ConnorW posted but without `>>> 8` as the color will not have an alpha value.
I've tried something like this, and it doesn't work.

pawn Код:
stock getClanColor(clanid) {
    new color_show = 0xFFFFFFFF;
    sscanf(clanInfo[clanid][clanColor], "x", color_show);
    return color_show;
}
Reply
#6

A player is asked to set a color for the clan. They type: FF0000
You retrieve it and store it as integer:
pawn Код:
// example:
new new_color;

if (strlen(inputtext) == 6 && !sscanf(inputtext, "x", new_color))
{
    // Assign to `clanColor`
    .. = (new_color << 8) | 0xFF;
}
else error..
Now you have an integer color with a full alpha and you can use it directly to the client message:
pawn Код:
SendClientMessage(playerid, clanInfo[clanid][clanColor], "This is the clan color");
Or you want to embed the color only for some part of the text:
pawn Код:
// example:
format(string, sizeof string, "A new gang {%06x}%s {FFFFFF}has been created.", new_clan_color >>> 8, new_clan_name);
SendClientMessage(playerid, -1, string);
The text will be all in white color except the clan name which will be in the clan color.
Reply
#7

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
A player is asked to set a color for the clan. They type: FF0000
You retrieve it and store it as integer:
pawn Код:
// example:
new new_color;

if (strlen(inputtext) == 6 && !sscanf(inputtext, "x", new_color))
{
    // Assign to `clanColor`
    .. = (new_color << 8) | 0xFF;
}
else error..
Now you have an integer color with a full alpha and you can use it directly to the client message:
pawn Код:
SendClientMessage(playerid, clanInfo[clanid][clanColor], "This is the clan color");
Or you want to embed the color only for some part of the text:
pawn Код:
// example:
format(string, sizeof string, "A new gang {%06x}%s {FFFFFF}has been created.", new_clan_color >>> 8, new_clan_name);
SendClientMessage(playerid, -1, string);
The text will be all in white color except the clan name which will be in the clan color.
it doesn't work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)