14.06.2012, 21:23
Hello, i use mysql, and how to make a timer, max limit to login is 30 seconds .... ? example please...
new
gLoginTime[MAX_PLAYERS],
gLogged[MAX_PLAYERS]
;
forward MaxLoginTimer();
public MaxLoginTimer()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
// for every player that isn't logged in
// then we add 1 to the login-time
if(gLogged[i] == 0)
{
gLoginTime++;
}
if(gLoginTime[i] == 30)
{
SendClientMessage(i, -1, "You have been kicked for not logging in time.");
Kick(i);
}
}
return 1;
}
Hmm, I'd say that's quite cumbersome. I'd rather set a SetTimerEx with an interval of 30 seconds to kick the player. On login, simply kill the timer. Less code and less overhead.
|
function LimiteTempoAccesso() { for(new i=0; i<MAX_PLAYERS; i++) { if(UtenteInfo[i][STATO_UTENTE_ACCESSO] == false) { UtenteInfo[i][STATO_UTENTE_LIMITE_ACCESSO] ++; } if(UtenteInfo[i][STATO_UTENTE_LIMITE_ACCESSO] == 30) // THIS LINE { SendClientMessage(i, -1, "SERVER: Sei stato cacciato. Tempo limite per accedere raggiunto"); Kick(i); } } return 1; }
OnPlayerConnect(playerid)
{
//code
SetTimerEx("LoginCheck", 30000, false, "i", playerid); //set the timer.
}
OnDialogResponse..
{
//logincheck
//if succes; PlayerInfo[playerid][pLogged] = 1; //Check if the player if logged in (this should be in your register script), set whatever variable you use to indicate a player is logged in and replace PlayerInfo[playerid][pLogged] with that, I assume it should be relatively straightforward.
}
forward LoginCheck(playerid);
public LoginCheck(playerid)
{
if(!PlayerInfo[playerid][pLogged] != 1) //if the player is logged in, do nothing.
{ //Kick player and send message if he isn't logged in
SendClientMessage(playerid, -1, "You were kicked for failing to login in time.");
new string[80];
format(string, sizeof(string), "{AUTOKICK} %s(%d) has been kicked for failing to log in.", PlayerName(playerid), playerid);
SendClientMessageToAll(-1, string);
Kick(playerid);
}
}
stock PlayerName(playerid)
{
new playername[24];
GetPlayerName(playerid, playername, sizeof(playername));
return playername;
} //Simple function that returns the playername, used in LoginCheck()