SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 24/04/2012, 10:35 PM   #1
2KY
Gangsta
 
2KY's Avatar
 
Join Date: Jan 2012
Location: United States
Posts: 950
Reputation: 166
Default How would I go about setting a colour as a string?

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

Quote:
Colour = FFFFFF
So what I'm trying to do is..

pawn Code:
format( colStr, sizeof( colStr ), "0x%sFF", accInfo [ playerid ] [ Colour ] );
SetPlayerColor( playerid, colStr );

How would I go about doing this?
__________________
Check out my wiki page
2KY is offline   Reply With Quote
Old 24/04/2012, 10:47 PM   #2
iRage
Huge Clucker
 
iRage's Avatar
 
Join Date: Aug 2011
Posts: 232
Reputation: 44
Default Re: How would I go about setting a colour as a string?

You'll have to create an enum for accInfo.
PHP Code:
enum playerenum
{
     
Colour
}
new 
accInfo[MAX_PLAYERS][playerenum]; 
Assign it a value.
PHP Code:
accInfo[playerid][Colour] = FFFFFF 
Then the code you inserted would work perfectly.
PHP Code:
new colStr[12];
formatcolStrsizeofcolStr ), "0x%sFF"accInfo playerid ] [ Colour ] );
SetPlayerColorplayeridcolStr ); 
__________________
Quote:
Originally Posted by iRage - My Releases

[GM] zGaming Roleplay [Scratch GM]
[FS] FireHell
[FS] Anti-AmmoHack
iRage is offline   Reply With Quote
Old 24/04/2012, 10:52 PM   #3
2KY
Gangsta
 
2KY's Avatar
 
Join Date: Jan 2012
Location: United States
Posts: 950
Reputation: 166
Default Re: How would I go about setting a colour as a string?

Quote:
Originally Posted by iRage View Post
You'll have to create an enum for accInfo.
PHP Code:
enum playerenum
{
     
Colour
}
new 
accInfo[MAX_PLAYERS][playerenum]; 
Assign it a value.
PHP Code:
accInfo[playerid][Colour] = FFFFFF 
Then the code you inserted would work perfectly.
PHP Code:
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)
__________________
Check out my wiki page
2KY is offline   Reply With Quote
Old 24/04/2012, 10:56 PM   #4
Marco_Valentine
Huge Clucker
 
Join Date: Apr 2011
Location: South, Australia
Posts: 211
Reputation: 29
Default Re: How would I go about setting a colour as a string?

two people making this mistake..

just use:

Code:
SetPlayerColor( playerid, accInfo [ playerid ] [ Colour ] );
__________________
If I have helped you, Please +Rep me . Just hit the black star under my name. Thanks
Marco_Valentine is offline   Reply With Quote
Old 24/04/2012, 11:09 PM   #5
2KY
Gangsta
 
2KY's Avatar
 
Join Date: Jan 2012
Location: United States
Posts: 950
Reputation: 166
Default Re: How would I go about setting a colour as a string?

Quote:
Originally Posted by Marco_Valentine View Post
two people making this mistake..

just use:

Code:
SetPlayerColor( playerid, accInfo [ playerid ] [ Colour ] );
I suppose I'll just modify my file-write to 0xFFFFFFFF rather than just FFFFFFF.
__________________
Check out my wiki page
2KY is offline   Reply With Quote
Old 24/04/2012, 11:22 PM   #6
OPremium
Big Clucker
 
OPremium's Avatar
 
Join Date: Oct 2010
Posts: 153
Reputation: 59
Default Respuesta: How would I go about setting a colour as a string?

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

pawn Code:
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 View Post
Quote:
Originally Posted by Marco_Valentine View Post
two people making this mistake..

just use:

Code:
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!
OPremium is offline   Reply With Quote
Old 24/04/2012, 11:33 PM   #7
2KY
Gangsta
 
2KY's Avatar
 
Join Date: Jan 2012
Location: United States
Posts: 950
Reputation: 166
Default Re: Respuesta: How would I go about setting a colour as a string?

Quote:
Originally Posted by OPremium View Post
Use sscanf or try hexstr by ******:

pawn Code:
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.
__________________
Check out my wiki page
2KY is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[HELP]Colour string does not appear... TheBluec0de Help Archive 0 23/08/2011 06:02 PM
Editing admins colour ( duty colour ) Chivava Help Archive 7 01/07/2011 03:38 PM
Houw to Change [OOC chat colour and IC chat colour] help please Karl115 Help Archive 5 27/05/2010 08:39 PM
Setting String Depending On Float (I think?) NeRoSiS Help Archive 5 07/06/2009 11:49 AM


All times are GMT. The time now is 02:48 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.