Number plate color
#1

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

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

Are numbers at the beginning or the end?
Reply
#4

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
Reply
#5

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));
Reply
#6

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);
Reply
#7

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)