SA-MP Forums Archive
[TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. (/showthread.php?tid=85008)



[TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. - illay - 04.07.2009

g-Max Players
Version: 0.2-Fixed
Description: Replace MAX_PLAYERS (200) to gMaxPlayers(Current online Players)

pawn Код:
#include <a_samp>

new gMaxPlayers;

public OnFilterScriptInit(){
  gMaxPlayers=0;
}

public OnPlayerConnect(playerid)
{
  if(gMaxPlayers < playerid) gMaxPlayers = playerid;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  if(gMaxPlayers == playerid){
        for(new i = playerid-1; i >= 0; i--) {
            if(IsPlayerConnected(i)) {
                gMaxPlayers = i;
            break;
            }
        }
    }
    return 1;
}
Example:
pawn Код:
public Example();

public Example() {
    for(new i = 0; i < gMaxPlayers; i++){
      return 1;
    }
    return 1;
}
[img][/img]


Re: [TUTORIAL] Using my gPlayers (Current Online Players) (Replace MAX_PLAYERS) - yezizhu - 04.07.2009

haha
id0 connect,g = 0.
So 0 player online XD
But this code is great, let's make it work^^


Re: [TUTORIAL] Using my gPlayers (Current Online Players) (Replace MAX_PLAYERS) - yezizhu - 04.07.2009

Think about
gMaxPlayers+1
gMaxPlayers-1

I love your amazing idea~veryvery great!



Re: [TUTORIAL] Using my gPlayers (Current Online Players) (Replace MAX_PLAYERS) - illay - 04.07.2009

@ yezizhu

Think about
gMaxPlayers+1 } omg
gMaxPlayers-1 }

--

Version 0.2 Reseased. Bug fixed. Thanks


Re: [TUTORIAL] Using my gPlayers (Current Online Players) (Replace MAX_PLAYERS) - yezizhu - 04.07.2009

edit
Код:
public Example();
public Example() {
for(new i = 0; i <= gMaxPlayers; i++){
return 1;
} return 1;
}
to
Код:
forward Example();
public Example() {
for(new i = 0; i < gMaxPlayers; i++){
return 1;
} return 1;
}
You'd better not to chang our custom because We used to using '<' ,not '<='.


Re: [TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. - [DrM]spatrik - 04.07.2009

-.-, the code by Kowalski


Re: [TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. - illay - 05.07.2009

Lol mean. I write yesterday the code.


Re: [TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. - [DrM]spatrik - 05.07.2009

I use the code in we LSTD mode.

Here Kowalski's code:

pawn Код:
new HighestID;

public OnPlayerConnect(playerid)
{
  if(HighestID < playerid) HighestID = playerid;
  return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  if(HighestID == playerid)
  {
    for(new i = playerid-1; i >= 0; i--)
    {
      if(IsPlayerConnected(i))
      {
        HighestID = i;
        break;
      }
    }
  }
  return 1;
}



Re: [TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. - Donny_k - 05.07.2009

pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS //put the number from your cfg here, you should know it as you wrote it



Re: [TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. - [DrM]spatrik - 05.07.2009

Quote:
Originally Posted by Donny
pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS //put the number from your cfg here, you should know it as you wrote it
The HighestID is better in big script


Re: [TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts. - illay - 05.07.2009

LSTDM* Stealed by Me
--
gMaxPlayers by Me not Kowalski.