| soccdoodcss |
12-03-2006 17:19 |
How To: Create Menus, from MenuMod1.2b
1 Attachment(s)
I have made a menu tutorial, i took it out of my MenuMod
This is a snippet of the code, for the full code + tutorial download my attatched .sma
Hope this helps!
Good luck to all you coders out there.:up:
PHP Code:
// Tell the plugin what modules to use #include <amxmodx> #include <cstrike> #include <fun>
// Self Explanitory #define PLUGIN "MenuMod" #define VERSION "1.2b" #define AUTHOR "Bent"
/* CVARS "menu_enable" 1 (menus on), 2 (menus off)
REQUIRES ADMIN_LEVEL_A
SAY COMMANDS /menu (general menu) /grav (self-gravity) /heal (self-health) /slap (self-slap?? do you hate yourself??) /money (self-money) / **NEW/armor (self-armor) / **NEW/speed (self-speed) / **NEW/noclip (self-noclip)
MODULES <amxmodx> <amxmisc> <cstrike> <fun> */
//Assigns specific keys for the menus ( 1, 2, 3, 4, 5, 6, 7, 8, 9 ) new keys = MENU_KEY_0 | MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_4 | MENU_KEY_5 | MENU_KEY_6 | MENU_KEY_7 | MENU_KEY_8 | MENU_KEY_9
//Creates the global variable new g_Switch;
public plugin_init() { //Info on Plugin (Name, Version, Author) register_plugin("Menu Commands", "1.2b", "Bent/soccdoodcss") //Make the global variable "g_Switch" a cvar ("console command", "default setting(1)") g_Switch = register_cvar("menu_enable", "1") //Creates the menu id("name"), keys, "function") register_menucmd(register_menuid("BentMenu"), 1023, "PressedBentMenu") register_menucmd(register_menuid("GravMenu"), 1023, "PressedGravMenu") register_menucmd(register_menuid("HealMenu"), 1023, "PressedHealMenu") register_menucmd(register_menuid("SlapMenu"), 1023, "PressedSlapMenu") register_menucmd(register_menuid("MoneyMenu"), 1023, "PressedMoneyMenu") register_menucmd(register_menuid("ArmorMenu"), 1023, "PressedArmorMenu") register_menucmd(register_menuid("SpeedMenu"), 1023, "PressedSpeedMenu") register_menucmd(register_menuid("NoclipMenu"), 1023, "PressedNoclipMenu") //Registers the console command("console command", "Function", admin flags, "info") register_clcmd("show_menu","ShowBentMenu",ADMIN_LEVEL_A,"-displays Bent's menu") register_clcmd("say /menu","ShowBentMenu",ADMIN_LEVEL_A,"-displays Bent's menu") register_clcmd("grav_menu","ShowGravMenu",ADMIN_LEVEL_A,"-displays Grav menu") register_clcmd("say /grav","ShowGravMenu",ADMIN_LEVEL_A,"-displays Grav menu") register_clcmd("heal_menu","ShowHealMenu",ADMIN_LEVEL_A,"-displays Heal menu") register_clcmd("say /heal","ShowHealMenu",ADMIN_LEVEL_A,"-displays Heal menu") register_clcmd("slap_menu","ShowSlapMenu",ADMIN_LEVEL_A,"-displays Slap menu") register_clcmd("say /slap","ShowSlapMenu",ADMIN_LEVEL_A,"-displays Slap menu") register_clcmd("money_menu","ShowMoneyMenu",ADMIN_LEVEL_A,"-displays Money menu") register_clcmd("say /money","ShowMoneyMenu",ADMIN_LEVEL_A,"-displays Money menu") register_clcmd("armor_menu","ShowArmorMenu",ADMIN_LEVEL_A,"-displays Armor menu") register_clcmd("say /armor","ShowArmorMenu",ADMIN_LEVEL_A,"-displays Armor menu") register_clcmd("speed_menu","ShowSpeedMenu",ADMIN_LEVEL_A,"-displays Speed menu") register_clcmd("say /speed","ShowSpeedMenu",ADMIN_LEVEL_A,"-displays Speed menu") register_clcmd("noclip_menu","ShowNoclipMenu",ADMIN_LEVEL_A,"-displays Noclip menu") register_clcmd("say /noclip","ShowNoclipMenu",ADMIN_LEVEL_A,"-displays Noclip menu") } //Function (uses id parameter) //id = the player that used the function public ShowBentMenu(id) { //Checks the g_switch cvar //if 0, it backs out of the function if(get_pcvar_num(g_Switch)==0) { return PLUGIN_HANDLED; }else{ //if something else, show the menu(user, keys(we made "new keys" earlier), //what the menu displays "\w" means make the menu white //"^n" prints text on the next line show_menu(id, keys, "\wKyle Menu^n1.Health + 250^n2.Money + 1000^n3.Armor + 100^n4.Speed 900^n5.Slap Self To 1 Health^n6.Slap Self 5 Damage^n7.Change Gravity To 400^n8.Reset^n9.Exit", -1, "BentMenu") // Display menu } //backs out of function return PLUGIN_HANDLED; }
//Function public PressedBentMenu(id, key) { //new constant (name = command(user)) //get_user_health(id) finds the users health new Health = get_user_health(id); //begins the menu (uses keys) switch (key) { //The commands //case 0 = 1 on the keyboard //case 1 = 2 on the keyboard, etc. //set_user health(user, health(remember the get user health that we assigned to the //health constant?) Amount) case 0: set_user_health(id, Health +250) case 1: cs_set_user_money(id, cs_get_user_money(id) +1000) case 2: set_user_armor(id, get_user_armor(id) +100) case 3: set_user_maxspeed(id,900.0) case 4: set_user_health(id,1) case 5: set_user_health(id, Health -5) case 6: set_user_gravity(id,0.5) //You can also do multiple commands per case like seen here on the reset key case 7:{ set_user_armor(id,0) set_user_maxspeed(id,5.0) cs_set_user_money(id,800) set_user_health(id,100) return PLUGIN_HANDLED } case 8: return PLUGIN_HANDLED; } return PLUGIN_HANDLED } public ShowGravMenu(id) { if(get_pcvar_num(g_Switch)==1) { show_menu(id, keys, "\rGravity Menu^n1 Gavity 800^n2 Gravity 600^n3 Gravity 400^n4 Gravity 200^n5 Gravity 0^n6 Exit^n", -1, "GravMenu") // Display menu } return PLUGIN_HANDLED; }
//an easier way to set the cases is to assign a Float //After each comma represent a new case new const Float:gravity[5] = {1.0, 0.75, 0.5, 0.25, 0.00001}
public PressedGravMenu(id, key) { //if the key pressed is between case 0 and 4 if(0 <= key <= 4) //then assign the specified gravity(the Float constant) set_user_gravity(id, gravity[key]) //back out of the plugin return PLUGIN_HANDLED } //The rest of this plugin is repetative //End of Tutorial
-Bent/Soccdoodcss:up:
|