Raised This Month: $51 Target: $400
 12% 

/team switcher


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Gameplay       
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 03-23-2006 , 08:10   /team switcher
Reply With Quote #1

I created this plugin with the help of our many scriptykiddys and hope it will help people..

PURPOSE:
Allows players to type these commands in say or say_team:
  • /ct
    /spec
    /t
and it will place that player on the team they typed if they are not already on that team.

Works fine. (January 2007)
Attached Files
File Type: sma Get Plugin or Get Source (team_say_switch.sma - 1057 views - 2.1 KB)

Last edited by SweatyBanana; 01-07-2007 at 03:44.
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-23-2006 , 08:58  
Reply With Quote #2

a)

If you find yourself calling a specific function more than once in your own function, you're doing something wrong.

Sample of your code:
Code:
public TEAMCT( id ) {     if(cs_get_user_team(id) == CS_TEAM_CT)     {         client_print(1, print_chat, "[TEAMS] You are already on the CT team.")         return PLUGIN_HANDLED     }           if(cs_get_user_team(id) != CS_TEAM_CT)     {         return PLUGIN_CONTINUE     }           else     {         new name[32]         get_user_name(id,name,31)         if(is_user_alive(id)) user_kill(id)         cs_set_user_team ( id, CS_TEAM_CT, CS_CT_URBAN)         client_print(0, print_chat, "[TEAMS] %s has switched himself to the CT team.", name)     }     return PLUGIN_CONTINUE }
Revised, calling cs_set_user_team() only once:
Code:
public TEAMCT( id ) {     new CsTeams:team = cs_get_user_team(id);     if(team == CS_TEAM_CT)     {         client_print(1, print_chat, "[TEAMS] You are already on the CT team.")         return PLUGIN_HANDLED     }           if(team != CS_TEAM_CT)     {         return PLUGIN_CONTINUE     }           else     {         new name[32]         get_user_name(id,name,31)         if(is_user_alive(id)) user_kill(id)         cs_set_user_team ( id, CS_TEAM_CT, CS_CT_URBAN)         client_print(0, print_chat, "[TEAMS] %s has switched himself to the CT team.", name)     }     return PLUGIN_CONTINUE }
Apparently v3x tried in vain to make you aware of this earlier...
Quote:
Originally Posted by v3x
Code:
new CsTeams:team = cs_get_user_team(id); if(team == CS_TEAM_CT /* or whatever */) {   // }
b)

You have 3 separate functions that all do, more or less, the same thing. One for CTs, one for Ts, and one for Spectators. Your code could be a third of it's current size if you merge the three together so that you have only one code base instead of 3 copies with only certain variables changing.

c)

I strongly suggest you use the ML system that AMXX provides. Not only for easy translations but also so people can easily alter the English messages if they choose.

d)

Let's return to that sample function of yours that I quoted earlier...
Code:
public TEAMCT( id ) {     if(cs_get_user_team(id) == CS_TEAM_CT)     {         client_print(1, print_chat, "[TEAMS] You are already on the CT team.")         return PLUGIN_HANDLED     }           if(cs_get_user_team(id) != CS_TEAM_CT)     {         return PLUGIN_CONTINUE     }           else     {         new name[32]         get_user_name(id,name,31)         if(is_user_alive(id)) user_kill(id)         cs_set_user_team ( id, CS_TEAM_CT, CS_CT_URBAN)         client_print(0, print_chat, "[TEAMS] %s has switched himself to the CT team.", name)     }     return PLUGIN_CONTINUE }
Your else statement will NEVER get run. First, you check if it's a CT and you return. Next, you check if it is not a CT and you return. Guess what? The team will always be one of those two values. You couldn't have possibly tested this plugin or you would have found this out already.

Apparently VEN tried in vain to make you aware of this earlier...
Quote:
Originally Posted by VEN
Do you aware that your "else" statements contain unreachable code?
e)

Quote:
Originally Posted by Gender Specific Code
client_print(0, print_chat, "[TEAMS] %s has switched himself to the CT team.", name)
I recommend that you find a gender neutral way of indicating someone has switched to another team. While CS is dominated by males, there are a large number of females that play too.

f)

Care to compare/constrast this with the standard way of changing your team?
Brad is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-23-2006 , 09:25  
Reply With Quote #3

This can be made better:

Code:
public TEAMCT( id )  {      if(cs_get_user_team(id) == CS_TEAM_CT)      {          client_print(id, print_chat, "[TEAMS] You are already on the CT team.")          return PLUGIN_HANDLED      }      else      {          new name[32]          get_user_name(id,name,31)          if(is_user_alive(id)) user_kill(id)          cs_set_user_team ( id, CS_TEAM_CT, CS_CT_URBAN)          client_print(0, print_chat, "[TEAMS] %s has switched himself to the CT team.", name)      }      return PLUGIN_CONTINUE  }
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 03-23-2006 , 17:05  
Reply With Quote #4

a.) OK FIXING.
b.) Workin on it.
c.) how does that work? where do i get the code for that?
d.) didnt realize that.
e.) eh...ok...didnt think it was that big a deal
f.)

MINE:
easier...lets a player change their team regardless of team balancer.
easy to use.
etc..etc...

The built in version is bad in my opinion.
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-23-2006 , 17:10  
Reply With Quote #5

Quote:
Originally Posted by SweatyBanana
a.) OK FIXING.
b.) Workin on it.
c.) how does that work? where do i get the code for that?
d.) didnt realize that.
e.) eh...ok...didnt think it was that big a deal
f.)

MINE:
easier...lets a player change their team regardless of team balancer.
easy to use.
etc..etc...

The built in version is bad in my opinion.
If this gets approved I will smash my head into the wall. And Brad, that doesn't mean approve this so I injure myself.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-23-2006 , 17:11  
Reply With Quote #6

c) http://wiki.amxmodx.org/index.php/Ad...ingual_Support
e) It's not a big deal. Just a suggestion.

If a server doesn't want the team balancer to affect players switching, why would they enable the team balancer?
Brad is offline
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 03-23-2006 , 17:12  
Reply With Quote #7

idk lol...but hawk this shud be approved just so u do

working on it
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-23-2006 , 17:16  
Reply With Quote #8

As tempting as it is to approve it just for the resultant head injury... Banana has yet to convince me how this is any better than how players can do it normally.
Brad is offline
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 03-23-2006 , 17:18  
Reply With Quote #9

OK...

1.) FASTER SWITCH
2.) Doesnt have to pick a model
3.) spec switching without having to be dead to switch.(or typing kill in console)

4.) You love me
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 03-23-2006 , 17:21  
Reply With Quote #10

hmmm...hows that?

ill work on the multilingual..

anyway, ill also work on making it smaller.
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Reply



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 09:10.


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