| xbatista |
09-04-2009 11:02 |
Setting team bug
I'm just confused in those codes, I don't understand why sometimes terrorist got respawned in ct respawn zone .. ?
( This plugin switches teams when terrorist killed ct, and in ct team max 4 ct players. )
Btw if someone can,then please recode this code.
PHP Code:
// Global
#define MAX_CTS 4
new bool:g_bSwitch[ 33 ];
// In plugin_init
register_message( get_user_msgid( "TeamInfo" ), "msg_TeamInfo" );
register_logevent("logevent_round_end", 2, "1=Round_End");
register_event("DeathMsg", "event_deathmsg", "a")
//Round end event
public logevent_round_end()
{
static i, CsTeams:team;
for( i = 1 ; i <= g_iMaxPlayers ; i++ )
{
if( !is_user_connected( i ) || !g_bSwitch[ i ]
|| !( CS_TEAM_UNASSIGNED < ( team = cs_get_user_team( i ) ) < CS_TEAM_SPECTATOR ) )
continue;
cs_set_user_team( i, ( team % CS_TEAM_CT ) + CS_TEAM_T );
g_bSwitch[ i ] = false;
}
}
// Team info message
public msg_TeamInfo(msgid, dest, receiver, id)
{
if( dest != MSG_ALL && dest != MSG_BROADCAST ) return;
new teamname[3];
get_msg_arg_string(2, teamname, sizeof(teamname) - 1);
new FmTeams:team;
for( new FmTeams:i = FM_TEAM_UNASSIGNED; i < FmTeams; i++ )
{
if( g_TeamInfo[i][0] == teamname[0] )
{
team = i;
break;
}
}
new client = get_msg_arg_int(1);
if( team == FM_TEAM_CT && fm_get_user_team(client) == team )
{
new ctnum;
for( new i = 1; i <= g_iMaxPlayers; i++ )
{
if( i != client
&& is_user_connected(i)
&& fm_get_user_team(i) == FM_TEAM_CT
&& ++ctnum == MAX_CTS )
{
set_pdata_int(client, 114, _:FM_TEAM_T);
set_msg_arg_string(2, g_TeamInfo[FM_TEAM_T]);
break;
}
}
}
if( g_bSwitch[ id ] )
{
g_bSwitch[id] = false;
}
}
// DeathMsg
public event_deathmsg()
{
new i_victim = read_data(2)
new i_attacker = read_data(1)
if ( !(1 <= i_victim <= g_iMaxPlayers) )
return;
if( cs_get_user_team( i_attacker ) == CS_TEAM_T && cs_get_user_team( i_victim ) == CS_TEAM_CT )
{
if( !g_bSwitch[ i_attacker ] )
{
g_bSwitch[ i_attacker ] = true;
if( !g_bSwitch[ i_victim ] )
{
g_bSwitch[ i_victim ] = true;
}
}
}
}
|