How would I go about setting a colour as a string?
#1

Inside of my user files, colours are saved like so;

Quote:

Colour = FFFFFF

So what I'm trying to do is..

pawn Код:
format( colStr, sizeof( colStr ), "0x%sFF", accInfo [ playerid ] [ Colour ] );
SetPlayerColor( playerid, colStr );
How would I go about doing this?
Reply
#2

You'll have to create an enum for accInfo.
PHP код:
enum playerenum
{
     
Colour
}
new 
accInfo[MAX_PLAYERS][playerenum]; 
Assign it a value.
PHP код:
accInfo[playerid][Colour] = FFFFFF 
Then the code you inserted would work perfectly.
PHP код:
new colStr[12];
formatcolStrsizeofcolStr ), "0x%sFF"accInfo playerid ] [ Colour ] );
SetPlayerColorplayeridcolStr ); 
Reply
#3

Quote:
Originally Posted by iRage
Посмотреть сообщение
You'll have to create an enum for accInfo.
PHP код:
enum playerenum
{
     
Colour
}
new 
accInfo[MAX_PLAYERS][playerenum]; 
Assign it a value.
PHP код:
accInfo[playerid][Colour] = FFFFFF 
Then the code you inserted would work perfectly.
PHP код:
new colStr[12];
formatcolStrsizeofcolStr ), "0x%sFF"accInfo playerid ] [ Colour ] );
SetPlayerColorplayeridcolStr ); 
I've got all of that, and that's EXACTLY what I have. You can't set a colour as a string like that.

Quote:

newmode.pwn(295) : error 035: argument type mismatch (argument 2)

Reply
#4

two people making this mistake..

just use:

Код:
SetPlayerColor( playerid, accInfo [ playerid ] [ Colour ] );
Reply
#5

Quote:
Originally Posted by Marco_Valentine
Посмотреть сообщение
two people making this mistake..

just use:

Код:
SetPlayerColor( playerid, accInfo [ playerid ] [ Colour ] );
I suppose I'll just modify my file-write to 0xFFFFFFFF rather than just FFFFFFF.
Reply
#6

Use sscanf or try hexstr by ******:

pawn Код:
stock hexstr(string[])
{
    new
        ret,
        val,
        i;
    if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X')) i = 2;
    while (string[i])
    {
        ret <<= 4;
        val = string[i++] - '0';
        if (val > 0x09) val -= 0x07;
        if (val > 0x0F) val -= 0x20;
        if (val < 0x01) continue;
        if (val < 0x10) ret += val;
    }
    return ret;
}
-------------------------------------------------------------------------------------------

Quote:
Originally Posted by 2KY
Посмотреть сообщение
Quote:
Originally Posted by Marco_Valentine
Посмотреть сообщение
two people making this mistake..

just use:

Код:
SetPlayerColor( playerid, accInfo [ playerid ] [ Colour ] );
I suppose I'll just modify my file-write to 0xFFFFFFFF rather than just FFFFFFF.
It would still be an string!
Reply
#7

Quote:
Originally Posted by OPremium
Посмотреть сообщение
Use sscanf or try hexstr by ******:

pawn Код:
stock hexstr(string[])
{
    new
        ret,
        val,
        i;
    if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X')) i = 2;
    while (string[i])
    {
        ret <<= 4;
        val = string[i++] - '0';
        if (val > 0x09) val -= 0x07;
        if (val > 0x0F) val -= 0x20;
        if (val < 0x01) continue;
        if (val < 0x10) ret += val;
    }
    return ret;
}
-------------------------------------------------------------------------------------------



It would still be an string!
Oddly enough it still works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)