How to make Max Player On Team
#1

Hello guys, i need your help.. I want to make TDM.. how to make max player on Team ? example, if Team 1 10 Player, on Team 2 Just 2 Players.. if Team 1 15 Player, on Team 2 just 3 Players..
Reply
#2

What...? be more specific please..
Reply
#3

Quote:
Originally Posted by Strier
Посмотреть сообщение
What...? be more specific please..
okay.. the script have 2 Team..
Criminals 1 and
Cops 2

How to make if Criminals 10 player, and on Cops Just 2 Players.. if Criminals 15 Player, on Cops just 3 Players.. so, player cant join cops if cops is already max player..

sorry my bad english..
Reply
#4

http://forum.sa-mp.com/archive/index.php/t-296611.html

There..
Reply
#5

pawn Код:
//[Tutorial] Simple Team Balancer [SA-MP] @ http://www.devshack.info - Tutorial by Weponz Inc. © 2010 - 2011
#include <a_samp>//If i need to explain this to you, may god have mercy on your soul..
//-----------------------------------[STEP 1]---------------------------------//
//Ok, Im going to use two teams for this tutorial, TEAM_ONE & TEAM_TWO,
//you could simply add more later. Type the following below:
#define TEAM_ONE 0
#define TEAM_TWO 1
//-----------------------------------[STEP 2]---------------------------------//
//Ok, now we have defined our teams(classes) we need to make a variable
//that checks the players team, so we can use a function(shown below)
//later to check there team, type the following below:
static gTeam[MAX_PLAYERS];//Yes its very common..
//Now we can use gTeam[playerid] == TEAM_ONE or gTeam[playerid] == TEAM_TWO..
//-----------------------------------[STEP 2]---------------------------------//
//Now, we need to create a stock which loops through MAX_PLAYERS, counting
//how many online players are in our specified team, returning a player count
//as an integra(number), This stock was developed by myself so keep my credits!
//i will show you below how it works:
stock GetPlayersInTeamFromMaxPlayers(teamid)//Stock developed by Weponz (Weponz Inc. © 2010 - 2011)
{
    new playercount = 0;//Set our count to 0 as we have not counted any players yet..
    for(new i = 0; i < MAX_PLAYERS; i++)//Loop through MAX_PLAYERS(I suggest you redefine MAX_PLAYERS to ensure max efficency)..
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;//If a player is in class selection continue..
        if(gTeam[i] != teamid) continue;//If a player is NOT in the specified teamid continue..
        playercount++;//else (there in the teamid) so count the player in the team..
    }
    return playercount;//Return the total players counted in the specified team..
}
//-----------------------------------[STEP 3]---------------------------------//
//Ok, now we can count how many players are in w/e team we check
//with our new function GetPlayersInTeamFromMaxPlayers(teamid) we can now
//check for team in-balance under OnPlayerRequestSpawn as its most efficent..
public OnPlayerRequestSpawn(playerid)
{
    new team1 = GetPlayersInTeamFromMaxPlayers(TEAM_ONE);//team1 = how many players are in TEAM_ONE..
    new team2 = GetPlayersInTeamFromMaxPlayers(TEAM_TWO);//team2 = how many players are in TEAM_TWO..
    if(team1 > team2 && gTeam[playerid] == TEAM_ONE)//if team1 has more players than team2 and the player is trying to spawn as TEAM_ONE..
    {
        GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Another Team!", 3000, 5);//Tell them its full, choose another team..
        return 0;//And stop them from spawning..
    }
    else if(team2 > team1 && gTeam[playerid] == TEAM_TWO)//if team2 has more players than team1 and the player is trying to spawn as TEAM_TWO..
    {
        GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Another Team!", 3000, 5);//Tell them its full, choose another team..
        return 0;//And stop them from spawning..
    }
    return 1;
}
//Bang, you now have a team balancer.
//Enjoy,
//-------------------------------[End OF Tutorial]----------------------------//

//Tutorial by Weponz Inc. © 2010 - 2011
hope this helps
Reply
#6

Lmfao, you took this piece of code from that achieve link...
Reply
#7

yeah.. thanks all.. but, how to setting 5 player in team 1 for 1 player in team 2 ?
Reply
#8

You will need a ratio variale
pawn Код:
#include <a_samp>


//Your Teams
#define Criminal 0
#define Cops 1

static gTeam[MAX_PLAYERS];

stock TeamCheck(teamid)
{
    new count = 0;//for counting players
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
            if(gTeam[i] != teamid) continue;
            playercount++;//else (there in the teamid) so count the player in the team..
    }
        return count;
}

public OnPlayerRequestSpawn(playerid)
{
    new copcount = TeamCheck(Cops);
    new crimcount = TeamCheck(Criminal);
    new Float:ratio = 0;
    if(gTeam[playerid] == Criminal)
    {
        if(copcount != 0) ratio = crimcount/copcount;
        if(ratio >= 5) GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Cops Team!", 3000, 5);
        return 0;
    }
    if(gTeam[playerid] == Cops)
    {
        if(copcount != 0) ratio = crimcount/copcount;
        if(ratio < 5) GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Criminal Team!", 3000, 5);
        return 0;
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by [MM]RoXoR[FS]
Посмотреть сообщение
You will need a ratio variale
pawn Код:
#include <a_samp>


//Your Teams
#define Criminal 0
#define Cops 1

static gTeam[MAX_PLAYERS];

stock TeamCheck(teamid)
{
    new count = 0;//for counting players
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
            if(gTeam[i] != teamid) continue;
            playercount++;//else (there in the teamid) so count the player in the team..
    }
        return count;
}

public OnPlayerRequestSpawn(playerid)
{
    new copcount = TeamCheck(Cops);
    new crimcount = TeamCheck(Criminal);
    new Float:ratio = 0;
    if(gTeam[playerid] == Criminal)
    {
        if(copcount != 0) ratio = crimcount/copcount;
        if(ratio >= 5) GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Cops Team!", 3000, 5);
        return 0;
    }
    if(gTeam[playerid] == Cops)
    {
        if(copcount != 0) ratio = crimcount/copcount;
        if(ratio < 5) GameTextForPlayer(playerid, "~r~Team Full!~n~~w~Choose Criminal Team!", 3000, 5);
        return 0;
    }
    return 1;
}
Код:
C:\Documents and Settings\SMART XP\Desktop\mysqlaccscriptrelease\gamemodes\t.pwn(35) : error 017: undefined symbol "playercount"
C:\Documents and Settings\SMART XP\Desktop\mysqlaccscriptrelease\gamemodes\t.pwn(35) : warning 215: expression has no effect
C:\Documents and Settings\SMART XP\Desktop\mysqlaccscriptrelease\gamemodes\t.pwn(37) : warning 217: loose indentation
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
the script on line 35 - 37:

Код:
        playercount++;//else (there in the teamid) so count the player in the team..
    }
        return count;
whats wrong ?
Reply
#10

Change playercount to count.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)