Auto save when using GivePlayerMoney
#1

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
Reply
#2

hook GivePlayerMoney

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

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.
Reply
#4

Код:
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.
Reply
#5

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 )
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)