AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CT team can have max 4 ct's players. (https://forums.alliedmods.net/showthread.php?t=83419)

xbatista 01-09-2009 11:31

CT team can have max 4 ct's players.
 
So this code worst coded and cause a lot of bugs ,maybe someone can give me better code?
In ct team can be max 4 players,this code buggy I don't how ,but somehow in team can be more than 4 players and when round starts(and 4 players in ct team) then one of them are switched to terrorist team and who was switched he is in ct base!.
So anyone can give a good working code?

Quote:

public message_teaminfo(msg_id, msg_dest){
if (msg_dest != MSG_ALL && msg_dest != MSG_BROADCAST) return;
new id = get_msg_arg_int(1)
static team[2]
get_msg_arg_string(2, team, sizeof team - 1)
if(team[0] == 'U' || team[0] == 'S') return;
new cts = ckrun_get_ct_num()
if(cts >= 4){
cs_set_user_team(id, CS_TEAM_T, CS_DONTCHANGE)
set_msg_arg_string(2, "TERRORIST")
}
Quote:

stock ckrun_get_ct_num(){
new num = 0 , i
for (i = 1; i <= g_maxplayers; i++){
if (is_user_connected(i) && get_user_team(i) == 2)
num ++
}
return num
}
And register this message in plugin_init:
Quote:

register_message(get_user_msgid("TeamInfo"), "message_teaminfo")

Exolent[jNr] 01-09-2009 12:17

Re: CT team can have max 4 ct's players.
 
Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> #define MAX_CTS 4 enum FmTeams {     FM_TEAM_UNASSIGNED,     FM_TEAM_T,     FM_TEAM_CT,     FM_TEAM_SPECTATOR }; new const g_TeamInfo[FmTeams][] = {     "UNASSIGNED",     "TERRORIST",     "CT",     "SPECTATOR" }; #define fm_get_user_team(%1) FmTeams:get_pdata_int(%1, 114) new g_max_clients; public plugin_init() {     register_message(get_user_msgid("TeamInfo"), "MessageTeamInfo");         g_max_clients =  get_maxplayers(); } public MessageTeamInfo(msgid, dest, receiver) {     if( dest != MSG_ALL ) return;         new client = get_msg_arg_int(1);     if( !is_user_connected(client) ) 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;         }     }         if( team != FM_TEAM_CT || team == fm_get_user_team(client) ) return;         new ctnum;     for( new i = 1; i <= g_max_clients; i++ )     {         if( i != client         && is_user_connected(i)         && fm_get_user_team(i) == FM_TEAM_CT         && ++ctnum == MAX_CTS )         {             set_msg_arg_string(2, g_TeamInfo[FM_TEAM_T]);             return;         }     } }

xbatista 01-09-2009 12:21

Re: CT team can have max 4 ct's players.
 
WoW, thanks :up: Going to test.

EDIT: Compiles bad,error 017 undefined symbol DLFunc_ClientInfoChanged,expected token: ";", but found ")" , all errors on that line.

X0Left4dead0X 01-09-2009 12:49

Re: CT team can have max 4 ct's players.
 
Hehe it looks like this is for Left 4 Dead in counter-strike:D

xbatista 01-09-2009 12:56

Re: CT team can have max 4 ct's players.
 
YES,becouse my code is bad,like always ;)

EDIT: WoW I can't believe! Exolent you done mistake :DDD
dllfunc(DLFunc_ClientUserInfoChanged
must be ->
dllfunc(DLLFunc_ClientUserInfoChanged

xD

X0Left4dead0X 01-09-2009 13:12

Re: CT team can have max 4 ct's players.
 
Oh yeah my bad :P

xbatista 01-09-2009 13:57

Re: CT team can have max 4 ct's players.
 
So I tested it,code not works :(| None effect.

EDIT : Oops sorry it works,but when player connected he can join to ct if there are 4 cts and more..

Exolent[jNr] 01-09-2009 14:28

Re: CT team can have max 4 ct's players.
 
Okay, I rewrote a new version.

xbatista 01-09-2009 15:12

Re: CT team can have max 4 ct's players.
 
Sorry for stupid question,I good configured it? :
register_message( get_user_msgid( "TeamInfo" ), "msg_TeamInfo" );
PHP Code:

public msg_TeamInfomidDestid )
{
    new 
client get_msg_arg_int(1);
    if( !
is_user_connected(client) )
    {
    new 
teamname[3];
    
get_msg_arg_string(2teamnamesizeof(teamname) - 1);
    
    new 
FmTeams:team;
    for( new 
FmTeams:FM_TEAM_UNASSIGNEDFmTeamsi++ )
    {
        if( 
g_TeamInfo[i][0] == teamname[0] )
        {
            
team i;
            break;
        }
    }
    
    if( 
team != FM_TEAM_CT || team == fm_get_user_team(client) )
    {
    new 
ctnum;
    for( new 
1<= g_maxplayersi++ )
    {
        if( 
!= client
        
&& is_user_connected(i)
        && 
fm_get_user_team(i) == FM_TEAM_CT
        
&& ++ctnum == MAX_CTS )
        {
            
set_msg_arg_string(2g_TeamInfo[FM_TEAM_T]);
            return 
PLUGIN_CONTINUE;
        }
//    }
    
return PLUGIN_HANDLED;
    }
}
    return 
PLUGIN_HANDLED;
    }
    if( 
Dest != MSG_ALL && Dest != MSG_BROADCAST )
    {
        return 
PLUGIN_CONTINUE;
    }
    if( !
get_pcvar_nump_On ) )
    {
        return 
PLUGIN_CONTINUE;
    }
    
    if( 
g_bSwitchid ] )
    {
        
g_bSwitchid ] = false;
    }
    
    return 
PLUGIN_CONTINUE;



Exolent[jNr] 01-09-2009 15:48

Re: CT team can have max 4 ct's players.
 
It seems as if you don't know how to script.


All times are GMT -4. The time now is 09:15.

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