MySQL Problem - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: MySQL Problem (
/showthread.php?tid=275842)
MySQL Problem -
EviLpRo - 11.08.2011
hello everyone
have me small problem with mysql.
i need return the clan color, and convert to rgba colors,
but the problem its is:
the stock:
pawn Код:
stock GetClanColorName(const clanname[])
{
new szResult[256],Arg[3][70],Info[256];
format(szResult,256,"SELECT `Color` FROM `Clans` WHERE `Name`='%s'",clanname);
mysql_query(szResult);
mysql_store_result();
if(mysql_retrieve_row()) mysql_fetch_row_format(Info,"|");
mysql_free_result();
split(Info,Arg,',');
print(Info);
return rgba2hex(strval(Arg[0]),strval(Arg[1]),strval(Arg[2]));
}
the clan color save in mysql table like this:
101,
252,
11
101 - R
252 - G
11 - B
rgba2hex stock:
pawn Код:
stock rgba2hex(r,g,b,a=255) return (r*16777216) + (g*65536) + (b*256) + a;
split public:
pawn Код:
public split(const strsrc[], strdest[][], delimiter)
{
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc)){
if(strsrc[i]==delimiter || i==strlen(strsrc)){
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
the color everytime its black...
thank in advance to helpers
Re: MySQL Problem -
MadeMan - 11.08.2011
Try removing mysql_retrieve_row()
pawn Код:
stock GetClanColorName(const clanname[])
{
new szResult[256],Arg[3][70],Info[256];
format(szResult,256,"SELECT `Color` FROM `Clans` WHERE `Name`='%s'",clanname);
mysql_query(szResult);
mysql_store_result();
mysql_fetch_row_format(Info,"|");
mysql_free_result();
split(Info,Arg,',');
print(Info);
return rgba2hex(strval(Arg[0]),strval(Arg[1]),strval(Arg[2]));
}
Re: MySQL Problem -
XGh0stz - 11.08.2011
Код:
stock HexToInteger(String[])
{ if(String[0]==0)
{ return 0;}
new Result;
new Current;
Current=1;
new Loop;
for(Loop=strlen(String);Loop>0;Loop--)
{ if(String[Loop-1]<58)
{ Result=Result+Current*(String[Loop-1]-48);}
else
{ Result=Result+Current*(String[Loop-1]-65+10);}
Current=Current*16;}
return Result;}
This may or may not be of some assistance, but it's an alternative way I personally use to store colors:
For example, when I need to retrieve a saved color from a simple string, I convert using the above function
Код:
SetPlayerColor(playerid,HexToInteger(String));
I didn't create the function, but found it somewhere on SA-MP and decided to share
Re: MySQL Problem -
EviLpRo - 11.08.2011
Quote:
Originally Posted by MadeMan
Try removing mysql_retrieve_row()
pawn Код:
stock GetClanColorName(const clanname[]) { new szResult[256],Arg[3][70],Info[256]; format(szResult,256,"SELECT `Color` FROM `Clans` WHERE `Name`='%s'",clanname); mysql_query(szResult); mysql_store_result(); mysql_fetch_row_format(Info,"|"); mysql_free_result(); split(Info,Arg,','); print(Info); return rgba2hex(strval(Arg[0]),strval(Arg[1]),strval(Arg[2])); }
|
thank's you very much man