23.01.2015, 13:05
Hello , me they should have such a thing as a server lock for 1 minute and automatic unlocking after 1 minute. How to do it?
new gLockTimer;
CMD:lockserver(playerid, params[])
{
new password[20], seconds, str[60];
if(sscanf(params, "s[20]i", password, seconds)) return SendClientMessage(playerid, -1, "Usage: /lockserver [password] [seconds]");
format(str, 60, "You have successfully locked the server with the password %s!", password);
SendClientMessage(playerid, -1, str);
format(str, 30, "password %s", password);
SendRconCommand(str);
KillTimer(gLockTimer), gLockTimer = SetTimer("UnlockServer", seconds*1000, 0);
return 1;
}
forward UnlockServer();
public UnlockServer()
{
SendRconCommand("password 0");
KillTimer(gLockTimer);
return 1;
}
new gLockTimer, ServerLocked = 0, LockSeconds = -1;
CMD:lockserver(playerid, params[])
{
new password[20], minutes, str[60];
if(!IsPlayerAdmin(playerid)) return 0;
if(sscanf(params, "s[20]i", password, seconds)) return SendClientMessage(playerid, -1, "Usage: /lockserver [password] [seconds]");
format(str, 60, "You have successfully locked the server with the password %s!", password);
SendClientMessage(playerid, -1, str);
format(str, 30, "password %s", password);
KillTimer(gLockTimer), gLockTimer = SetTimer("ServerLockTimeUpdater", 1000, 1);
SendRconCommand(str), ServerLocked = 1, LockSeconds = seconds;
return 1;
}
forward ServerLockTimeUpdater();
public ServerLockTimeUpdater()
{
LockSeconds--;
if(LockSeconds <= -1) return SendRconCommand("password 0"), KillTimer(gLockTimer), LockSeconds = -1, ServerLocked = 0;
new str[30];
format(str, 30, "hostname Server locked for: %i seconds", LockSeconds);
SendRconCommand(str);
return 1;
}