|
|
#1 |
|
Little Clucker
![]() Join Date: May 2008
Posts: 6
Reputation: 0
|
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;
}
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);
|
|
|
|
|
|
#2 |
|
Little Clucker
![]() Join Date: Feb 2012
Location: United Kingdom
Posts: 36
Reputation: 4
|
Please wrap your code in [code ][/ code] tags (to avoid problems, such as a smiley appearing)
|
|
|
|
|
|
#3 |
|
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Sep 2007
Location: Belgium
Posts: 4,915
Reputation: 1424
|
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.
|
|
|
|
|
|
#4 |
|
Little Clucker
![]() Join Date: May 2008
Posts: 6
Reputation: 0
|
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!
|
|
|
|
|
|
#5 | |
|
Huge Clucker
![]() ![]() ![]() Join Date: Jul 2010
Location: Oxelösund, Sweden
Posts: 270
Reputation: 9
|
Quote:
But how can I use those numbers if I for example want to colour a string or set a players color? |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |