/* plugin_cavey_menu.sma version 1.36, By Caveman ICQ# 70710878 Please read the readme Also available from http://www.scriptordie.com/ */ new STRING_VERSION[]= "13:16 24/02/2003"; #include <core> #include <console> #include <string> #include <admin> #include <adminlib> #include <plugin> #include <cavey> #if _cavey_included < 6 /*This will cause a nice error if you need to update the cavey.inc*/ Update_Your_Cavey_Inc() #endinput #endif /***********************************************************/ /* Settings you can fiddle with */ /***********************************************************/ /***********************************************************/ /* Settings I dont recommend you fiddle with */ /***********************************************************/ /*This block of things defines how much memory the plugin * *has to play with. */ /*How much it may use at one time (in blocks) (One block = 4bytes)*/ #pragma dynamic 32768 /* Maximum nuber of Xth level menus. Set it to at least one* * more than you will use! DO NOT SET ANY TO 0!!!! */ #define MAX_TOP_LAYER_MENUS 14 #define MAX_LAYER2_MENUS 40 #define MAX_LAYER3_MENUS 80 /*to the multiple of the previous menu */ #define MAX_LAYER4_MENUS 120 /*with the number you wish to add. This*/ #define MAX_LAYER5_MENUS 90 /*will result in HUGE arrays!! */ /*This bit is how long a menu description may be. * *Realistically this can not be more than 60 or the dll * *starts blocking it, but 100 seems a nice safe number */ #define MAX_MENU_DESCRIPTION 100 /*This bit is how long a menu command may be.*/ #define MAX_MENU_DATA 120 /***********************************************************/ /***********************************************************/ /*If you fiddle with these, your warranty is null and void!*/ /* YOU HAVE BEEN WARNED!!! */ /***********************************************************/ /***********************************************************/ /*Definitions*/ #define NO_MENU 0 #if MAX_MENU_DATA > MAX_MENU_DESCRIPTION #define MAX_TEMP_LENGTH MAX_MENU_DATA #else #define MAX_TEMP_LENGTH MAX_MENU_DESCRIPTION #endif /*This is coded into the dll*/ #define MAX_MENU_LENGTH 512 /* + 2 allows shift of one so layer 5 is on #5 and also * * allows room for a NULL */ #define MAX_LAYERS ( 5 + 2 ) /*These concern the positions of numeric variables in the DATA part of the menu arrays DONT SCREW WITH THESE, I have not filled in all the indices correctly yet*/ #define MENU_DATA_VARIABLE 6 /*This is a number of the values below*/ #define MENU_TYPE_VARIABLE 0 #define START_MENU_VARIABLE 1 #define END_MENU_VARIABLE 2 #define TOGGLE_START_VARIABLE 3 #define TOGGLE_STEP_VARIABLE 4 #define TOGGLE_END_VARIABLE 5 #define ADD_MENU 1 #define MENU_PLAYER 2 #define MENU_AMCMD 3 #define MENU_COMMAND 4 #define MENU_TOGGLE 5 #define MENU_SELF 6 /*These are settings and global variables, DONT SCREW WITH THEM!!!*/ new Debug; new ACCESS_EXECUTE; new ACCESS_TOGGLE; new ACCESS_MENU; new ACCESS_ADMINISTRATE; /*The arrays that contain the data*/ new TopMenuDesc[MAX_TOP_LAYER_MENUS][MAX_MENU_DESCRIPTION]; /*Level description*/ new TopMenuCvar[MAX_TOP_LAYER_MENUS][MAX_MENU_DATA]; new Top_menus = 0; /*Number of top level menus. Also number of current menu when building menus*/ new TopMenuVariable[MAX_TOP_LAYER_MENUS][MENU_DATA_VARIABLE]; new OneMenuDesc[MAX_LAYER2_MENUS][MAX_MENU_DESCRIPTION]; new OneMenuCvar[MAX_LAYER2_MENUS][MAX_MENU_DATA]; new One_menus = 0; new OneMenuVariable[MAX_LAYER2_MENUS][MENU_DATA_VARIABLE]; new TwoMenuDesc[MAX_LAYER3_MENUS][MAX_MENU_DESCRIPTION]; new TwoMenuCvar[MAX_LAYER3_MENUS][MAX_MENU_DATA]; new Two_menus = 0; new TwoMenuVariable[MAX_LAYER3_MENUS][MENU_DATA_VARIABLE]; new ThreeMenuDesc[MAX_LAYER4_MENUS][MAX_MENU_DESCRIPTION]; new ThreeMenuCvar[MAX_LAYER4_MENUS][MAX_MENU_DATA]; new Three_menus = 0; new ThreeMenuVariable[MAX_LAYER4_MENUS][MENU_DATA_VARIABLE]; new FourMenuDesc[MAX_LAYER5_MENUS][MAX_MENU_DESCRIPTION]; new FourMenuCvar[MAX_LAYER5_MENUS][MAX_MENU_DATA]; new Four_menus = 0; new FourMenuVariable[MAX_LAYER5_MENUS][MENU_DATA_VARIABLE]; /*An array the correct size to take the players*/ new PlayerArray[MAX_PLAYERS][MAX_NAME_LENGTH]; new UserMenu[MAX_PLAYERS][MAX_LAYERS]; /*0 is menu status (what level they are on), 1 through five are selections made on a level*/ new UserPage[MAX_PLAYERS]={NO_MENU,...}; /*Page that user is on inside a multipaged menu*/ new PlayerCommand[MAX_PLAYERS][MAX_MENU_DATA]; /*Holds selected command*/ new PlayerDesc[MAX_PLAYERS][MAX_MENU_DESCRIPTION]; /*Holds selected command description*/ new PlayerUserID[MAX_PLAYERS][MAX_PLAYERS]; /*Holds the userindexes of players*/ new UserPlayer[MAX_PLAYERS]; /*If they are using the player menu or not*/ new KillUserMenu[MAX_PLAYERS]; /*Sets whether to kill the users status in the menu on next event*/ new disabled=0; new HIDE_TEXT=0; new DEFAULT_TEXT[MAX_MENU_DESCRIPTION]; /*Some bits are only supported by a few mods, these variables say which bit is enabled*/ new COLOURED_MENUS; new _FA = 0; /***********************************************************/ /***********************************************************/ public plugin_init(){ cavey_vault_init("CAVEY_MENU_DEBUG", 0, Debug); cavey_vault_sinit("CAVEY_PATH", "cavey/", cavey_path, MAX_TEXT_LENGTH); if ((getvar("file_access_read") == 0) || ((getvar("file_access_read") == 0) && (Debug !=0)) ) { disabled = 1; plugin_registerinfo("AdminMod Menu Plugin","(Disabled) Your settings are not correct. Please see the readme.",STRING_VERSION); plugin_registercmd("admin_menu","err",ACCESS_ALL,"admin_menu: (Disabled) Please see the readme."); menu_error("[MENU] ERROR File_access_read and/or file_access_write set to 0",1); return PLUGIN_CONTINUE; } else if (!cavey_fileexists("menu/menu.ini")){ disabled = 1; plugin_registerinfo("AdminMod Menu Plugin","(Disabled) Could not find the menu.ini",STRING_VERSION); plugin_registercmd("admin_menu","err",ACCESS_ALL,"admin_menu: (Disabled) Please see the readme."); return PLUGIN_CONTINUE; } if (Debug > 0) { plugin_registercmd("admin_cavey_debug","admin_cavey_debug",ACCESS_ALL,"admin_cavey_debug: Outputs debug info to the debug.log."); cavey_resetfile("menu/debug.log"); } plugin_registerinfo("AdminMod Menu Plugin","AdminMenu Plugin by Joe 'Caveman' Noyes.",STRING_VERSION); plugin_registercmd("admin_menu","admin_menu",ACCESS_ALL,"admin_menu: Displays AdminMenu."); plugin_registercmd("radio1","reset_state",ACCESS_ALL); plugin_registercmd("radio2","reset_state",ACCESS_ALL); plugin_registercmd("radio3","reset_state",ACCESS_ALL); plugin_registercmd("showbriefing","reset_state",ACCESS_ALL); plugin_registercmd("admin_killmenu","reset_state",ACCESS_ALL); plugin_registercmd("chooseteam","reset_state",ACCESS_ALL); plugin_registercmd("admin_menu_admin","admin_menu_admin",ACCESS_ALL,"admin_menu_admin : Allows admins to alter MENU settings on the fly"); _CS = ( get_mod("Counter-Strike") ); _FA = ( get_mod("Firearms") ); if (_FA){ /*Special stuff for firearms and compatible*/ COLOURED_MENUS = 0; plugin_registercmd("vguimenuoption","menuselect",ACCESS_ALL); } else if (_CS){ /*Special stuff for CS and compatible*/ COLOURED_MENUS = 1; plugin_registercmd("menuselect","menuselect",ACCESS_ALL); plugin_registercmd("buy","reset_state",ACCESS_ALL); plugin_registercmd("buyequip","reset_state",ACCESS_ALL); } else { /*Special stuff for everything else*/ COLOURED_MENUS = 0; plugin_registercmd("menuselect","menuselect",ACCESS_ALL); } cavey_vault_init("MENU_HIDE_OPTIONS", 1, HIDE_TEXT); cavey_vault_sinit("MENU_DEFAULT_TEXT", "-= Unavailable =-", DEFAULT_TEXT, MAX_MENU_DESCRIPTION); cavey_vault_init("MENU_ACCESS_CONTROL", ACCESS_RCON, ACCESS_ADMINISTRATE); cavey_vault_init("MENU_ACCESS_TOGGLE", ACCESS_KICK, ACCESS_TOGGLE); cavey_vault_init("MENU_ACCESS_EXECUTE", ACCESS_RCON, ACCESS_EXECUTE); cavey_vault_init("MENU_ACCESS_MENU", ACCESS_ALL, ACCESS_MENU); ReadCfg("menu/menu.ini"); new strMap[MAX_DATA_LENGTH]; new sData[MAX_TEXT_LENGTH]; currentmap(strMap, MAX_DATA_LENGTH); snprintf(sData,MAX_TEXT_LENGTH,"menu/%s.ini",strMap); if (cavey_fileexists(sData)){ ReadCfg(sData); } return PLUGIN_CONTINUE; } /* Make sure you have file_access_read set to 1 */ ReadCfg(MenuFile[]){ new iLine = 1; new sData[7*MAX_TEMP_LENGTH]; new pWord[MAX_TEMP_LENGTH]; new pParm1[MAX_TEMP_LENGTH]; new pParm2[MAX_TEMP_LENGTH]; new pParm3[MAX_TEMP_LENGTH]; new pParm4[MAX_TEMP_LENGTH]; new pParm5[MAX_TEMP_LENGTH]; new pParm6[MAX_TEMP_LENGTH]; if ( cavey_fileexists(MenuFile) ) { for (iLine = 1;cavey_readfile(MenuFile,sData,iLine,MAX_DATA_LENGTH);iLine++){ new iscomment = 0; new type; pWord[0]=0; /*Clear last word - in case of strgsplit failure*/ pParm1[0]=0; /*Clear last word - in case of strgsplit failure*/ pParm2[0]=0; /*Clear last word - in case of strgsplit failure*/ strgsplit(sData, " ", "^"", pWord, MAX_DATA_LENGTH, pParm1, MAX_DATA_LENGTH,pParm2,MAX_DATA_LENGTH,pParm3,MAX_DATA_LENGTH,pParm4,MAX_DATA_LENGTH,pParm5,MAX_DATA_LENGTH,pParm6,MAX_DATA_LENGTH); new layer = strtonum(pParm1); new toggle[3] = {0,...}; /*Generate stuff that is system specific to put in arrays later*/ if ( streq(pWord,"add_menu") ) { type = ADD_MENU; if (layer == 5){ snprintf(sData,MAX_TEXT_LENGTH, "[MENU]ERROR Cannot add level to 5, config %s%s line %d", cavey_path, MenuFile, iLine); menu_error(sData,1); return 1; } } else if ( streq(pWord,"menu_player") ) { type = MENU_PLAYER; } else if ( streq(pWord,"menu_amcmd") ) { type = MENU_AMCMD; } else if ( streq(pWord,"menu_console") ) { type = MENU_COMMAND; } else if ( streq(pWord,"menu_selfexec") ) { type = MENU_SELF; } else if ( streq(pWord,"menu_toggle")) { type = MENU_TOGGLE; toggle[0]=strtonum(pParm4); toggle[1]=strtonum(pParm5); toggle[2]=strtonum(pParm6); } else if ( streq(pWord,"add_file")) { if (ReadCfg(pParm2)==1){ return 1; } iscomment = 1; } else { iscomment = 1; } /*Put the data in the arrays and update menu lists*/ if (iscomment == 1){ /*Dont need to add this....*/ } else if ( (layer == 1) && (Top_menus < (MAX_TOP_LAYER_MENUS-1) ) ){ Top_menus = Top_menus + 1; TopMenuVariable[Top_menus][MENU_TYPE_VARIABLE]=type; TopMenuVariable[Top_menus][START_MENU_VARIABLE]=One_menus+1; TopMenuVariable[Top_menus][END_MENU_VARIABLE]=One_menus; TopMenuVariable[Top_menus][TOGGLE_START_VARIABLE]=toggle[0]; TopMenuVariable[Top_menus][TOGGLE_STEP_VARIABLE]=toggle[1]; TopMenuVariable[Top_menus][TOGGLE_END_VARIABLE]=toggle[2]; strcpy(TopMenuDesc[Top_menus],pParm2,MAX_MENU_DESCRIPTION); strcpy(TopMenuCvar[Top_menus],pParm3,MAX_MENU_DATA); if (Debug > 1 ){ snprintf(sData,MAX_DATA_LENGTH, "Stored level 1 Desc %s Command %s Variable %d %d %d %d %d Address %d %d",TopMenuDesc[Top_menus],TopMenuCvar[Top_menus],TopMenuVariable[Top_menus][1],TopMenuVariable[Top_menus][2],TopMenuVariable[Top_menus][3],TopMenuVariable[Top_menus][4],TopMenuVariable[Top_menus][5],layer,Top_menus); cavey_writefile("menu/debug.log",sData,-1); } } else if ( (layer == 2) && (One_menus < (MAX_LAYER2_MENUS-1) ) ){ One_menus = One_menus + 1; TopMenuVariable[Top_menus][END_MENU_VARIABLE]=TopMenuVariable[Top_menus][END_MENU_VARIABLE]+1; OneMenuVariable[One_menus][MENU_TYPE_VARIABLE]=type; OneMenuVariable[One_menus][START_MENU_VARIABLE]=Two_menus+1; OneMenuVariable[One_menus][END_MENU_VARIABLE]=Two_menus; OneMenuVariable[One_menus][TOGGLE_START_VARIABLE]=toggle[0]; OneMenuVariable[One_menus][TOGGLE_STEP_VARIABLE]=toggle[1]; OneMenuVariable[One_menus][TOGGLE_END_VARIABLE]=toggle[2]; strcpy(OneMenuDesc[One_menus],pParm2,MAX_MENU_DESCRIPTION); strcpy(OneMenuCvar[One_menus],pParm3,MAX_MENU_DATA); if (Debug > 1 ){ snprintf(sData,MAX_DATA_LENGTH, "^tStored level 2 Desc %s Command %s Variable %d %d %d %d %d Address %d %d",OneMenuDesc[One_menus],OneMenuCvar[One_menus],OneMenuVariable[One_menus][1],OneMenuVariable[One_menus][2],OneMenuVariable[One_menus][3],OneMenuVariable[One_menus][4],OneMenuVariable[One_menus][5],layer,One_menus); cavey_writefile("menu/debug.log",sData,-1); } } else if ( (layer == 3) && (Two_menus < (MAX_LAYER3_MENUS-1) ) ){ Two_menus = Two_menus + 1; OneMenuVariable[One_menus][END_MENU_VARIABLE]=OneMenuVariable[One_menus][END_MENU_VARIABLE]+1; TwoMenuVariable[Two_menus][MENU_TYPE_VARIABLE]=type; TwoMenuVariable[Two_menus][START_MENU_VARIABLE]=Three_menus+1; TwoMenuVariable[Two_menus][END_MENU_VARIABLE]=Three_menus; TwoMenuVariable[Two_menus][TOGGLE_START_VARIABLE]=toggle[0]; TwoMenuVariable[Two_menus][TOGGLE_STEP_VARIABLE]=toggle[1]; TwoMenuVariable[Two_menus][TOGGLE_END_VARIABLE]=toggle[2]; strcpy(TwoMenuDesc[Two_menus],pParm2,MAX_MENU_DESCRIPTION); strcpy(TwoMenuCvar[Two_menus],pParm3,MAX_MENU_DATA); if (Debug > 1 ){ snprintf(sData,MAX_DATA_LENGTH, "^t^tStored level 3 Desc %s Command %s Variable %d %d %d %d %d Address %d %d",TwoMenuDesc[Two_menus],TwoMenuCvar[Two_menus],TwoMenuVariable[Two_menus][1],TwoMenuVariable[Two_menus][2],TwoMenuVariable[Two_menus][3],TwoMenuVariable[Two_menus][4],TwoMenuVariable[Two_menus][5],layer,Two_menus); cavey_writefile("menu/debug.log",sData,-1); } } else if ( (layer == 4) && (Three_menus < (MAX_LAYER4_MENUS-1) ) ){ Three_menus = Three_menus + 1; TwoMenuVariable[Two_menus][END_MENU_VARIABLE]=TwoMenuVariable[Two_menus][END_MENU_VARIABLE]+1; ThreeMenuVariable[Three_menus][MENU_TYPE_VARIABLE]=type; ThreeMenuVariable[Three_menus][START_MENU_VARIABLE]=Four_menus+1; ThreeMenuVariable[Three_menus][END_MENU_VARIABLE]=Four_menus; ThreeMenuVariable[Three_menus][TOGGLE_START_VARIABLE]=toggle[0]; ThreeMenuVariable[Three_menus][TOGGLE_STEP_VARIABLE]=toggle[1]; ThreeMenuVariable[Three_menus][TOGGLE_END_VARIABLE]=toggle[2]; strcpy(ThreeMenuDesc[Three_menus],pParm2,MAX_MENU_DESCRIPTION); strcpy(ThreeMenuCvar[Three_menus],pParm3,MAX_MENU_DATA); if (Debug > 1 ){ snprintf(sData,MAX_DATA_LENGTH, "^t^t^tStored level 4 Desc %s Command %s Variable %d %d %d %d %d Address %d %d",ThreeMenuDesc[Three_menus],ThreeMenuCvar[Three_menus],ThreeMenuVariable[Three_menus][1],ThreeMenuVariable[Three_menus][2],ThreeMenuVariable[Three_menus][3],ThreeMenuVariable[Three_menus][4],ThreeMenuVariable[Three_menus][5],layer,Three_menus); cavey_writefile("menu/debug.log",sData,-1); } } else if ( (layer == 5) && (Four_menus < (MAX_LAYER5_MENUS-1) ) ){ Four_menus = Four_menus + 1; ThreeMenuVariable[Three_menus][END_MENU_VARIABLE]=ThreeMenuVariable[Three_menus][END_MENU_VARIABLE]+1; /*START_MENU_VARIABLE and END_MENU_VARIABLE are not set as there is no lower menu!!*/ FourMenuVariable[Four_menus][MENU_TYPE_VARIABLE]=type; FourMenuVariable[Four_menus][TOGGLE_START_VARIABLE]=toggle[0]; FourMenuVariable[Four_menus][TOGGLE_STEP_VARIABLE]=toggle[1]; FourMenuVariable[Four_menus][TOGGLE_END_VARIABLE]=toggle[2]; strcpy(FourMenuDesc[Four_menus],pParm2,MAX_MENU_DESCRIPTION); strcpy(FourMenuCvar[Four_menus],pParm3,MAX_MENU_DATA); if (Debug > 1 ){ snprintf(sData,MAX_DATA_LENGTH, "^t^t^t^tStored level 5 Desc %s Command %s Variable %d %d %d %d %d Address %d %d",FourMenuDesc[Four_menus],FourMenuCvar[Four_menus],FourMenuVariable[Four_menus][1],FourMenuVariable[Four_menus][2],FourMenuVariable[Four_menus][3],FourMenuVariable[Four_menus][4],FourMenuVariable[Four_menus][5],layer,Four_menus); cavey_writefile("menu/debug.log",sData,-1); } } else if ( ( layer > 5 ) ){ snprintf(sData,MAX_TEXT_LENGTH, "[MENU] ERROR Trying to add to non-existent level, config %s%s line %d", cavey_path, MenuFile, iLine); menu_error(sData,1); return 1; } else if ( (Top_menus >= (MAX_TOP_LAYER_MENUS-1) ) || (One_menus >= (MAX_LAYER2_MENUS-1) ) || (Two_menus >= (MAX_LAYER3_MENUS-1) )|| (Three_menus > (MAX_LAYER4_MENUS-1) )|| (Four_menus > (MAX_LAYER5_MENUS-1) ) ){ snprintf(sData,MAX_TEXT_LENGTH, "[MENU] ERROR Menu bigger than allocated memory, config %s%s line %d", cavey_path, MenuFile, iLine); menu_error(sData,1); return 1; } } } else { snprintf(sData, MAX_DATA_LENGTH, "[MENU] Could not find file %s%s", cavey_path, MenuFile); log(sData); menu_error(sData,1); } return 0; } public admin_cavey_debug(HLCommand,HLData,HLUserName,UserIndex){ new i; new sData[MAX_DATA_LENGTH]; cavey_writefile("menu/debug.log"," - - - ",-1); for (i = 1; i <= Top_menus;i++){ snprintf(sData,MAX_DATA_LENGTH, "TopMenus Desc ^"%s^" Cvar ^"%s^" Vars %d %d %d %d %d %d",TopMenuDesc[i],TopMenuCvar[i],TopMenuVariable[i][0],TopMenuVariable[i][1],TopMenuVariable[i][2],TopMenuVariable[i][3],TopMenuVariable[i][4],TopMenuVariable[i][5]); cavey_writefile("menu/debug.log",sData,-1); } for (i = 1; i <= One_menus;i++){ snprintf(sData,MAX_DATA_LENGTH, "^tOneMenus Desc ^"%s^" Cvar ^"%s^" Vars %d %d %d %d %d %d",OneMenuDesc[i],OneMenuCvar[i],OneMenuVariable[i][0],OneMenuVariable[i][1],OneMenuVariable[i][2],OneMenuVariable[i][3],OneMenuVariable[i][4],OneMenuVariable[i][5]); cavey_writefile("menu/debug.log",sData,-1); } for (i = 1; i <= Two_menus;i++){ snprintf(sData,MAX_DATA_LENGTH, "^t^tTwoMenus Desc ^"%s^" Cvar ^"%s^" Vars %d %d %d %d %d %d",TwoMenuDesc[i],TwoMenuCvar[i],TwoMenuVariable[i][0],TwoMenuVariable[i][1],TwoMenuVariable[i][2],TwoMenuVariable[i][3],TwoMenuVariable[i][4],TwoMenuVariable[i][5]); cavey_writefile("menu/debug.log",sData,-1); } for (i = 1; i <= Three_menus;i++){ snprintf(sData,MAX_DATA_LENGTH, "^t^t^tThreeMenus Desc ^"%s^" Cvar ^"%s^" Vars %d %d %d %d %d %d",ThreeMenuDesc[i],ThreeMenuCvar[i],ThreeMenuVariable[i][0],ThreeMenuVariable[i][1],ThreeMenuVariable[i][2],ThreeMenuVariable[i][3],ThreeMenuVariable[i][4],ThreeMenuVariable[i][5]); cavey_writefile("menu/debug.log",sData,-1); } for (i = 1; i <= Four_menus;i++){ snprintf(sData,MAX_DATA_LENGTH, "^t^t^t^tFourMenus Desc ^"%s^" Cvar ^"%s^" Vars %d %d %d %d %d %d",FourMenuDesc[i],FourMenuCvar[i],FourMenuVariable[i][0],FourMenuVariable[i][1],FourMenuVariable[i][2],FourMenuVariable[i][3],FourMenuVariable[i][4],FourMenuVariable[i][5]); cavey_writefile("menu/debug.log",sData,-1); } say("Output complete"); return PLUGIN_CONTINUE; } menu_error(sData[],iValue){ if (getvar("file_access_write") == 1){ disabled = iValue; cavey_writefile("menu/error.log",sData,-1); strcpy(DEFAULT_TEXT,sData,MAX_MENU_DESCRIPTION); } else { disabled = iValue; strcpy(DEFAULT_TEXT,sData,MAX_MENU_DESCRIPTION); } return 0; } public admin_menu(HLCommand,HLData,HLUserName,UserIndex){ new i; new Data[MAX_DATA_LENGTH]; convert_string(HLUserName,Data,MAX_DATA_LENGTH); if (disabled != 0 ){ say("[MENU] Menu plugin disabled. Please consult the readme and the error log."); selfmessage(DEFAULT_TEXT); return PLUGIN_CONTINUE; } if (UserIndex == 0 ){ return PLUGIN_CONTINUE; } if ( access(ACCESS_MENU, Data)==0 ){ return PLUGIN_CONTINUE; /*Command hidden from those without access*/ } if (Debug > 1){ snprintf(Data,MAX_DATA_LENGTH, "^nUser ^"%d^" selected ^"admin_menu^" - %d %d %d %d %d",UserIndex,UserMenu[UserIndex][0],UserMenu[UserIndex][1],UserMenu[UserIndex][3],UserMenu[UserIndex][4],UserMenu[UserIndex][5]); cavey_writefile("menu/debug.log",Data,-1); } UserMenu[UserIndex][0]=1; /*Sets CurrentLayer to 1 VERY IMPORTANT!!!*/ for (i=1;i<=5;i++){ UserMenu[UserIndex][i]=0; } KillUserMenu[UserIndex] = vote_allowed(); UserPlayer[UserIndex] = 0; UserPage[UserIndex] = 0; display_menu(UserIndex); return PLUGIN_HANDLED; } /*This should set the user such that when do_action is called it only has to look up the users details, look up the action and act accordingly*/ public menuselect(HLCommand,HLData,HLUserName,UserIndex){ if (disabled == 1){ return PLUGIN_CONTINUE; } new Data[MAX_DATA_LENGTH]; convert_string(HLData,Data,MAX_DATA_LENGTH); /*The "Last-" variables tell us what the action was in response to*/ new LastLayer = UserMenu[UserIndex][0]; /*iMenu has the users response to the menus questions*/ new iMenu = strtonum(Data); if (LastLayer == 0){ /*User was not in the menu*/ KillUserMenu[UserIndex] = vote_allowed(); /*If it was in response to a vote, then oh well....*/ if (Debug > 2) say("[MENU DEBUG] User was not in menu, menuselect ignored"); return PLUGIN_CONTINUE; } /*If vote_allowed != 1 then a vote was called. "recently". If KillUserMenu is still 1 then they selected last before the vote, so we need to ignore it. If vote_allowed is 1 though, a changes from not allowed to allowed has no menu so it is okay. However, in rare cases it is possible to still "accidentally" screw up....*/ if ( (KillUserMenu[UserIndex] != vote_allowed() ) && (vote_allowed() != 1) ){ /*User was in menu system when a vote got called*/ KillUserMenu[UserIndex] = vote_allowed(); display_menu(UserIndex); if (Debug > 2) say("[MENU DEBUG] Vote filtering occured"); return PLUGIN_CONTINUE; } new LastMenu = UserMenu[UserIndex][LastLayer-1]; if ( iMenu > 10 || iMenu < 0 ){ /*There is no case for this, someone else can deal with it*/ if (Debug > 2) say("[MENU DEBUG] Unhandled case in menuselect"); return PLUGIN_CONTINUE; } if ( iMenu == 10 || iMenu == 0 ){ /*0 ALWAYS quit unless they set it to go back*/ new UserName[MAX_NAME_LENGTH]; convert_string(HLUserName,UserName,MAX_NAME_LENGTH); get_userinfo(UserName,"am_menugoback",Data,MAX_DATA_LENGTH); if (Debug > 2) say("[MENU DEBUG] Menuselect 0"); if (strtonum(Data) == 1){ if (Debug > 2) say("[MENU DEBUG] am_menugoback set, so staying with menu"); UserMenu[UserIndex][0] = UserMenu[UserIndex][0] - 1; UserPlayer[UserIndex] = 0; if ( UserMenu[UserIndex][0] > 0 ) do_action(UserIndex); } else { UserMenu[UserIndex][0] = NO_MENU; UserPlayer[UserIndex] = 0; } return PLUGIN_HANDLED; } else if (UserPlayer[UserIndex] == 1){/*The player handling code is different!!*/ if ( iMenu == 8 ){ /*0 is ALWAYS previous page*/ UserPage[UserIndex] = UserPage[UserIndex]-1; /*User "location" does not change Decrease pages by one*/ show_playermenu(UserIndex); return PLUGIN_HANDLED; } else if ( iMenu == 9 ){ /*0 is ALWAYS next page*/ UserPage[UserIndex] = UserPage[UserIndex]+1; /*User "location" does not change Increase pages by one*/ show_playermenu(UserIndex); return PLUGIN_HANDLED; } else { do_playeraction(iMenu,UserIndex); return PLUGIN_HANDLED; } } else if ( iMenu == 8 ){ /*0 is ALWAYS previous page*/ UserPage[UserIndex] = UserPage[UserIndex]-1; /*User "location" does not change Decrease pages by one*/ display_menu(UserIndex); return PLUGIN_HANDLED; } else if ( iMenu == 9 ){ /*0 is ALWAYS next page*/ UserPage[UserIndex] = UserPage[UserIndex]+1; /*User "location" does not change Increase pages by one*/ display_menu(UserIndex); return PLUGIN_HANDLED; } /*Modify users location*/ /*Thoughts. Current layer was a menu and had the start address of where the selection came from in [1] of its Variable array. Fetch it ...... */ new Start; if ( LastLayer == 1 ){ Start = 1; /*Is ALWAYS 1 due to way it was set into arrays*/ } else if ( LastLayer == 2 ){ Start = TopMenuVariable[LastMenu][START_MENU_VARIABLE]; } else if ( LastLayer == 3 ){ Start = OneMenuVariable[LastMenu][START_MENU_VARIABLE]; } else if ( LastLayer == 4 ){ Start = TwoMenuVariable[LastMenu][START_MENU_VARIABLE]; } else if ( LastLayer == 5 ){ Start = ThreeMenuVariable[LastMenu][START_MENU_VARIABLE]; } else if ( LastLayer >= 6 ){ menu_error("[MENU] Attempt to access a non-existent level in menuselect",0); } /*The menu they selected*/ new Address; /* = Menu Address + What page were they on + the menu they selected minus the "iMenu fiddle factor" */ Address = Start + ( UserPage[UserIndex] * 7 ) + iMenu - 1; UserMenu[UserIndex][UserMenu[UserIndex][0]]=Address; /*Set Current menu to one selected from menu*/ UserMenu[UserIndex][0] = UserMenu[UserIndex][0] + 1; /*Progress to the nextlayer*/ if (Debug > 1 ){ snprintf(Data,MAX_DATA_LENGTH, "User ^"%d^" selected ^"%d^" - %d %d %d %d %d",UserIndex,iMenu,UserMenu[UserIndex][0],UserMenu[UserIndex][1],UserMenu[UserIndex][3],UserMenu[UserIndex][4],UserMenu[UserIndex][5]); cavey_writefile("menu/debug.log",Data,-1); } do_action(UserIndex); return PLUGIN_HANDLED; } /*Remember - Up one layer and read currentmenu to get addresses*/ do_action(UserIndex){ new CurrentLayer = UserMenu[UserIndex][0]; new CurrentMenu = UserMenu[UserIndex][CurrentLayer-1]; UserPage[UserIndex] = 0; /*This saves having to write it out a zillion times*/ if ( CurrentLayer == 1 ){ /*They are set to view the top menu, this is for am_menugoback*/ display_menu(UserIndex); } else if ( CurrentLayer == 2 ){ /*They just selected from level one (called top)*/ layer_action(UserIndex,TopMenuDesc[CurrentMenu],TopMenuCvar[CurrentMenu],TopMenuVariable[CurrentMenu]); } else if ( CurrentLayer == 3 ){ /*They just selected from level two (called one)*/ layer_action(UserIndex,OneMenuDesc[CurrentMenu],OneMenuCvar[CurrentMenu],OneMenuVariable[CurrentMenu]); } else if ( CurrentLayer == 4 ){ /*They just selected from level three (called two)*/ layer_action(UserIndex,TwoMenuDesc[CurrentMenu],TwoMenuCvar[CurrentMenu],TwoMenuVariable[CurrentMenu]); } else if ( CurrentLayer == 5 ){ /*They just selected from level four (called three)*/ layer_action(UserIndex,ThreeMenuDesc[CurrentMenu],ThreeMenuCvar[CurrentMenu],ThreeMenuVariable[CurrentMenu]); } else if ( CurrentLayer == 6 ){ /*They just selected from level five (called four)*/ layer_action(UserIndex,FourMenuDesc[CurrentMenu],FourMenuCvar[CurrentMenu],FourMenuVariable[CurrentMenu]); } else if ( CurrentLayer > 6 ){ menu_error("[MENU] ERROR Attempt to access a non-existent layer in do_action",0); } } layer_action(UserIndex,MenuDesc[],MenuCvar[],MenuVariable[]){ new type = MenuVariable[0]; new Data[MAX_DATA_LENGTH]; new User[MAX_NAME_LENGTH]; new sAuthID[MAX_AUTHID_LENGTH],SessioID,iTeam,iDead; plrinfo(UserIndex,User,MAX_NAME_LENGTH,SessioID,sAuthID,iTeam,iDead); if ( type == ADD_MENU ){ display_menu(UserIndex); return 0; /*Exit this function successfully*/ } else if ( type == MENU_PLAYER ){ UserPlayer[UserIndex] = 1; strcpy(PlayerCommand[UserIndex],MenuCvar,MAX_MENU_DATA); strcpy(PlayerDesc[UserIndex],MenuDesc,MAX_MENU_DESCRIPTION); show_playermenu(UserIndex); return 0; } else if ( type == MENU_AMCMD ){ new Argus[MAX_DATA_LENGTH]; new Command[MAX_DATA_LENGTH]; strcpy(Data,MenuCvar,MAX_DATA_LENGTH); new Colon = strcount(Data,';')+1; new access_level,rejected=0; for (new i=0;i<Colon;i++){ new temp[MAX_DATA_LENGTH]; split(Data,";",temp,MAX_DATA_LENGTH,Data,MAX_DATA_LENGTH); strbreak(temp,Command,Argus,MAX_DATA_LENGTH); if (plugin_checkcommand(Command,access_level)<=0){ rejected = 1; } else { plugin_exec(Command,Argus); } } if (rejected !=0){ getstrvar("admin_reject_msg",Argus,MAX_DATA_LENGTH); messageex(User,Argus,print_chat); } if (Debug > 0) messageex(User,MenuDesc,print_chat); } else if ( type == MENU_COMMAND ){ strcpy(Data,MenuCvar,MAX_DATA_LENGTH); if (access(ACCESS_EXECUTE, User)!=0){ new Colon = strcount(Data,';')+1; for (new i=0;i<Colon;i++){ new temp[MAX_DATA_LENGTH]; split(Data,";",temp,MAX_DATA_LENGTH,Data,MAX_DATA_LENGTH); exec(temp); } if (Debug > 0) messageex(User,MenuDesc,print_chat); } else { getstrvar("admin_reject_msg",Data,MAX_DATA_LENGTH); messageex(User,Data,print_chat); } } else if ( type == MENU_TOGGLE ){ if (access(ACCESS_TOGGLE, User)!=0){ new Cvar[MAX_DATA_LENGTH]; new newCvar[MAX_DATA_LENGTH]; new iCvar; getstrvar(MenuCvar,Cvar,MAX_DATA_LENGTH); iCvar = strtonum(Cvar); iCvar += MenuVariable[TOGGLE_STEP_VARIABLE]; if (iCvar > MenuVariable[TOGGLE_END_VARIABLE] ){ iCvar = MenuVariable[TOGGLE_START_VARIABLE]; } snprintf(newCvar, MAX_DATA_LENGTH, "%s %d",MenuCvar,iCvar); exec(newCvar); snprintf(newCvar, MAX_DATA_LENGTH, "%s set to %d",MenuCvar,iCvar); say(newCvar); } else { getstrvar("admin_reject_msg",Data,MAX_DATA_LENGTH); messageex(User,Data,print_chat); } } else if ( type == MENU_SELF ){ strcpy(Data,MenuCvar,MAX_DATA_LENGTH); if (getvar("allow_client_exec")!=0){ new Colon = strcount(Data,';')+1; for (new i=0;i<Colon;i++){ new temp[MAX_DATA_LENGTH]; split(Data,";",temp,MAX_DATA_LENGTH,Data,MAX_DATA_LENGTH); execclient(User,temp); } if (Debug > 0) messageex(User,MenuDesc,print_chat); } else { getstrvar("admin_reject_msg",Data,MAX_DATA_LENGTH); messageex(User,Data,print_chat); } } else { snprintf(Data,MAX_DATA_LENGTH, "[MENU] ERROR Unknown menu type %d",type); menu_error(Data,0); } get_userinfo(User,"am_menugoback",Data,MAX_DATA_LENGTH); if (strtonum(Data) == 1 && UserMenu[UserIndex][0] != NO_MENU){ if (Debug > 2) say("[MENU DEBUG] am_menugoback set, so staying with menu"); UserMenu[UserIndex][0] = UserMenu[UserIndex][0] - 1; UserPlayer[UserIndex] = 0; do_action(UserIndex); } else { if (Debug > 2) say("[MENU DEBUG] Done action so quitting menu"); UserMenu[UserIndex][0] = NO_MENU; UserPlayer[UserIndex] = 0; } return 0; } /*Errors*/ display_menu(UserIndex){ /*Building the menu*/ new MenuText[MAX_MENU_LENGTH]; new MenuTemp[MAX_DATA_LENGTH]; /*Key monitor*/ new act_keys = 0; new mKeys[10] = {1,2,4,8,16,32,64,128,256,512}; /*Handling variables*/ new Page = UserPage[UserIndex]; new pages_num = 0; /*Total possible number of pages for that menu*/ new list_begin; /*This first menu that gets displayed after pages*/ new list_end; /*This last menu that gets displayed after pages*/ new start; /*This first menu on the sub-menu*/ new final; /*This last menu on the sub-menu*/ new menus_num; /*Should be final - start + 1*/ new CurrentLayer = UserMenu[UserIndex][0]; /*Oi, cavey, this is correct!!*/ new CurrentMenu = UserMenu[UserIndex][CurrentLayer - 1]; /*Oi, cavey, this is correct ?*/ /*Remember - Up one layer and read currentmenu to get addresses*/ /*Loop variables*/ new i=0; new j=0; new UserName[MAX_NAME_LENGTH]; playerinfo(UserIndex,UserName,MAX_NAME_LENGTH); if ( CurrentLayer == 0){ /*Exit system*/ return 0; } else if ( CurrentLayer == 1 ){ /*Display main menu*/ while( pages_num * 7 < Top_menus ){ /*Count number of pages*/ ++pages_num; } list_begin = (Page * 7) + 1; /*$MODSP*/ if (COLOURED_MENUS){ snprintf(MenuText, MAX_MENU_LENGTH, "\yMain Menu ( Page %d/%d )\w^n^n" ,Page+1,pages_num); } else { snprintf(MenuText, MAX_MENU_LENGTH, "Main Menu ( Page %d/%d )^n^n" ,Page+1,pages_num); } if ( Top_menus > list_begin + 6){ /*If the rest of the commands wont fit on one page*/ list_end = list_begin + 6; } else { list_end = Top_menus; } final = Top_menus; /*Set menu items 1 through 7*/ for (i = list_begin; i <= list_end; ++i){ new hasaccess = 0; if (TopMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_TOGGLE){ hasaccess = access(ACCESS_TOGGLE); } else if (TopMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_COMMAND){ hasaccess = access(ACCESS_EXECUTE); } else if (TopMenuVariable[i][MENU_TYPE_VARIABLE]==ADD_MENU){ hasaccess = access(ACCESS_MENU); } else if (TopMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_PLAYER || TopMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_AMCMD){ new Command[MAX_MENU_DATA]; new Data[MAX_MENU_DATA]; strbreak(TopMenuCvar[i],Command,Data,MAX_MENU_DATA); new blah; hasaccess = plugin_checkcommand(Command,blah); } else if (TopMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_SELF){ hasaccess = getvar("allow_client_exec"); } else { hasaccess = 1; } if (hasaccess == 0){ if (COLOURED_MENUS){ snprintf(MenuTemp,MAX_DATA_LENGTH, "\d%d. %s\w^n", j+1, TopMenuDesc[i] ); } else if (HIDE_TEXT==0){ snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1,DEFAULT_TEXT); } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "^n"); } strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); j++; } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1, TopMenuDesc[i] ); strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); act_keys += mKeys[j]; j++; } } } else if ( CurrentLayer == 2 ){ /*They just selected from level one (called top)*/ start = TopMenuVariable[CurrentMenu][START_MENU_VARIABLE]; final = TopMenuVariable[CurrentMenu][END_MENU_VARIABLE]; menus_num = final - start + 1; /*Correct*/ while( pages_num * 7 < menus_num ){ ++pages_num; } list_begin = start + (Page * 7); /*Correct!*/ /*$MODSP*/ if (COLOURED_MENUS){ snprintf(MenuText, MAX_MENU_LENGTH, "\y%s ( Page %d/%d )\w^n^n" ,TopMenuDesc[CurrentMenu],Page+1,pages_num); } else { snprintf(MenuText, MAX_MENU_LENGTH, "%s ( Page %d/%d )^n^n" ,TopMenuDesc[CurrentMenu],Page+1,pages_num); } if ( final > list_begin + 6){ /*If the rest of the commands wont fit on one page*/ list_end = list_begin + 6; } else { list_end = final; } /*Set menu items 1 through 7 inclusive ( and 1 + 6 = 7 )*/ for (i = list_begin; i <= list_end; ++i) { new hasaccess = 1; if (OneMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_TOGGLE){ hasaccess = access(ACCESS_TOGGLE); } else if (OneMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_COMMAND){ hasaccess = access(ACCESS_EXECUTE); } else if (OneMenuVariable[i][MENU_TYPE_VARIABLE]==ADD_MENU){ hasaccess = access(ACCESS_MENU); } else if (OneMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_PLAYER || OneMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_AMCMD){ new Command[MAX_MENU_DATA]; new Data[MAX_MENU_DATA]; strbreak(OneMenuCvar[i],Command,Data,MAX_MENU_DATA); new blah; hasaccess = plugin_checkcommand(Command,blah); } else if (OneMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_SELF){ hasaccess = getvar("allow_client_exec"); } else { hasaccess = 1; } if (hasaccess == 0){ if (COLOURED_MENUS){ snprintf(MenuTemp,MAX_DATA_LENGTH, "\d%d. %s\w^n", j+1, OneMenuDesc[i] ); } else if (HIDE_TEXT==0){ snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1,DEFAULT_TEXT); } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "^n"); } strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); j++; } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1, OneMenuDesc[i] ); strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); act_keys += mKeys[j]; j++; } } } else if ( CurrentLayer == 3 ){ /*They just selected from level three (called two)*/ start = OneMenuVariable[CurrentMenu][START_MENU_VARIABLE]; final = OneMenuVariable[CurrentMenu][END_MENU_VARIABLE]; menus_num = final - start + 1; /*Correct*/ while( pages_num * 7 < menus_num ){ ++pages_num; } list_begin = start + (Page * 7); /*Correct!*/ /*$MODSP*/ if (COLOURED_MENUS){ snprintf(MenuText, MAX_MENU_LENGTH, "\y%s ( Page %d/%d )\w^n^n" ,OneMenuDesc[CurrentMenu],Page+1,pages_num); } else { snprintf(MenuText, MAX_MENU_LENGTH, "%s ( Page %d/%d )^n^n" ,OneMenuDesc[CurrentMenu],Page+1,pages_num); } if ( final > list_begin + 6){ /*If the rest of the commands wont fit on one page*/ list_end = list_begin + 6; } else { list_end = final; } /*Set menu items 1 through 7 inclusive ( and 1 + 6 = 7 )*/ for (i = list_begin; i <= list_end; ++i){ new hasaccess = 0; if (TwoMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_TOGGLE){ hasaccess = access(ACCESS_TOGGLE); } else if (TwoMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_COMMAND){ hasaccess = access(ACCESS_EXECUTE); } else if (TwoMenuVariable[i][MENU_TYPE_VARIABLE]==ADD_MENU){ hasaccess = access(ACCESS_MENU); } else if (TwoMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_PLAYER || TwoMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_AMCMD){ new Command[MAX_MENU_DATA]; new Data[MAX_MENU_DATA]; strbreak(TwoMenuCvar[i],Command,Data,MAX_MENU_DATA); new blah; hasaccess = plugin_checkcommand(Command,blah); } else if (TwoMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_SELF){ hasaccess = getvar("allow_client_exec"); } else { hasaccess = 1; } if (hasaccess == 0){ if (COLOURED_MENUS){ snprintf(MenuTemp,MAX_DATA_LENGTH, "\d%d. %s\w^n", j+1, TwoMenuDesc[i] ); } else if (HIDE_TEXT==0){ snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1,DEFAULT_TEXT); } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "^n"); } strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); j++; } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1, TwoMenuDesc[i] ); strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); act_keys += mKeys[j]; j++; } } } else if ( CurrentLayer == 4 ){ /*They just selected from level four (called three)*/ start = TwoMenuVariable[CurrentMenu][START_MENU_VARIABLE]; final = TwoMenuVariable[CurrentMenu][END_MENU_VARIABLE]; menus_num = final - start + 1; /*Correct*/ while( pages_num * 7 < menus_num ){ ++pages_num; } list_begin = start + (Page * 7); /*Correct!*/ /*$MODSP*/ if (COLOURED_MENUS){ snprintf(MenuText, MAX_MENU_LENGTH, "\y%s ( Page %d/%d )\w^n^n" ,TwoMenuDesc[CurrentMenu],Page+1,pages_num); } else { snprintf(MenuText, MAX_MENU_LENGTH, "%s ( Page %d/%d )^n^n" ,TwoMenuDesc[CurrentMenu],Page+1,pages_num); } if ( final > (list_begin + 6) ){ /*If the rest of the commands wont fit on one page*/ list_end = list_begin + 6; } else { list_end = final; } /*Set menu items 1 through 7 inclusive ( and 1 + 6 = 7 )*/ for (i = list_begin; i <= list_end; ++i) { new hasaccess = 0; if (ThreeMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_TOGGLE){ hasaccess = access(ACCESS_TOGGLE); } else if (ThreeMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_COMMAND){ hasaccess = access(ACCESS_EXECUTE); } else if (ThreeMenuVariable[i][MENU_TYPE_VARIABLE]==ADD_MENU){ hasaccess = access(ACCESS_MENU); } else if (ThreeMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_PLAYER || ThreeMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_AMCMD){ new Command[MAX_MENU_DATA]; new Data[MAX_MENU_DATA]; strbreak(ThreeMenuCvar[i],Command,Data,MAX_MENU_DATA); new blah; hasaccess = plugin_checkcommand(Command,blah); } else if (ThreeMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_SELF){ hasaccess = getvar("allow_client_exec"); } else { hasaccess = 1; } if (hasaccess == 0){ if (COLOURED_MENUS){ snprintf(MenuTemp,MAX_DATA_LENGTH, "\d%d. %s\w^n", j+1, ThreeMenuDesc[i] ); } else if (HIDE_TEXT==0){ snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1,DEFAULT_TEXT); } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "^n"); } strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); j++; } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1, ThreeMenuDesc[i] ); strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); act_keys += mKeys[j]; j++; } } } else if ( CurrentLayer == 5 ){ /*They just selected from level five (called four)*/ start = ThreeMenuVariable[CurrentMenu][START_MENU_VARIABLE]; final = ThreeMenuVariable[CurrentMenu][END_MENU_VARIABLE]; menus_num = final - start + 1; /*Correct*/ while( pages_num * 7 < menus_num ){ ++pages_num; } list_begin = start + (Page * 7); /*Correct!*/ /*$MODSP*/ if (COLOURED_MENUS){ snprintf(MenuText, MAX_MENU_LENGTH, "\y%s ( Page %d/%d )\w^n^n" ,ThreeMenuDesc[CurrentMenu],Page+1,pages_num); } else { snprintf(MenuText, MAX_MENU_LENGTH, "%s ( Page %d/%d )^n^n" ,ThreeMenuDesc[CurrentMenu],Page+1,pages_num); } if ( final > list_begin + 6){ /*If the rest of the commands wont fit on one page*/ list_end = list_begin + 6; } else { list_end = final; } /*Set menu items 1 through 7 inclusive ( and 1 + 6 = 7 )*/ for (i = list_begin; i <= list_end; ++i){ new hasaccess = 0; if (FourMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_TOGGLE){ hasaccess = access(ACCESS_TOGGLE); } else if (FourMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_COMMAND){ hasaccess = access(ACCESS_EXECUTE); } else if (FourMenuVariable[i][MENU_TYPE_VARIABLE]==ADD_MENU){ hasaccess = access(ACCESS_MENU); } else if (FourMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_PLAYER || FourMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_AMCMD){ new Command[MAX_MENU_DATA]; new Data[MAX_MENU_DATA]; strbreak(FourMenuCvar[i],Command,Data,MAX_MENU_DATA); new blah; hasaccess = plugin_checkcommand(Command,blah); } else if (FourMenuVariable[i][MENU_TYPE_VARIABLE]==MENU_SELF){ hasaccess = getvar("allow_client_exec"); } else { hasaccess = 1; } if (hasaccess==0){ if (COLOURED_MENUS){ snprintf(MenuTemp,MAX_DATA_LENGTH, "\d%d. %s\w^n", j+1, FourMenuDesc[i] ); } else if (HIDE_TEXT==0){ snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1,DEFAULT_TEXT); } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "^n"); } strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); j++; } else { snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1, FourMenuDesc[i] ); strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); act_keys += mKeys[j]; j++; } } } else { menu_error("[MENU] ERROR Attempt to show non-existent layer in display_menu", 1); } if ( Page > 0 ) { strcat(MenuText,"^n8. Previous...",MAX_MENU_LENGTH); act_keys += mKeys[7]; } if ( list_end < final ){ strcat(MenuText,"^n9. Next...^n",MAX_MENU_LENGTH); act_keys += mKeys[8]; } get_userinfo(UserName,"am_menugoback",MenuTemp,MAX_DATA_LENGTH); if (strtonum(MenuTemp) == 1){ strcat(MenuText,"^n0. Back^n",MAX_MENU_LENGTH); } else { strcat(MenuText,"^n0. Cancel^n",MAX_MENU_LENGTH); } act_keys += mKeys[9]; menu(UserName,MenuText,act_keys); return 0; } /*No errors*/ show_playermenu(UserIndex){ new MenuText[MAX_MENU_LENGTH]; new MenuTemp[MAX_DATA_LENGTH]; new act_keys = 0; new mKeys[10] = {1,2,4,8,16,32,64,128,256,512}; new Page = UserPage[UserIndex]; new pages_num = 0; new list_begin; new list_end; new i=0; new j=0; GetPlayersList(UserIndex); /*Build list of players and get number of players*/ while(pages_num * 7 < PlayerArray[0][0]){ /*Count number of pages*/ ++pages_num; } list_begin = 1; list_begin += Page * 7; if (COLOURED_MENUS){ snprintf(MenuText, MAX_MENU_LENGTH, "\y%s ( Page %d/%d )\w^n^n" ,PlayerDesc[UserIndex],Page+1,pages_num); } else { snprintf(MenuText, MAX_MENU_LENGTH, "%s ( Page %d/%d )^n^n" ,PlayerDesc[UserIndex],Page+1,pages_num); } if ( PlayerArray[0][0] > list_begin + 6 ){ /*If the rest of the players will fit on one page*/ list_end = list_begin + 6; } else { list_end = PlayerArray[0][0]; } /*Set menu items 1 through 7*/ for (i = list_begin; i <= list_end; ++i) { snprintf(MenuTemp,MAX_DATA_LENGTH, "%d. %s^n", j+1, PlayerArray[i] ); strcat(MenuText, MenuTemp, MAX_MENU_LENGTH); act_keys += mKeys[j]; j++; } if ( Page > 0 ) { strcat(MenuText,"^n8. Previous...",MAX_MENU_LENGTH); act_keys += mKeys[7]; } if ( list_end < PlayerArray[0][0] ){ strcat(MenuText,"^n9. Next...^n",MAX_MENU_LENGTH); act_keys += mKeys[8]; } strcat(MenuText,"^n0. Cancel^n",MAX_MENU_LENGTH); act_keys += mKeys[9]; new UserName[MAX_NAME_LENGTH]; playerinfo(UserIndex,UserName,MAX_NAME_LENGTH); menu(UserName,MenuText,act_keys); return 0; } do_playeraction(iMenu,UserIndex){ /*I wonder why I called it number.....*/ new number[MAX_DATA_LENGTH]; new User[MAX_NAME_LENGTH]; new UserName[MAX_NAME_LENGTH]; new Command[MAX_DATA_LENGTH]; new Data[MAX_DATA_LENGTH]; new iUserID, sAuthID[MAX_AUTHID_LENGTH], iTeam, iDead; plrinfo(UserIndex,UserName,MAX_NAME_LENGTH,iUserID, sAuthID, iTeam, iDead); strcpy(number,PlayerCommand[UserIndex],MAX_DATA_LENGTH); if(plrinfo(PlayerUserID[UserIndex][UserPage[UserIndex] * 7 + iMenu],User,MAX_NAME_LENGTH,iUserID, sAuthID, iTeam, iDead)){ new Colon = strcount(number,';')+1; new access_level,rejected =0; for (new i=0;i<Colon;i++){ new temp[MAX_DATA_LENGTH]; if (Colon>1){ split(number,";",temp,MAX_DATA_LENGTH,number,MAX_DATA_LENGTH); } else { strcpy(temp, number, MAX_DATA_LENGTH); } if (strcasestr(temp,"%PLAYER%")!=-1){ strsubst(temp,"'","^"",MAX_DATA_LENGTH); strsubst(temp,"%PLAYER%",User,MAX_DATA_LENGTH); } else { strbreak(temp,Command,Data,MAX_DATA_LENGTH); if (strlen(Data) >0){ snprintf(temp,MAX_DATA_LENGTH,"%s ^"%s^" %s",Command,User,Data); } else { snprintf(temp,MAX_DATA_LENGTH,"%s %s",Command,User); } } split(temp," ",Command,MAX_DATA_LENGTH,Data,MAX_DATA_LENGTH); if (plugin_checkcommand(Command,access_level)<=0){ rejected=1; } else { plugin_exec(Command,Data); if (Debug > 0) messageex(UserName,Command,print_chat); if (Debug > 0) messageex(UserName,Data,print_chat); } } if (rejected != 0){ getstrvar("admin_reject_msg",Data,MAX_DATA_LENGTH); messageex(UserName,Data,print_chat); } } /*FIND*/ get_userinfo(UserName,"am_menugoback",Data,MAX_DATA_LENGTH); if (strtonum(Data) == 1){ if (Debug > 2) say("[MENU DEBUG] am_menugoback set, so staying with menu"); do_action(UserIndex); } else { if (Debug > 2) say("[MENU DEBUG] Done action so quitting menu"); UserMenu[UserIndex][0] = NO_MENU; UserPlayer[UserIndex] = 0; } return 0; } /* << Everything past here is FINE! >> */ /*Get indexes of players for menu*/ GetPlayersList(UserIndex){ new maxplayers = maxplayercount(); new isvalid[MAX_NAME_LENGTH]; /*To check if player is in game*/ new i, j = 0; for (i = 1; i <=maxplayers ; ++i){ if (playerinfo(i,isvalid,MAX_NAME_LENGTH)){ j++; snprintf(PlayerArray[j],MAX_NAME_LENGTH,"%s",isvalid); PlayerUserID[UserIndex][j] = i; } } PlayerArray[0][0]=j; return j; /*return number of players*/ } /*CS Commands like "buy" or "radio1" display new menu so reset state in this plugin*/ public reset_state(HLCommand,HLData,HLUserName,UserIndex){ UserMenu[UserIndex][0] = NO_MENU; return PLUGIN_CONTINUE; } public plugin_connect(HLUserName, HLIP, UserIndex) { if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS) { UserMenu[UserIndex][0] = NO_MENU; /*Reset menu state*/ } KillUserMenu[UserIndex] = vote_allowed(); return PLUGIN_CONTINUE; } public plugin_disconnect(HLUserName,UserIndex) { if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS) { UserMenu[UserIndex][0] = NO_MENU; /*Reset menu state*/ } return PLUGIN_CONTINUE; } public err(HLCommand,HLData,HLUserName,UserIndex){ say("Cavey's menu plugin has been disabled. Please see the readme."); return PLUGIN_CONTINUE; } public admin_menu_admin(HLCommand,HLData,HLUserName,UserIndex){ new Command[MAX_COMMAND_LENGTH]; new Data[MAX_DATA_LENGTH]; new UserName[MAX_NAME_LENGTH]; convert_string(HLUserName, UserName, MAX_NAME_LENGTH); convert_string(HLCommand,Command,MAX_COMMAND_LENGTH); convert_string(HLData,Data,MAX_DATA_LENGTH); if ( access(ACCESS_ADMINISTRATE, UserName)==0 ){ return PLUGIN_CONTINUE; /*Command hidden from those without access*/ } if ( strlen(Data) == 0 ){ /*Give general instructions*/ messageex(UserName, "Information sent to console" ,print_chat); selfmessage("-------- AdminMenu Function -------------------------------------------------------"); selfmessage(" admin_menu_admin acs_control - Who is able to access this configuration function."); selfmessage(" admin_menu_admin acs_menu - Who is able to use the admin_menu function."); selfmessage(" admin_menu_admin acs_toggle - Who is able to use menu ^"toggle^" functions."); selfmessage(" admin_menu_admin acs_exec - Who is able to use menu ^"execute^" functions."); selfmessage(" admin_menu_admin add_file - Adds a file to the menu structure."); selfmessage(" "); selfmessage(" Type in one of the strings to see details on that section"); selfmessage("-------- End AdminMenu -----------------------------------------------------------"); } else { new Section[MAX_DATA_LENGTH]; new Value[MAX_DATA_LENGTH]; strbreak(Data,Section,Value, MAX_DATA_LENGTH); new iValue = strtonum(Value); if (strcasestr(Section, "acs_control") != -1){ if ( strlen(Value) == 0 ){ /*Section instructions*/ selfmessage("-------- AdminMenu Function -- Administrator Access -------------------------------------------"); snprintf(Data, MAX_DATA_LENGTH, " admin_menu_admin acs_control <value> - %d ACCESS_CHAT",ACCESS_CHAT); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_KICK",ACCESS_KICK); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_BAN",ACCESS_BAN); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_IMMUNITY",ACCESS_IMMUNITY); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_RCON",ACCESS_RCON); selfmessage(Data); selfmessage(" "); snprintf(Data, MAX_DATA_LENGTH, " Setting currently %d - default is %d", ACCESS_ADMINISTRATE, ACCESS_RCON); selfmessage(Data); selfmessage("-------- End AdminMenu -----------------------------------------------------------"); } else if ( iValue == ACCESS_CHAT || iValue == ACCESS_KICK || iValue == ACCESS_BAN || iValue == ACCESS_IMMUNITY || iValue == ACCESS_RCON ){ set_vaultdata("MENU_ACCESS_CONTROL",Value); ACCESS_ADMINISTRATE = iValue; snprintf(Data, MAX_DATA_LENGTH, "[MENU] ^"Administrator Access^" successfully set to %s", Value); selfmessage(Data); } else { snprintf(Data, MAX_DATA_LENGTH, "[MENU] Unable to set ^"Administrator Access^" to ^"%s^"", Value); selfmessage(Data); } } else if (strcasestr(Section, "acs_menu") != -1){ if ( strlen(Value) == 0 ){ /*Section instructions*/ selfmessage("-------- AdminMenu Function -- Menu Access -------------------------------------------"); snprintf(Data, MAX_DATA_LENGTH, " admin_menu_admin acs_menu <value> - %d ACCESS_ALL",ACCESS_ALL); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_CHAT",ACCESS_CHAT); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_RESERVE_NICK",ACCESS_RESERVE_NICK); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_KICK",ACCESS_KICK); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_BAN",ACCESS_BAN); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_IMMUNITY",ACCESS_IMMUNITY); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_RCON",ACCESS_RCON); selfmessage(Data); selfmessage(" "); snprintf(Data, MAX_DATA_LENGTH, " Setting currently %d - default is %d", ACCESS_MENU, ACCESS_ALL); selfmessage(Data); selfmessage("-------- End AdminMenu -----------------------------------------------------------"); } else if ( iValue == ACCESS_CHAT || iValue == ACCESS_ALL || iValue == ACCESS_RESERVE_NICK || iValue == ACCESS_KICK || iValue == ACCESS_BAN || iValue == ACCESS_IMMUNITY || iValue == ACCESS_RCON ){ set_vaultdata("MENU_ACCESS_MENU",Value); ACCESS_MENU = iValue; snprintf(Data, MAX_DATA_LENGTH, "[MENU] ACCESS_MENU successfully set to %s", Value); selfmessage(Data); } else { snprintf(Data, MAX_DATA_LENGTH, "[MENU] Unable to set ^"ACCESS_MENU^" to ^"%s^"", Value); selfmessage(Data); } } else if (strcasestr(Section, "acs_toggle") != -1){ if ( strlen(Value) == 0 ){ /*Section instructions*/ selfmessage("-------- AdminMenu Function -- Menu Toggle Access -------------------------------------------"); snprintf(Data, MAX_DATA_LENGTH, " admin_menu_admin acs_toggle <value> - %d ACCESS_CHAT",ACCESS_CHAT); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_KICK",ACCESS_KICK); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_BAN",ACCESS_BAN); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_IMMUNITY",ACCESS_IMMUNITY); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_RCON",ACCESS_RCON); selfmessage(Data); selfmessage(" "); snprintf(Data, MAX_DATA_LENGTH, " Setting currently %d - default is %d", ACCESS_TOGGLE, ACCESS_KICK); selfmessage(Data); selfmessage("-------- End AdminMenu -----------------------------------------------------------"); } else if ( iValue == ACCESS_CHAT || iValue == ACCESS_KICK || iValue == ACCESS_BAN || iValue == ACCESS_IMMUNITY || iValue == ACCESS_RCON ){ set_vaultdata("MENU_ACCESS_TOGGLE",Value); ACCESS_TOGGLE = iValue; snprintf(Data, MAX_DATA_LENGTH, "[MENU] ACCESS_TOGGLE successfully set to ^"%s^"", Value); selfmessage(Data); } else { snprintf(Data, MAX_DATA_LENGTH, "[MENU] Unable to set ^"ACCESS_TOGGLE^" to ^"%s^"", Value); selfmessage(Data); } } else if (strcasestr(Section, "acs_exec") != -1){ if ( strlen(Value) == 0 ){ /*Section instructions*/ selfmessage("-------- AdminMenu Function -- Menu Exec Access -------------------------------------------"); snprintf(Data, MAX_DATA_LENGTH, " admin_menu_admin acs_exec <value> - %d ACCESS_CHAT",ACCESS_CHAT); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_KICK",ACCESS_KICK); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_BAN",ACCESS_BAN); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_IMMUNITY",ACCESS_IMMUNITY); selfmessage(Data); snprintf(Data, MAX_DATA_LENGTH, " - %d ACCESS_RCON",ACCESS_RCON); selfmessage(Data); selfmessage(" "); snprintf(Data, MAX_DATA_LENGTH, " Setting currently %d - default is %d", ACCESS_EXECUTE, ACCESS_RCON); selfmessage(Data); selfmessage("-------- End AdminMenu -----------------------------------------------------------"); } else if ( iValue == ACCESS_CHAT || iValue == ACCESS_KICK || iValue == ACCESS_BAN || iValue == ACCESS_IMMUNITY || iValue == ACCESS_RCON ){ set_vaultdata("MENU_ACCESS_EXECUTE",Value); ACCESS_EXECUTE = iValue; snprintf(Data, MAX_DATA_LENGTH, "[MENU] ACCESS_EXECUTE setting set to ^"%s^"", Value); selfmessage(Data); } else { snprintf(Data, MAX_DATA_LENGTH, "[MENU] Unable to set ^"ACCESS_EXECUTE^" to ^"%s^"", Value); selfmessage(Data); } } else if (strcasestr(Section, "add_file") != -1){ if ( strlen(Value) == 0 ){ /*Section instructions*/ selfmessage("-------- Menu Function -- Adding a menu -------------------------------------------"); selfmessage(" admin_menu_admin add_file <filename>"); selfmessage(" "); selfmessage(" WARNING - if the file is not formatted correctly this WILL go tits up "); selfmessage(" "); selfmessage("-------- End AdminMenu -----------------------------------------------------------"); } else if ( cavey_fileexists(Value) ){ snprintf(Data, MAX_DATA_LENGTH, "menu/%s", Value); if ( ReadCfg(Data) == 0 ){ snprintf(Data, MAX_DATA_LENGTH, "[MENU] File ^"%s^" successfully added", Value); selfmessage(Data); } else { snprintf(Data, MAX_DATA_LENGTH, "[MENU] An error occured while adding file ^"%s^"", Value); selfmessage(Data); } } else { snprintf(Data, MAX_DATA_LENGTH, "[MENU] Unable to add file ^"%s^": File Not Found", Value); selfmessage(Data); } } else { /*Error*/ } } return PLUGIN_HANDLED; }