SA-MP Forums Archive
Auto save when using GivePlayerMoney - 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)
+--- Thread: Auto save when using GivePlayerMoney (/showthread.php?tid=650158)



Auto save when using GivePlayerMoney - JnniorDoug - 21.02.2018

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


Re: Auto save when using GivePlayerMoney - Nero_3D - 21.02.2018

hook GivePlayerMoney

There is an example right at the end of the first post
https://sampforum.blast.hk/showthread.php?tid=574534


Re: Auto save when using GivePlayerMoney - AstroPoid - 21.02.2018

i barely use mysql , i'm working with sqlite in all my progress , if you want to make a command saving money every time it will be heavy on data storing , specially if someone spammed it , i suggest you to do them onplayerdisconnect , or timer or whatever , They will be stored. there are a few tutorials over samp forums shows how make tables and store variables at , consider take a look on.


Re: Auto save when using GivePlayerMoney - AstroPoid - 22.02.2018

Код:
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);
}
try this , untested.
hope it works.


Re: Auto save when using GivePlayerMoney - PepsiCola23 - 22.02.2018

PHP код:
        mysql_format(SQLstr,128,"UPDATE `users` SET `YourMoneyColumnName`='%d' WHERE `id` = '%d' LIMIT 1",PlayerData[playerid][Cash],PlayerData[playerid][ID]);
        
mysql_tquery(SQLstr""""); 
also,i suggest you use server sided money ,create a variable to store money [cash] for example , like this
PHP код:
GivePlayerCash(playeridmoney)
{
    
PlayerData[playerid][Cash] += money;
    if(
PlayerData[playerid][IsLoggedIn] == true)
     {
        new 
str[128];
        
mysql_format(SQLstr,128,"UPDATE `users` SET `Cash`='%d' WHERE `id` = '%d' LIMIT 1",PlayerData[playerid][Cash],PlayerData[playerid][ID]);
        
mysql_tquery(SQLstr"""");
    }
    
UpdateMoneyBar(playerid,PlayerData[playerid][Cash]);
    if(
PlayerData[playerid][Cash] != GetPlayerMoney(playerid))
    {
        
GivePlayerMoney(playeridPlayerData[playerid][Cash] - GetPlayerMoney(playerid));
    }
    return 
PlayerData[playerid][Cash];

and use GivePlayerCash instead of GivePlayerMoney so money can`t be hacked.

Код:
UpdateMoneyBar is defined GivePlayerMoney ( #define UpdateMoneyBar GivePlayerMoney )



Re: Auto save when using GivePlayerMoney - RogueDrifter - 22.02.2018

Quote:
Originally Posted by AstroPoid
Посмотреть сообщение
Код:
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);
}
try this , untested.
hope it works.
I suggest you start reading threads before replying to them, he asked how to do them the moment they're given, not OnPlayerDisconnect , which will not get called if the server crashes = lost stats.

On topic: as someone else suggested that can be done through hooking GivePlayerMoney.