SA-MP Forums Archive
[HELP]Limit login - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP]Limit login (/showthread.php?tid=351071)



[HELP]Limit login - TheBluec0de - 14.06.2012

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


Re: [HELP]Limit login - ReneG - 14.06.2012

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.


Re: [HELP]Limit login - Vince - 14.06.2012

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.


Re: [HELP]Limit login - ReneG - 14.06.2012

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.


Re: [HELP]Limit login - TheBluec0de - 14.06.2012

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;
}



Re: [HELP]Limit login - TheBluec0de - 15.06.2012

bump


Re: [HELP]Limit login - TheBluec0de - 15.06.2012

bump...


Re: [HELP]Limit login - ReneG - 15.06.2012

You are not allowed to bump within 48 hours.


Re: [HELP]Limit login - TheBluec0de - 15.06.2012

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


Re: [HELP]Limit login - Revo - 16.06.2012

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.