How to get free slots
#1

Hey i wanted to make 2 player slots for admins but what i maked didnt work:
This is under onplayerconnect
pawn Код:
if(GetMaxPlayers() -2)
    {
        if(APlayerData[playerid][PlayerLevel] < 1)
        {
            SendClientMessage(playerid, 0xFFFFFFF,"Last 2 slots are for admins");
            Kick(playerid);
            return 1;
        }
    }
Can anyone help me? i dont know why its not working got no errors but its neither working
Reply
#2

pawn Код:
if((GetMaxPlayers() + 2) == 10) //Change the 10 to your maximum player slots
Try that. I'm assuming GetMaxPlayers gets the number of players currently in the server. And remember to call this after you load their admin data.
Reply
#3

pawn Код:
public OnPlayerConnect(playerid)
{
    new maxplayers = GetMaxPlayers(), players = 0;
    for(new i = 0; i < GetMaxPlayers(); i++)
    {
        if(IsPlayerConnected(i)) players++;
    }
    if(players == maxplayers-2 && APlayerData[playerid][PlayerLevel] < 1) return SendClientMessage(playerid, 0xFFFFFFF,"Last 2 slots are for admins"), Kick(playerid);
    return 1;
}

Untested, but should work.
Reply
#4

Doesnt work Anything else?
Reply
#5

It's silly to make a loop like that every time someone connects, instead why not simply have a variable that tracks how many people are connected? For example:

pawn Код:
new players_connected;

public OnPlayerConnect(playerid)
{
    players_connected++;
    if((players_connected >= GetMaxPlayers() - 2) && APlayerData[playerid][PlayerLevel] < 1) return SendClientMessage(playerid, 0xFFFFFFF,"Last 2 slots are for admins"), Kick(playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    players_connected--;
    return 1;
}
Absolutely no need for loops being processed every time someone connects
Reply
#6

Thaankkkssssssssssssss It works!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)