SA-MP Forums Archive
Update a mysql tabel when the player is offline. - 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: Update a mysql tabel when the player is offline. (/showthread.php?tid=659516)



Update a mysql tabel when the player is offline. - akaDragonu - 05.10.2018

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], id, color, timer, faction, rank, raport1, raport2, raport3, time, status, playerid, statuss, tim; 
    
format(query, sizeof(query), "SELECT * FROM `users` WHERE `FactionID` >= '1'");
    new 
Cache:check = mysql_query(SQL, query); for(new i, j = cache_get_row_count(); i != j; ++i)
    {
        
cache_get_field_content(i, "name", result); format(name, 256, result); 
        
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(SQL, query, sizeof(query), "UPDATE `users` SET `RaportTimer` = '%d' WHERE `name` = '%s' 
                        AND `id` = '%d'"
, PlayerInfo[playerid][ResetRaportDate], GPlayerName(playerid), PlayerInfo[playerid][AccountID]); mysql_tquery(SQL, query, "", "");
            if(
PlayerInfo[playerid][ResetRaportDate] == 0)
            { 
                if(
PlayerInfo[playerid][FactionID] == 1 || PlayerInfo[playerid][FactionID] == 2 || PlayerInfo[playerid][FactionID] == 4 || PlayerInfo[playerid] 
                                [
FactionID] == 12 || PlayerInfo[playerid][FactionID] == 20 || PlayerInfo[playerid][FactionID] == 21) color = 0x8D8DFFAA;
                else if(
PlayerInfo[playerid][FactionID] != 1 || PlayerInfo[playerid][FactionID] != 2 || PlayerInfo[playerid][FactionID] != 4 || PlayerInfo[playerid] 
                                [
FactionID] != 12 || PlayerInfo[playerid][FactionID] != 20 || PlayerInfo[playerid][FactionID] != 21) color = 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 - 1; mysql_format(SQL, query, sizeof(query), "UPDATE `users` SET `RaportTimer` = '%d' WHERE `name` = '%s' AND `id` = '%d'", tim, 
                        
name, id); mysql_tquery(SQL, query, "", "");
            if(
tim == 0)
            {
                new 
d,m,y,h,mi,s; getdate(y,m,d); gettime(h,mi,s);
                if(
faction         == 1 || faction == 2 || faction == 4 || faction == 12 || faction == 20 || faction == 21) color = 0x8D8DFFAA;
                else if(
faction != 1 || faction != 2 || faction != 4 || faction != 12 || faction != 20 || faction != 21) color = 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 timer, but 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?


Re: Update a mysql tabel when the player is offline. - Vennox - 06.10.2018

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], id, color, timer, faction, rank, raport1, raport2, raport3, time, status, playerid, statuss, tim;  
    
format(query, sizeof(query), "SELECT * FROM `users` WHERE `FactionID` >= '1'"); 
    new 
Cache:check = mysql_query(SQL, query); for(new i, j = cache_get_row_count(); i != j; ++i) 
    { 
        
cache_get_field_content(i, "name", result); format(name, 256, result);  
        
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(SQL, query, sizeof(query), "UPDATE `users` SET `RaportTimer` = '%d' WHERE `name` = '%s'  
                        AND `id` = '%d'"
, PlayerInfo[playerid][ResetRaportDate], GPlayerName(playerid), PlayerInfo[playerid][AccountID]); mysql_tquery(SQL, query, "", ""); 
            if(
PlayerInfo[playerid][ResetRaportDate] == 0) 
            {  
                if(
PlayerInfo[playerid][FactionID] == 1 || PlayerInfo[playerid][FactionID] == 2 || PlayerInfo[playerid][FactionID] == 4 || PlayerInfo[playerid]  
                                [
FactionID] == 12 || PlayerInfo[playerid][FactionID] == 20 || PlayerInfo[playerid][FactionID] == 21) color = 0x8D8DFFAA; 
                else if(
PlayerInfo[playerid][FactionID] != 1 || PlayerInfo[playerid][FactionID] != 2 || PlayerInfo[playerid][FactionID] != 4 || PlayerInfo[playerid]  
                                [
FactionID] != 12 || PlayerInfo[playerid][FactionID] != 20 || PlayerInfo[playerid][FactionID] != 21) color = 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 - 1; mysql_format(SQL, query, sizeof(query), "UPDATE `users` SET `RaportTimer` = '%d' WHERE `name` = '%s' AND `id` = '%d'", tim,  
                        
name, id); mysql_tquery(SQL, query, "", ""); 
            if(
tim == 0) 
            { 
                new 
d,m,y,h,mi,s; getdate(y,m,d); gettime(h,mi,s); 
                if(
faction         == 1 || faction == 2 || faction == 4 || faction == 12 || faction == 20 || faction == 21) color = 0x8D8DFFAA; 
                else if(
faction != 1 || faction != 2 || faction != 4 || faction != 12 || faction != 20 || faction != 21) color = 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 timer, but 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; 



Re: Update a mysql tabel when the player is offline. - akaDragonu - 06.10.2018

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.