AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Auto Switch Teams Every X Rounds (https://forums.alliedmods.net/showthread.php?t=137016)

nikhilgupta345 09-01-2010 15:05

Auto Switch Teams Every X Rounds
 
1 Attachment(s)
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.


alan_el_more 09-01-2010 15:49

Re: Auto Team Switcher in X rounds
 
Indent your code!!!

nikhilgupta345 09-01-2010 16:56

Re: Auto Team Switcher in X rounds
 
I do two spaces :/ How many should I make it?

RedRobster 09-01-2010 17:41

Re: Auto Team Switcher in X rounds
 
I would say 4 at the minimum.

Exolent[jNr] 09-01-2010 18:11

Re: Auto Team Switcher in X rounds
 
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.

Nextra 09-01-2010 18:32

Re: Auto Team Switcher in X rounds
 
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 ;)

nikhilgupta345 09-01-2010 18:50

Re: Auto Team Switcher in X rounds
 
Updated except for the switch. Just wondering does it optimize it that much with just two if/if else statements?

Nextra 09-01-2010 19:26

Re: Auto Team Switcher in X rounds
 
Quote:

Originally Posted by nikhilgupta345 (Post 1288463)
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.

nikhilgupta345 09-01-2010 20:23

Re: Auto Team Switcher in X rounds
 
Oops, my bad :p

Added the switch.

Nextra 09-02-2010 07:30

Re: Auto Team Switcher in X rounds
 
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[..])


All times are GMT -4. The time now is 22:10.

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