Timestamp
#1

Hey i want to make /settempadmin iam using mysql r41-2

I read much about unix timestamp but cant understand
Could any one help?
Reply
#2

Decide how many days/months you want the player to be admin. Convert that time span to seconds (e.g. 2 days = 2 x 24 (hours in a day) x 60 (minutes in an hour) x 60 (seconds in a minute) = 172800 seconds). Get the current timestamp (literally just gettime()). Add the two together and save the result in the account.

On login (or wherever you want to do the expiry check) you check if the current time (again, literally just gettime()) is greater than whatever is stored. If it is then the time has expired and you can do the reset procedure. Very, very simple.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Decide how many days/months you want the player to be admin. Convert that time span to seconds (e.g. 2 days = 2 x 24 (hours in a day) x 60 (minutes in an hour) x 60 (seconds in a minute) = 172800 seconds). Get the current timestamp (literally just gettime()). Add the two together and save the result in the account.

On login (or wherever you want to do the expiry check) you check if the current time (again, literally just gettime()) is greater than whatever is stored. If it is then the time has expired and you can do the reset procedure. Very, very simple.
Any example code?
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Decide how many days/months you want the player to be admin. Convert that time span to seconds (e.g. 2 days = 2 x 24 (hours in a day) x 60 (minutes in an hour) x 60 (seconds in a minute) = 172800 seconds). Get the current timestamp (literally just gettime()). Add the two together and save the result in the account.

On login (or wherever you want to do the expiry check) you check if the current time (again, literally just gettime()) is greater than whatever is stored. If it is then the time has expired and you can do the reset procedure. Very, very simple.
also how can i sscanf it the params? also how can i check i didn't understand that part :/
Reply
#5

PHP код:
CMD:settemplevel(playeridparams[])
{
    new 
lookupidstr[128], level,days;
    if(
pData[playerid][Admin] >= || IsPlayerAdmin(playerid))
    {
        if(
sscanf(params,"udd",lookupid,level,days)) return SendClientMessage(playeridCOLOR_YELLOW"Usage: /setlevel (UserID | UserName) (level) (days)");
        if(
pData[lookupid][Admin] > pData[playerid][Admin]) return SendClientMessage(playerid, -1"Sorry you cant setlevel becoz his level is higher then you");
        if(
level == || level 10 || level == 0) return SendClientMessage(playeridred"ERROR: Invalid Level [Levels 3 to 10]"); // you can change this to any level you want
        
if(!IsPlayerConnected(lookupid)) return SendClientMessage(playerid,0xFF0000FF"Sorry this player isnt connected ");
        if(
level pData[lookupid][Admin])
        {
            new 
irc[130];
            
format(irc,sizeof(str),"8,3* Admin %s (ID: %d) Demoted %s (ID: %d) to level %d for %d days",GetName(playerid), playerid,GetName(lookupid),lookupid,level,days);
            
IRC_GroupSay(groupIDIRC_CHANNELirc);
            
format(strsizeof(str), "Admin %s (ID:%d) has temp demoted you to level %d for %d days",GetName(playerid), playeridleveldays);
            
SendClientMessage(lookupid0xFF0000FFstr);
            
format(strsizeof(str),"You have demoted %s (ID:%d) to level %d",GetName(lookupid),lookupid,level);
            
SendClientMessage(playerid, -1str);
            
ta[lookupid] = gettime() + days*86400;
            
pData[lookupid][Admin] = level;
            if(
pData[lookupid][Admin] == 1)
            {
            
onlineadmins--;
            new 
strings[100+1000];
            
format(stringssizeof(strings), "Online Admins: %d",onlineadmins);
            
TextDrawSetString(oastrings);
            
TextDrawShowForPlayer(playeridoa);
            }
        }
        if(
level pData[lookupid][Admin])
        {
            new 
irc[130];
            
format(irc,sizeof(str),"8,3* Admin %s (ID: %d) granted level %d to %s (ID: %d)",GetName(playerid), playeridlevel,GetName(lookupid),lookupid);
            
IRC_GroupSay(groupIDIRC_CHANNELirc);
            
format(strsizeof(str), "* You have been granted permanent Admin Level %d by %s (ID: %d)",levelGetName(playerid), playerid);
            
SendClientMessage(lookupidCOLOR_GREENstr);
            
ta[lookupid] = gettime() + days*86400;
            ForEach(
iMAX_PLAYERS)
            {
                if(
pData[i][Admin] >= 3)
                {
                  
format(str,sizeof(str),"* Admin %s (ID: %d) granted permanent Admin level %d to %s (ID: %d)",GetName(playerid),playerid,level,GetName(lookupid),lookupid);
                  
SendClientMessage(i0x00FFC1FFstr);                   
                }
            }

            
format(strsizeof(str),"You have setted %s (ID:%d) to level %d",GetName(lookupid),lookupid,level);
            
SendClientMessage(playeridCOLOR_YELLOWstr);
            if(
level >= 3)
            {
            if(
pData[lookupid][Admin] < 3){onlineadmins++;}//If not already an admin count ++
            
pData[lookupid][Admin] = level;//now set the level
            
new strings[100+1000];
            
format(stringssizeof(strings), "Online Admins: %d",onlineadmins);
            
TextDrawSetString(oastrings);
            
TextDrawShowForPlayer(playeridoa);
            }
        }
        
printf("Setted level %d",level);
        
SavePlayerData(playerid);
    }
    else return 
SendClientMessage(playeridCOLOR_YELLOW"Only +level 9 can use this command");
    return 
1;

and onplayerconnect

PHP код:
    if(ta[playerid] >= gettime())
    {
        
SendClientMessage(playerid,COLOR_GREEN"Your Admin level is not expired");
    }
    else
    {
        
SendClientMessage(playerid,COLOR_GREEN,"Your level is expired");
    } 
But still when i rejoin it doesn't send me this messages
Reply
#6

You need to save the time to a place - so when the player joins, the server know what the time was set to.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)