Help with this timer.
#1

Hello.
I have a problem with a timer. I made an automated raport for factions, for each member, for 7 days. The explanation of the system is: if the member does not have the finished report, he / she will be automatically given rank 1 / rank up if he / she has finished, rank 2+ receive a warning / rank up if finished.

Timer for the function `CheckRaport` which I put it on in OnGameModeInit:
PHP код:
foreach(new playerPlayer) if(PlayerInfo[player][FactionID] >= && PlayerInfo[player][FactionRank] >= 1) {
RaportTimer[playerid] = SetTimerEx("CheckRaport"1000true"i"player);

And kill timer on in OnGameModeExit:
PHP код:
foreach(new playerPlayer) if(PlayerInfo[player][FactionID] >= && PlayerInfo[player][FactionRank] >= 1) {
KillTimer(RaportTimer[player]);

PS: Should I put these on OnPlayerConnect? I don't know..

The function `CheckRaport(playerid)` called when the timer of 7 days for each member of a faction is gone:
(It's a long one, but it's not finished anyway.)
PHP код:
forward CheckRaport(playerid);
public 
CheckRaport(playerid)
{
    new 
faction PlayerInfo[playerid][FactionID], rank PlayerInfo[playerid][FactionRank], query[256], string[256], date[256], name[30], leader[30], result[256], whorankedup[256], whorankedidday,month,year,h,mi,sgetdate(year,month,day); gettime(h,mi,s);
    
format(querysizeof(query), "SELECT * FROM `users` WHERE `name` = '%s' AND `FactionID` >= 1"GPlayerName(playerid));
    new 
Cache:check mysql_query(SQLquery); if(cache_get_field_count() > 0)
    {
        new 
resetdate[128]; format(resetdate128"%s"getdate(year,month,day));
        
cache_get_field_content(0"ResetRaportDate"result); format(date256result);
        if(
strcmp(dateresetdatetrue) == 0)
        {
            
KillTimer(RaportTimer[playerid]);
            
format(query256"SELECT * FROM `users` WHERE `FactionID` = '%d' AND `FactionRank` = '7'"faction);
            new 
Cache:masta mysql_query(SQLquery); if(cache_get_row_count() >= 1) {
                
cache_get_field_content(0"name"result); format(leader30result);
                
whorankedid cache_get_field_content_int(0"id");
                new 
lead GetPlayerID(leader);
                if(
IsPlayerConnected(lead)) {
                    
format(whorankedupsizeof(whorankedup), "%s"name);
                }
                else if(!
IsPlayerConnected(lead)) {
                    
format(whorankedupsizeof(whorankedup), "AdmBot");
                }
                return 
1;
            }
            
cache_delete(masta);
            if(
rank == && faction >= 1)
            {
                if(
PlayerInfo[playerid][FactionRaport][0] >= FactionInfo[faction][Raport1][0] && PlayerInfo[playerid][FactionRaport][1] >= FactionInfo[faction][Raport2][0] && PlayerInfo[playerid][FactionRaport][2] >= FactionInfo[faction][Raport3][0])    
                { 
// daca are raportul de factiune terminat si are rank 1, sa ii dea automat rank 2 + resetarea raportului!!
                    
if(PlayerInfo[playerid][FactionWarns] == 0)
                    {
                        new 
rankname[256]; 
                        if(
rank+1         == 2format(ranknamesizeof(rankname), "%s"FactionInfo[PlayerInfo[playerid][FactionID]][RankName2]);
                        else if(
rank+1     == 3format(ranknamesizeof(rankname), "%s"FactionInfo[PlayerInfo[playerid][FactionID]][RankName3]);
                        else if(
rank+1    == 4format(ranknamesizeof(rankname), "%s"FactionInfo[PlayerInfo[playerid][FactionID]][RankName4]);
                        else if(
rank+1     == 5format(ranknamesizeof(rankname), "%s"FactionInfo[PlayerInfo[playerid][FactionID]][RankName5]);
                        else if(
rank+1     == 6format(ranknamesizeof(rankname), "%s"FactionInfo[PlayerInfo[playerid][FactionID]][RankName6]);
                        
format(string,                 sizeof(string),     "{67AAB1}(Faction) {CECECE}%s's faction rank was changed from %d to %d, by %s. {67AAB1}(auto)",         GPlayerName(playerid), rank,         rank+1whorankedup),     SendFactionMessage(factionGreystring),                                                                         Factionlog(PlayerInfo[playerid][FactionID], PlayerInfo[playerid][AccountID], PlayerInfo[whorankedid][AccountID], string);
                        
format(string,                 sizeof(string),     "{67AAB1}(Faction) {CECECE}You've been promoted to the rank of %s (%d), by %s. {67AAB1}(auto)",         GPlayerName(playerid), rankname,     rank,     whorankedup),     SendClientMessage(playeridYellow2string);
                        
mysql_format(SQLquery,     sizeof(query),         "UPDATE `users` SET `FactionRank` = '%d' WHERE `name` = '%s'",                             rank+1,         GPlayerName(playerid));                                                                                                                                                     mysql_tquery(SQLquery"""");     
                        
mysql_format(SQLquery,     sizeof(query),         "UPDATE `users` SET `ResetRaportDate` = '%02d-%02d-%d %02d:%02d:%02d', `FactionRaport1` = '0', `FactionRaport2` = '0' AND `FactionRaport3` = '0' WHERE `name` = '%s'",     day,month,year,h,mi,sGPlayerName(playerid));                                                                 mysql_tquery(SQLquery"""");
                        
PlayerInfo[playerid][FactionRank]         = 2PlayerInfo[playerid][ResetDateYear]     = year;
                        
PlayerInfo[playerid][FactionRaport][0]     = 0PlayerInfo[playerid][ResetDateMonth]     = month;
                        
PlayerInfo[playerid][FactionRaport][1]     = 0PlayerInfo[playerid][ResetDateDay]     = day;
                        
PlayerInfo[playerid][FactionRaport][2]     = 0
                        
RaportTimer[playerid] = SetTimerEx("CheckRaport"1000true"i"playerid); return 1;
                    }
                }
                else if(
PlayerInfo[playerid][FactionRaport][0] < FactionInfo[faction][Raport1][0] && PlayerInfo[playerid][FactionRaport][1] < FactionInfo[faction][Raport2][0] && PlayerInfo[playerid][FactionRaport][2] < FactionInfo[faction][Raport3][0])    
                { 
// daca are raportul de factiune neterminat si are rank 1, sa ii dea automat uninvite din factiune si variabilele raportului pe 0!!
                    
if(PlayerInfo[playerid][FactionWarns] >= 0)
                    {
                        
format(string,                 sizeof(string),     "Ai fost demis de %s din factiunea din care faceai parte %s (rank %d) dupa %d zile, cu 60 FP. Motiv: Raport incomplet. (auto)"whorankedupGetFactionName(faction), rankPlayerInfo[playerid][FactionTime]);
                        
mysql_format(SQLquery,     sizeof(query),         "INSERT INTO `emails` (`playerid`, `Message`) VALUES('%d','%s')",                                                                 PlayerInfo[playerid][AccountID], string);                                                                                                             mysql_tquery(SQLquery"""");
                        
format(string,                 sizeof(string),     "%s was uninvited by %s from faction %s (rank %d) after %d days, with 60 FP. Reason: Raport incomplet."GPlayerName(playerid), whorankedupGPlayerName(playerid), GetFactionName(faction), rankPlayerInfo[playerid][FactionTime]), SendFactionMessage(factionGreystring),     Factionlog(PlayerInfo[playerid][FactionID], PlayerInfo[playerid][AccountID], PlayerInfo[whorankedid][AccountID], string);
                        
mysql_format(SQLquery,     sizeof(query),         "INSERT INTO `faction_logs` (`text`,`player`,`leader`) VALUES ('%s', '%d', '%d')"stringPlayerInfo[playerid][AccountID], PlayerInfo[whorankedid][AccountID]);                                                                                                                     mysql_tquery(SQLquery"""");
                        
mysql_format(SQLquery,     sizeof(query),         "UPDATE `users` SET `FactionID` = '0', `FactionRank` = '0', `Skin` = '250', `FactionSkin` = '-1', `FactionPunish` = '60', `FactionWarns` = '0', `FactionTime` = '0', `FactionJoin` = '0' WHERE `id` = '%d'"PlayerInfo[playerid][AccountID]);                                         mysql_tquery(SQLquery"""");
                        
mysql_format(SQLquery,     sizeof(query),         "UPDATE `users` SET `ResetRaportDate` = '0', `FactionRaport1` = '0', `FactionRaport2` = '0' AND `FactionRaport3` = '0' WHERE `name` = '%s'",                         GPlayerName(playerid));                                                                                         mysql_tquery(SQLquery"""");
                        
PlayerInfo[playerid][FactionID]                 = 0;  PlayerInfo[playerid][FactionRank]         = 0;
                        
PlayerInfo[playerid][FactionWarns]                 = 0;  PlayerInfo[playerid][FactionPunish]         = 60;
                        
PlayerInfo[playerid][FactionTime]                 = 0;  PlayerInfo[playerid][Skin]                 = 250;
                        
PlayerInfo[playerid][FactionSkin]                 = -1PlayerInfo[playerid][FactionRaport][0]     = 0
                        
PlayerInfo[playerid][FactionRaport][1]             = 0;  PlayerInfo[playerid][FactionRaport][2]     = 0;
                        
SetPlayerArmourEx(playerid0); tazer[playerid] = 0;  OnDuty[playerid] = 0ResetPlayerWeapons(playerid);
                        
SetPlayerSkin(playeridPlayerInfo[playerid][Skin]);                         SpawnPlayer(playerid); return 1;
                    }
                }
                return 
1;
            }        
        }
        return 
1;
    }        
    
cache_delete(check); return 1;        

I also made a test command by updating the `ResetRaportDate` table at the time the command is typed, but no results..:
PHP код:
CMD:resetraport(playeridparams[])
{
    new 
playerstring[256], query[256], d,m,y,h,mi,sgetdate(y,m,d); gettime(h,mi,s);
    if(
PlayerInfo[playerid][AdminLevel] >= 6)
    {
        if(
sscanf(params"u"player)) return SendClientMessage(playeridCOLOR_TEAL"Usage: {CECECE}/resetraport <player id>");
        if(
PlayerInfo[player][FactionID] >= && PlayerInfo[player][FactionRank] <= 6)
        {
            
format(stringsizeof(string), "Administrator %s reseted %s faction raport."GPlayerName(playerid), GPlayerName(player)), SendMessageToAdmins(DarkNiceRedstring);
            
mysql_format(SQLquerysizeof(query), "UPDATE `users` SET `ResetRaportDate` = '%02d-%02d-%d %02d:%02d:%02d', `FactionRaport1` = '0', `FactionRaport2` = '0' AND `FactionRaport3` = '0' WHERE `name` = '%s'"d,m,y,h,mi,sGPlayerName(player)); mysql_tquery(SQLquery"""");
            
PlayerInfo[playerid][ResetDateYear] = yPlayerInfo[playerid][ResetDateMonth] = mPlayerInfo[playerid][ResetDateDay] = d; return 1;
        }
        else return 
SendClientMessage(playeridGrey"This player doesn't have a faction!");
    }
    else return 
0;

1. How can I create a 7-day timer correctly?
2. Or how can I solve this problem?
Thank you in advance! I hope I understand, I'm waiting for your answers!
Reply
#2

Help please
Reply
#3

try to use a variable by saving the timestamp using gettime () + 3600 * 7 and create a function that when the player logger checks if the timestamp of the variable is greater than the one in which it logs, or creates a function with the same function with a timer which is performed every hour
Reply
#4

Ok, I will try, be right back
Reply
#5

You made it!! @Criniti
Thank you!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)