Raised This Month: $ Target: $400
 0% 

Menu Save Player Choice [-HELP-]


Post New Thread Reply   
 
Thread Tools Display Modes
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-21-2016 , 07:21   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #41

Quote:
Originally Posted by zmd94 View Post
Firstly, you need to this code before public plugin_init() part:
Code:
native give_brickpeace(id)
Then, just do as below:
PHP Code:
new const PrimaryData[][PRIMARYWEAPON] =
{
    {
"\yAK47""weapon_ak47"}, 
    {
"\yM4A1""weapon_m4a1"}, 
    {
"\yAWP""weapon_awp"},
    
// Just use first array as second array is no use because we are using custom native
    
{"\yBricks"""}

Then, we need to add different check at the primary_handler:
PHP Code:
public primary_handler(idmenuiditem)
{
    if(
is_user_alive(id))
    {
        if(
item == MENU_EXIT)
        {
            return 
PLUGIN_HANDLED
        
}
        
        
// Check for equal name to use custom native
        
if (equali(PrimaryData[item][WeaponName], "Bricks")
        {
            
// As we are using custom native, we need to change how we save the primary weapon for future use
            // Save primary weapon name for future use
            
copy(g_PreviousPrimary[id], charsmax(g_PreviousPrimary), PrimaryData[item][WeaponName])
        
            
// Use custom native to give the weapon
            
give_brickpeace(id)
        }
        else
        {
            
// Save primary weapon ID for future use
            
copy(g_PreviousPrimary[id], charsmax(g_PreviousPrimary), PrimaryData[item][WeaponID])
        
            
menu_cancel(id)
        
            
// Player recieve weapon
            
give_item(idg_PreviousPrimary[id])
        }
    }
    
    return 
PLUGIN_HANDLED

Next, we need to edit the main_handler:
PHP Code:
public main_handler(idmenuitem)
{
    if(
item == MENU_EXIT
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    switch(
item)
    {
        
// Player need new weapon
        
case 0:
        {
            
// Open primary weapon menu
            
PrimayMenu(id)
        }
        
// Player use previous weapon
        
case 1:
        {
            
// Add new check for primary weapon
            // Check for equal name to use custom native
            
if (equali(g_PreviousPrimary[id], "Bricks")
            {
                
// Use custom native to give the weapon
                
give_brickpeace(id)
            }
            
// This is not custom weapon
            
else
            {
                
// Give weapon
                
give_item(idg_PreviousPrimary[id])
            }
            
            
// If you do not use custom native for secondary weapon, just use as below
            // to give weapon
            
give_item(idg_PreviousSecondary[id])
        }
    }
    
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED

Thats it.
I will try a this a little bit later and post feedback.
There is another bug with the weapons saving.
It does save them when I am alone in the server but when there is another player it does not save them somehow? Any ideas?

I wrote something like a debug in the case see:

Code:
        case 1:         {             give_item(id, g_PreviousPrimary[id])             give_item(id, g_PreviousSecondary[id])             ColorChat(id, NORMAL, "%s", g_PreviousSecondary[id])             ColorChat(id, NORMAL, "%s", g_PreviousPrimary[id])                 }

What does the vars return?
Something like a shit lol..

Code:
wweapon_glock18
wweapon_ak47
I think that's why can't give the items.. but why it happens so?

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

Just show your full code.
zmd94 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-22-2016 , 07:37   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #43

Quote:
Originally Posted by zmd94 View Post
Just show your full code.
The full code is about 3 hundred lines.
I will give the part needed:

The part where you choose to get new guns or old

Code:
public ShowMainGunsMenu(id) {     if(!is_user_alive(id)) return PLUGIN_HANDLED         new menu = menu_create("\rChoose Your Guns", "MainGunsMenu_Handler");     menu_additem(menu, "\yNew Guns", "", 0)     menu_additem(menu, "\yPrevious Guns", "", 0)     menu_additem(menu, "\yPrevious \d& \ySave", "", 0)     menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)     menu_setprop(menu, MPROP_BACKNAME, "Back")     menu_setprop(menu, MPROP_NEXTNAME, "Next")     menu_setprop(menu, MPROP_EXITNAME, "Exit")     menu_setprop(menu, MPROP_NOCOLORS, 1)     menu_display(id, menu, 0);     return PLUGIN_HANDLED; } public MainGunsMenu_Handler(id, menu, item) {       if(item == MENU_EXIT)     {         menu_destroy(menu)         return PLUGIN_HANDLED     }     switch(item)     {         case 0:         {             ShowPrimaryGunsMenu(id)         }         case 1:         {             give_item(id, g_PreviousPrimary[id])             give_item(id, g_PreviousSecondary[id])             ColorChat(id, NORMAL, "%s", g_PreviousSecondary[id])             ColorChat(id, NORMAL, "%s", g_PreviousPrimary[id])         }         case 2:         {             g_bShowGunsMenu[id] = false             give_item(id, g_PreviousPrimary[id])             give_item(id, g_PreviousSecondary[id])                      }     }     menu_destroy(menu)     return PLUGIN_HANDLED; }

The both menus and their handlers:

Code:
public ShowSecondaryGunsMenu(id) {     if(is_user_alive(id))     {         menu_display(id, g_SecWpnMenu, 0)     } } public secondary_handler(id, menuid, item) {     if(is_user_alive(id))     {         if(item == MENU_EXIT)         {             return PLUGIN_HANDLED         }                 copy(g_PreviousSecondary[id], charsmax(g_PreviousSecondary), SecondaryData[item][WeaponID])                 menu_cancel(id)                 give_item(id, g_PreviousSecondary[id])         new iWeaponId = get_weaponid(g_PreviousSecondary[id])         cs_set_user_bpammo(id, iWeaponId, g_WeaponBPAmmo[iWeaponId])     }     return PLUGIN_HANDLED }   public ShowPrimaryGunsMenu(id) {     if(is_user_alive(id))     {         menu_display(id, g_PrimWpnMenu, 0)     } } public primary_handler(id, menuid, item) {     if(is_user_alive(id))     {         if(item == MENU_EXIT)         {             return PLUGIN_HANDLED         }                 copy(g_PreviousPrimary[id], charsmax(g_PreviousPrimary), PrimaryData[item][WeaponID])                 menu_cancel(id)                 give_item(id, g_PreviousPrimary[id])         new iWeaponId1 = get_weaponid(g_PreviousPrimary[id])         cs_set_user_bpammo(id, iWeaponId1, g_WeaponBPAmmo[iWeaponId1])         ShowSecondaryGunsMenu(id)     }     return PLUGIN_HANDLED }

Plugin init:

Code:
    g_SecWpnMenu = menu_create("\rChoose Secondary Weapon", "secondary_handler")     g_PrimWpnMenu = menu_create("\rChoose Primary Weapon", "primary_handler")         new szItemSec[64]     for(new i; i < sizeof(SecondaryData); i++)     {         formatex(szItemSec, charsmax(szItemSec), "%s", SecondaryData[i][WeaponName])         menu_additem(g_SecWpnMenu, szItemSec)     }     new szItemPrim[64]     for(new i; i < sizeof(PrimaryData); i++)     {         formatex(szItemPrim, charsmax(szItemPrim), "%s", PrimaryData[i][WeaponName])         menu_additem(g_PrimWpnMenu, szItemPrim)     }

Everything else:


Code:
enum _:SECONDARYWEAPON {     WeaponName[64],     WeaponID[64] } enum _:PRIMARYWEAPON {     PrimWeaponName[64],     PrimWeaponID[64] } new const SecondaryData[][SECONDARYWEAPON] = {     {"\yGlock", "weapon_glock18"},     {"\yUsp", "weapon_usp"},     {"\yDeagle", "weapon_deagle"} } new const PrimaryData[][PRIMARYWEAPON] = {     {"\yAK47", "weapon_ak47"},     {"\yM4A1", "weapon_m4a1"},     {"\yAWP", "weapon_awp"} } new g_WeaponBPAmmo[] = {     0, 52, 0, 90, 1, 32, 1, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120, 30,    120, 200, 32, 90, 120, 90, 2, 35, 90, 90, 0, 100 }; new g_WeaponSlots[] = {     0, 2, 0, 1, 4, 1, 5, 1, 1, 4, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4, 2, 1, 1, 3, 1 }; new const g_MaxClipAmmo[] = {     0,     13,     0,     10,     0,     7,     0,     30,     30,     0,     15,     20,     25,     30,     35,     25,     12,     20,     10,     30,     100,     8,     30,     30,     20,     0,     7,     30,     30,     0,     50 }
KaLoIaN is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 06-22-2016 , 20:46   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #44

How, do you register g_PreviousPrimary and g_PreviousSecondary variables?
zmd94 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-23-2016 , 07:00   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #45

Ah sorry I forgot.
I register them the way you told me :

Code:
new g_PreviousSecondary[33] new g_SecWpnMenu new g_PreviousPrimary[33] new g_PrimWpnMenu
KaLoIaN is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 06-23-2016 , 11:06   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #46

The g_PreviousSecondary and g_PreviousPrimary variables are incorrect. Please register them as below:
PHP Code:
new g_PreviousSecondary[33][32]
new 
g_PreviousPrimary[33][32
Just see again my code from here:

https://forums.alliedmods.net/showpo...0&postcount=34
zmd94 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-23-2016 , 14:51   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #47

Quote:
Originally Posted by zmd94 View Post
The g_PreviousSecondary and g_PreviousPrimary variables are incorrect. Please register them as below:
PHP Code:
new g_PreviousSecondary[33][32]
new 
g_PreviousPrimary[33][32
Just see again my code from here:

https://forums.alliedmods.net/showpo...0&postcount=34
Thank you! It has worked perfectly.

The natives things you told me they also worked with few little mistakes but I figured them out by my self. At Bricks for example (give_brickpeace native) how I can make it

PHP Code:
if(g_iLevel[id] >= 5)
{
// make the Bricks with "\d" (make it at inactive color)
// write at chat "you need ... level to get this weapon"
// reopen the menu
}
else
{
// the code to give Bricks

If it is even possible ?

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

To print chat, you can use client_print native. Just see below thread for further explanation:

http://www.amxmodx.org/api/amxmodx/client_print

Below is an example:
Code:
client_print(id, print_chat, "Print something")
Next, if you want to change the color, you need to register again the menu before open it for the player. Something such below:
PHP Code:
if(g_iLevel[id] >= 5)
{
    
// List again all the primary weapon
    // No need to register PrimaryData array as it is global
    // Next, make the Bricks with "\d"
    
const PrimaryData[][PRIMARYWEAPON] =
    {
        {
"\yAK47""weapon_ak47"}, 
        {
"\yM4A1""weapon_m4a1"}, 
        {
"\yAWP""weapon_awp"},
        {
"\dBricks"""}
    }
    
    
// Readded the items into the menu
    
new szItemPrim[64]
    for(new 
isizeof(PrimaryData); i++)
    {
        
formatex(szItemPrimcharsmax(szItemPrim), "%s"PrimaryData[i][WeaponName])
        
menu_additem(g_PrimWpnMenuszItemPrim)
    }
    
    
// Print message
    
    // Reopen the menu
    
menu_display(idg_PrimWpnMenu0)
}
else
{
     
// the code to give Bricks


Last edited by zmd94; 06-23-2016 at 21:12.
zmd94 is offline
KaLoIaN
Senior Member
Join Date: Feb 2013
Old 06-24-2016 , 12:11   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #49

Quote:
Originally Posted by zmd94 View Post
To print chat, you can use client_print native. Just see below thread for further explanation:

http://www.amxmodx.org/api/amxmodx/client_print

Below is an example:
Code:
client_print(id, print_chat, "Print something")
Next, if you want to change the color, you need to register again the menu before open it for the player. Something such below:
PHP Code:
if(g_iLevel[id] >= 5)
{
    
// List again all the primary weapon
    // No need to register PrimaryData array as it is global
    // Next, make the Bricks with "\d"
    
const PrimaryData[][PRIMARYWEAPON] =
    {
        {
"\yAK47""weapon_ak47"}, 
        {
"\yM4A1""weapon_m4a1"}, 
        {
"\yAWP""weapon_awp"},
        {
"\dBricks"""}
    }
    
    
// Readded the items into the menu
    
new szItemPrim[64]
    for(new 
isizeof(PrimaryData); i++)
    {
        
formatex(szItemPrimcharsmax(szItemPrim), "%s"PrimaryData[i][WeaponName])
        
menu_additem(g_PrimWpnMenuszItemPrim)
    }
    
    
// Print message
    
    // Reopen the menu
    
menu_display(idg_PrimWpnMenu0)
}
else
{
     
// the code to give Bricks

But when I add 10 guns more I will have hundred of loops and checks in the menu...
Is there another way?

If not - here the menu just does not show:

Code:
public ShowPrimaryGunsMenu(id) {     /*if(is_user_alive(id))     {         menu_display(id, g_PrimWpnMenu, 0)     }*/         if(g_iLevel[id] >= 5)     {         new PrimaryData[][PRIMARYWEAPON] =         {             {"\yAK47", "weapon_ak47"},             {"\yM4A1", "weapon_m4a1"},             {"\yAWP", "weapon_awp"},             {"\dHK416 [LEVEL: 33]", ""},             {"\yEthereal", ""},             {"\yLaserChain", ""}         }                 new szItemPrim[64]         for(new i; i < sizeof(PrimaryData); i++)         {             formatex(szItemPrim, charsmax(szItemPrim), "%s", PrimaryData[i][WeaponName])             menu_additem(g_PrimWpnMenu, szItemPrim)         }     }     else     {         menu_display(id, g_PrimWpnMenu, 0)     } } public primary_handler(id, menuid, item) {     if(is_user_alive(id))     {         if(item == MENU_EXIT)         {             return PLUGIN_HANDLED         }                 if(equali(PrimaryData[item][WeaponName], "\yHK416"))         {             copy(g_PreviousPrimary[id], charsmax(g_PreviousPrimary), PrimaryData[item][WeaponName])                     give_weapon_hk416(id)         }         else if(equali(PrimaryData[item][WeaponName], "\yEthereal"))         {             copy(g_PreviousPrimary[id], charsmax(g_PreviousPrimary), PrimaryData[item][WeaponName])                     give_ethereal(id)         }         else if(equali(PrimaryData[item][WeaponName], "\yLaserChain"))         {             copy(g_PreviousPrimary[id], charsmax(g_PreviousPrimary), PrimaryData[item][WeaponName])                     give_laser_chain(id)         }               else         {             copy(g_PreviousPrimary[id], charsmax(g_PreviousPrimary), PrimaryData[item][WeaponID])                         menu_cancel(id)                         give_item(id, g_PreviousPrimary[id])             new iWeaponId1 = get_weaponid(g_PreviousPrimary[id])             cs_set_user_bpammo(id, iWeaponId1, g_WeaponBPAmmo[iWeaponId1])         }         ShowSecondaryGunsMenu(id)     }     return PLUGIN_HANDLED }
KaLoIaN is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 06-24-2016 , 13:09   Re: Menu Save Player Choice [-HELP-]
Reply With Quote #50

The easiest way is not to make the menu global. Then, detect the player level when we want to create the menu. Next, configure the item color:
PHP Code:
public ShowPrimaryGunsMenu(id)
{
    
// Reset g_PreviousPrimary[id]
    
g_PreviousPrimary[id] = ""
    
    
new PrimWpnMenu menu_create("\yPrimary Weapon""primary_handler")
    
    
menu_additem(PrimWpnMenu"\yAK47")
    
menu_additem(PrimWpnMenu"\yM4A1")
    
menu_additem(PrimWpnMenu"\yAWP")
    
    
// If player level is more than "5"
    
if(g_iLevel[id] >= 5)
    {
        
// The item will be in yellow color
        
menu_additem(PrimWpnMenu"\yHK416")
    }
    else
    {
        
// The item will be in gray color
        
menu_additem(PrimWpnMenu"\dHK416")
    }
    
    
menu_additem(PrimWpnMenu"\yEthereal")
    
menu_additem(PrimWpnMenu"\yLaser Chain")
    
    
menu_display(idPrimWpnMenu0)

Next, you must edit the primary_handler:
PHP Code:
public primary_handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    switch(
item)
    {
        
// Represent first item in the menu
        
case 0:
        {
            
g_PreviousPrimary[id] = "weapon_ak47"
            
            
give_item(idg_PreviousPrimary[id])
            new 
iWeaponId1 get_weaponid(g_PreviousPrimary[id])
            
cs_set_user_bpammo(idiWeaponId1g_WeaponBPAmmo[iWeaponId1])
        }
        case 
1:
        {
            
g_PreviousPrimary[id] = "weapon_m4a1"
            
            
give_item(idg_PreviousPrimary[id])
            new 
iWeaponId1 get_weaponid(g_PreviousPrimary[id])
            
cs_set_user_bpammo(idiWeaponId1g_WeaponBPAmmo[iWeaponId1])
        }
        case 
2:
        {
            
g_PreviousPrimary[id] = "weapon_awp"
            
            
give_item(idg_PreviousPrimary[id])
            new 
iWeaponId1 get_weaponid(g_PreviousPrimary[id])
            
cs_set_user_bpammo(idiWeaponId1g_WeaponBPAmmo[iWeaponId1])
        }
        case 
3:
        {
            
// Add check for player level
            // If player level is more than "5"
            
if(g_iLevel[id] >= 5)
            {
                
// Then, we give the weapon
                
g_PreviousPrimary[id] = "HK416")
                
give_weapon_hk416(id)
            }
            else
            {
                
// Print message
                
client_print(idprint_chat"Access denied")
                
                
// Show the primary menu again
                
ShowPrimaryGunsMenu(id)
            }
        }
        case 
4:
        {
            
g_PreviousPrimary[id] = "Ethereal"
            
give_ethereal(id)
        }
        case 
5:
        {
            
g_PreviousPrimary[id] = "Laser Chain")
            
give_laser_chain(id)
        }
    }
    
    
// If g_PreviousPrimary[id] is not empty
    
if(!(equal(g_PreviousPrimary[id],"")))
    {
        
// Show secondary menu
        
ShowSecondaryGunsMenu(id)
    }
    
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED


Last edited by zmd94; 06-24-2016 at 13:16.
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 00:34.


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