03.05.2017, 17:45
Hey i want to make /settempadmin iam using mysql r41-2
I read much about unix timestamp but cant understand
Could any one help?
I read much about unix timestamp but cant understand
Could any one help?
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. |
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. |
CMD:settemplevel(playerid, params[])
{
new lookupid, str[128], level,days;
if(pData[playerid][Admin] >= 9 || IsPlayerAdmin(playerid))
{
if(sscanf(params,"udd",lookupid,level,days)) return SendClientMessage(playerid, COLOR_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 == 2 || level > 10 || level == 0) return SendClientMessage(playerid, red, "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(groupID, IRC_CHANNEL, irc);
format(str, sizeof(str), "Admin %s (ID:%d) has temp demoted you to level %d for %d days",GetName(playerid), playerid, level, days);
SendClientMessage(lookupid, 0xFF0000FF, str);
format(str, sizeof(str),"You have demoted %s (ID:%d) to level %d",GetName(lookupid),lookupid,level);
SendClientMessage(playerid, -1, str);
ta[lookupid] = gettime() + days*86400;
pData[lookupid][Admin] = level;
if(pData[lookupid][Admin] == 1)
{
onlineadmins--;
new strings[100+1000];
format(strings, sizeof(strings), "Online Admins: %d",onlineadmins);
TextDrawSetString(oa, strings);
TextDrawShowForPlayer(playerid, oa);
}
}
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), playerid, level,GetName(lookupid),lookupid);
IRC_GroupSay(groupID, IRC_CHANNEL, irc);
format(str, sizeof(str), "* You have been granted permanent Admin Level %d by %s (ID: %d)",level, GetName(playerid), playerid);
SendClientMessage(lookupid, COLOR_GREEN, str);
ta[lookupid] = gettime() + days*86400;
ForEach(i, MAX_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(i, 0x00FFC1FF, str);
}
}
format(str, sizeof(str),"You have setted %s (ID:%d) to level %d",GetName(lookupid),lookupid,level);
SendClientMessage(playerid, COLOR_YELLOW, str);
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(strings, sizeof(strings), "Online Admins: %d",onlineadmins);
TextDrawSetString(oa, strings);
TextDrawShowForPlayer(playerid, oa);
}
}
printf("Setted level %d",level);
SavePlayerData(playerid);
}
else return SendClientMessage(playerid, COLOR_YELLOW, "Only +level 9 can use this command");
return 1;
}
if(ta[playerid] >= gettime())
{
SendClientMessage(playerid,COLOR_GREEN, "Your Admin level is not expired");
}
else
{
SendClientMessage(playerid,COLOR_GREEN,"Your level is expired");
}