AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   My WeaponMenu Doesn't work (https://forums.alliedmods.net/showthread.php?t=11453)

NiGHTFiRE 03-20-2005 01:30

My WeaponMenu Doesn't work
 
My weapon menu doesn't work. I get six errors with this: What did I do wrong?

Code:
#include <amxmodx> #include <amxmisc> #include <fun> public plugin_init() {   register_plugin("Weapon Menu", "0.10", "NiGHTFiRE")   new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2| MENU_KEY_3   register_menucmd(register_menuid("Which Weapon?"), keys, "giveWeapon")   register_clcmd("giveme", "showWeaponmenu")   public showWeaponMenu(id) {      new menu[192]      new keys = MENU_KEY_0 |MENU_KEY_1 |MENU_KEY_2|MENU_KEY_3            format(menu, 191, "Which Weapon?^n^n1. AK47^n2. M4A1^n3. AWP^n4. Deagle")      show_menu(id, keys, menu)      return PLUGIN_HANDLED } public giveWeapon(id, key) {     if (key == 0)     {         give_item(id, "weapon_ak47")       } else if  (key == 1) {        give_item(id, "weapon_m4a1")       } else if (key == 2) {         give_item(id, "weapon_awp")       } else if (key == 3) {        give_item(id, "weapon_deagle"         } }

Please give me examples with code so I can learn.
Thanks

v3x 03-20-2005 01:42

Umm, try this:
Code:
#include <amxmodx> #include <amxmisc> #include <fun> public plugin_init() {   register_plugin("Weapon Menu", "0.10", "NiGHTFiRE")   register_menucmd(register_menuid("\yWhich Weapon?"), 1023, "giveWeapon")   register_clcmd("giveme","showWeaponMenu", ADMIN_SLAY, "Shows the menu for giving weapons")   register_clcmd("say /giveme","showWeaponMenu", ADMIN_SLAY, "Shows the menu for giving weapons")   return PLUGIN_CONTINUE } public showWeaponMenu(id) {     new szMenuBody[256]     new keys     new len = format(szMenuBody, 255, "\yWhich weapon?:^n")     len += format(szMenuBody[len], 255-len, "^n\w1. AK-47")     len += format(szMenuBody[len], 255-len, "^n\w2. M4A1")     len += format(szMenuBody[len], 255-len, "^n\w3. AWP")     len += format(szMenuBody[len], 255-len, "^n\w4. Deagle")     len += format(szMenuBody[len], 255-len, "^n^n\w0. Exit")     keys = (1<<0|1<<1|1<<2|1<<3|1<<9)         show_menu(id, keys, szMenuBody, -1)     return PLUGIN_CONTINUE } public giveWeapon(id, key) {     switch(key) {         case 0:         {             give_item(id, "weapon_ak47")         }         case 1: {             give_item(id, "weapon_m4a1")         }         case 2: {             give_item(id, "weapon_awp")         }         case 3: {             give_item(id, "weapon_deagle")         }     }     return PLUGIN_HANDLED }

Also, I changed all of those else if's into one simple switch statement.

*Edited (x2)*

NiGHTFiRE 03-20-2005 02:07

Thanks i will test it, but what does this do?

Code:
len += format(szMenuBody[len], 255-len new len = format(szMenuBody, 255
How can you know like what numbers you should have? Like you typed:
Code:
register_menucmd(register_menuid("Which Weapon?"), 1023, "giveWeapon")
But why did you take 1023 and this with 255-len and the new szmenubody[256]?
Thanks

edit: Where did you learn where to script? If you know any good website(I have read the documents on this website) that I could learn I would be very thankfull!

v3x 03-20-2005 02:12

Take a look @ this thread:
http://forums.alliedmods.net/showthread.php?t=9736
It will help clear up a few things.

Also, I might have messed up on my keys or something, since I'm pretty new to menus. :oops:

Where did I learn?
1. Already had some prior coding knowledge (PHP).
2. Posting questions here.
3. A friend helps me out when I'm stuck.

Edit: Yes, I did mess up on my keys (try the new one). But I'm not to sure as to why it's not giving the weapon.


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

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