#1

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

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!
Reply
#3

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

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;

Reply
#5

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;

Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)