Color in a format string - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Color in a format string (
/showthread.php?tid=589479)
Color in a format string -
morris91 - 19.09.2015
Hey guys i have a little problem and wondering if anyone can help me.
I have a achievement script which in my dialog i use %s to show if the achievement as been achieved or not. but i would like this to be red if not achieved and green if achieved
pawn Код:
if(GetPVarInt(id, string) == 0)
{
format(string2, sizeof(string2), "Not Completed");
}
if(GetPVarInt(id, string) == 1)
{
format(string2, sizeof(string2), "Completed");
}
I was wondering in my gm when i do a string like "Parkour Master: %s" it will say be green if achieved and red if not.
Hope i made this clear. Thanks in advance.
Re: Color in a format string -
jlalt - 19.09.2015
PHP код:
if(GetPVarInt(id, string) == 0)
{
format(string2, sizeof(string2), "{FF000}Not Completed");
}
if(GetPVarInt(id, string) == 1)
{
format(string2, sizeof(string2), "{33FF33}Completed");
}
Re: Color in a format string -
Vince - 19.09.2015
Do not use format to copy strings. It's terribly slow. Besides, it looks like "string2" is just a normal array, in which case you should be able to do only this:
PHP код:
string2 = (GetPVarInt(id, string)) ? ("{33FF33}Completed") : ("{FF3333}Not Completed");
Re: Color in a format string -
xVIP3Rx - 20.09.2015
You could also, for a little memory optimization(I think), get rid of "string2" and put
pawn Код:
(GetPVarInt(id, string)) ? ("{33FF33}Completed") : ("{FF3333}Not Completed")
right where you use the string2
example:
pawn Код:
//instead of
new string[x];
string = (GetPVarInt(id, string)) ? ("{33FF33}Completed") : ("{FF3333}Not Completed");
SendClientMessage(playerid, -1, string);
//do
SendClientMessage(playerid, -1, (GetPVarInt(id, string)) ? ("{33FF33}Completed") : ("{FF3333}Not Completed"));
Its a little better (In my option) as it takes less space and doesn't use that "little" heap size, but if you're using the value twice I think using a string will be better, as you don't have to get the value twice..