21.02.2018, 22:25
Hello, Can someone teach me how I can save in MYSQL whenever I use GivePlayerMoney, I do not want to always have to write the code, I hope you understand me
new query[500]; public OnGameModeInit() { format(query, sizeof(query), "CREATE TABLE IF NOT EXIST `user` (`name`, `money`)"); } public OnPlayerDisconnect(playerid) { format(query, sizeof(query), "UPDATE `user` SET `money` = %d, WHERE `name` = '%e', GetPlayerMoney(playerid), GetPlayerName(playerid)); mysql_query(Database, query); }
mysql_format(SQL, str,128,"UPDATE `users` SET `YourMoneyColumnName`='%d' WHERE `id` = '%d' LIMIT 1",PlayerData[playerid][Cash],PlayerData[playerid][ID]);
mysql_tquery(SQL, str, "", "");
GivePlayerCash(playerid, money)
{
PlayerData[playerid][Cash] += money;
if(PlayerData[playerid][IsLoggedIn] == true)
{
new str[128];
mysql_format(SQL, str,128,"UPDATE `users` SET `Cash`='%d' WHERE `id` = '%d' LIMIT 1",PlayerData[playerid][Cash],PlayerData[playerid][ID]);
mysql_tquery(SQL, str, "", "");
}
UpdateMoneyBar(playerid,PlayerData[playerid][Cash]);
if(PlayerData[playerid][Cash] != GetPlayerMoney(playerid))
{
GivePlayerMoney(playerid, PlayerData[playerid][Cash] - GetPlayerMoney(playerid));
}
return PlayerData[playerid][Cash];
}
UpdateMoneyBar is defined GivePlayerMoney ( #define UpdateMoneyBar GivePlayerMoney )
Код:
new query[500]; public OnGameModeInit() { format(query, sizeof(query), "CREATE TABLE IF NOT EXIST `user` (`name`, `money`)"); } public OnPlayerDisconnect(playerid) { format(query, sizeof(query), "UPDATE `user` SET `money` = %d, WHERE `name` = '%e', GetPlayerMoney(playerid), GetPlayerName(playerid)); mysql_query(Database, query); } hope it works. |