Update a mysql tabel when the player is offline.
#1

Hello.
How to update a mysql tabel when the player is offline? I made an automatic faction raport reset system, and and this is the timer defined in OnGameModeInit:

PHP код:
public 
        new 
query[2048], string[2048], result[256], name[30], idcolortimerfactionrankraport1raport2raport3timestatusplayeridstatusstim
    
format(querysizeof(query), "SELECT * FROM `users` WHERE `FactionID` >= '1'");
    new 
Cache:check mysql_query(SQLquery); for(new icache_get_row_count(); != j; ++i)
    {
        
cache_get_field_content(i"name"result); format(name256result); 
        
timer             cache_get_field_content_int(i"RaportTimer");     raport2     cache_get_field_content_int(i"FactionRaport2");
        
faction         cache_get_field_content_int(i"FactionID");        raport3     cache_get_field_content_int(i"FactionRaport3");
        
rank             cache_get_field_content_int(i"FactionRank");           time         cache_get_field_content_int(i"FactionTime");
        
raport1         cache_get_field_content_int(i"FactionRaport1");    id         cache_get_field_content_int(i"id");
        
status         cache_get_field_content_int(i"Status");            playerid     GetPlayerID(name); statuss status;
        if(
IsPlayerConnected(playerid) || statuss == 1// daca este online
        
{
            
PlayerInfo[playerid][ResetRaportDate]--; mysql_format(SQLquerysizeof(query), "UPDATE `users` SET `RaportTimer` = '%d' WHERE `name` = '%s' 
                        AND `id` = '%d'"
PlayerInfo[playerid][ResetRaportDate], GPlayerName(playerid), PlayerInfo[playerid][AccountID]); mysql_tquery(SQLquery"""");
            if(
PlayerInfo[playerid][ResetRaportDate] == 0)
            { 
                if(
PlayerInfo[playerid][FactionID] == || PlayerInfo[playerid][FactionID] == || PlayerInfo[playerid][FactionID] == || PlayerInfo[playerid
                                [
FactionID] == 12 || PlayerInfo[playerid][FactionID] == 20 || PlayerInfo[playerid][FactionID] == 21color 0x8D8DFFAA;
                else if(
PlayerInfo[playerid][FactionID] != || PlayerInfo[playerid][FactionID] != || PlayerInfo[playerid][FactionID] != || PlayerInfo[playerid
                                [
FactionID] != 12 || PlayerInfo[playerid][FactionID] != 20 || PlayerInfo[playerid][FactionID] != 21color 0x009ACDFF;
                if(
PlayerInfo[playerid][FactionRank] == 1)
                {
                                        
//PS: This is the timer update when the player is online
                                
}
        }
        else if(!
IsPlayerConnected(playerid) || statuss == 0// daca nu este online
        
{
            
tim timer 1mysql_format(SQLquerysizeof(query), "UPDATE `users` SET `RaportTimer` = '%d' WHERE `name` = '%s' AND `id` = '%d'"tim
                        
nameid); mysql_tquery(SQLquery"""");
            if(
tim == 0)
            {
                new 
d,m,y,h,mi,sgetdate(y,m,d); gettime(h,mi,s);
                if(
faction         == || faction == || faction == || faction == 12 || faction == 20 || faction == 21color 0x8D8DFFAA;
                else if(
faction != || faction != || faction != || faction != 12 || faction != 20 || faction != 21color 0x009ACDFF;
                if(
rank == 1)
                {
                        
//PS: This is the timer update when the player is offline
                                        //PS: Here its the problem, when I connect to the server, and are online and I'm looking at the database, I only update myself, the other players 
                                        
in the factions remain the same timerbut when I disconnect and I'm in the "offline" section, it keeps updating me on the base but others do not
                }
            }
            return 1;
        }
        return 1;            
    }        
    cache_delete(check); return 1; 
I don't know how to resolve this problem, question its: How to update a mysql table when the players in factions its offline?
Reply
#2

probema ta este ca folosesti return in loop (for). cand folosesti return, returneaza functia si loop-ul nu mai continua. in loc de return 1 in interiorul loop-ului trebuie sa folosesti continue;

cam asa ar trb sa fie codul tau:
PHP код:
public  
        new 
query[2048], string[2048], result[256], name[30], idcolortimerfactionrankraport1raport2raport3timestatusplayeridstatusstim;  
    
format(querysizeof(query), "SELECT * FROM `users` WHERE `FactionID` >= '1'"); 
    new 
Cache:check mysql_query(SQLquery); for(new icache_get_row_count(); != j; ++i
    { 
        
cache_get_field_content(i"name"result); format(name256result);  
        
timer             cache_get_field_content_int(i"RaportTimer");     raport2     cache_get_field_content_int(i"FactionRaport2"); 
        
faction         cache_get_field_content_int(i"FactionID");        raport3     cache_get_field_content_int(i"FactionRaport3"); 
        
rank             cache_get_field_content_int(i"FactionRank");           time         cache_get_field_content_int(i"FactionTime"); 
        
raport1         cache_get_field_content_int(i"FactionRaport1");    id         cache_get_field_content_int(i"id"); 
        
status         cache_get_field_content_int(i"Status");            playerid     GetPlayerID(name); statuss status
        if(
IsPlayerConnected(playerid) || statuss == 1// daca este online 
        

            
PlayerInfo[playerid][ResetRaportDate]--; mysql_format(SQLquerysizeof(query), "UPDATE `users` SET `RaportTimer` = '%d' WHERE `name` = '%s'  
                        AND `id` = '%d'"
PlayerInfo[playerid][ResetRaportDate], GPlayerName(playerid), PlayerInfo[playerid][AccountID]); mysql_tquery(SQLquery""""); 
            if(
PlayerInfo[playerid][ResetRaportDate] == 0
            {  
                if(
PlayerInfo[playerid][FactionID] == || PlayerInfo[playerid][FactionID] == || PlayerInfo[playerid][FactionID] == || PlayerInfo[playerid]  
                                [
FactionID] == 12 || PlayerInfo[playerid][FactionID] == 20 || PlayerInfo[playerid][FactionID] == 21color 0x8D8DFFAA
                else if(
PlayerInfo[playerid][FactionID] != || PlayerInfo[playerid][FactionID] != || PlayerInfo[playerid][FactionID] != || PlayerInfo[playerid]  
                                [
FactionID] != 12 || PlayerInfo[playerid][FactionID] != 20 || PlayerInfo[playerid][FactionID] != 21color 0x009ACDFF
                if(
PlayerInfo[playerid][FactionRank] == 1
                { 
                                        
//PS: This is the timer update when the player is online 
                                

        } 
        else if(!
IsPlayerConnected(playerid) || statuss == 0// daca nu este online 
        

            
tim timer 1mysql_format(SQLquerysizeof(query), "UPDATE `users` SET `RaportTimer` = '%d' WHERE `name` = '%s' AND `id` = '%d'"tim,  
                        
nameid); mysql_tquery(SQLquery""""); 
            if(
tim == 0
            { 
                new 
d,m,y,h,mi,sgetdate(y,m,d); gettime(h,mi,s); 
                if(
faction         == || faction == || faction == || faction == 12 || faction == 20 || faction == 21color 0x8D8DFFAA
                else if(
faction != || faction != || faction != || faction != 12 || faction != 20 || faction != 21color 0x009ACDFF
                if(
rank == 1
                { 
                        
//PS: This is the timer update when the player is offline 
                                        //PS: Here its the problem, when I connect to the server, and are online and I'm looking at the database, I only update myself, the other players  
                                        
in the factions remain the same timerbut when I disconnect and I'm in the "offline" section, it keeps updating me on the base but others do not 
                } 
            } 
           continue; 
        } 
        continue;             
    }         
    cache_delete(check); return 1; 
Reply
#3

Multumesc, o sa incerc acum. Deci faza e ca trebuie sa pun "continue" dupa ce updatez timerul si in baza de date, dar nu cred ca e nevoie sa pun "continue" si la cei conectati, nu? Pentru ca se actulizeaza corect, adica nu is probleme la cei online.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)