Raised This Month: $94 Target: $400
 23% 

Auto Switch Teams Every X Rounds


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands        Approver:   ConnorMcLeod (74)
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 09-01-2010 , 16:05   Auto Switch Teams Every X Rounds
Reply With Quote #1

Auto Team Switch Every X Rounds

Author: nikhilgupta345

Info:
This plugin allows you to switch sides of teams every set number of rounds. Also gives a command to restart the number of rounds played.

Cvars:
amx_atsrounds - sets the number of rounds before a team switch occurs.

Commands:
amx_roundrestart - restarts the number of rounds that have been played.
say /roundnumber - displays the amount of rounds that have been played.

Credits:
Nextra - Giving suggestions and making the code more efficient.
Tirant - Giving suggestions as well and providing code for the delay.
Connormcleod - Final suggestions on optimizing code.

Changelog:
Code:
v1.0 - Initial release
v1.01 - Fixed Bugs - Optimized Code
v1.1 - Fixed crashing with certain amount of people.
v1.1.1 - Added new client command - /roundnumber, which displays the amount of rounds that have passed.
v1.2 - Further optimized. Changed name of cvar to make it easier to remember. Commented.
Attached Files
File Type: sma Get Plugin or Get Source (autoteamswitch.sma - 5564 views - 4.5 KB)

Last edited by nikhilgupta345; 11-04-2010 at 20:20.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
alan_el_more
Veteran Member
Join Date: Jul 2008
Location: amxmodx-es.com
Old 09-01-2010 , 16:49   Re: Auto Team Switcher in X rounds
Reply With Quote #2

Indent your code!!!
__________________
alan_el_more is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 09-01-2010 , 17:56   Re: Auto Team Switcher in X rounds
Reply With Quote #3

I do two spaces :/ How many should I make it?
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
RedRobster
Veteran Member
Join Date: Apr 2010
Location: Your Closet
Old 09-01-2010 , 18:41   Re: Auto Team Switcher in X rounds
Reply With Quote #4

I would say 4 at the minimum.
__________________
RedRobster is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-01-2010 , 19:11   Re: Auto Team Switcher in X rounds
Reply With Quote #5

Don't listen to them.
The size of the indention does not matter as long as it is consistent.

Your plugin has 2 separate indention patterns:
PHP Code:
// indented with 1 tab
public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_concmd("amx_roundrestart""restartnumber"ADMIN_KICK)
    
    
roundchange register_cvar("amx_atsroundnumber""15")
    
register_logevent("roundend"2"1=Round_End")
    
    
pRoundchange get_pcvar_num(roundchange)
}

// indented with 2 spaces

public roundend()
{
  if(
roundnumber == pRoundchange)
  {
    new 
players[32], numplayer;
    
get_players(playersnum)
    for(new 
ii<numi++)
    {
      
player=players[i]
      
      if(
cs_get_user_team(player) == CS_TEAM_CT)
      
cs_set_user_team(playerCS_TEAM_T)

      else if(
cs_get_user_team(player) == CS_TEAM_T)
      
cs_set_user_team(playerCS_TEAM_CT)
    }
  }
  
  
roundnumber ++

Pick 1 indent style and use it throughout the whole plugin.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 09-01-2010 , 19:32   Re: Auto Team Switcher in X rounds
Reply With Quote #6

Suggestions:
- You unnecessarily make the cvar unchangeable mid-game imho. Why save it in plugin init instead of comparing (>=) the actual cvar value?
- Also I believe you should update the roundnumber before and not after you compare it to the cvar. If you set the cvar to 1, your plugin will actually switch the teams after round 2 and not after round 1.
- You could use a switch-statement instead of if/elseif when you check for the player teams.
- The roundnumber should also be reset on gamerestart/game commencing and similar events.
- You should ident your code consistently, but Exolent already told you that ;)
__________________
In Flames we trust!
Nextra is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 09-01-2010 , 19:50   Re: Auto Team Switcher in X rounds
Reply With Quote #7

Updated except for the switch. Just wondering does it optimize it that much with just two if/if else statements?
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 09-01-2010 , 20:26   Re: Auto Team Switcher in X rounds
Reply With Quote #8

Quote:
Originally Posted by nikhilgupta345 View Post
Updated except for the switch. Just wondering does it optimize it that much with just two if/if else statements?
Of course it is not lightyears faster but you would save the extra cs_get_user_team call and switch directives (for cases similar to this) are in general slightly faster than consecutive if/elseif statements. But the extra cs_get_user_team call is more important and definitely worth to be optimized out.

Also, you accidentally uploaded the compiled .amxx file.
__________________
In Flames we trust!
Nextra is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 09-01-2010 , 21:23   Re: Auto Team Switcher in X rounds
Reply With Quote #9

Oops, my bad :p

Added the switch.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 09-02-2010 , 08:30   Re: Auto Team Switcher in X rounds
Reply With Quote #10

New set of suggestions:
- switch( cs_get_user_team( player ) ) directly, no need for a new var.
- Why do you not use pcvars anymore? It was correct before.
- You should compare the round using >=, so the teams will be correctly switched even when the admin decides to lower the cvar value.
- Does the register_event forward work when you just use the reset-command function with it?
- Indent the return after if(!cmd_access[..])
__________________
In Flames we trust!
Nextra is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:08.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode