HELP.. Data Mysql to var function -
Zafire1410 - 04.08.2010
Hi, i am scripting a roleplay gamemode.. i create a function to take data from mysql and store it in a variable but that doesnt works for me.. it supose to SendClientMessage "Your Sex: 2" but it said "Your Sex: 0".. here is my code..
Forward for the function
Код:
forward MysqlCargarDato(playerid, var[]);
I have this enum for the vars
Код:
enum playeri
{
id,
nombre[30],
pass[30],
cedula,
edad,
sexo,
nivel,
dinero,
trabajo,
lic1,
lic2,
lic3,
lic4,
lic5,
admin,
phone,
banco,
skin,
px,
py,
pz,
vida,
armor,
spawned
}
new pinfo[MAX_PLAYERS][playeri];
Here is OnPlayerSpawn foor SendClientMessage
Код:
public OnPlayerSpawn(playerid)
{
new texto[128];
SetPlayerInterior(playerid,0);
MysqlCargarDato(playerid, "sexo");
format(texto, sizeof(texto), "Your Sex: %i", pinfo[playerid][sexo]);
SendClientMessage(playerid, COLOR_LIGHTBLUE, texto);
return 1;
}
And now my mysql function..
Код:
public MysqlCargarDato(playerid, var[])
{
new variable[128];
new query[128];
new pnombre[MAX_PLAYER_NAME];
GetPlayerName(playerid, pnombre, sizeof(pnombre));
format(query, sizeof(query), "SELECT %s FROM `jugadores` WHERE nombre='%s'", var, pnombre);
format(variable, sizeof(variable), "pinfo[playerid][%s]", var);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(variable);
mysql_free_result();
}
I supose u will help me, thx a lot and bleess!!
Re: HELP.. Data Mysql to var function -
Zafire1410 - 05.08.2010
Please help me i need help
Re: HELP.. Data Mysql to var function -
Johndaonee - 05.08.2010
format(texto, sizeof(texto), "Your Sex: %s", pinfo[playerid][sexo]);
Change the %i to %s if the sexo is text, if its number then %d
Re: HELP.. Data Mysql to var function -
Zafire1410 - 05.08.2010
The Sex is number!!.. i need it sais "Your Sex: 2" because the sex is 2 in the mysql database.. but says "Your Sex: 0" i am using %d and if u use %i said the samething!!! "Your Sex: 0" :S
Re: HELP.. Data Mysql to var function -
Kar - 05.08.2010
pawn Код:
public OnPlayerSpawn(playerid)
{
new texto[128];
SetPlayerInterior(playerid,0);
MysqlCargarDato(playerid, "sexo");
format(texto, sizeof(texto), "Your Sex: %s", pinfo[playerid][sexo]);
SendClientMessage(playerid, COLOR_LIGHTBLUE, texto);
return 1;
}
Re: HELP.. Data Mysql to var function -
Zafire1410 - 05.08.2010
Thx but now it said "Your Sex: " nothing! that is because you sai i use %s and the var its a number and if i use %i or %d said "Your Sex: 0" :S i think the problem is in the function
Код:
public MysqlCargarDato(playerid, var[])
{
new variable[128];
new query[128];
new pnombre[MAX_PLAYER_NAME];
GetPlayerName(playerid, pnombre, sizeof(pnombre));
format(query, sizeof(query), "SELECT %s FROM `jugadores` WHERE nombre='%s'", var, pnombre);
format(variable, sizeof(variable), "pinfo[playerid][%s]", var);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(variable);
mysql_free_result();
}