AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Teams control (https://forums.alliedmods.net/showthread.php?t=214392)

GhostMan 04-26-2013 10:27

Teams control
 
I'm using code from one very old plugin to limit CT team. Becouse it is old code i'm pretty sure that there is more efficient way to do what i want. Moreover, this code works not quite exact as i would like.

What i need is:
1. If somebody connects to server and CT team is already reached it's limit so the player is automaticaly joined T team.
2. Prevention from joining CT team if it's already reached it's limit.

The code i'm using is
PHP Code:

public plugin_init()
{
    
register_clcmd("chooseteam""client_chooseteam")
    
register_message(get_user_msgid("ShowMenu"), "ShowMenu")
    
register_message(get_user_msgid("VGUIMenu"), "VGUIMenu")
    
    
cvar_maxcts register_cvar("amx_maxcts""2")
}

public 
client_chooseteam(id)
{
    new 
ctcount
    ctcount 
active_players(CS_TEAM_CT)

    if(
ctcount >= get_pcvar_num(cvar_maxcts) && cs_get_user_team(id) == CS_TEAM_T)
    {
        
client_print(idprint_chat"[AMX] You can't change your team.")
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE
}

public 
ShowMenu(iMsgidiDestid)
{
    new 
code[32]
    
get_msg_arg_string(4codecharsmax(code))

    if(
equal(code"#Team_Select") || equal(code"#IG_Team_Select") && cs_get_user_team(id) != CS_TEAM_CT)
    {
        new 
ctcount
        ctcount 
active_players(CS_TEAM_CT)

        if(
ctcount >= get_pcvar_num(cvar_maxcts))
        {
            new 
param[2]
            
param[0] = iMsgid
            set_task
(0.1"join_terrorist"idparamsizeof(param))
            return 
PLUGIN_HANDLED
        
}
    }
    return 
PLUGIN_CONTINUE
}

public 
VGUIMenu(iMsgidiDestid)
{
    if(
get_msg_arg_int(1) != 2)
    {
        return 
PLUGIN_CONTINUE
    
}

    new 
ctcount
    ctcount 
active_players(CS_TEAM_CT)

    if(
ctcount >= get_pcvar_num(cvar_maxcts) && cs_get_user_team(id) != CS_TEAM_CT)
    {
        new 
param[2]
        
param[0] = iMsgid
        set_task
(0.1"join_terrorist"idparamsizeof(param))

        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE
}

public 
join_terrorist(param[], id)
{
    
handle_join(idparam[0], /*CS_TEAM_T*/ 1)
    
set_task(5.0"check_valid_team"id)
}

public 
check_valid_team(id)
{
    if(!
is_user_connected(id))
        return

    if(
cs_get_user_team(id) != CS_TEAM_T)
    {
        
cs_set_user_team(idCS_TEAM_T)
    }
}

stock active_players(CsTeams:teambool:aliveonly false)
{
    new 
players[32], inumiactiveCsTeams:playerteam

    
(aliveonly) ? get_players(playersinum"ah") : get_players(playersinum"h")

    
active 0

    
for (0inum; ++i)
    {
        
playerteam cs_get_user_team(players[i])

        if(
playerteam == team)
            
active++
    }
    return 
active
}

stock handle_join(idiMsgidiTeam)
{
    new 
iMsgBlock
    iMsgBlock 
get_msg_block(iMsgid)
    
set_msg_block(iMsgidBLOCK_SET)

    new 
team[2]
    
num_to_str(iTeamteamcharsmax(team))

    
engclient_cmd(id"jointeam"team)
    
engclient_cmd(id"joinclass""1")

    
set_msg_block(iMsgidiMsgBlock)

    
client_print(idprint_chat"[AMX] You can't change your team!")


I don't understand most of the code so it is quite hard for me to edit it the way i want. I would appreciate if i could get the code which would do the functions i mentiont above or at least link to the plugin who has same functions so i could take that part of the code and use it where i need.


All times are GMT -4. The time now is 10:47.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.