Color in a format string
#1

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.
Reply
#2

PHP код:
if(GetPVarInt(idstring) == 0)
        {
            
format(string2sizeof(string2), "{FF000}Not Completed");
        }
        if(
GetPVarInt(idstring) == 1)
        {
            
format(string2sizeof(string2), "{33FF33}Completed");
        } 
Reply
#3

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(idstring)) ? ("{33FF33}Completed") : ("{FF3333}Not Completed"); 
Reply
#4

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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)