SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 11/06/2012, 01:44 PM   #1
MR_MAN
Little Clucker
 
Join Date: May 2008
Posts: 6
Reputation: 0
Default Can someone explain how this function works?

Basically I'm trying to send the players color as a hex value toa database, using a intTohex function to convert the integer value to hex!

Here is the function
Code:
#define IntToDual(%0) IntToBase(%0, 2)
#define IntToOctal(%0) IntToBase(%0, 8)
#define IntToHex(%0) IntToBase(%0, 16)
stock IntToBase(number, const base) {
    new str[32];
    if(1 < base < 37) {
        new
            m = 1,
            depth = 0;
        while (m <= number) {
            m *= base;
            depth++;
        }
        for ( ; (--depth) != -1; ) {
            str[depth] = (number % base);
            number = ((number - str[depth]) / base);
            if(str[depth] > 9) str[depth] += 'A'; else str[depth] += '0';
        }
    }
    return str;
}
And here is the code I'm using to send the value to the database
Code:
new string[128];
	format(string, sizeof(string), "INSERT INTO test (Name,Text,Color)  VALUES ('%s','%s','%x')", gPlayerName[playerid], text, IntToBase(GetPlayerColor(playerid)));
	mysql_query(string);
However I'm not getting the results I wanted... well none at all! Could someone explain how could I achieve this?
MR_MAN is offline   Reply With Quote
Old 11/06/2012, 01:46 PM   #2
Stevee
Little Clucker
 
Join Date: Feb 2012
Location: United Kingdom
Posts: 36
Reputation: 4
Default Re: Can someone explain how this function works?

Please wrap your code in [code ][/ code] tags (to avoid problems, such as a smiley appearing)
Stevee is offline   Reply With Quote
Old 11/06/2012, 01:47 PM   #3
Vince
High-roller
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 4,915
Reputation: 1424
Default Re: Can someone explain how this function works?

Sigh. Colors are numbers! Unless you intend to constantly peek and poke in the database manually, you should just save your colors as integers. You will end up with something like -16776961 for the color red, but that's absolutely fine.
__________________

Progress doesn't come from early risers — progress is made by lazy men looking for easier ways to do things.
Robert A. Heinlein
Vince is offline   Reply With Quote
Old 11/06/2012, 01:53 PM   #4
MR_MAN
Little Clucker
 
Join Date: May 2008
Posts: 6
Reputation: 0
Default Re: Can someone explain how this function works?

My problem is that I'm trying to use the values in the database to set the color of a html element, so I need it in a hex format!
MR_MAN is offline   Reply With Quote
Old 11/06/2012, 02:00 PM   #5
[NWA]Hannes
Huge Clucker
 
[NWA]Hannes's Avatar
 
Join Date: Jul 2010
Location: Oxelösund, Sweden
Posts: 270
Reputation: 9
Default Re: Can someone explain how this function works?

Quote:
Originally Posted by Vince View Post
Sigh. Colors are numbers! Unless you intend to constantly peek and poke in the database manually, you should just save your colors as integers. You will end up with something like -16776961 for the color red, but that's absolutely fine.
GetPlayerColor returns the colors as numbers like you said.

But how can I use those numbers if I for example want to colour a string or set a players color?
__________________
My old account is bajskorv123, I made a new one during the account reset a few years ago. Now in afterhand I see that bajskorv123 still exists, and I wish that I could merge my posts with it.
[NWA]Hannes 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
How can i explain this function? Artie_Scorpion Scripting Help 6 02/01/2012 05:04 PM
Can someone explain to me how params[] works? Placebo Help Archive 9 28/03/2011 09:15 AM
Can someone explain to me how this works... CT_Ronnie_Deo Help Archive 1 16/08/2010 10:20 PM
Can somebody explain the function SetPlayerVirtualWorld Rensy Help Archive 1 18/03/2010 07:51 PM
new public function, but only ID 0 works :( devil614 Help Archive 10 13/05/2009 02:29 PM


All times are GMT. The time now is 09:11 AM.


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