AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optimize ChooseTeam Menu? (https://forums.alliedmods.net/showthread.php?t=214500)

Blizzard_87 04-27-2013 19:18

Optimize ChooseTeam Menu?
 
ive made this choose team menu for when someone presses ( M ).

just wondering if it can be optimized smaller?

Code:
#include < amxmodx > #include < amxmisc > #include < cstrike > #define PLUGIN "Custom ChooseTeam" #define VERSION "1.0" #define AUTHOR "Blizzard" //new CsTeams:g_szTeam[ 32 ]; new bool:g_szCurrentTeam[ 33 ][ 4 ]; new g_CallBack; new const TeamNames[][] = {     "Terrorist",     "Counter-Terrorist",     "Auto-Select",     "Spectate" }; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         g_CallBack = menu_makecallback("CheckCurrentTeam");         register_clcmd("chooseteam", "cmdChooseTeam", 0); } public cmdChooseTeam(id) {     CheckTeam(id)         new Item[ 101 ], iNum;         formatex(Item, 100, "Choose Team:");     new menu = menu_create(Item, "ChooseTeam_handler");         for( iNum = 0; iNum < sizeof TeamNames; iNum++ )     {         formatex(Item, 100, "%s", TeamNames[ iNum ]);         menu_additem(menu, Item, "0", 0, g_CallBack);     }     menu_display(id, menu, 0);     return PLUGIN_HANDLED; } public CheckCurrentTeam(id, menu, item) {     switch(g_szCurrentTeam[ id ][ item ])     {         case true: return ITEM_DISABLED;         case false: return ITEM_ENABLED;     }         return PLUGIN_CONTINUE; } public ChooseTeam_handler(id, menu, item) {     if( item == MENU_EXIT )     {         menu_destroy(menu);         return PLUGIN_HANDLED;     }             set_user_team( id, item )     menu_destroy(menu);     return PLUGIN_HANDLED; } public CheckTeam(id) {     if(is_user_connected(id))     {         switch(cs_get_user_team(id))         {             case CS_TEAM_T:             {                 g_szCurrentTeam[ id ][ 0 ] = true;                 g_szCurrentTeam[ id ][ 1 ] = false;                 g_szCurrentTeam[ id ][ 2 ] = false;                 g_szCurrentTeam[ id ][ 3 ] = false;             }             case CS_TEAM_CT:             {                   g_szCurrentTeam[ id ][ 0 ] = false;                 g_szCurrentTeam[ id ][ 1 ] = true;                 g_szCurrentTeam[ id ][ 2 ] = false;                 g_szCurrentTeam[ id ][ 3 ] = false;             }             case CS_TEAM_SPECTATOR:             {                 g_szCurrentTeam[ id ][ 0 ] = false;                 g_szCurrentTeam[ id ][ 1 ] = false;                 g_szCurrentTeam[ id ][ 2 ] = false;                 g_szCurrentTeam[ id ][ 3 ] = true;             }         }     } } stock set_user_team( id, teamnum) {     new players[32], pNum;         get_players(players, pNum)         user_kill( id )     switch(teamnum)     {         case 0: cs_set_user_team( id, CS_TEAM_T );         case 1: cs_set_user_team( id, CS_TEAM_CT );         case 2:         {             switch( random_num( 1, 100 ) )             {                 case 1..49: cs_set_user_team( id, CS_TEAM_T );                 case 50..100: cs_set_user_team( id, CS_TEAM_CT );             }         }         case 3: cs_set_user_team( id, CS_TEAM_SPECTATOR );     }         if(pNum == 1)     {         server_cmd("sv_restart 1")     } }

EDIT: added Callback its a lil better....

but still need to know if i can do this whole plugin better?

ConnorMcLeod 04-28-2013 05:07

Re: Optimize ChooseTeam Menu?
 
You can't set teams properly like this.
Better to just edit the menu text that the game send to player, and to remove some keys from it if you need, then when player chooses the key, game gonna handle it and properly set teams.

Blizzard_87 04-28-2013 05:18

Re: Optimize ChooseTeam Menu?
 
thanks. could you give small example on how to correctly. or a link for me to read up on it?

ConnorMcLeod 04-28-2013 05:28

Re: Optimize ChooseTeam Menu?
 
Example is on the forum, let's search for it.

Blizzard_87 04-28-2013 09:49

Re: Optimize ChooseTeam Menu?
 
ive now changed it with usage of
Code:
new CsTeams:g_szTeams[ 33 ];

is this a more efficient way of changing teams?

ConnorMcLeod 04-28-2013 17:59

Re: Optimize ChooseTeam Menu?
 
No no no...


You are lucky : http://forums.alliedmods.net/showpos...35&postcount=4

Blizzard_87 04-28-2013 20:26

Re: Optimize ChooseTeam Menu?
 
Quote:

Originally Posted by ConnorMcLeod (Post 1941810)

thats editing the current default choose team menu....

the one i made is a custom one that replaces the original one instead of using the default ones (menu / gui )

ConnorMcLeod 04-29-2013 00:38

Re: Optimize ChooseTeam Menu?
 
And you can't do that, has already been tested in the past and doesn't work at all.

Blizzard_87 04-29-2013 02:23

Re: Optimize ChooseTeam Menu?
 
Quote:

Originally Posted by ConnorMcLeod (Post 1941936)
And you can't do that, has already been tested in the past and doesn't work at all.

ok thanks for your help.


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

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