SA-MP Forums Archive
Number plate color - 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: Number plate color (/showthread.php?tid=532644)



Number plate color - FullCircle - 19.08.2014

Hello, I want to color only numbers in licence plate...
I tried this:

pawn Код:
format(string, sizeof(string), "%s", cInformacion[ID][cPatente]);
format(string2, sizeof(string2), "%s {FF0000}%d", string, cInformacion[ID][cPatente]);
But doesn't work, the letters are right, but the numbers no, help...
Thanks.


Re: Number plate color - Virtual1ty - 19.08.2014

This doesn't make any sense, why format two strings, and is "cPatente" a string, or an integer?


Re: Number plate color - Norrin - 19.08.2014

Are numbers at the beginning or the end?


Respuesta: Number plate color - FullCircle - 19.08.2014

The 'cPatente' is the number plate, Ex: "ASD123", the letters appears, but the numbers no, I used %d for only use the numbers with color


Re: Number plate color - Threshold - 20.08.2014

You are using cInformacion[ID][cPatente] as a string AND an integer...

pawn Код:
format(string2, sizeof(string2), "%s {FF0000}%03d", cInformacion[ID][cPatente], random(999));



Re: Number plate color - Virtual1ty - 20.08.2014

You can use strins() for this. Though there might be an optimised way of doing this by only looping through the string once and copying/modifying it at once. (I'm not sure about the "if" check though, seems alright to me)
pawn Код:
new insertAt = -1;
for (new i = 0; i < strlen(cInformacion[ID][cPatente]); i++)
{
    if ('0' <= cInformacion[ID][cPatente][i] <= '9')
    {
        insertAt = i;
        break;
    }
}
new string[32];
strcpy(string, cInformacion[ID][cPatente], 32);
if (insertAt != -1)
    strins(string, "{FF0000}", insertAt);



Re: Number plate color - Threshold - 20.08.2014

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
You can use strins() for this. Though there might be an optimised way of doing this by only looping through the string once and copying/modifying it at once. (I'm not sure about the "if" check though, seems alright to me)
pawn Код:
new insertAt = -1;
for (new i = 0; i < strlen(cInformacion[ID][cPatente]); i++)
{
    if ('0' <= cInformacion[ID][cPatente][i] <= '9')
    {
        insertAt = i;
        break;
    }
}
new string[32];
strcpy(string, cInformacion[ID][cPatente], 32);
if (insertAt != -1)
    strins(string, "{FF0000}", insertAt);
Why? 'format' is perfectly fine here...


Re: Number plate color - Virtual1ty - 20.08.2014

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Why? 'format' is perfectly fine here...
It is, but nowhere did the OP state that he wishes to use random numbers after the text, then your function would be suited, but the way I see it, he has it predefined and saved as the plate text, and he only wanted to color the number part.
Depends on what the OP wants, but I do agree with you on this Threshold.


Respuesta: Re: Number plate color - FullCircle - 20.08.2014

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
You can use strins() for this. Though there might be an optimised way of doing this by only looping through the string once and copying/modifying it at once. (I'm not sure about the "if" check though, seems alright to me)
pawn Код:
new insertAt = -1;
for (new i = 0; i < strlen(cInformacion[ID][cPatente]); i++)
{
    if ('0' <= cInformacion[ID][cPatente][i] <= '9')
    {
        insertAt = i;
        break;
    }
}
new string[32];
strcpy(string, cInformacion[ID][cPatente], 32);
if (insertAt != -1)
    strins(string, "{FF0000}", insertAt);
Thanks, I can use it...