| 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(id, print_chat, "[AMX] You can't change your team.") return PLUGIN_HANDLED } return PLUGIN_CONTINUE }
public ShowMenu(iMsgid, iDest, id) { new code[32] get_msg_arg_string(4, code, charsmax(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", id, param, sizeof(param)) return PLUGIN_HANDLED } } return PLUGIN_CONTINUE }
public VGUIMenu(iMsgid, iDest, id) { 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", id, param, sizeof(param))
return PLUGIN_HANDLED } return PLUGIN_CONTINUE }
public join_terrorist(param[], id) { handle_join(id, param[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(id, CS_TEAM_T) } }
stock active_players(CsTeams:team, bool:aliveonly = false) { new players[32], inum, i, active, CsTeams:playerteam
(aliveonly) ? get_players(players, inum, "ah") : get_players(players, inum, "h")
active = 0
for (i = 0; i < inum; ++i) { playerteam = cs_get_user_team(players[i])
if(playerteam == team) active++ } return active }
stock handle_join(id, iMsgid, iTeam) { new iMsgBlock iMsgBlock = get_msg_block(iMsgid) set_msg_block(iMsgid, BLOCK_SET)
new team[2] num_to_str(iTeam, team, charsmax(team))
engclient_cmd(id, "jointeam", team) engclient_cmd(id, "joinclass", "1")
set_msg_block(iMsgid, iMsgBlock)
client_print(id, print_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.
|