AlliedModders

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

emperial159 05-08-2011 13:46

Team_swtich
 
Hi. When a lot of people playing crashing the team_switch some people don't swtich them why? plz help

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN "Auto Team Switcher"
#define VERSION "1.0"
#define AUTHOR "nikhilgupta345"

#pragma semicolon 1

new roundnumber 0;
new 
Atsround;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_clcmd"say /roundnumber""sayRound" );
    
register_concmd"amx_roundrestart""restartnumber"ADMIN_KICK );
    
    
register_logevent"roundend"2"1=Round_End" );
    
register_event"TextMsg","restart","a","2&#Game_C""2&#Game_W" ); // Event for "Game Commencing" TextMsg and "Game Will Restart in X Seconds" TextMsg
    
    
Atsround register_cvar"amx_atsrounds""15" );
    
}

public 
sayRoundid )
{
    
client_printidprint_chat"The current round is %i."roundnumber );
    return 
PLUGIN_HANDLED;
}

public 
roundend()
{
    
roundnumber++;
    
    if( 
roundnumber >= get_pcvar_numAtsround ) )
    {
        new 
players[32], num;
        
get_playersplayersnum );
        
        for( new 
inumi++ )
            
add_delayplayers[i] ); // Prevent Server Crash with a lot of people.
            
    
}
}


public 
restartnumberidlevelcid )
{
    if( !
cmd_accessidlevelcid) )
        return 
PLUGIN_HANDLED;
    
    
roundnumber 0;
    return 
PLUGIN_HANDLED;
}

public 
restartid )
{
    
roundnumber 0;
    return 
PLUGIN_HANDLED;
}

public 
changeTeamid )
{
    switch( 
cs_get_user_teamid ) )
    {
        case 
CS_TEAM_CTcs_set_user_teamidCS_TEAM_T );
        
        case 
CS_TEAM_Tcs_set_user_teamidCS_TEAM_CT );
    }

    
roundnumber 0;
}

add_delayid )
{
    switch( 
id )
    {
        case 
1..7set_task0.1"changeTeam"id );
        case 
8..15set_task0.2"changeTeam"id );
        case 
16..23set_task0.3"changeTeam"id );
        case 
24..32set_task0.4"changeTeam"id );
    }



ProIcons 05-09-2011 11:39

Re: Team_swtich
 
[pawn]
the server will not crash by changing all players teams...

Code:
public roundend() {     roundnumber++;         if( roundnumber >= get_pcvar_num( Atsround ) )     {         new players[32], num;         get_players( players, num, "h");                 for( new i; i < num; i++ )         {             new id=players[i];             switch (get_user_team(id))             {                 case 1: cs_set_user_team(id, CS_TEAM_CT);                 case 2: cs_set_user_team(id, CS_TEAM_T);             }         }     } }

This should work...

SonicSonedit 05-09-2011 13:06

Re: Team_swtich
 
emperial159
I don't know how cs module works, but check error logs - maybe you also should check if player is connecting before calling add_delay( players[i] );

emperial159 05-09-2011 14:42

Re: Team_swtich
 
Oke i doned but round changing always one time but i do 2 rounds...

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN "Auto Team Switcher"
#define VERSION "1.0"
#define AUTHOR "nikhilgupta345"

#pragma semicolon 1

new roundnumber 0;
new 
Atsround;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_clcmd"say /roundnumber""sayRound" );
    
register_concmd"amx_roundrestart""restartnumber"ADMIN_KICK );
    
    
register_logevent"roundend"2"1=Round_End" );
    
register_event"TextMsg","restart","a","2&#Game_C""2&#Game_W" ); // Event for "Game Commencing" TextMsg and "Game Will Restart in X Seconds" TextMsg
    
    
Atsround register_cvar"amx_atsrounds""15" );
    
}

public 
sayRoundid )
{
    
client_printidprint_chat"The current round is %i."roundnumber );
    return 
PLUGIN_HANDLED;
}

public 
roundend() 
{     
       
roundnumber++;         
       if( 
roundnumber >= get_pcvar_numAtsround ) )     
       {           
       new 
players[32], num;        
       
get_playersplayersnum"h");                 
       for( new 
inumi++ )         
       {               
       new 
id=players[i];             
       switch (
get_user_team(id))             
       {                 
            case 
1cs_set_user_team(idCS_TEAM_CT);                 
            case 
2cs_set_user_team(idCS_TEAM_T);             
           }         
        }     
    } 
}


public 
restartnumberidlevelcid )
{
    if( !
cmd_accessidlevelcid) )
        return 
PLUGIN_HANDLED;
    
    
roundnumber 0;
    return 
PLUGIN_HANDLED;
}

public 
restartid )
{
    
roundnumber 0;
    return 
PLUGIN_HANDLED;
}

public 
changeTeamid )
{
    switch( 
cs_get_user_teamid ) )
    {
        case 
CS_TEAM_CTcs_set_user_teamidCS_TEAM_T );
        
        case 
CS_TEAM_Tcs_set_user_teamidCS_TEAM_CT );
    }

    
roundnumber 0;



ProIcons 05-09-2011 14:49

Re: Team_swtich
 
i can't even understand what do you mean but try this...

Code:
public roundend() {         roundnumber++;             if( roundnumber >= get_pcvar_num( Atsround ) )         {                   new players[32], num;                 get_players( players, num, "h");                         for( new i; i < num; i++ )                 {                           new id=players[i];                         switch (get_user_team(id))                         {                                 case 1: cs_set_user_team(id, CS_TEAM_CT);                                     case 2: cs_set_user_team(id, CS_TEAM_T);                             }                 }         roundnumber=0;     } }

emperial159 06-13-2011 10:12

Re: Team_swtich
 
Ty it's working but the server breaking when are 10x10 players...

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
 
#define PLUGIN "Auto Team Switcher"
#define VERSION "1.0"
#define AUTHOR "nikhilgupta345"
 
#pragma semicolon 1
 
new roundnumber 0;
new 
Atsround;
 
public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
   
    
register_clcmd"say /roundnumber""sayRound" );
    
register_concmd"amx_roundrestart""restartnumber"ADMIN_KICK );
   
    
register_logevent"roundend"2"1=Round_End" );
    
register_event"TextMsg","restart","a","2&#Game_C""2&#Game_W" ); // Event for "Game Commencing" TextMsg and "Game Will Restart in X Seconds" TextMsg
   
    
Atsround register_cvar"amx_atsrounds""15" );
   
}
 
public 
sayRoundid )
{
    
client_printidprint_chat"The current round is %i."roundnumber );
    return 
PLUGIN_HANDLED;
}
 
public 
roundend()
{    
    
roundnumber++;        
    if( 
roundnumber >= get_pcvar_numAtsround ) )    
    {          
        new 
players[32], num;        
        
get_playersplayersnum"h");                
        for( new 
inumi++ )        
        {              
            new 
id=players[i];            
            switch (
get_user_team(id))            
            {                
                case 
1cs_set_user_team(idCS_TEAM_CT);                
                    case 
2cs_set_user_team(idCS_TEAM_T);            
                }        
        }    
        
roundnumber 0;
    }
}
 
public 
restartnumberidlevelcid )
{
    if( !
cmd_accessidlevelcid) )
        return 
PLUGIN_HANDLED;
   
    
roundnumber 0;
    return 
PLUGIN_HANDLED;
}
 
public 
restartid )
{
    
roundnumber 0;
    return 
PLUGIN_HANDLED;
}
 
public 
changeTeamid )
{
    
set_hudmessage(150210500.460.4500.02.02.01.0, -1);
        
show_hudmessage(0"Switching Teams");
 
    switch( 
cs_get_user_teamid ) )
    {
        case 
CS_TEAM_CTcs_set_user_teamidCS_TEAM_T );
       
        case 
CS_TEAM_Tcs_set_user_teamidCS_TEAM_CT );
    }
 
    
roundnumber 0;



Exolent[jNr] 06-13-2011 12:43

Re: Team_swtich
 
Your original code is fine.
You just need to remove task if the player disconnects, because a player can disconnect before the task is executed, thus giving you the invalid player error.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN "Auto Team Switcher"
#define VERSION "1.0"
#define AUTHOR "nikhilgupta345"

#pragma semicolon 1

new roundnumber 0;
new 
Atsround;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_clcmd"say /roundnumber""sayRound" );
    
register_concmd"amx_roundrestart""restartnumber"ADMIN_KICK );
    
    
register_logevent"roundend"2"1=Round_End" );
    
register_event"TextMsg","restart","a","2&#Game_C""2&#Game_W" ); // Event for "Game Commencing" TextMsg and "Game Will Restart in X Seconds" TextMsg
    
    
Atsround register_cvar"amx_atsrounds""15" );
    
}

public 
client_disconnectid )
{
    
remove_taskid );
}

public 
sayRoundid )
{
    
client_printidprint_chat"The current round is %i."roundnumber );
    return 
PLUGIN_HANDLED;
}

public 
roundend()
{
    
roundnumber++;
    
    if( 
roundnumber >= get_pcvar_numAtsround ) )
    {
        new 
players[32], num;
        
get_playersplayersnum );
        
        for( new 
inumi++ )
            
set_taskfloat), "changeTeam"players[i] );
            
    }
}


public 
restartnumberidlevelcid )
{
    if( !
cmd_accessidlevelcid) )
        return 
PLUGIN_HANDLED;
    
    
roundnumber 0;
    return 
PLUGIN_HANDLED;
}

public 
restartid )
{
    
roundnumber 0;
    return 
PLUGIN_HANDLED;
}

public 
changeTeamid )
{
    switch( 
cs_get_user_teamid ) )
    {
        case 
CS_TEAM_CTcs_set_user_teamidCS_TEAM_T );
        
        case 
CS_TEAM_Tcs_set_user_teamidCS_TEAM_CT );
    }

    
roundnumber 0;



emperial159 06-13-2011 12:53

Re: Team_swtich
 
Look error...

Exolent[jNr] 06-13-2011 13:18

Re: Team_swtich
 
Try it now.

emperial159 06-15-2011 07:54

Re: Team_swtich
 
Working 10x10 ,but when the map change there are first round and is 1 switch team when go onother round there is 2 switch... And sometimes people don't swtich them...


All times are GMT -4. The time now is 04:25.

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