stock SavePlayerPos(playerid)
{
new query[500], Float:posX, Float:posY, Float:posZ;
GetPlayerPos(playerid, posX, posY, posZ);
format(query, sizeof(query), "UPDATE `accounts` SET `playerX` = '%f', `playerY` = '%f', `playerZ` = '%f' WHERE `playerName` = '%s'", posX, posY, posZ, playerInfo[playerid][playerName]);
mysql_tquery(Database, query);
}
stock LoadPlayerStats(playerid)
{
new query[200], name[24];
GetPlayerName(playerid, name, 24);
format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `playerName` = '%e' LIMIT 1", name);
mysql_tquery(Database, query);
cache_get_value_int(0, "playerAdmin", playerInfo[playerid][playerAdmin]);
cache_get_value_int(0, "playerMod", playerInfo[playerid][playerMod]);
cache_get_value_int(0, "playerHelper", playerInfo[playerid][playerHelper]);
cache_get_value_int(0, "playerLevel", playerInfo[playerid][playerLevel]);
cache_get_value_int(0, "playerCash", playerInfo[playerid][playerCash]);
cache_get_value_name_float(0, "playerX", playerInfo[playerid][playerX]);
cache_get_value_name_float(0, "playerY", playerInfo[playerid][playerY]);
cache_get_value_name_float(0, "playerZ", playerInfo[playerid][playerZ]);
SetPlayerScore(playerid, playerInfo[playerid][playerLevel]);
GivePlayerMoney(playerid, playerInfo[playerid][playerCash]);
SetSpawnInfo(playerid, 0,0,playerInfo[playerid][playerX],playerInfo[playerid][playerY], playerInfo[playerid][playerZ], 0, 0, 0, 0, 0,0,0);
printf("player loaded.");
}
[12:31:31] [join] yllo has joined the server (0:127.0.0.1)
[12:31:31] player loaded.
[12:31:31] SELECT * FROM `accounts` WHERE `playerName` = 'yllo' LIMIT 1
[12:31:46] Player saved.
[12:31:46] [part] yllo has left the server (0:1)
You should also free the query results with mysql_free_result().
|
stock LoadPlayerStats(playerid)
{
new query[200], name[24], Cache: result;
GetPlayerName(playerid, name, 24);
format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `playerName` = '%e' LIMIT 1", name);
result = mysql_query(Database, query);
if(cache_num_rows())
{
cache_get_value_int(0, "playerAdmin", playerInfo[playerid][playerAdmin]);
cache_get_value_int(0, "playerMod", playerInfo[playerid][playerMod]);
cache_get_value_int(0, "playerHelper", playerInfo[playerid][playerHelper]);
cache_get_value_int(0, "playerLevel", playerInfo[playerid][playerLevel]);
cache_get_value_int(0, "playerCash", playerInfo[playerid][playerCash]);
cache_get_value_name_float(0, "playerX", playerInfo[playerid][playerX]);
cache_get_value_name_float(0, "playerY", playerInfo[playerid][playerY]);
cache_get_value_name_float(0, "playerZ", playerInfo[playerid][playerZ]);
}
SetPlayerScore(playerid, playerInfo[playerid][playerLevel]);
GivePlayerMoney(playerid, playerInfo[playerid][playerCash]);
SetSpawnInfo(playerid, 0,0,playerInfo[playerid][playerX],playerInfo[playerid][playerY], playerInfo[playerid][playerZ], 0, 0, 0, 0, 0,0,0);
cache_delete(result);
printf("player loaded.");
}