AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   (help) What's wrong with my menu (https://forums.alliedmods.net/showthread.php?t=143935)

keyblade 11-27-2010 05:46

(help) What's wrong with my menu
 
This is my code:

Code:


#include <amxmodx>
#include <amxmisc>
#include <fun>
#define PLUGIN "weapons shop"
#define VERSION "1.0"
#define AUTHOR "Ice-Action |#KeyBlade"

public plugin_init()
{
      register_plugin(PLUGIN, VERSION, AUTHOR)
      new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2
      register_menucmd(register_menuid("choose weapons"), keys, "giveWeapon")
      register_clcmd("say /bw", "showWeaponMenu")
}

public showWeaponMenu(id)
{
    new menu[192]
    new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2
    format(menu, 191, "choose weapons^n^n1-AK47^n2-M4A1^n3-AWP^n^n^n^n^n^n^n^n0-Exit")
    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")
    }
}

I press 3 in the game but I can't get AWP.What's wrong?

I'm a script beginner.Sorry for my bad english.

ConnorMcLeod 11-27-2010 05:59

Re: (help) What's wrong with my menu
 
you forgot MENU_KEY_3 on both keys list.
Also, you have to return PLUGIN_HANDLED in menu handler.

In menu handler, use a switch statement

Code:

switch( key )
{
    case 0:give_item(id, "weapon_ak47")
    case 1:give_item(id, "weapon_XXX")
    case 2:give_item(id, "weapon_XXX")
}


Also, i think you are a bit confused :

MENU_KEY_1 represent slot1

but in handler, key : 0 represent slot 1



MENU_KEY_0 represent slot 0 (exit)
key : 9 is slot 0 (exit)

keyblade 11-27-2010 06:50

Re: (help) What's wrong with my menu
 
Thank you very much!


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

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