AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu doesent shows up. (https://forums.alliedmods.net/showthread.php?t=215656)

Menethil 05-10-2013 17:58

Menu doesent shows up.
 
I Have a dilema.

I've tryed to make this weapons menu but at some point something went wrong.

Once I started adding things, menues arent showing when choosing from General menu.

It's shows only one time at spawn and that's it. If I select primary/secondary etc, nothing happens, so I tryed to remake it from 0. Same thing, I face this problem, maybe someone spot it better, any idea?
PHP Code:

#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>


#define fm_get_user_team(%1)    get_pdata_int(%1,114)

new PRIMARY_WEAPON_BIT[33];
new 
SECONDARY_WEAPON_BIT[33];
new 
GRENADE_WEAPON_BIT[33];


new 
g_Weapons_Menues[][]=
{
    
"Primary Weapons Menu",
    
"Secondary Weapons Menu",
    
"Grenades Menu",
    
"Remember Selection and Exit"
};

new 
g_Primary_Weapons[][] = 
{
    
"AK-47",
    
"M4A1",
    
"AWP"
};

new 
g_Secondary_Weapons[][] =
{
    
"Deagle",
    
"USP",
    
"Glock"
};

new 
g_Grenades[][] =
{
    
"HE Grenade",
    
"Flashbang",
    
"All Grenades"
};

const 
PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90);
const 
SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE);

new 
g_RememberSelection[33];


public 
plugin_init(){
    
register_plugin("[PvP] Weapons Menu""1.1""NeuTroN");
    
    
RegisterHam(Ham_Spawn"player""forward_Player_Spawned", .Post=true);
    
    
register_clcmd("say /guns""show_Weapons_Menu");
    
}

public 
client_connect(id){
    
g_RememberSelection[id] = false;
    
    
PRIMARY_WEAPON_BIT[id] = 0;
    
SECONDARY_WEAPON_BIT[id] = 0;
    
GRENADE_WEAPON_BIT[id] = 0;
}

public 
forward_Player_Spawned(id){

    if(
is_user_bot(id))
    return;
    
    if(!
is_user_alive(id))
    return;
    
    if(
fm_get_user_team(id) != 2)
    return;
    
    
    if(
g_RememberSelection[id]){
        switch(
PRIMARY_WEAPON_BIT[id]){
            case 
1:{
                
fm_give_item(id"weapon_ak47");
            }
            case 
2:{
                
fm_give_item(id"weapon_m4a1");
            }
            case 
3:{
                
fm_give_item(id"weapon_awp");
            }
        }
        
        switch(
SECONDARY_WEAPON_BIT[id]){
            case 
1:{
                
fm_give_item(id"weapon_deagle");
            }
            case 
2:{
                
fm_give_item(id"weapon_usp");    
            }
            case 
3:{
                
fm_give_item(id"weapon_glock");
            }
        }
        
        switch(
GRENADE_WEAPON_BIT[id]){
            case 
1:{
                
fm_give_item(id"weapon_hegrenade");
            }
            case 
2:{
                
fm_give_item(id"weapon_flashbang");
                
fm_give_item(id"weapon_flashbang");
            }
            case 
3:{
                
fm_give_item(id"weapon_hegrenade");
                
fm_give_item(id"weapon_flashbang");
                
fm_give_item(id"weapon_flashbang");
            }
        }
        
    }
    else {
        
set_task(0.2"show_Weapons_Menu"id);
    }
}

public 
show_Weapons_Menu(id){
    new 
szText[100];
    
    
formatex(szText,99"\yWeapons General Menu"); 
    new 
menu menu_create(szText"Menu_Handler");
    
    new 
ItemName[64];
    for(new 
ii<sizeof(g_Weapons_Menues); i++)
    {

        
formatex(ItemNamecharsmax(ItemName), "%s"g_Weapons_Menues[i]);
    
        
menu_additem(menuItemName);
    }

    
menu_setprop(menuMPROP_NUMBER_COLOR"\y");
    
    
menu_display(idmenu0);
    
    return 
PLUGIN_HANDLED;
}

public 
Menu_Handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {    
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    
    new 
data], iName64 ], accesscallback;
    
menu_item_getinfomenuitemaccessdatacharsmaxdata ), iNamecharsmaxiName ), callback );

    new 
key str_to_numdata );
    
    switch(
key)
    {
        case 
1:{
        
show_Primary_Weapons_Menu(id);
        }
        case 
2:{ 
        
show_Secondary_Weapons_Menu(id);
        }
        case 
3:{
        
show_Grenade_Weapons_Menu(id);
        }
        case 
4:{
        
save_selection(id);
        }
    }
    
    return 
PLUGIN_HANDLED;
}

public 
show_Primary_Weapons_Menu(id){
    new 
szText[100];
    
    
formatex(szText,99"\yPrimary Weapons Menu"); 
    new 
menu menu_create(szText"Primary_Weapons_Menu_Handler"); 
    
    new 
ItemName[64];
    for(new 
ii<sizeof(g_Primary_Weapons); i++)
    {

        
formatex(ItemNamecharsmax(ItemName), "%s"g_Primary_Weapons]);
    
        
menu_additem(menuItemName);
    }

    
menu_setprop(menuMPROP_NUMBER_COLOR"\y");
    
    
menu_display(idmenu0);
    
    return 
PLUGIN_HANDLED;
}

public 
Primary_Weapons_Menu_Handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {    
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data], iName64 ], accesscallback;
    
menu_item_getinfomenuitemaccessdatacharsmaxdata ), iNamecharsmaxiName ), callback );

    new 
key str_to_numdata );
    
    switch(
key)
    {
        case 
1:{
        
drop_weapons(id1);
        
fm_give_item(id"weapon_ak47");
        
PRIMARY_WEAPON_BIT[id] = 1;
        
show_Secondary_Weapons_Menu(id);
        }
        case 
2:{
        
drop_weapons(id1);
        
fm_give_item(id"weapon_m4a1");
        
PRIMARY_WEAPON_BIT[id] = 2;
        
show_Secondary_Weapons_Menu(id);
        }
        case 
3:{
        
drop_weapons(id1);
        
fm_give_item(id"weapon_awp");
        
PRIMARY_WEAPON_BIT[id] = 3;
        
show_Secondary_Weapons_Menu(id);
        }
    }
    
    return 
PLUGIN_HANDLED;
}

public 
show_Secondary_Weapons_Menu(id){
    new 
szText[100];
    
    
formatex(szText,99"\ySecondary Weapons Menu"); 
    new 
menu menu_create(szText"Secondary_Weapons_Menu_Handler"); 
    
    new 
ItemName[64];
    for(new 
ii<sizeof(g_Secondary_Weapons); i++)
    {

        
formatex(ItemNamecharsmax(ItemName), "%s"g_Secondary_Weapons]);
    
        
menu_additem(menuItemName);
    }

    
menu_setprop(menuMPROP_NUMBER_COLOR"\y");
    
    
menu_display(idmenu0);
    
    return 
PLUGIN_HANDLED;
}

public 
Secondary_Weapons_Menu_Handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {    
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data], iName64 ], accesscallback;
    
menu_item_getinfomenuitemaccessdatacharsmaxdata ), iNamecharsmaxiName ), callback );

    new 
key str_to_numdata );
    
    switch(
key)
    {
        case 
1:{
        
drop_weapons(id2);
        
fm_give_item(id"weapon_deagle");
        
SECONDARY_WEAPON_BIT[id] = 1;
        
show_Grenade_Weapons_Menu(id);
        }
        case 
2:{
        
drop_weapons(id2);
        
fm_give_item(id"weapon_usp");
        
SECONDARY_WEAPON_BIT[id] = 2;
        
show_Grenade_Weapons_Menu(id);
        }
        case 
3:{
        
drop_weapons(id2);
        
fm_give_item(id"weapon_glock");
        
SECONDARY_WEAPON_BIT[id] = 3;
        
show_Grenade_Weapons_Menu(id);
        }
    }
    
    return 
PLUGIN_HANDLED;
}

public 
show_Grenade_Weapons_Menu(id){
    new 
szText[100];
    
    
formatex(szText,99"\yGrenade Weapons Menu"); 
    new 
menu menu_create(szText"Grenade_Weapons_Menu_Handler") ;
    
    new 
ItemName[64];
    for(new 
ii<sizeof(g_Grenades); i++)
    {

        
formatex(ItemNamecharsmax(ItemName), "%s"g_Grenades]);
    
        
menu_additem(menuItemName);
    }

    
menu_setprop(menuMPROP_NUMBER_COLOR"\y");
    
    
menu_display(idmenu0);
    
    return 
PLUGIN_HANDLED;
}

public 
Grenade_Weapons_Menu_Handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {    
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }

    
    new 
data], iName64 ], accesscallback;
    
menu_item_getinfomenuitemaccessdatacharsmaxdata ), iNamecharsmaxiName ), callback );

    new 
key str_to_numdata );
    
    switch(
key)
    {
        case 
1:{
        
fm_give_item(id"weapon_hegrenade");
        
GRENADE_WEAPON_BIT[id] = 1;
        }
        case 
2:{
        
fm_give_item(id"weapon_flashbang");
        
fm_give_item(id"weapon_flashbang");
        
GRENADE_WEAPON_BIT[id] = 2;
        }
        case 
3:{
        
fm_give_item(id"weapon_hegrenade");
        
fm_give_item(id"weapon_flashbang");
        
fm_give_item(id"weapon_flashbang");
        
GRENADE_WEAPON_BIT[id] = 3;
        }

    }
    
    return 
PLUGIN_HANDLED;
}

public 
save_selection(id){
    
g_RememberSelection[id] = true;
}
                
        
stock drop_weapons(iddropwhat)
{
    static 
weapons[32], numiweaponid;
    
num 0// reset passed weapons count (bugfix)
    
get_user_weapons(idweaponsnum);
    
    for (
0numi++)
    {
        
// Prevent re-indexing the array
        
weaponid weapons[i];
        
        if ((
dropwhat == && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM)))
        {
            static 
wname[32];
            
get_weaponname(weaponidwnamecharsmax(wname));
          
            
engclient_cmd(id"drop"wname);

        }
    }
}

stock fm_give_item(id, const item[])
{
    static 
ent;
    
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocStringitem));
    if (!
pev_valid(ent)) return;
    
    static 
Float:originF[3];
    
pev(idpev_originoriginF);
    
set_pev(entpev_originoriginF);
    
set_pev(entpev_spawnflagspev(entpev_spawnflags) | SF_NORESPAWN);
    
dllfunc(DLLFunc_Spawnent);
    
    static 
save;
    
save pev(entpev_solid);
    
dllfunc(DLLFunc_Touchentid);
    if (
pev(entpev_solid) != save)
        return;
    
    
engfunc(EngFunc_RemoveEntityent);



Blizzard_87 05-10-2013 18:23

Re: Menu doesent shows up.
 
Code:
public show_Weapons_Menu(id){     new szText[100];         formatex(szText,99, "\yWeapons General Menu");     new menu = menu_create(szText, "Menu_Handler");         new ItemName[64];     for(new i; i<sizeof(g_Weapons_Menues); i++)     {         formatex(ItemName, charsmax(ItemName), "%s", g_Weapons_Menues[i]);             menu_additem(menu, ItemName);     }     menu_setprop(menu, MPROP_NUMBER_COLOR, "\y");         menu_display(id, menu, 0);         return PLUGIN_HANDLED; }

why do you format the menuitem names again... they are already strings also change this
Code:
new g_Weapons_Menues[][]=
to a const
Code:
new const g_Weapons_Menues[][]=

now when you add items into menu_additem

you can just directly add from the const.

Code:
public show_Weapons_Menu(id){     new szText[100];         formatex(szText,99, "\yWeapons General Menu");     new menu = menu_create(szText, "Menu_Handler");         for( new i; i < sizeof( g_Weapons_Menues ); i++)     {             menu_additem(menu, g_Weapons_Menues [ i ]);     }     menu_setprop(menu, MPROP_NUMBER_COLOR, "\y");         menu_display(id, menu, 0);         return PLUGIN_HANDLED; }

do the same for all others.

EDIT:

not sure but you should prolly change way menu shows...

show primary menu first then once selected then it opens up the secondary then after that the nades...

Menethil 05-10-2013 18:34

Re: Menu doesent shows up.
 
formating the text was just to give a little color to the menu, here is a simple way w/o color, but this is not the problem.

Also the 'const' isnt a problem.

The fun fact is, it worked when I tested first time, then I added/modifyed something and now menues are not popping up, dunno why, I went letter by letter, and still can't find the problem

Edit:
Yes I did ( getting infos from dozens of plugins from alliedmodders)

Blizzard_87 05-10-2013 18:37

Re: Menu doesent shows up.
 
Quote:

Originally Posted by Menethil (Post 1949594)
formating the text was just to give a little color to the menu, here is a simple way w/o color, but this is not the problem.

Also the 'const' isnt a problem.

The fun fact is, it worked when I tested first time, then I added/modifyed something and now menues are not popping up, dunno why, I went letter by letter, and still can't find the problem

so you did write this plugin originally ?

Emp` 05-10-2013 20:10

Re: Menu doesent shows up.
 
The problem is that you are not detecting the items in the handler function. Either switch with which item was pressed or add data with the item for which one is pressed.

Blizzard_87 05-10-2013 20:29

Re: Menu doesent shows up.
 
1 Attachment(s)
I made up a weapons menu my style that uses same weapons that you have in your menu...

Menethil 05-11-2013 09:37

Re: Menu doesent shows up.
 
@Blizzard_87, wasnt really a request, but ty for helping.( I really apreciate, I'll use some from u)

I took a look at csdm and zombieplague mods, and I solved it in my "old" way, without declaring the itmes intro array of strings, just directly adding items with menu_additem

Blizzard_87 05-11-2013 10:07

Re: Menu doesent shows up.
 
Quote:

Originally Posted by Menethil (Post 1949907)
@Blizzard_87, wasnt really a request, but ty for helping.( I really apreciate, I'll use some from u)

I took a look at csdm and zombieplague mods, and I solved it in my "old" way, without declaring the itmes intro array of strings, just directly adding items with menu_additem

no worries

Lolz0r 08-17-2014 08:44

Re: Menu doesent shows up.
 
Hey Blizzard, can you add some features to weapon menu :

- remove BuyZone, Money, Round Timer and C4
- added one He Grenade after every spawn, and +1 He Grenade after every headshot kill
- added "refill weapon on kill"
- block drop command

Thanks. :)

skz 08-17-2014 09:05

Re: Menu doesent shows up.
 
Why don't you search? There're a lot of plugins who have that functions


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

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