[HELP]Limit login
#1

Hello, i use mysql, and how to make a timer, max limit to login is 30 seconds .... ? example please...
Reply
#2

Make a new variable to hold the log-in time for the players', and one to check if the player is logged in.

Then set a repeating timer under OnGameModeInit of 1 second to loop through all the players and if they aren't logged in, then add 1 to their log-in time. If the log-in time is 30 then kick them.
pawn Код:
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;
}
Since the check is ran every second. 30 = 30 seconds. You could even use foreach, and y_timers for more efficiency.
Reply
#3

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.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
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.
That's actually much more efficient.

The method I provided is just another method not a lot of people use.
Reply
#5

i have a problem please help....

tag mistmatch...

Код:
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;
}
Reply
#6

bump
Reply
#7

bump...
Reply
#8

You are not allowed to bump within 48 hours.
Reply
#9

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
You are not allowed to bump within 48 hours.
ok but, where should I set the timer? is not gamemode is FS
Reply
#10

Quote:
Originally Posted by TheBluec0de
Посмотреть сообщение
ok but, where should I set the timer? is not gamemode is FS
If you're using the method provided Vince provided

pawn Код:
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()
This should be a good base to start with.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)