[TUTORIAL] Correct MAX_PLAYERS: gMaxPlayers. Reduced timeouts.
#1

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]
Reply
#2

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

Think about
gMaxPlayers+1
gMaxPlayers-1

I love your amazing idea~veryvery great!
Reply
#4

@ yezizhu

Think about
gMaxPlayers+1 } omg
gMaxPlayers-1 }

--

Version 0.2 Reseased. Bug fixed. Thanks
Reply
#5

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 '<='.
Reply
#6

-.-, the code by Kowalski
Reply
#7

Lol mean. I write yesterday the code.
Reply
#8

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;
}
Reply
#9

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

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
Reply
#11

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


Forum Jump:


Users browsing this thread: 1 Guest(s)