Color help -
None1337 - 30.09.2018
So I have a string like: clanInfo[clanid][clanColor] = "FF0000"
and I want to make something like this:
PHP код:
SendClientMessage(playerid, 0xFF0000FF, "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?
Re: Color help -
d3Pedro - 30.09.2018
Код:
new string[64];
format(string, sizeof(string), "This is a {%06x}clan color", clanInfo[clanid][clanColor] >>> 8);
SendClientMessage(playerid, -1, string);
Re: Color help -
ReD_HunTeR - 30.09.2018
pawn Код:
stock GetClanColor(clanid)
{
new color;
color = clanInfo[clanid][clanColor];
color <<= 8;
color |= 0xFF;
return color;
}
try this, not sure if it works.
Re: Color help -
Calisthenics - 30.09.2018
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.
Re: Color help -
None1337 - 30.09.2018
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;
}
Re: Color help -
Calisthenics - 30.09.2018
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.
Re: Color help -
None1337 - 30.09.2018
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.