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

menu problems


Post New Thread Reply   
 
Thread Tools Display Modes
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-26-2021 , 17:22   Re: menu problems
Reply With Quote #11

@Shadows Adi, add a function to the menu so it can operate. From my previous experience, menu's won't show as long as there's no matching function.
__________________

Last edited by Napoleon_be; 01-26-2021 at 17:22.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-27-2021 , 01:13   Re: menu problems
Reply With Quote #12

so, is right how i use static g_iData[MAX_PLAYERS +1][PlayerData] ?
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "super"

enum _:MenuItems{
    
ItemName[16],
    
ItemPrice
}

enum _:PlayerData{
    
Points[MAX_PLAYERS+1],
    
ShopItems[MAX_PLAYERS+1][33]
}

static 
g_iData[MAX_PLAYERS +1][PlayerData]

static 
g_iMenu[][MenuItems] = {
    {
"Speed"1500},
    {
"Gravity"3500},
    {
"AWP"4750}
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("radio1""awesomemenu")
    
register_clcmd("amx_give""givepoints")
}

public 
givepoints(idg_iData[id][Points] += 500 


public awsomemenu(id)
{
    new 
iMenu menu_create("\r[TEST]\w Menu""menu_handler")
    static 
menudata[256]
    
    for ( new 
0MenuItemsi++)
    {
        
formatex(menudatacharsmax(menudata), "\w%s \d- \r[\y%d\r]"g_iMenu[i][ItemName], g_iMenu[i][ItemPrice])
        
menu_additem(iMenumenudata)
    }
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_ALL)
    
menu_display(idiMenu0)
}

public 
menu_handler(idiMenukey)
{
    if ( 
key == MENU_EXIT )
    {
        
menu_destroy(iMenu)
        return 
1;
    }
    
    for (new 
ig_iMenui++)
    {    
        if (
g_iData[id][Points] < g_iMenu[i][ItemPrice])
        {
            
client_print_color(idprint_team_default"^4[^3TEST^4]^1 You don't have enough money!")
            
awesomemenu(id)
            return 
PLUGIN_HANDLED
        
}
    }
    
    switch(
key)
    {
        case 
0:
        {
            if(
g_iData[id][ShopItems[id][key]] == 0)
            {
                
g_iData[id][ShopItems[id][key]] = 1
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You bought^4 %s^1!"g_iMenu[key][ItemName])
                
awesomemenu(id)
                return 
PLUGIN_HANDLED
            
}
            
            if(
g_iData[id][ShopItems[id][key]] == 1)
            {
                
g_iData[id][ShopItems[id][key]] = 2
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You enabled^4 %s^1!"g_iMenu[key][ItemName])
                
set_user_maxspeed(id240.0)
            }
            else if (
g_iData[id][ShopItems[id][key]] == 2)
            {
                
g_iData[id][ShopItems[id][key]] = 1
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You disabled^4 %s^1!"g_iMenu[key][ItemName])
                
set_user_maxspeed(id250)
            }
        } 
    }

i want to give a value for each player for this enum:
PHP Code:
enum _:PlayerData{
    
Points[MAX_PLAYERS+1],
    
ShopItems[MAX_PLAYERS+1][33//owned items

then save enum PlayerData using nvault_array. is this possible ?

Last edited by lexzor; 01-27-2021 at 01:16.
lexzor is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-27-2021 , 06:47   Re: menu problems
Reply With Quote #13

Why static?!

Quote:
Code:
enum _:PlayerData{     Points[MAX_PLAYERS+1],     ShopItems[MAX_PLAYERS+1][33] //owned items } static g_iData[MAX_PLAYERS +1][PlayerData]
So basically what you have here is g_iData[id][ShopItems][id][id]

=>


Code:
enum _:PlayerData{     Points,     Trie:ShopItems } new g_iData[MAX_PLAYERS +1][PlayerData]
__________________

Last edited by OciXCrom; 01-27-2021 at 06:50.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-27-2021 , 10:07   Re: menu problems
Reply With Quote #14

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "super"

enum _:MenuItems{
    
ItemName[16],
    
ItemPrice
}

enum _:PlayerData{
    
Points[33],
    
ShopItems[33]
}

static 
g_iData[MAX_PLAYERS +1][PlayerData]

static 
g_iMenu[][MenuItems] = {
    {
"Speed"1500},
    {
"Gravity"3500},
    {
"AWP"4750}
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("radio1""awesomemenu")
    
register_clcmd("amx_give""givepoints")
}

public 
givepoints(idg_iData[id][Points] += 500 


public awsomemenu(id)
{
    new 
iMenu menu_create("\r[TEST]\w Menu""menu_handler")
    static 
menudata[256]
    
    for ( new 
0g_iMenu[][MenuItems]; i++)
    {
        
formatex(menudatacharsmax(menudata), "\w%s \d- \r[\y%d\r]"g_iMenu[i][ItemName], g_iMenu[i][ItemPrice])
        
menu_additem(iMenumenudata)
    }
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_ALL)
    
menu_display(idiMenu0)
}

public 
menu_handler(idiMenukey)
{
    if ( 
key == MENU_EXIT )
    {
        
menu_destroy(iMenu)
        return 
1;
    }
    
    for (new 
ig_iMenu[]; i++)
    {    
        if (
g_iData[id][Points] < g_iMenu[i][ItemPrice])
        {
            
client_print_color(idprint_team_default"^4[^3TEST^4]^1 You don't have enough money!")
            
awesomemenu(id)
            return 
PLUGIN_HANDLED
        
}
    }
    
    switch(
key)
    {
        case 
0:
        {
            if(
g_iData[id][ShopItems[key]] == 0)
            {
                
g_iData[id][ShopItems[key]] = 1
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You bought^4 %s^1!"g_iMenu[key][ItemName])
                
awesomemenu(id)
                return 
PLUGIN_HANDLED
            
}
            
            if(
g_iData[id][ShopItems[key]] == 1)
            {
                
g_iData[id][ShopItems[key]]  = 2
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You enabled^4 %s^1!"g_iMenu[key][ItemName])
                
set_user_maxspeed(id240.0)
            }
            else if (
g_iData[id][ShopItems[key]] == 2)
            {
                
g_iData[id][ShopItems[key]] = 1
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You disabled^4 %s^1!"g_iMenu[key][ItemName])
                
set_user_maxspeed(id250)
            }
        } 
    }

i get an error in loop statement, idk how to get g_iMenu size.

so i have to use trie and can't do smth like above, right ?

Last edited by lexzor; 01-27-2021 at 10:08.
lexzor is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-27-2021 , 10:24   Re: menu problems
Reply With Quote #15

Quote:
Originally Posted by OciXCrom View Post
Why static?!



So basically what you have here is g_iData[id][ShopItems][id][id]

=>


Code:
enum _:PlayerData{     Points,     Trie:ShopItems } new g_iData[MAX_PLAYERS +1][PlayerData]
Bitsums? g_bShopItems[id][probably team] = SHOP_ITEM_1|SHOP_ITEM2

@lexzor, change

Code:
 for(new i=0; i<g_iMenu; i++
Use sizeof, see mai example.
__________________
LondoN is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-27-2021 , 10:52   Re: menu problems
Reply With Quote #16

Thanks london i don t know how i could forgot about size of.

so i want to use ShopItems like this:

let s imagine that in shop i have 2 items:
PHP Code:
ShopItems[id][0]
ShopItems[id][1

i want to to something like this:
PHP Code:
ShopItems[id][0] = // Player haven't bought this item and he have to
// After player buy the item ->
ShopItems[id][0] = // Player disabled his bought item, let's imagine this is the speed item
ShopItems[id][0] = // Player enabled speed item from shop 
and same situation for
PHP Code:
 ShopItems[id][1
Ok, but now i want to save this ShopItems because owned items would reset on the nextmap and i don t want this.

so, i HAVE TO use "trie" in that enum to do this or there is another useful and easy method to do smth like this ? I already learned not so much things about enum and i don't really getting used of how to use them and using trie with enum will blow my brain.

Last edited by lexzor; 01-27-2021 at 10:54.
lexzor is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-27-2021 , 11:17   Re: menu problems
Reply With Quote #17

You'll need some sort of database (sql, nvault) if u want to save anything on mapchange.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-27-2021 , 11:39   Re: menu problems
Reply With Quote #18

Yes, i will try with nVault array and that's why i try to use enum because i read in a post from this forum that i have to use enum if i want to save more things per players (like points and shopitems[i mean item bought]) using nvault array because double dimensional array are not supported but would be ok if i would use enum.

but i still don t know how to do this
lexzor is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-27-2021 , 12:31   Re: menu problems
Reply With Quote #19

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "super"

enum _:MenuItems{
    
ItemName[16],
    
ItemPrice
}

enum _:PlayerData{
    
Points[33],
    
ShopItems[33]
}

static 
g_iData[MAX_PLAYERS +1][PlayerData]

static 
g_iMenu[][MenuItems] = {
    {
"Speed"1500},
    {
"Gravity"3500},
    {
"AWP"4750}
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("amx_radio151""awesomemenu")
    
register_clcmd("amx_give""givepoints")
}

public 
givepoints(idg_iData[id][Points] += 500 


public awesomemenu(id)
{
    new 
iMenu menu_create("\r[TEST]\w Menu""menu_handler")
    static 
menudata[256]
    
    for ( new 
0sizeof(g_iMenu); i++)
    {
        if (
g_iData[id][ShopItems] == 0)
        
formatex(menudatacharsmax(menudata), "\w%s \d- \r[\y%d\r]"g_iMenu[i][ItemName], g_iMenu[i][ItemPrice])
    else if (
g_iData[id][ShopItems] > 0)
    
formatex(menudatacharsmax(menudata), "\w%s \d- \r[\y%s\r]"g_iMenu[i][ItemName], g_iData[id][ShopItems] == "OFF" "ON")
        
menu_additem(iMenumenudata)
    }
    
    
formatex(menudatacharsmax(menudata), "Points \r[\y%i\r]"g_iData[id][Points])
    
menu_addtext(iMenumenudata0)
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_ALL)
    
menu_display(idiMenu0)
}

public 
menu_handler(idiMenukey)
{
    if ( 
key == MENU_EXIT )
    {
        
menu_destroy(iMenu)
        return 
1;
    }
    
    for (new 
isizeof(g_iMenu); i++)
    {    
        if (
g_iData[id][Points] < g_iMenu[i][ItemPrice])
        {
            
client_print_color(idprint_team_default"^4[^3TEST^4]^1 You don't have enough money!")
            
awesomemenu(id)
            return 
PLUGIN_HANDLED
        
}
    }
    
    switch(
key)
    {
        case 
0:
        {
            if(
g_iData[id][ShopItems] == 0)
            {
                
g_iData[id][ShopItems] = 1
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You bought^4 %s^1!"g_iMenu[key][ItemName])
                
awesomemenu(id)
                return 
PLUGIN_HANDLED
            
}
            
            if(
g_iData[id][ShopItems] == 1)
            {
                
g_iData[id][ShopItems]  = 2
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You enabled^4 %s^1!"g_iMenu[key][ItemName])
                
set_user_maxspeed(id240.0)
            }
            else if (
g_iData[id][ShopItems] == 2)
            {
                
g_iData[id][ShopItems] = 1
                client_print_color
(idprint_team_default"^4[^3TEST^4]^1 You disabled^4 %s^1!"g_iMenu[key][ItemName])
                
set_user_maxspeed(id250.0)
            }
         
awesomemenu(id)
         return 
1;
        } 
    }

ok, now if i buy first item, the second one and the third one will be bought too. can someone just show me 1 example of the code above of how i could use trie?

Last edited by lexzor; 01-27-2021 at 12:43.
lexzor is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-27-2021 , 17:32   Re: menu problems
Reply With Quote #20

Quote:
i get an error in loop statement, idk how to get g_iMenu size.
I already showed you how in one of my previous comment. sizeof(g_iMenu) is all you need.

Quote:
Bitsums? g_bShopItems[id][probably team] = SHOP_ITEM_1|SHOP_ITEM2
Limited to 32 items.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 11:23.


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