MySQL saving/loading.
#1

Hey,

I am trying to learn MySQL.
But im stuck at the saving and loading part. Somehow, the stats don't save/load.
Cause I'm new with SQL, im sure i made a very basic mistake. Can anyone look to this code's and help me?

Код:
public SavePlayerStats(playerid)
{
    new Float:hp;
    new Float:am;
    new Float:saveX, Float:saveY, Float:saveZ;
    GetPlayerName(playerid, pname, sizeof (pname));
    GetPlayerIp(playerid, ip, 16);
	GetPlayerHealth(playerid,hp);
	GetPlayerArmour(playerid,am);
	GetPlayerPos(playerid, saveX, saveY, saveZ);
	pInfo[playerid][money] = GetPlayerMoneyEx(playerid);
	SaveWeaponsToFile(playerid);
	format(file, sizeof file,"UPDATE `users` SET `money` = '%d', `kills` = '%d', `deaths` = '%d', `adminlevel` = '%d', `license` = '%d', `job` = '%d', WHERE `username` = '%s'",pInfo[playerid][money],pInfo[playerid][kills],pInfo[playerid][deaths],pInfo[playerid][adminlevel],pInfo[playerid][license],pInfo[playerid][job],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `weaponlicense` = '%d', `flyinglicense` = '%d', `bankmoney` = '%d', `skin` = '%d', `fightstyle` = '%d', `beer` = '%d', `cigarets` = '%d', `chainlock` = '%d', `sprunk` = '%d', WHERE `username` = '%s'",pInfo[playerid][weaponlic],pInfo[playerid][flylic],pInfo[playerid][bankmoney],pInfo[playerid][skin],pInfo[playerid][fightstyle],pInfo[playerid][beer],pInfo[playerid][cigarets],pInfo[playerid][chainlock],pInfo[playerid][sprunk],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `health` = '%f' WHERE `username` = '%s'",floatround(hp),pname);
	if(hp != 0.0) mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `armour` = '%f' WHERE `username` = '%s'",floatround(am),pname);
	if(am != 0.0) mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `spawnX` = '%0.3f' WHERE `username` = '%s'",saveX,pname);
	if(saveX != 0.0) mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `spawnY` = '%0.3f' WHERE `username` = '%s'",saveY,pname);
	if(saveY != 0.0) mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `spawnZ` = '%0.3f' WHERE `username` = '%s'",saveZ,pname);
	if(saveZ != 0.0) mysql_query(file);
	//-
	format(file, sizeof file,"UPDATE `users` SET `cellphone` = '%d' WHERE `username` = '%s'",pInfo[playerid][havephone],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `weed` = '%d' WHERE `username` = '%s'",pInfo[playerid][weed],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `seeds` = '%d' WHERE `username` = '%s'",pInfo[playerid][seeds],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `prepaid` = '%d' WHERE `username` = '%s'",pInfo[playerid][prepaid],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `jerrycan` = '%d' WHERE `username` = '%s'",pInfo[playerid][jerrycan],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `dlock` = '%d' WHERE `username` = '%s'",pInfo[playerid][dlock],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `gps` = '%d' WHERE `username` = '%s'",pInfo[playerid][GPS],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `warns` = '%d' WHERE `username` = '%s'",pInfo[playerid][warns],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `vip` = '%d' WHERE `username` = '%s'",pInfo[playerid][VIP],pname);
	mysql_query(file);
	format(file, sizeof file,"UPDATE `users` SET `ip adress` = '%s' WHERE `username` = '%s'",ip,pname);
	mysql_query(file);
    SavePlayerFactionInfo(playerid);
	//print("SavePlayerStats Called!");
}

public LoadPlayerStats(playerid)
{
    new Float:POS[3];
    GetPlayerName(playerid, pname, sizeof (pname));
    format(file, sizeof file,"SELECT `money` FROM `users` WHERE `username` = '%s'",pname);
    pInfo[playerid][money] = mysql_query(file);
    format(file, sizeof file,"SELECT `license` FROM `users` WHERE `username` = '%s'",pname);
    pInfo[playerid][license]  = mysql_query(file);
    format(file, sizeof file,"SELECT `weaponlicense` FROM `users` WHERE `username` = '%s'", pname);
    pInfo[playerid][weaponlic]  = mysql_query(file);
    format(file, sizeof file,"SELECT `flylicense` FROM `users` WHERE `username` = '%s'", pname);
    pInfo[playerid][flylic]  = mysql_query(file);
    format(file, sizeof file,"SELECT `fightstyle` FROM `users` WHERE `username` = '%s'", pname);
    pInfo[playerid][fightstyle] = mysql_query(file);
    format(file, sizeof file,"SELECT `adminlevel` FROM `users` WHERE `username` = '%s'", pname);
    pInfo[playerid][adminlevel] = mysql_query(file);
    format(file, sizeof file,"SELECT `jerrycan` FROM `users` WHERE `username` = '%s'", pname);
	pInfo[playerid][jerrycan] = mysql_query(file);
	format(file, sizeof file,"SELECT `weed` FROM `users` WHERE `username` = '%s'", pname);
   	pInfo[playerid][weed] = mysql_query(file);
   	format(file, sizeof file,"SELECT `seeds` FROM `users` WHERE `username` = '%s'", pname);
	pInfo[playerid][seeds] = mysql_query(file);
	format(file, sizeof file,"SELECT `beer` FROM `users` WHERE `username` = '%s'", pname);
	pInfo[playerid][beer] = mysql_query(file);
	format(file, sizeof file,"SELECT `sprunk` FROM `users` WHERE `username` = '%s'", pname);
	pInfo[playerid][sprunk] = mysql_query(file);
	format(file, sizeof file,"SELECT `cigarets` FROM `users` WHERE `username` = '%s'", pname);
	pInfo[playerid][cigarets] = mysql_query(file);
	format(file, sizeof file,"SELECT `chainlock` FROM `users` WHERE `username` = '%s'", pname);
	pInfo[playerid][chainlock] = mysql_query(file);
	format(file, sizeof file,"SELECT `spawnX` FROM `users` WHERE `username` = '%s'", pname);
	POS[0] = mysql_query(file);
	format(file, sizeof file, "SELECT `spawnY` FROM `users` WHERE `username` = '%s'", pname);
 	POS[1] = mysql_query(file);
 	format(file, sizeof file,"SELECT `spawnZ` FROM `users` WHERE `username` = '%s'", pname);
 	POS[2] = mysql_query(file);
 	format(file, sizeof file,"SELECT `cellphone` FROM `users` WHERE `username` = '%s'", pname);
 	pInfo[playerid][havephone] = mysql_query(file);
 	SetPlayerPos(playerid, POS[0], POS[1], POS[2]);
    LoadJob(playerid);
    LoadPlayerFactionInfo(playerid);
    GivePlayerMoneyEx(playerid, pInfo[playerid][money]);
    SetPlayerFightingStyle(playerid, pInfo[playerid][fightstyle]);
    LoadWeaponsToFile(playerid);
    SetTimerEx("Loadmorestats",100,false,"i",playerid);
    return 1;
}
Reply


Messages In This Thread
MySQL saving/loading. - by Danny - 22.04.2011, 15:18
Re: MySQL saving/loading. - by sobolanux - 22.04.2011, 15:35

Forum Jump:


Users browsing this thread: 1 Guest(s)