SA-MP Forums Archive
How would I go about setting a colour as a 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: How would I go about setting a colour as a string? (/showthread.php?tid=337085)



How would I go about setting a colour as a string? - 2KY - 24.04.2012

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?


Re: How would I go about setting a colour as a string? - iRage - 24.04.2012

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



Re: How would I go about setting a colour as a string? - 2KY - 24.04.2012

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)




Re: How would I go about setting a colour as a string? - Marco_Valentine - 24.04.2012

two people making this mistake..

just use:

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



Re: How would I go about setting a colour as a string? - 2KY - 24.04.2012

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.


Respuesta: How would I go about setting a colour as a string? - OPremium - 24.04.2012

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!


Re: Respuesta: How would I go about setting a colour as a string? - 2KY - 24.04.2012

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.