Hi all.
i've made this team swap and all seems good but when the round that cnrtolled by cvar comes the team does not swap, any idea why it doesn't work.
Here the fixed Code :
PHP Code:
#include <amxmodx>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#define PLUGIN "Team Swap"
#define VERSION "0.2"
#define AUTHOR "yas17sin"
#define TAG "TAG"
#define TASK_SHOW_LEVEL 10113
#define isTeam(%0) (CS_TEAM_T <= cs_get_user_team(%0) <= CS_TEAM_CT)
#define MAX_PLAYERS 32
new g_msgsync;
new iCount;
new cvar_enable, cvar_round_needed, cvar_round_hud;
public plugin_init()
{
register_plugin(AUTHOR, VERSION, PLUGIN)
register_event( "HLTV", "Event_NewRound", "a", "1=0", "2=0" );
register_logevent("EventRoundEnd", 2, "1=Round_End" );
RegisterHam( Ham_Spawn, "player", "FwdPlayerSpawnPost", 1 );
g_msgsync = CreateHudSyncObj();
cvar_enable = register_cvar("amx_plugin_on", "1");
cvar_round_needed = register_cvar("amx_round_needed", "4");
cvar_round_hud = register_cvar("amx_hud_on", "1");
register_clcmd("say /round", "round_now")
register_clcmd("say_team /round", "round_now")
register_clcmd("say /rnd", "round_now")
register_clcmd("say_team /rnd", "round_now")
}
public client_disconnect(id)
{
remove_task( TASK_SHOW_LEVEL + id );
}
public Event_NewRound()
{
if(!get_pcvar_num(cvar_enable))
return;
iCount++
if( iCount > get_pcvar_num(cvar_round_needed) )
{
set_task(1.0, "Swap")
}
}
public FwdPlayerSpawnPost(id)
{
if(!get_pcvar_num(cvar_round_hud))
return HAM_HANDLED;
set_task(0.1, "task_show_level", TASK_SHOW_LEVEL + id)
return PLUGIN_CONTINUE;
}
public task_show_level(task)
{
new id = task - TASK_SHOW_LEVEL
set_hudmessage(0, 255, 0, 0.44, 0.01, 0, 6.0, 300.0)
ShowSyncHudMsg(id, g_msgsync, "[%s] Round Remain For Swap : %d/%d", TAG, iCount, get_pcvar_num(cvar_round_needed));
set_task(0.1, "task_show_level", TASK_SHOW_LEVEL + id)
}
public Swap(id)
{
if(!get_pcvar_num(cvar_enable))
return;
new iPlayers[MAX_PLAYERS], iNum, id
get_players(iPlayers, iNum)
for(new i;i < iNum;i++)
{
id = iPlayers[i]
if(isTeam(id))
{
cs_set_user_team(id, cs_get_user_team(id) == CS_TEAM_CT ? CS_TEAM_T : CS_TEAM_CT)
}
}
iCount = 0;
}
public round_now(id)
{
client_print(id, print_center, "[%s] the round now is %d/%d", TAG, iCount, get_pcvar_num(cvar_round_needed))
}
public EventRoundEnd()
{
if(get_pcvar_num(cvar_round_hud))
return
client_print(0, print_center, "[%s] the round now is %d/%d", TAG, iCount, get_pcvar_num(cvar_round_needed))
}
P.S : thanks for advance.
__________________