Raised This Month: $51 Target: $400
 12% 

Menu Save Player Choice [-HELP-]


Post New Thread Reply   
 
Thread Tools Display Modes
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 06-12-2016 , 23:28   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #21

What the problem with this code:

https://forums.alliedmods.net/showpo...3&postcount=11
zmd94 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-13-2016 , 03:39   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #22

I don't understand the code ( I mean the part with arrays and PreviousWeapons public) ...
KaLoIaN is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 06-13-2016 , 12:01   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #23

In the menu handle, you just need to get the selected item. Then, store it.

PHP Code:
public HandlePrimaryWeapons(idiMenuiItem)
{
    new 
szKey[3], iSelectedWeaponDummy;
    
    
// Gets the primary weapon selected.
    
menu_item_getinfo(iMenuiItemDummyszKey2""0Dummy); 
    
    
iSelectedWeapon str_to_num(szKey);
    
    
// Stores the selected weapon for option 2 and 3 on the main menu
    
g_ipPreviousWeapons[id] = iSelectedWeapon
    
    new 
WeaponName[32], szArrayData[32];
    
    
// Gets the weapon name from the array
    
ArrayGetString(g_PrimaryWeaponsiSelectedWeaponszArrayDatacharsmax(szArrayData)); 
    
    
// Removes the spaces
    
replace_all(szArrayDatacharsmax(szArrayData), " """); 
    
    
// Adds weapon_ to the weapon name
    
format(WeaponNamecharsmax(WeaponName), "weapon_%s"szArrayData);
    
    
// Converts all to lower case
    
strtolower(WeaponName);
    
    
// Gives primary weapon
    
GiveWeapons(idWeaponName); 
    
    
menu_display(idg_sWeaponMenu); //Displays secondary weapons menu
}

public 
HandleSecondaryWeapons(idiMenuiItem)
{
    new 
szKey[3], iSelectedWeaponDummy;
    
    
// Gets the secondary weapon selected
    
menu_item_getinfo(iMenuiItemDummyszKey2""0Dummy); 
    
    
iSelectedWeapon str_to_num(szKey);
    
    
//Stores the selected weapon for option 2 and 3 on the main menu
    
g_isPreviousWeapons[id] = iSelectedWeapon
    
    new 
WeaponName[32], szArrayData[32];
    
    
// Gets the weapon name from the array
    
ArrayGetString(g_SecondaryWeaponsiSelectedWeaponszArrayDatacharsmax(szArrayData)); 
    
    
// Removes the spaces
    
replace_all(szArrayDatacharsmax(szArrayData), " """); 
    
    
// Adds weapon_ to the weapon name
    
format(WeaponNamecharsmax(WeaponName), "weapon_%s"szArrayData); 
    
    
// Converts all to lower case
    
strtolower(WeaponName);
    
    
// Gives secondary weapon
    
GiveWeapons(idWeaponName); 

zmd94 is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 06-13-2016 , 13:01   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #24

Also you can simple give item by getting item name:

new szData[2], szName[20];
new _access, item_callback;
//heres the function that will give us that information ( since it doesnt magicaly appear )
menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );

strtolower(szName);

format(szName, charsmax(szName), "weapon_%s", szName)

give_item(id, szName)
siriusmd99 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-14-2016 , 14:25   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #25

Quote:
Originally Posted by siriusmd99 View Post
Also you can simple give item by getting item name:

new szData[2], szName[20];
new _access, item_callback;
//heres the function that will give us that information ( since it doesnt magicaly appear )
menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );

strtolower(szName);

format(szName, charsmax(szName), "weapon_%s", szName)

give_item(id, szName)

I don't understood you both.. you and zmd94..!?
Can you show me it on a simple menu + handler ?
KaLoIaN is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 06-15-2016 , 01:12   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #26

Example:
PHP Code:
#include <amxmodx>
#include <fun>

enum _:SECONDARYWEAPON
{
    
WeaponName[64],
    
WeaponID[64]
}

new const 
SecondaryData[][SECONDARYWEAPON] =
{
    {
"9x19mm Side-arm""weapon_glock18"}, 
    {
"KM.45 Tactical""weapon_usp"}, 
    {
"228 Compact""weapon_p228"},
    {
"Night Haw2.50c""weapon_deagle"}
}

// Variables
new g_PreviousSecondary[33]
new 
g_WeaponMenu

public plugin_init() 
{
    
// Command to open menu
    
register_clcmd("say /ww""WeaponMenu")
    
register_clcmd("say_team /ww""WeaponMenu")
    
    
// Create global weapon menu
    
g_WeaponMenu menu_create("\ySecondary Weapons Menu""secondary_handler")
    
    new 
szItem[64]
    for(new 
isizeof(SecondaryData); i++)
    {
        
formatex(szItemcharsmax(szItem), "%s"SecondaryData[i][WeaponName])
        
menu_additem(g_WeaponMenuszItem)
    }
}

public 
WeaponMenu(id)
{
    if(
is_user_alive(id))
    {
        
menu_display(idg_WeaponMenu0)
    }
}

public 
secondary_handler(idmenuiditem)
{
    if(
is_user_alive(id))
    {
        if(
item == MENU_EXIT)
        {
            return 
PLUGIN_HANDLED
        
}
        
        
// Save secondary weapon ID for future use
        
g_PreviousSecondary[id] = WeaponsData[item][WeaponID]
        
        
menu_cancel(id)
        
        
// Player recieve weapon
        
give_item(idg_PreviousSecondary[id])
    }
    
    return 
PLUGIN_HANDLED


Last edited by zmd94; 06-15-2016 at 06:45.
zmd94 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-15-2016 , 08:43   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #27

Quote:
Originally Posted by zmd94 View Post
Example:
PHP Code:
#include <amxmodx>
#include <fun>

enum _:SECONDARYWEAPON
{
    
WeaponName[64],
    
WeaponID[64]
}

new const 
SecondaryData[][SECONDARYWEAPON] =
{
    {
"9x19mm Side-arm""weapon_glock18"}, 
    {
"KM.45 Tactical""weapon_usp"}, 
    {
"228 Compact""weapon_p228"},
    {
"Night Haw2.50c""weapon_deagle"}
}

// Variables
new g_PreviousSecondary[33]
new 
g_WeaponMenu

public plugin_init() 
{
    
// Command to open menu
    
register_clcmd("say /ww""WeaponMenu")
    
register_clcmd("say_team /ww""WeaponMenu")
    
    
// Create global weapon menu
    
g_WeaponMenu menu_create("\ySecondary Weapons Menu""secondary_handler")
    
    new 
szItem[64]
    for(new 
isizeof(SecondaryData); i++)
    {
        
formatex(szItemcharsmax(szItem), "%s"SecondaryData[i][WeaponName])
        
menu_additem(g_WeaponMenuszItem)
    }
}

public 
WeaponMenu(id)
{
    if(
is_user_alive(id))
    {
        
menu_display(idg_WeaponMenu0)
    }
}

public 
secondary_handler(idmenuiditem)
{
    if(
is_user_alive(id))
    {
        if(
item == MENU_EXIT)
        {
            return 
PLUGIN_HANDLED
        
}
        
        
// Save secondary weapon ID for future use
        
g_PreviousSecondary[id] = WeaponsData[item][WeaponID]
        
        
menu_cancel(id)
        
        
// Player recieve weapon
        
give_item(idg_PreviousSecondary[id])
    }
    
    return 
PLUGIN_HANDLED

Thank you!
But there is something :
I've got undefined symbol here:

Code:
g_PreviousSecondary[id] = WeaponsData[item][WeaponID]
WeaponsData .. Where is declared ?
KaLoIaN is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 06-15-2016 , 10:14   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #28

My mistake. Just change below:
Code:
g_PreviousSecondary[id] = WeaponsData[item][WeaponID]
-->
Code:
g_PreviousSecondary[id] = SecondaryData[item][WeaponID]
zmd94 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-15-2016 , 14:29   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #29

Code:
public ShowSecondaryGunsMenu(id)
{
    if(is_user_alive(id))
    {
        menu_display(id, g_WeaponMenu, 0)
    }
}

public secondary_handler(id, menuid, item)
{
    if(is_user_alive(id))
    {
        if(item == MENU_EXIT)
        {
            return PLUGIN_HANDLED
        }
        g_PreviousSecondary[id] = SecondaryData[item][WeaponID]
        
        menu_cancel(id)
        give_item(id, g_PreviousSecondary[id])
    }
    
    return PLUGIN_HANDLED
}
When I select something from the menu it just does not gives it to me ...

Code:
new const SecondaryData[][SECONDARYWEAPON] =
{
    {"\yGlock", "weapon_glock18"}, 
    {"\yUsp", "weapon_usp"}, 
    {"\yDeagle", "weapon_deagle"}
}

Ahhh sorry I think I got your idea.. I must use this example to retrieve the last choice from the menu, allright. But how I am supposed to give the secondary weapons ?

Code:
 give_item(id, SecondaryData[id])
?

Last edited by KaLoIaN; 06-15-2016 at 14:33.
KaLoIaN is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 06-15-2016 , 19:17   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #30

Just try below:
Code:
public secondary_handler(id, menuid, item)
{
    if(is_user_alive(id))
    {
        if(item == MENU_EXIT)
        {
            return PLUGIN_HANDLED
        }
        g_PreviousSecondary[id] = SecondaryData[item][WeaponID]
        
        menu_cancel(id)
        give_item(id, g_PreviousSecondary[id])
    }
    
    return PLUGIN_HANDLED
}
-->
Code:
public secondary_handler(id, menuid, item)
{
    if(is_user_alive(id))
    {
        if(item == MENU_EXIT)
        {
            return PLUGIN_HANDLED
        }
        
        new sWeaponID[32]
        copy(sWeaponID, charsmax(sWeaponID), SecondaryData[item][WeaponID])
        g_PreviousSecondary[id] = sWeaponID
        
        menu_cancel(id)
        
        give_item(id, sWeaponID)
    }
    
    return PLUGIN_HANDLED
}
zmd94 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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