SA-MP Forums Archive
Save - 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: Save (/showthread.php?tid=633628)



Save - Loinal - 04.05.2017

OnGameMode in it

Код:
SetTimer("SaveAllData", 180000, 1);
and code

PHP код:
forward SaveAllData();
public 
SaveAllData()
{
    for (new 
0MAX_PLAYERSi++)
    {
        if( 
IsPlayerConnected) )
        {
    new 
query[150+1000];
    
mysql_format(mysqlquerysizeof(query), "UPDATE `players` SET `IP` = '%e', `Admin` = %d, `VIP` = %d, `Kills` = %d,`Cookies` = %d,`Cakes` = %d,`Icecream` = %d, `Deaths` = %d, `Score` = %d, `Money` = %d, `Hours` = %d,\
     `Minutes` = %d, `RaceWon` = %d WHERE `ID` = %d"
,
    
IP[i], pData[i][Admin], pData[i][VIP], pData[i][Kills],pData[i][Cookies],pData[i][Cakes],pData[i][Icecream], pData[i][Deaths], GetPlayerScore(i),\
     
GetPlayerMoney(i), pData[i][pHours], pData[i][pMinutes],pData[i][RaceWon],pData[i][ID]);
    
mysql_query(mysqlquery);
        }
        new 
str[128];
        
SendClientMessageToAll(0x009D00DB,"Your player data have been saved into(Database)");
        
format(strsizeof(str),"* AutoSaveSystem saved all the online player stats (Total %d)",GetOnLinePlayers());
        
IRC_GroupSay(groupIDIRC_CHANNELstr);
    }
    return 
1;

that spams on the chat why?


Re: Save - Logic_ - 04.05.2017

Logical enough since you've put the messages to be sent under the Loop! Moving the code outside the loop will fix it. Also, use foreach or GetPlayerPoolSize loops!


Re: Save - denNorske - 04.05.2017

PHP код:
forward SaveAllData(); 
public 
SaveAllData() 

    for (new 
0MAX_PLAYERSi++) 
    { 
        if( 
IsPlayerConnected) ) 
        { 
            new 
query[236+75]; 
            
mysql_format(mysqlquerysizeof(query), "UPDATE `players` SET `IP` = '%e', `Admin` = %d, `VIP` = %d, `Kills` = %d,`Cookies` = %d,`Cakes` = %d,`Icecream` = %d, `Deaths` = %d, `Score` = %d, `Money` = %d, `Hours` = %d,\
             `Minutes` = %d, `RaceWon` = %d WHERE `ID` = %d"

            
IP[i], pData[i][Admin], pData[i][VIP], pData[i][Kills],pData[i][Cookies],pData[i][Cakes],pData[i][Icecream], pData[i][Deaths], GetPlayerScore(i),\
             
GetPlayerMoney(i), pData[i][pHours], pData[i][pMinutes],pData[i][RaceWon],pData[i][ID]); 
            
mysql_query(mysqlquery); 
        } 
        
    } 
    
//put it outside the loop. Fixed
    
new str[128]; 
    
SendClientMessageToAll(0x009D00DB,"Your player data have been saved into(Database)"); 
    
format(strsizeof(str),"* AutoSaveSystem saved all the online player stats (Total %d)",GetOnLinePlayers()); 
    
IRC_GroupSay(groupIDIRC_CHANNELstr); 
    return 
1

Put the message code outside the loop. Else you're sending a message to everyone, each time the i increases.


Re: Save - Loinal - 04.05.2017

Should be

PHP код:
forward SaveAllData();
public 
SaveAllData()
{
    for (new 
0MAX_PLAYERSi++)
    {
        if( 
IsPlayerConnected) )
        {
    new 
query[150+1000];
    
mysql_format(mysqlquerysizeof(query), "UPDATE `players` SET `IP` = '%e', `Admin` = %d, `VIP` = %d, `Kills` = %d,`Cookies` = %d,`Cakes` = %d,`Icecream` = %d, `Deaths` = %d, `Score` = %d, `Money` = %d, `Hours` = %d,\
     `Minutes` = %d, `RaceWon` = %d WHERE `ID` = %d"
,
    
IP[i], pData[i][Admin], pData[i][VIP], pData[i][Kills],pData[i][Cookies],pData[i][Cakes],pData[i][Icecream], pData[i][Deaths], GetPlayerScore(i),\
     
GetPlayerMoney(i), pData[i][pHours], pData[i][pMinutes],pData[i][RaceWon],pData[i][ID]);
    
mysql_query(mysqlquery);
        new 
str[128];
        
SendClientMessageToAll(0x009D00DB,"Your player data have been saved into(Database)");
        
format(strsizeof(str),"* AutoSaveSystem saved all the online player stats (Total %d)",GetOnLinePlayers());
        
IRC_GroupSay(groupIDIRC_CHANNELstr);
        }
    }
    return 
1;




Re: Save - Logic_ - 04.05.2017

Nope, please read the posts properly:

Quote:
Originally Posted by Logic_
Посмотреть сообщение
Logical enough since you've put the messages to be sent under the Loop! Moving the code outside the loop will fix it. Also, use foreach or GetPlayerPoolSize loops!
Example:
PHP код:
forward SaveAllData();
public 
SaveAllData()
{
    new 
query[300];
    foreach(new 
iPlayer)
    {
        
mysql_format(mysqlquerysizeof query"UPDATE `players` SET `IP` = '%e', `Admin` = %d, `VIP` = %d, `Kills` = %d,`Cookies` = %d,`Cakes` = %d,`Icecream` = %d, `Deaths` = %d, `Score` = %d, `Money` = %d, `Hours` = %d,\
            `Minutes` = %d, `RaceWon` = %d WHERE `ID` = %d"
,
        
IP[i], pData[i][Admin], pData[i][VIP], pData[i][Kills],pData[i][Cookies],pData[i][Cakes],pData[i][Icecream], pData[i][Deaths], GetPlayerScore(i),
        
GetPlayerMoney(i), pData[i][pHours], pData[i][pMinutes],pData[i][RaceWon],pData[i][ID]);
        
mysql_query(mysqlquery);
    }
    new 
str[128];
    
SendClientMessageToAll(0x009D00DB,"Your player data have been saved into Database.");
    
format(strsizeof(str),"* Auto Save System has saved all the online player stats (Total %d)",GetOnLinePlayers());
    
IRC_GroupSay(groupIDIRC_CHANNELstr);
    return 
1;




Re: Save - Vince - 04.05.2017

Just don't use this method at all. Update data in small chunks as and when it changes. This is far less stressful on the MySQL server than a hundred queries with a load of data that all come in at the exact same time.