Raised This Month: $ Target: $400
 0% 

/team switcher


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


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:11.


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