Raised This Month: $49 Target: $400
 12% 

Help Add flags instead of random player selection


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alyona
Member
Join Date: Nov 2013
Location: tver
Old 03-09-2017 , 11:44   Help Add flags instead of random player selection
Reply With Quote #1

i want to add 1 option in this plugin ...

2 admins are selected as captains , if admins are not there then only random player is selected as captain .






PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define TASK_MENUCLOSE 9001
#define TASK_PLAYERSLIST 9002

#define MinPlayers 10

new const Prefix[] = "[Captain]";

new 
RandomPlayer1;
new 
RandomPlayer2;

new 
bool:CaptainSort;

public 
plugin_init()
{
    
register_plugin("Captain Sorting""1.0""kramesa");
    
    
register_clcmd("say /capsort""StartCaptain");
    
    
register_clcmd("chooseteam""Block");
    
register_clcmd("jointeam""Block");
}

public 
StartCaptain(id)
{
    if(
is_user_admin(id))
    {
        if(
CaptainSort == true)
        {
            
client_print(idprint_chat"%s Captain Sort already running."Prefix);
            return 
PLUGIN_HANDLED;
        }
        
Captain();
        return 
PLUGIN_HANDLED;
    }
    
client_print(idprint_chat"%s Only admins have access to this command."Prefix);
    return 
PLUGIN_HANDLED;
}

public 
Block(id)
{
    if(
CaptainSort == true)
    {
        
client_print(idprint_chat"%s Captain Sort is running."Prefix);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;
}

public 
client_putinserver(id
{
    if(!
is_user_connected(RandomPlayer1) && CaptainSort && get_user_flags(id) & ADMIN_KICK)
    {
        
RandomPlayer1 id;
        
        new 
First_Captain[35];
        
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain));
        
        
client_print(0print_chat"%s The new Captain of CTs is: %s"PrefixFirst_Captain);
        
set_cvar_num("sv_restartround"1);
    }
    if(!
is_user_connected(RandomPlayer2) && CaptainSort && get_user_flags(id) & ADMIN_KICK)
    {
        
RandomPlayer2 id;
        
        new 
Second_Captain[35];
        
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain));
        
        
client_print(0print_chat"%s The new Captain of Ts is: %s"PrefixSecond_Captain);
        
set_cvar_num("sv_restartround"1)
    }
}

public 
Captain()
{
    new 
iPlayers[32], iNum;
    
get_players(iPlayersiNum"ch");
    
    if(
iNum MinPlayers)
    {
        
client_print(0print_chat"%s Need have more %d players to start Captain Sort."Prefix, (iNum MinPlayers));
        return 
PLUGIN_HANDLED;
    }
    for(new 
iiNumi++)
    {
        
user_silentkill(iPlayers[i]);
        
cs_set_user_team(iPlayers[i], 3);
    }
    if(
get_user_flags(iPlayers[iNum]) & ADMIN_KICK) {
        
RandomPlayer1 iPlayers[random(iNum)];
        
RandomPlayer2 iPlayers[random(iNum)];
    }
    
    while(
RandomPlayer1 == RandomPlayer2)
    {
        
RandomPlayer2 iPlayers[random(iNum)];
    }
    
cs_set_user_team(RandomPlayer1CS_TEAM_CT);
    
cs_set_user_team(RandomPlayer2CS_TEAM_T);
    
    new 
First_Captain[35], Second_Captain[35];
    
    
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain));
    
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain));
    
    
client_print(0print_chat"%s The Captain's are: %s (TRs) and %s (CTs)."PrefixFirst_CaptainSecond_Captain);
    
client_print(0print_chat"%s If no player is selected in 10 seconds, a player will be chosen random."Prefix);
    
    
set_cvar_num("sv_restartround"1)
    
    new 
First random(2)
    
    
set_task(1.5"captain_menu"First RandomPlayer1 RandomPlayer2);
    
set_task(0.2"PlayersList"TASK_PLAYERSLIST__"b");
    
    
CaptainSort true
    
return PLUGIN_CONTINUE
}

public 
captain_menu(id)
{
    new 
menu menu_create("Select a Player:""captainmenu_handler")
    
    
set_task(11.5"menu_task"id TASK_MENUCLOSE);
    
    new 
players[32], pnumtempid;
    new 
szName[32], szTempid[10];
    
    
get_players(playerspnum"ch")
    
    if(
pnum == 0)
    {
        
remove_task(id+TASK_MENUCLOSE)
        
remove_task(TASK_PLAYERSLIST)
        
CaptainSort false
        
        client_print
(0print_chat"%s Closing Captain Sort. Missing players."Prefix);
        return 
PLUGIN_HANDLED;
    }
    for(new 
ii<pnumi++)
    {
        
tempid players[i];
        
        if(
cs_get_user_team(tempid) != CS_TEAM_SPECTATOR) continue;
        
        
get_user_name(tempidszNamecharsmax(szName));
        
num_to_str(tempidszTempidcharsmax(szTempid));
        
        
menu_additem(menuszNameszTempid,0);
    }
    
menu_setprop(menuMPROP_EXITMEXIT_NEVER);
    
    
menu_display(idmenu0);
    return 
PLUGIN_HANDLED;
}

public 
captainmenu_handler(id,menu,item)
{
    if(
item == MENU_EXIT)
    {
        
menu_display(id,menu,0)
        return 
PLUGIN_HANDLED;
    }
    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), szNamecharsmax(szName), callback);
    
    new 
tempid str_to_num(data)
    
    new 
name[35], namec[35];
    
get_user_name(tempidnamecharsmax(name));
    
get_user_name(idnameccharsmax(namec));
    
    
cs_set_user_team(tempidcs_get_user_team(id));
    
client_print(0print_chat"%s %s choose the player %s"Prefixnamecname);
    
    
set_cvar_num("sv_restart",1)
    
    
remove_task(id+TASK_MENUCLOSE)
    
    new 
iPlayers[32],pnum
    get_players
(iPlayers,pnum,"h")
    
    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2))
    {
        
set_task(1.5,"captain_menu",id == RandomPlayer1 RandomPlayer2 RandomPlayer1)
    }
    else
    {
        
set_task(5.0,"CheckCaptainJoin",id == RandomPlayer1 RandomPlayer1 RandomPlayer2)
    }
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED
}

public 
menu_task(id)
{
    
id -= TASK_MENUCLOSE
    
    
new players[32], pnum;
    
get_players(playerspnum"ch");
    
    new 
randomnum random(pnum)
    new 
bool:has_spec
    
    
for(new ipnumi++)
    {
        if(
cs_get_user_team(players[i]) == CS_TEAM_SPECTATOR)
        {
            
has_spec true
        
}
    }
    if(!
has_spec)
    {
        
remove_task(TASK_PLAYERSLIST);
        
CaptainSort false;
        return;
    }
    while(
cs_get_user_team(players[randomnum]) != CS_TEAM_SPECTATOR)
    {
        
randomnum random(pnum)
    }
    if(
is_user_connected(id))
    {
        
set_cvar_num("sv_restart",1)
        
cs_set_user_team(players[randomnum],cs_get_user_team(id))
        
        
set_task(1.5"captain_menu"id == RandomPlayer1 RandomPlayer2 RandomPlayer1);
    }
    else
    {
        
set_task(5.0"CheckCaptainJoin"id == RandomPlayer1 RandomPlayer2 RandomPlayer1);
        
        
client_print(0print_chat"%s Awaiting the arrival of a new Captain."Prefix);
    }
    
show_menu(id0"^n"1);
}

public 
CheckCaptainJoin(NextCaptainMenu)
{
    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2))
    {
        
set_task(1.5"captain_menu"NextCaptainMenu)
    }
    else
    {
        
set_task(5.0"CheckCaptainJoin"NextCaptainMenu)
    }
}

public 
PlayersList()
{
    new 
iPlayers[32], iNum;
    
get_players(iPlayersiNum"ch");
    
    new 
posTRposCTposSPEC;
    new 
HudTextTR[512], HudTextCT[512], HudTextSPEC[512];
    new 
szName[38], name[38];
    
    for(new 
iiNumi++)
    {
        
get_user_name(iPlayers[i], szNamecharsmax(szName));
        
        if(
iPlayers[i] == RandomPlayer1 || iPlayers[i] == RandomPlayer2)
        {
            
formatex(namecharsmax(name), "%s (C)"szName);
        }
        else
        {
            
name szName;
        }
        if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_T)
        {
            
posTR += formatex(HudTextTR[posTR], 511-posTR,"%s^n"name);
        }
        else if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_CT)
        {
            
posCT += formatex(HudTextCT[posCT], 511-posCT"%s^n"name);
        }
        else
        {
            
posSPEC += formatex(HudTextSPEC[posSPEC], 511-posSPEC"%s^n"name);
        }
    }
    for(new 
iiNumi++)
    {
        
set_hudmessage(255000.700.1600.01.10.00.01);
        
show_hudmessage(iPlayers[i], "Terrorists:");
        
        
set_hudmessage(2552552550.700.1900.01.10.00.02);
        
show_hudmessage(iPlayers[i], HudTextTR);
        
        
set_hudmessage(002550.700.5100.01.10.00.03);
        
show_hudmessage(iPlayers[i], "Counter-Terrorist:");
        
        
set_hudmessage(2552552550.700.5400.01.10.00.04);
        
show_hudmessage(iPlayers[i], HudTextCT);
    }

alyona is offline
clavificial
Junior Member
Join Date: Jan 2017
Old 03-10-2017 , 17:37   Re: Help Add flags instead of random player selection
Reply With Quote #2

Should two random admins be selected?
clavificial is offline
clavificial
Junior Member
Join Date: Jan 2017
Old 03-10-2017 , 18:24   Re: Help Add flags instead of random player selection
Reply With Quote #3

Hi

I've modified the code.
If 2 or more admins are online, 2 random admins will become captains
Otherwise, if 1 admin or less is online, 2 random players will become captains.


PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <cstrike> 

#define TASK_MENUCLOSE 9001 
#define TASK_PLAYERSLIST 9002 

#define MinPlayers 10 

new const Prefix[] = "[Captain]"

new 
RandomPlayer1
new 
RandomPlayer2

new 
bool:CaptainSort

public 
plugin_init() 

    
register_plugin("Captain Sorting""1.0""kramesa"); 
    
    
register_clcmd("say /capsort""StartCaptain"); 
    
    
register_clcmd("chooseteam""Block"); 
    
register_clcmd("jointeam""Block"); 


public 
StartCaptain(id

    
//Check wheter user is admin or not
    
if(is_user_admin(id)) 
    { 
        
//If captain is already running
        
if(CaptainSort == true
        { 
            
client_print(idprint_chat"%s Captain Sort already running."Prefix); 
            return 
PLUGIN_HANDLED
        } 
        
        
//Start the captain
        
Captain(); 
        return 
PLUGIN_HANDLED
    } 
    
client_print(idprint_chat"%s Only admins have access to this command."Prefix); 
    return 
PLUGIN_HANDLED


public 
Block(id

    if(
CaptainSort == true
    { 
        
client_print(idprint_chat"%s Captain Sort is running."Prefix); 
        return 
PLUGIN_HANDLED
    } 
    return 
PLUGIN_CONTINUE


public 
client_putinserver(id)  

    if(!
is_user_connected(RandomPlayer1) && CaptainSort && get_user_flags(id) & ADMIN_KICK
    { 
        
RandomPlayer1 id
        
        new 
First_Captain[35]; 
        
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain)); 
        
        
client_print(0print_chat"%s The new Captain of CTs is: %s"PrefixFirst_Captain); 
        
set_cvar_num("sv_restartround"1); 
    } 
    if(!
is_user_connected(RandomPlayer2) && CaptainSort && get_user_flags(id) & ADMIN_KICK
    { 
        
RandomPlayer2 id
        
        new 
Second_Captain[35]; 
        
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain)); 
        
        
client_print(0print_chat"%s The new Captain of Ts is: %s"PrefixSecond_Captain); 
        
set_cvar_num("sv_restartround"1
    } 


public 
Num_Admins_Online() {
    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    new 
numAdmins
    
for(new 0iNum;i++) {
        new 
id iPlayers[i]
        if(
get_user_flags(id) & ADMIN_KICK) {
            
numAdmins++
        }
    }
    return 
numAdmins
}

//adminOnly? 1 = only admins can be captains, 0 = all players can be captains
public RandomCaptain(adminOnly) {
    
//I think this is wrong... iPlayers[iNum] will never return an actual player.
    //On a closer look this is just a more pretentious way of saying "if (true)"
    
new iPlayers[32], iNum
    
get_players(iPlayersiNum"ch");

    
RandomPlayer1 iPlayers[random(iNum)]; 
    
    while(
adminOnly == && !(get_user_flags(RandomPlayer1) & ADMIN_KICK)) {    
        
RandomPlayer1 iPlayers[random(iNum)]; 
    }
    
    
RandomPlayer2 RandomPlayer1    
    
    
//Making sure not getting same captain for both teams
    
while(RandomPlayer1 == RandomPlayer2 || (adminOnly == && !(get_user_flags(RandomPlayer2) & ADMIN_KICK)))
    { 
        
RandomPlayer2 iPlayers[random(iNum)]; 
    } 
}

public 
Captain() 

    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    
    
//Run only if enough players are connected
    
if(iNum MinPlayers
    { 
        
client_print(0print_chat"%s Need have more %d players to start Captain Sort."Prefix, (iNum MinPlayers)); 
        return 
PLUGIN_HANDLED
    } 
    
    
//Sort players to spectators
    
for(new iiNumi++) 
    { 
        
user_silentkill(iPlayers[i]); 
        
cs_set_user_team(iPlayers[i], 3); 
    } 
    
    
//NEW CODE HERE
    
if(Num_Admins_Online() >= 2) {
        
RandomCaptain(1)
    } else {
        
RandomCaptain(0)
    }
    
//--------------
    
    //Set captains to respective teams
    
cs_set_user_team(RandomPlayer1CS_TEAM_CT); 
    
cs_set_user_team(RandomPlayer2CS_TEAM_T); 
    
    new 
First_Captain[35], Second_Captain[35]; 
    
    
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain)); 
    
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain)); 
    
    
client_print(0print_chat"%s The Captain's are: %s (TRs) and %s (CTs)."PrefixFirst_CaptainSecond_Captain); 
    
client_print(0print_chat"%s If no player is selected in 10 seconds, a player will be chosen random."Prefix); 
    
    
set_cvar_num("sv_restartround"1
    
    new 
First random(2
    
    
set_task(1.5"captain_menu"First RandomPlayer1 RandomPlayer2); 
    
set_task(0.2"PlayersList"TASK_PLAYERSLIST__"b"); 
    
    
CaptainSort true 
    
return PLUGIN_CONTINUE 


public 
captain_menu(id

    new 
menu menu_create("Select a Player:""captainmenu_handler"
    
    
set_task(11.5"menu_task"id TASK_MENUCLOSE); 
    
    new 
players[32], pnumtempid
    new 
szName[32], szTempid[10]; 
    
    
get_players(playerspnum"ch"
    
    if(
pnum == 0
    { 
        
remove_task(id+TASK_MENUCLOSE
        
remove_task(TASK_PLAYERSLIST
        
CaptainSort false 
        
        client_print
(0print_chat"%s Closing Captain Sort. Missing players."Prefix); 
        return 
PLUGIN_HANDLED
    } 
    for(new 
ii<pnumi++) 
    { 
        
tempid players[i]; 
        
        if(
cs_get_user_team(tempid) != CS_TEAM_SPECTATOR) continue; 
        
        
get_user_name(tempidszNamecharsmax(szName)); 
        
num_to_str(tempidszTempidcharsmax(szTempid)); 
        
        
menu_additem(menuszNameszTempid,0); 
    } 
    
menu_setprop(menuMPROP_EXITMEXIT_NEVER); 
    
    
menu_display(idmenu0); 
    return 
PLUGIN_HANDLED


public 
captainmenu_handler(id,menu,item

    if(
item == MENU_EXIT
    { 
        
menu_display(id,menu,0
        return 
PLUGIN_HANDLED
    } 
    new 
data[6], szName[64]; 
    new 
accesscallback
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), szNamecharsmax(szName), callback); 
    
    new 
tempid str_to_num(data
    
    new 
name[35], namec[35]; 
    
get_user_name(tempidnamecharsmax(name)); 
    
get_user_name(idnameccharsmax(namec)); 
    
    
cs_set_user_team(tempidcs_get_user_team(id)); 
    
client_print(0print_chat"%s %s choose the player %s"Prefixnamecname); 
    
    
set_cvar_num("sv_restart",1
    
    
remove_task(id+TASK_MENUCLOSE
    
    new 
iPlayers[32],pnum 
    get_players
(iPlayers,pnum,"ch"
    
    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2)) 
    { 
        
set_task(1.5,"captain_menu",id == RandomPlayer1 RandomPlayer2 RandomPlayer1
    } 
    else 
    { 
        
set_task(5.0,"CheckCaptainJoin",id == RandomPlayer1 RandomPlayer1 RandomPlayer2
    } 
    
menu_destroy(menu
    return 
PLUGIN_HANDLED 


public 
menu_task(id

    
id -= TASK_MENUCLOSE 
    
    
new players[32], pnum
    
get_players(playerspnum"ch"); 
    
    new 
randomnum random(pnum
    new 
bool:has_spec 
    
    
for(new ipnumi++) 
    { 
        if(
cs_get_user_team(players[i]) == CS_TEAM_SPECTATOR
        { 
            
has_spec true 
        

    } 
    if(!
has_spec
    { 
        
remove_task(TASK_PLAYERSLIST); 
        
CaptainSort false
        return; 
    } 
    while(
cs_get_user_team(players[randomnum]) != CS_TEAM_SPECTATOR
    { 
        
randomnum random(pnum
    } 
    if(
is_user_connected(id)) 
    { 
        
set_cvar_num("sv_restart",1
        
cs_set_user_team(players[randomnum],cs_get_user_team(id)) 
        
        
set_task(1.5"captain_menu"id == RandomPlayer1 RandomPlayer2 RandomPlayer1); 
    } 
    else 
    { 
        
set_task(5.0"CheckCaptainJoin"id == RandomPlayer1 RandomPlayer2 RandomPlayer1); 
        
        
client_print(0print_chat"%s Awaiting the arrival of a new Captain."Prefix); 
    } 
    
show_menu(id0"^n"1); 


public 
CheckCaptainJoin(NextCaptainMenu

    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2)) 
    { 
        
set_task(1.5"captain_menu"NextCaptainMenu
    } 
    else 
    { 
        
set_task(5.0"CheckCaptainJoin"NextCaptainMenu
    } 


public 
PlayersList() 

    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    
    new 
posTRposCTposSPEC
    new 
HudTextTR[512], HudTextCT[512], HudTextSPEC[512]; 
    new 
szName[38], name[38]; 
    
    for(new 
iiNumi++) 
    { 
        
get_user_name(iPlayers[i], szNamecharsmax(szName)); 
        
        if(
iPlayers[i] == RandomPlayer1 || iPlayers[i] == RandomPlayer2
        { 
            
formatex(namecharsmax(name), "%s (C)"szName); 
        } 
        else  
        { 
            
name szName
        } 
        if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_T
        { 
            
posTR += formatex(HudTextTR[posTR], 511-posTR,"%s^n"name); 
        } 
        else if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_CT
        { 
            
posCT += formatex(HudTextCT[posCT], 511-posCT"%s^n"name); 
        } 
        else 
        { 
            
posSPEC += formatex(HudTextSPEC[posSPEC], 511-posSPEC"%s^n"name); 
        } 
    } 
    for(new 
iiNumi++) 
    { 
        
set_hudmessage(255000.700.1600.01.10.00.01); 
        
show_hudmessage(iPlayers[i], "Terrorists:"); 
        
        
set_hudmessage(2552552550.700.1900.01.10.00.02); 
        
show_hudmessage(iPlayers[i], HudTextTR); 
        
        
set_hudmessage(002550.700.5100.01.10.00.03); 
        
show_hudmessage(iPlayers[i], "Counter-Terrorist:"); 
        
        
set_hudmessage(2552552550.700.5400.01.10.00.04); 
        
show_hudmessage(iPlayers[i], HudTextCT); 
    } 

clavificial is offline
alyona
Member
Join Date: Nov 2013
Location: tver
Old 03-11-2017 , 22:48   Re: Help Add flags instead of random player selection
Reply With Quote #4

Quote:
Originally Posted by clavificial View Post
Hi

I've modified the code.
If 2 or more admins are online, 2 random admins will become captains
Otherwise, if 1 admin or less is online, 2 random players will become captains.


PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <cstrike> 

#define TASK_MENUCLOSE 9001 
#define TASK_PLAYERSLIST 9002 

#define MinPlayers 10 

new const Prefix[] = "[Captain]"

new 
RandomPlayer1
new 
RandomPlayer2

new 
bool:CaptainSort

public 
plugin_init() 

    
register_plugin("Captain Sorting""1.0""kramesa"); 
    
    
register_clcmd("say /capsort""StartCaptain"); 
    
    
register_clcmd("chooseteam""Block"); 
    
register_clcmd("jointeam""Block"); 


public 
StartCaptain(id

    
//Check wheter user is admin or not
    
if(is_user_admin(id)) 
    { 
        
//If captain is already running
        
if(CaptainSort == true
        { 
            
client_print(idprint_chat"%s Captain Sort already running."Prefix); 
            return 
PLUGIN_HANDLED
        } 
        
        
//Start the captain
        
Captain(); 
        return 
PLUGIN_HANDLED
    } 
    
client_print(idprint_chat"%s Only admins have access to this command."Prefix); 
    return 
PLUGIN_HANDLED


public 
Block(id

    if(
CaptainSort == true
    { 
        
client_print(idprint_chat"%s Captain Sort is running."Prefix); 
        return 
PLUGIN_HANDLED
    } 
    return 
PLUGIN_CONTINUE


public 
client_putinserver(id)  

    if(!
is_user_connected(RandomPlayer1) && CaptainSort && get_user_flags(id) & ADMIN_KICK
    { 
        
RandomPlayer1 id
        
        new 
First_Captain[35]; 
        
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain)); 
        
        
client_print(0print_chat"%s The new Captain of CTs is: %s"PrefixFirst_Captain); 
        
set_cvar_num("sv_restartround"1); 
    } 
    if(!
is_user_connected(RandomPlayer2) && CaptainSort && get_user_flags(id) & ADMIN_KICK
    { 
        
RandomPlayer2 id
        
        new 
Second_Captain[35]; 
        
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain)); 
        
        
client_print(0print_chat"%s The new Captain of Ts is: %s"PrefixSecond_Captain); 
        
set_cvar_num("sv_restartround"1
    } 


public 
Num_Admins_Online() {
    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    new 
numAdmins
    
for(new 0iNum;i++) {
        new 
id iPlayers[i]
        if(
get_user_flags(id) & ADMIN_KICK) {
            
numAdmins++
        }
    }
    return 
numAdmins
}

//adminOnly? 1 = only admins can be captains, 0 = all players can be captains
public RandomCaptain(adminOnly) {
    
//I think this is wrong... iPlayers[iNum] will never return an actual player.
    //On a closer look this is just a more pretentious way of saying "if (true)"
    
new iPlayers[32], iNum
    
get_players(iPlayersiNum"ch");

    
RandomPlayer1 iPlayers[random(iNum)]; 
    
    while(
adminOnly == && !(get_user_flags(RandomPlayer1) & ADMIN_KICK)) {    
        
RandomPlayer1 iPlayers[random(iNum)]; 
    }
    
    
RandomPlayer2 RandomPlayer1    
    
    
//Making sure not getting same captain for both teams
    
while(RandomPlayer1 == RandomPlayer2 || (adminOnly == && !(get_user_flags(RandomPlayer2) & ADMIN_KICK)))
    { 
        
RandomPlayer2 iPlayers[random(iNum)]; 
    } 
}

public 
Captain() 

    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    
    
//Run only if enough players are connected
    
if(iNum MinPlayers
    { 
        
client_print(0print_chat"%s Need have more %d players to start Captain Sort."Prefix, (iNum MinPlayers)); 
        return 
PLUGIN_HANDLED
    } 
    
    
//Sort players to spectators
    
for(new iiNumi++) 
    { 
        
user_silentkill(iPlayers[i]); 
        
cs_set_user_team(iPlayers[i], 3); 
    } 
    
    
//NEW CODE HERE
    
if(Num_Admins_Online() >= 2) {
        
RandomCaptain(1)
    } else {
        
RandomCaptain(0)
    }
    
//--------------
    
    //Set captains to respective teams
    
cs_set_user_team(RandomPlayer1CS_TEAM_CT); 
    
cs_set_user_team(RandomPlayer2CS_TEAM_T); 
    
    new 
First_Captain[35], Second_Captain[35]; 
    
    
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain)); 
    
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain)); 
    
    
client_print(0print_chat"%s The Captain's are: %s (TRs) and %s (CTs)."PrefixFirst_CaptainSecond_Captain); 
    
client_print(0print_chat"%s If no player is selected in 10 seconds, a player will be chosen random."Prefix); 
    
    
set_cvar_num("sv_restartround"1
    
    new 
First random(2
    
    
set_task(1.5"captain_menu"First RandomPlayer1 RandomPlayer2); 
    
set_task(0.2"PlayersList"TASK_PLAYERSLIST__"b"); 
    
    
CaptainSort true 
    
return PLUGIN_CONTINUE 


public 
captain_menu(id

    new 
menu menu_create("Select a Player:""captainmenu_handler"
    
    
set_task(11.5"menu_task"id TASK_MENUCLOSE); 
    
    new 
players[32], pnumtempid
    new 
szName[32], szTempid[10]; 
    
    
get_players(playerspnum"ch"
    
    if(
pnum == 0
    { 
        
remove_task(id+TASK_MENUCLOSE
        
remove_task(TASK_PLAYERSLIST
        
CaptainSort false 
        
        client_print
(0print_chat"%s Closing Captain Sort. Missing players."Prefix); 
        return 
PLUGIN_HANDLED
    } 
    for(new 
ii<pnumi++) 
    { 
        
tempid players[i]; 
        
        if(
cs_get_user_team(tempid) != CS_TEAM_SPECTATOR) continue; 
        
        
get_user_name(tempidszNamecharsmax(szName)); 
        
num_to_str(tempidszTempidcharsmax(szTempid)); 
        
        
menu_additem(menuszNameszTempid,0); 
    } 
    
menu_setprop(menuMPROP_EXITMEXIT_NEVER); 
    
    
menu_display(idmenu0); 
    return 
PLUGIN_HANDLED


public 
captainmenu_handler(id,menu,item

    if(
item == MENU_EXIT
    { 
        
menu_display(id,menu,0
        return 
PLUGIN_HANDLED
    } 
    new 
data[6], szName[64]; 
    new 
accesscallback
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), szNamecharsmax(szName), callback); 
    
    new 
tempid str_to_num(data
    
    new 
name[35], namec[35]; 
    
get_user_name(tempidnamecharsmax(name)); 
    
get_user_name(idnameccharsmax(namec)); 
    
    
cs_set_user_team(tempidcs_get_user_team(id)); 
    
client_print(0print_chat"%s %s choose the player %s"Prefixnamecname); 
    
    
set_cvar_num("sv_restart",1
    
    
remove_task(id+TASK_MENUCLOSE
    
    new 
iPlayers[32],pnum 
    get_players
(iPlayers,pnum,"ch"
    
    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2)) 
    { 
        
set_task(1.5,"captain_menu",id == RandomPlayer1 RandomPlayer2 RandomPlayer1
    } 
    else 
    { 
        
set_task(5.0,"CheckCaptainJoin",id == RandomPlayer1 RandomPlayer1 RandomPlayer2
    } 
    
menu_destroy(menu
    return 
PLUGIN_HANDLED 


public 
menu_task(id

    
id -= TASK_MENUCLOSE 
    
    
new players[32], pnum
    
get_players(playerspnum"ch"); 
    
    new 
randomnum random(pnum
    new 
bool:has_spec 
    
    
for(new ipnumi++) 
    { 
        if(
cs_get_user_team(players[i]) == CS_TEAM_SPECTATOR
        { 
            
has_spec true 
        

    } 
    if(!
has_spec
    { 
        
remove_task(TASK_PLAYERSLIST); 
        
CaptainSort false
        return; 
    } 
    while(
cs_get_user_team(players[randomnum]) != CS_TEAM_SPECTATOR
    { 
        
randomnum random(pnum
    } 
    if(
is_user_connected(id)) 
    { 
        
set_cvar_num("sv_restart",1
        
cs_set_user_team(players[randomnum],cs_get_user_team(id)) 
        
        
set_task(1.5"captain_menu"id == RandomPlayer1 RandomPlayer2 RandomPlayer1); 
    } 
    else 
    { 
        
set_task(5.0"CheckCaptainJoin"id == RandomPlayer1 RandomPlayer2 RandomPlayer1); 
        
        
client_print(0print_chat"%s Awaiting the arrival of a new Captain."Prefix); 
    } 
    
show_menu(id0"^n"1); 


public 
CheckCaptainJoin(NextCaptainMenu

    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2)) 
    { 
        
set_task(1.5"captain_menu"NextCaptainMenu
    } 
    else 
    { 
        
set_task(5.0"CheckCaptainJoin"NextCaptainMenu
    } 


public 
PlayersList() 

    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    
    new 
posTRposCTposSPEC
    new 
HudTextTR[512], HudTextCT[512], HudTextSPEC[512]; 
    new 
szName[38], name[38]; 
    
    for(new 
iiNumi++) 
    { 
        
get_user_name(iPlayers[i], szNamecharsmax(szName)); 
        
        if(
iPlayers[i] == RandomPlayer1 || iPlayers[i] == RandomPlayer2
        { 
            
formatex(namecharsmax(name), "%s (C)"szName); 
        } 
        else  
        { 
            
name szName
        } 
        if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_T
        { 
            
posTR += formatex(HudTextTR[posTR], 511-posTR,"%s^n"name); 
        } 
        else if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_CT
        { 
            
posCT += formatex(HudTextCT[posCT], 511-posCT"%s^n"name); 
        } 
        else 
        { 
            
posSPEC += formatex(HudTextSPEC[posSPEC], 511-posSPEC"%s^n"name); 
        } 
    } 
    for(new 
iiNumi++) 
    { 
        
set_hudmessage(255000.700.1600.01.10.00.01); 
        
show_hudmessage(iPlayers[i], "Terrorists:"); 
        
        
set_hudmessage(2552552550.700.1900.01.10.00.02); 
        
show_hudmessage(iPlayers[i], HudTextTR); 
        
        
set_hudmessage(002550.700.5100.01.10.00.03); 
        
show_hudmessage(iPlayers[i], "Counter-Terrorist:"); 
        
        
set_hudmessage(2552552550.700.5400.01.10.00.04); 
        
show_hudmessage(iPlayers[i], HudTextCT); 
    } 

thnx its working fine but is it possible to make , if 1 admin is online then he can choose 2 player from the list as captains (either himself or 2 other diff player) . i meant admins will get option to choose captains . if no admin online then random captains are selected .
alyona is offline
clavificial
Junior Member
Join Date: Jan 2017
Old 03-12-2017 , 18:13   Re: Help Add flags instead of random player selection
Reply With Quote #5

Try this
amx_captain_ct "name" to set CT captain
amx_captain_t "name" to set T captain
both ct and t needs to be set, otherwise it will be randomized.

If you want to remove captains (in case you want to get random captains instead) you use the command amx_removecaptains

PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <cstrike> 

#define TASK_MENUCLOSE 9001 
#define TASK_PLAYERSLIST 9002 

#define MinPlayers 10 

new const Prefix[] = "[Captain]"

new 
RandomPlayer1
new 
RandomPlayer2

new 
bool:CaptainSort

public 
plugin_init() 

    
register_plugin("Captain Sorting""1.0""kramesa"); 
    
    
register_concmd("amx_captain_ct""cmd_ct_captain")
    
register_concmd("amx_captain_t""cmd_t_captain")
    
register_concmd("amx_removecaptains""cmd_removecaptains")
    
register_concmd("say /capsort""StartCaptain"); 
    
    
register_clcmd("chooseteam""Block"); 
    
register_clcmd("jointeam""Block"); 


public 
cmd_removecaptains(id) {
    if(!
is_user_admin(id)) {
        
client_print(idprint_console"%s You don't have access to that command"Prefix)
        return 
PLUGIN_HANDLED
    
}
    
    
RandomPlayer1 0
    RandomPlayer2 
0
    client_print
(idprint_console"%s The captains are now removed."Prefix)
    return 
PLUGIN_HANDLED
}

public 
cmd_ct_captain(id) {
    
cmd_captain(idCS_TEAM_CT)
    return 
PLUGIN_HANDLED
}

public 
cmd_t_captain(id) {
    
cmd_captain(idCS_TEAM_T)
    return 
PLUGIN_HANDLED
}

public 
cmd_captain(id, {CsTeams,_}:team) {
    if(!
is_user_admin(id)) {
        
client_print(idprint_console"%s You don't have access to that command"Prefix)
        return 
PLUGIN_HANDLED
    
}
    new 
args[32]
    
read_args(args31)
    
    new 
iPlayers[32]
    new 
iNum
    get_players
(iPlayersiNum"ch")
    
    for(new 
0iNumi++) {
        new 
temp_plr_name[32]
        
get_user_name(iPlayers[i], temp_plr_name31)
        
        if(
containi(temp_plr_nameargs)!=-1) {
            if(
team == CS_TEAM_CT) {
                
RandomPlayer1 iPlayers[i]
                
client_print(idprint_console"%s Player '%s' is now captain of the Counter-Terrorists."Prefixtemp_plr_name)
            } else if (
team == CS_TEAM_T) {
                
RandomPlayer2 iPlayers[i]
                
client_print(idprint_console"%s Player '%s' is now captain of the Terrorists."Prefixtemp_plr_name)
            }
            
            return 
PLUGIN_HANDLED
        
}
    }
    
    new 
cur_captain[32]
    new 
team_str[32]
    if(
team == CS_TEAM_CT) {
        
get_user_name(RandomPlayer1cur_captain31)
        
format(team_str31"Counter-Terrorist")
    } else if (
team == CS_TEAM_T) {
        
format(team_str31"Terrorist")
        
get_user_name(RandomPlayer2cur_captain31)
    }
    
    
client_print(idprint_console"%s Captain for %s is '%s'"Prefixteam_strcur_captain)
    return 
PLUGIN_HANDLED
}

public 
StartCaptain(id

    
//Check wheter user is admin or not
    
if(is_user_admin(id)) 
    { 
        
//If captain is already running
        
if(CaptainSort == true
        { 
            
client_print(idprint_chat"%s Captain Sort already running."Prefix); 
            return 
PLUGIN_HANDLED
        } 
        
        
//Start the captain
        
Captain(); 
        return 
PLUGIN_HANDLED
    } 
    
client_print(idprint_chat"%s Only admins have access to this command."Prefix); 
    return 
PLUGIN_HANDLED


public 
Block(id

    if(
CaptainSort == true
    { 
        
client_print(idprint_chat"%s Captain Sort is running."Prefix); 
        return 
PLUGIN_HANDLED
    } 
    return 
PLUGIN_CONTINUE


public 
client_putinserver(id)  

    if(!
is_user_connected(RandomPlayer1) && CaptainSort && get_user_flags(id) & ADMIN_KICK
    { 
        
RandomPlayer1 id
        
        new 
First_Captain[35]; 
        
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain)); 
        
        
client_print(0print_chat"%s The new Captain of CTs is: %s"PrefixFirst_Captain); 
        
set_cvar_num("sv_restartround"1); 
    } 
    if(!
is_user_connected(RandomPlayer2) && CaptainSort && get_user_flags(id) & ADMIN_KICK
    { 
        
RandomPlayer2 id
        
        new 
Second_Captain[35]; 
        
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain)); 
        
        
client_print(0print_chat"%s The new Captain of Ts is: %s"PrefixSecond_Captain); 
        
set_cvar_num("sv_restartround"1
    } 


public 
Num_Admins_Online() {
    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    new 
numAdmins
    
for(new 0iNum;i++) {
        new 
id iPlayers[i]
        if(
get_user_flags(id) & ADMIN_KICK) {
            
numAdmins++
        }
    }
    return 
numAdmins
}

//adminOnly? 1 = only admins can be captains, 0 = all players can be captains
public RandomCaptain(adminOnly) {
    
//I think this is wrong... iPlayers[iNum] will never return an actual player.
    //On a closer look this is just a more pretentious way of saying "if (true)"
    
new iPlayers[32], iNum
    
get_players(iPlayersiNum"ch");

    
RandomPlayer1 iPlayers[random(iNum)]; 
    
    while(
adminOnly == && !(get_user_flags(RandomPlayer1) & ADMIN_KICK)) {    
        
RandomPlayer1 iPlayers[random(iNum)]; 
    }
    
    
RandomPlayer2 RandomPlayer1    
    
    
//Making sure not getting same captain for both teams
    
while(RandomPlayer1 == RandomPlayer2 || (adminOnly == && !(get_user_flags(RandomPlayer2) & ADMIN_KICK)))
    { 
        
RandomPlayer2 iPlayers[random(iNum)]; 
    } 
}

public 
Captain() 

    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    
    
//Run only if enough players are connected
    
if(iNum MinPlayers
    { 
        
client_print(0print_chat"%s Need have more %d players to start Captain Sort."Prefix, (iNum MinPlayers)); 
        return 
PLUGIN_HANDLED
    } 
    
    
//Sort players to spectators
    
for(new iiNumi++) 
    { 
        
user_silentkill(iPlayers[i]); 
        
cs_set_user_team(iPlayers[i], 3); 
    } 
    
    if(!
is_user_connected(RandomPlayer1) || !is_user_connected(RandomPlayer2)) {
        
//NEW CODE HERE
        
if(Num_Admins_Online() >= 2) {
            
RandomCaptain(1)
        } else {
            
RandomCaptain(0)
        }
        
//--------------
    
}
    
    
//Set captains to respective teams
    
cs_set_user_team(RandomPlayer1CS_TEAM_CT); 
    
cs_set_user_team(RandomPlayer2CS_TEAM_T); 
    
    new 
First_Captain[35], Second_Captain[35]; 
    
    
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain)); 
    
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain)); 
    
    
client_print(0print_chat"%s The Captain's are: %s (TRs) and %s (CTs)."PrefixFirst_CaptainSecond_Captain); 
    
client_print(0print_chat"%s If no player is selected in 10 seconds, a player will be chosen random."Prefix); 
    
    
set_cvar_num("sv_restartround"1
    
    new 
First random(2
    
    
set_task(1.5"captain_menu"First RandomPlayer1 RandomPlayer2); 
    
set_task(0.2"PlayersList"TASK_PLAYERSLIST__"b"); 
    
    
CaptainSort true 
    
return PLUGIN_CONTINUE 


public 
captain_menu(id

    new 
menu menu_create("Select a Player:""captainmenu_handler"
    
    
set_task(11.5"menu_task"id TASK_MENUCLOSE); 
    
    new 
players[32], pnumtempid
    new 
szName[32], szTempid[10]; 
    
    
get_players(playerspnum"ch"
    
    if(
pnum == 0
    { 
        
remove_task(id+TASK_MENUCLOSE
        
remove_task(TASK_PLAYERSLIST
        
CaptainSort false 
        
        client_print
(0print_chat"%s Closing Captain Sort. Missing players."Prefix); 
        return 
PLUGIN_HANDLED
    } 
    for(new 
ii<pnumi++) 
    { 
        
tempid players[i]; 
        
        if(
cs_get_user_team(tempid) != CS_TEAM_SPECTATOR) continue; 
        
        
get_user_name(tempidszNamecharsmax(szName)); 
        
num_to_str(tempidszTempidcharsmax(szTempid)); 
        
        
menu_additem(menuszNameszTempid,0); 
    } 
    
menu_setprop(menuMPROP_EXITMEXIT_NEVER); 
    
    
menu_display(idmenu0); 
    return 
PLUGIN_HANDLED


public 
captainmenu_handler(id,menu,item

    if(
item == MENU_EXIT
    { 
        
menu_display(id,menu,0
        return 
PLUGIN_HANDLED
    } 
    new 
data[6], szName[64]; 
    new 
accesscallback
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), szNamecharsmax(szName), callback); 
    
    new 
tempid str_to_num(data
    
    new 
name[35], namec[35]; 
    
get_user_name(tempidnamecharsmax(name)); 
    
get_user_name(idnameccharsmax(namec)); 
    
    
cs_set_user_team(tempidcs_get_user_team(id)); 
    
client_print(0print_chat"%s %s choose the player %s"Prefixnamecname); 
    
    
set_cvar_num("sv_restart",1
    
    
remove_task(id+TASK_MENUCLOSE
    
    new 
iPlayers[32],pnum 
    get_players
(iPlayers,pnum,"ch"
    
    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2)) 
    { 
        
set_task(1.5,"captain_menu",id == RandomPlayer1 RandomPlayer2 RandomPlayer1
    } 
    else 
    { 
        
set_task(5.0,"CheckCaptainJoin",id == RandomPlayer1 RandomPlayer1 RandomPlayer2
    } 
    
menu_destroy(menu
    return 
PLUGIN_HANDLED 


public 
menu_task(id

    
id -= TASK_MENUCLOSE 
    
    
new players[32], pnum
    
get_players(playerspnum"ch"); 
    
    new 
randomnum random(pnum
    new 
bool:has_spec 
    
    
for(new ipnumi++) 
    { 
        if(
cs_get_user_team(players[i]) == CS_TEAM_SPECTATOR
        { 
            
has_spec true 
        

    } 
    if(!
has_spec
    { 
        
remove_task(TASK_PLAYERSLIST); 
        
CaptainSort false
        return; 
    } 
    while(
cs_get_user_team(players[randomnum]) != CS_TEAM_SPECTATOR
    { 
        
randomnum random(pnum
    } 
    if(
is_user_connected(id)) 
    { 
        
set_cvar_num("sv_restart",1
        
cs_set_user_team(players[randomnum],cs_get_user_team(id)) 
        
        
set_task(1.5"captain_menu"id == RandomPlayer1 RandomPlayer2 RandomPlayer1); 
    } 
    else 
    { 
        
set_task(5.0"CheckCaptainJoin"id == RandomPlayer1 RandomPlayer2 RandomPlayer1); 
        
        
client_print(0print_chat"%s Awaiting the arrival of a new Captain."Prefix); 
    } 
    
show_menu(id0"^n"1); 


public 
CheckCaptainJoin(NextCaptainMenu

    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2)) 
    { 
        
set_task(1.5"captain_menu"NextCaptainMenu
    } 
    else 
    { 
        
set_task(5.0"CheckCaptainJoin"NextCaptainMenu
    } 


public 
PlayersList() 

    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    
    new 
posTRposCTposSPEC
    new 
HudTextTR[512], HudTextCT[512], HudTextSPEC[512]; 
    new 
szName[38], name[38]; 
    
    for(new 
iiNumi++) 
    { 
        
get_user_name(iPlayers[i], szNamecharsmax(szName)); 
        
        if(
iPlayers[i] == RandomPlayer1 || iPlayers[i] == RandomPlayer2
        { 
            
formatex(namecharsmax(name), "%s (C)"szName); 
        } 
        else  
        { 
            
name szName
        } 
        if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_T
        { 
            
posTR += formatex(HudTextTR[posTR], 511-posTR,"%s^n"name); 
        } 
        else if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_CT
        { 
            
posCT += formatex(HudTextCT[posCT], 511-posCT"%s^n"name); 
        } 
        else 
        { 
            
posSPEC += formatex(HudTextSPEC[posSPEC], 511-posSPEC"%s^n"name); 
        } 
    } 
    for(new 
iiNumi++) 
    { 
        
set_hudmessage(255000.700.1600.01.10.00.01); 
        
show_hudmessage(iPlayers[i], "Terrorists:"); 
        
        
set_hudmessage(2552552550.700.1900.01.10.00.02); 
        
show_hudmessage(iPlayers[i], HudTextTR); 
        
        
set_hudmessage(002550.700.5100.01.10.00.03); 
        
show_hudmessage(iPlayers[i], "Counter-Terrorist:"); 
        
        
set_hudmessage(2552552550.700.5400.01.10.00.04); 
        
show_hudmessage(iPlayers[i], HudTextCT); 
    } 


Last edited by clavificial; 03-24-2017 at 06:11. Reason: Fixed duplicate variable name
clavificial is offline
alyona
Member
Join Date: Nov 2013
Location: tver
Old 03-14-2017 , 08:33   Re: Help Add flags instead of random player selection
Reply With Quote #6

Quote:
Originally Posted by clavificial View Post
Try this
amx_captain_ct "name" to set CT captain
amx_captain_t "name" to set T captain
both ct and t needs to be set, otherwise it will be randomized.

If you want to remove captains (in case you want to get random captains instead) you use the command amx_removecaptains

PHP Code:

#include <amxmodx> 
#include <amxmisc> 
#include <cstrike> 

#define TASK_MENUCLOSE 9001 
#define TASK_PLAYERSLIST 9002 

#define MinPlayers 10 

new const Prefix[] = "[Captain]"

new 
RandomPlayer1
new 
RandomPlayer2

new 
bool:CaptainSort

public 
plugin_init() 

    
register_plugin("Captain Sorting""1.0""kramesa"); 
    
    
register_concmd("amx_captain_ct""cmd_ct_captain")
    
register_concmd("amx_captain_t""cmd_t_captain")
    
register_concmd("amx_removecaptains""cmd_removecaptains")
    
register_concmd("say /capsort""StartCaptain"); 
    
    
register_clcmd("chooseteam""Block"); 
    
register_clcmd("jointeam""Block"); 


public 
cmd_removecaptains(id) {
    if(!
is_user_admin(id)) {
        
client_print(idprint_console"%s You don't have access to that command"Prefix)
        return 
PLUGIN_HANDLED
    
}
    
    
RandomPlayer1 0
    RandomPlayer2 
0
    client_print
(idprint_console"%s The captains are now removed."Prefix)
    return 
PLUGIN_HANDLED
}

public 
cmd_ct_captain(id) {
    
cmd_captain(idCS_TEAM_CT)
    return 
PLUGIN_HANDLED
}

public 
cmd_t_captain(id) {
    
cmd_captain(idCS_TEAM_T)
    return 
PLUGIN_HANDLED
}

public 
cmd_captain(id, {CsTeams,_}:team) {
    if(!
is_user_admin(id)) {
        
client_print(idprint_console"%s You don't have access to that command"Prefix)
        return 
PLUGIN_HANDLED
    
}
    new 
args[32]
    
read_args(args31)
    
    new 
iPlayers[32]
    new 
iNum
    get_players
(iPlayersiNum"ch")
    
    for(new 
0iNumi++) {
        new 
temp_plr_name[32]
        
get_user_name(iPlayers[i], temp_plr_name31)
        
        if(
containi(temp_plr_nameargs)!=-1) {
            if(
team == CS_TEAM_CT) {
                
RandomPlayer1 iPlayers[i]
                
client_print(idprint_console"%s Player '%s' is now captain of the Counter-Terrorists."Prefixtemp_plr_name)
            } else if (
team == CS_TEAM_T) {
                
RandomPlayer2 iPlayers[i]
                
client_print(idprint_console"%s Player '%s' is now captain of the Terrorists."Prefixtemp_plr_name)
            }
            
            return 
PLUGIN_HANDLED
        
}
    }
    
    new 
cur_captain[32]
    new 
team[32]
    if(
team == CS_TEAM_CT) {
        
get_user_name(RandomPlayer1cur_captain31)
        
format(team31"Counter-Terrorist")
    } else if (
team == CS_TEAM_T) {
        
format(team31"Terrorist")
        
get_user_name(RandomPlayer2cur_captain31)
    }
    
    
client_print(idprint_console"%s Captain for %s is '%s'"Prefixteamcur_captain)
    return 
PLUGIN_HANDLED
}

public 
StartCaptain(id

    
//Check wheter user is admin or not
    
if(is_user_admin(id)) 
    { 
        
//If captain is already running
        
if(CaptainSort == true
        { 
            
client_print(idprint_chat"%s Captain Sort already running."Prefix); 
            return 
PLUGIN_HANDLED
        } 
        
        
//Start the captain
        
Captain(); 
        return 
PLUGIN_HANDLED
    } 
    
client_print(idprint_chat"%s Only admins have access to this command."Prefix); 
    return 
PLUGIN_HANDLED


public 
Block(id

    if(
CaptainSort == true
    { 
        
client_print(idprint_chat"%s Captain Sort is running."Prefix); 
        return 
PLUGIN_HANDLED
    } 
    return 
PLUGIN_CONTINUE


public 
client_putinserver(id)  

    if(!
is_user_connected(RandomPlayer1) && CaptainSort && get_user_flags(id) & ADMIN_KICK
    { 
        
RandomPlayer1 id
        
        new 
First_Captain[35]; 
        
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain)); 
        
        
client_print(0print_chat"%s The new Captain of CTs is: %s"PrefixFirst_Captain); 
        
set_cvar_num("sv_restartround"1); 
    } 
    if(!
is_user_connected(RandomPlayer2) && CaptainSort && get_user_flags(id) & ADMIN_KICK
    { 
        
RandomPlayer2 id
        
        new 
Second_Captain[35]; 
        
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain)); 
        
        
client_print(0print_chat"%s The new Captain of Ts is: %s"PrefixSecond_Captain); 
        
set_cvar_num("sv_restartround"1
    } 


public 
Num_Admins_Online() {
    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    new 
numAdmins
    
for(new 0iNum;i++) {
        new 
id iPlayers[i]
        if(
get_user_flags(id) & ADMIN_KICK) {
            
numAdmins++
        }
    }
    return 
numAdmins
}

//adminOnly? 1 = only admins can be captains, 0 = all players can be captains
public RandomCaptain(adminOnly) {
    
//I think this is wrong... iPlayers[iNum] will never return an actual player.
    //On a closer look this is just a more pretentious way of saying "if (true)"
    
new iPlayers[32], iNum
    
get_players(iPlayersiNum"ch");

    
RandomPlayer1 iPlayers[random(iNum)]; 
    
    while(
adminOnly == && !(get_user_flags(RandomPlayer1) & ADMIN_KICK)) {    
        
RandomPlayer1 iPlayers[random(iNum)]; 
    }
    
    
RandomPlayer2 RandomPlayer1    
    
    
//Making sure not getting same captain for both teams
    
while(RandomPlayer1 == RandomPlayer2 || (adminOnly == && !(get_user_flags(RandomPlayer2) & ADMIN_KICK)))
    { 
        
RandomPlayer2 iPlayers[random(iNum)]; 
    } 
}

public 
Captain() 

    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    
    
//Run only if enough players are connected
    
if(iNum MinPlayers
    { 
        
client_print(0print_chat"%s Need have more %d players to start Captain Sort."Prefix, (iNum MinPlayers)); 
        return 
PLUGIN_HANDLED
    } 
    
    
//Sort players to spectators
    
for(new iiNumi++) 
    { 
        
user_silentkill(iPlayers[i]); 
        
cs_set_user_team(iPlayers[i], 3); 
    } 
    
    if(!
is_user_connected(RandomPlayer1) || !is_user_connected(RandomPlayer2)) {
        
//NEW CODE HERE
        
if(Num_Admins_Online() >= 2) {
            
RandomCaptain(1)
        } else {
            
RandomCaptain(0)
        }
        
//--------------
    
}
    
    
//Set captains to respective teams
    
cs_set_user_team(RandomPlayer1CS_TEAM_CT); 
    
cs_set_user_team(RandomPlayer2CS_TEAM_T); 
    
    new 
First_Captain[35], Second_Captain[35]; 
    
    
get_user_name(RandomPlayer1First_Captaincharsmax(First_Captain)); 
    
get_user_name(RandomPlayer2Second_Captaincharsmax(Second_Captain)); 
    
    
client_print(0print_chat"%s The Captain's are: %s (TRs) and %s (CTs)."PrefixFirst_CaptainSecond_Captain); 
    
client_print(0print_chat"%s If no player is selected in 10 seconds, a player will be chosen random."Prefix); 
    
    
set_cvar_num("sv_restartround"1
    
    new 
First random(2
    
    
set_task(1.5"captain_menu"First RandomPlayer1 RandomPlayer2); 
    
set_task(0.2"PlayersList"TASK_PLAYERSLIST__"b"); 
    
    
CaptainSort true 
    
return PLUGIN_CONTINUE 


public 
captain_menu(id

    new 
menu menu_create("Select a Player:""captainmenu_handler"
    
    
set_task(11.5"menu_task"id TASK_MENUCLOSE); 
    
    new 
players[32], pnumtempid
    new 
szName[32], szTempid[10]; 
    
    
get_players(playerspnum"ch"
    
    if(
pnum == 0
    { 
        
remove_task(id+TASK_MENUCLOSE
        
remove_task(TASK_PLAYERSLIST
        
CaptainSort false 
        
        client_print
(0print_chat"%s Closing Captain Sort. Missing players."Prefix); 
        return 
PLUGIN_HANDLED
    } 
    for(new 
ii<pnumi++) 
    { 
        
tempid players[i]; 
        
        if(
cs_get_user_team(tempid) != CS_TEAM_SPECTATOR) continue; 
        
        
get_user_name(tempidszNamecharsmax(szName)); 
        
num_to_str(tempidszTempidcharsmax(szTempid)); 
        
        
menu_additem(menuszNameszTempid,0); 
    } 
    
menu_setprop(menuMPROP_EXITMEXIT_NEVER); 
    
    
menu_display(idmenu0); 
    return 
PLUGIN_HANDLED


public 
captainmenu_handler(id,menu,item

    if(
item == MENU_EXIT
    { 
        
menu_display(id,menu,0
        return 
PLUGIN_HANDLED
    } 
    new 
data[6], szName[64]; 
    new 
accesscallback
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), szNamecharsmax(szName), callback); 
    
    new 
tempid str_to_num(data
    
    new 
name[35], namec[35]; 
    
get_user_name(tempidnamecharsmax(name)); 
    
get_user_name(idnameccharsmax(namec)); 
    
    
cs_set_user_team(tempidcs_get_user_team(id)); 
    
client_print(0print_chat"%s %s choose the player %s"Prefixnamecname); 
    
    
set_cvar_num("sv_restart",1
    
    
remove_task(id+TASK_MENUCLOSE
    
    new 
iPlayers[32],pnum 
    get_players
(iPlayers,pnum,"ch"
    
    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2)) 
    { 
        
set_task(1.5,"captain_menu",id == RandomPlayer1 RandomPlayer2 RandomPlayer1
    } 
    else 
    { 
        
set_task(5.0,"CheckCaptainJoin",id == RandomPlayer1 RandomPlayer1 RandomPlayer2
    } 
    
menu_destroy(menu
    return 
PLUGIN_HANDLED 


public 
menu_task(id

    
id -= TASK_MENUCLOSE 
    
    
new players[32], pnum
    
get_players(playerspnum"ch"); 
    
    new 
randomnum random(pnum
    new 
bool:has_spec 
    
    
for(new ipnumi++) 
    { 
        if(
cs_get_user_team(players[i]) == CS_TEAM_SPECTATOR
        { 
            
has_spec true 
        

    } 
    if(!
has_spec
    { 
        
remove_task(TASK_PLAYERSLIST); 
        
CaptainSort false
        return; 
    } 
    while(
cs_get_user_team(players[randomnum]) != CS_TEAM_SPECTATOR
    { 
        
randomnum random(pnum
    } 
    if(
is_user_connected(id)) 
    { 
        
set_cvar_num("sv_restart",1
        
cs_set_user_team(players[randomnum],cs_get_user_team(id)) 
        
        
set_task(1.5"captain_menu"id == RandomPlayer1 RandomPlayer2 RandomPlayer1); 
    } 
    else 
    { 
        
set_task(5.0"CheckCaptainJoin"id == RandomPlayer1 RandomPlayer2 RandomPlayer1); 
        
        
client_print(0print_chat"%s Awaiting the arrival of a new Captain."Prefix); 
    } 
    
show_menu(id0"^n"1); 


public 
CheckCaptainJoin(NextCaptainMenu

    if(
is_user_connected(RandomPlayer1) && is_user_connected(RandomPlayer2)) 
    { 
        
set_task(1.5"captain_menu"NextCaptainMenu
    } 
    else 
    { 
        
set_task(5.0"CheckCaptainJoin"NextCaptainMenu
    } 


public 
PlayersList() 

    new 
iPlayers[32], iNum
    
get_players(iPlayersiNum"ch"); 
    
    new 
posTRposCTposSPEC
    new 
HudTextTR[512], HudTextCT[512], HudTextSPEC[512]; 
    new 
szName[38], name[38]; 
    
    for(new 
iiNumi++) 
    { 
        
get_user_name(iPlayers[i], szNamecharsmax(szName)); 
        
        if(
iPlayers[i] == RandomPlayer1 || iPlayers[i] == RandomPlayer2
        { 
            
formatex(namecharsmax(name), "%s (C)"szName); 
        } 
        else  
        { 
            
name szName
        } 
        if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_T
        { 
            
posTR += formatex(HudTextTR[posTR], 511-posTR,"%s^n"name); 
        } 
        else if(
cs_get_user_team(iPlayers[i]) == CS_TEAM_CT
        { 
            
posCT += formatex(HudTextCT[posCT], 511-posCT"%s^n"name); 
        } 
        else 
        { 
            
posSPEC += formatex(HudTextSPEC[posSPEC], 511-posSPEC"%s^n"name); 
        } 
    } 
    for(new 
iiNumi++) 
    { 
        
set_hudmessage(255000.700.1600.01.10.00.01); 
        
show_hudmessage(iPlayers[i], "Terrorists:"); 
        
        
set_hudmessage(2552552550.700.1900.01.10.00.02); 
        
show_hudmessage(iPlayers[i], HudTextTR); 
        
        
set_hudmessage(002550.700.5100.01.10.00.03); 
        
show_hudmessage(iPlayers[i], "Counter-Terrorist:"); 
        
        
set_hudmessage(2552552550.700.5400.01.10.00.04); 
        
show_hudmessage(iPlayers[i], HudTextCT); 
    } 

each time it says player with this name doesnt exist , if the players name is big... its fine only wen the nick is short n easy ... tried with "" also ..

can u do like this wen admin types /capsort by say or by console it should show menu of players list . Admin should select 2 players from the list for captain .Instead of cvar amx_captain_ct "name" , amx_captain_t "name" ... That will be my last request please... Sorry for too many changes ...
alyona is offline
deepaklost
Member
Join Date: Jan 2011
Old 03-16-2017 , 15:16   Re: Help Add flags instead of random player selection
Reply With Quote #7

round is restarted on each player selection . can any1 explain why is it needed ?? why not make it without restart multiple times. ??
deepaklost is offline
hufuishu
Junior Member
Join Date: Aug 2016
Old 03-17-2017 , 06:11   Re: Help Add flags instead of random player selection
Reply With Quote #8

Quote:
Originally Posted by deepaklost View Post
round is restarted on each player selection . can any1 explain why is it needed ?? why not make it without restart multiple times. ??
no one should use this as it has so many bugs and..it needs total refreshment
hufuishu is offline
alyona
Member
Join Date: Nov 2013
Location: tver
Old 03-23-2017 , 13:03   Re: Help Add flags instead of random player selection
Reply With Quote #9

Quote:
Originally Posted by hufuishu View Post
no one should use this as it has so many bugs and..it needs total refreshment
ignore him guys... it was him who requested the plugin and later deleted the post to be kept secret
alyona is offline
hufuishu
Junior Member
Join Date: Aug 2016
Old 03-25-2017 , 13:53   Re: Help Add flags instead of random player selection
Reply With Quote #10

Quote:
Originally Posted by alyona View Post
ignore him guys... it was him who requested the plugin and later deleted the post to be kept secret
Lol...First thing , that wasn't me..its a long story, second thing..this is a capt sort plugin which has bugs and needs a total refreshment as it makes random players captain.

There's one more plugin named Mix Selection 1.0..https://forums.alliedmods.net/showth...xSelection+1.0

But this too needs a refreshment as it doesn't work anymore...

I personally use Amx match deluxe., just added few things in that to make it an advanced war plugin...
Attached Files
File Type: sma Get Plugin or Get Source (CaptainSort.sma - 404 views - 7.3 KB)
hufuishu is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:14.


Powered by vBulletin®
Copyright ©2000 - 2022, vBulletin Solutions, Inc.
Theme made by Freecode