Raised This Month: $32 Target: $400
 8% 

menu problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-24-2021 , 20:01   menu problems
Reply With Quote #1

hello i have this code

PHP Code:
new items[] = {
    
"Speed",
    
"Gravity"
}

new 
price[] = {
    
"1500",
    
"3500"
}

public 
awesomemenu(id){
    new 
iMenu menu_create("\r[STATE3]\y Test menu""awesomemenu_handler")
    new 
menuformat[1024]
    
    for (new 
i=0i<2i++){
        if(
item[i][id] == 0)
            
formatex(menuformatcharsmax(menuformat), "%s \d- \r[\y%s\r]"items[i], price[i])
        else if (
item[i][id] == || item[i][id] == 2)
            
formatex(menuformatcharsmax(menuformat), "%s \d- \y%s"items[i], item[i][id] == "\y[ON]" "\r[OFF]")
        
menu_additem(iMenumenuformat[i])
    }
    
    
formatex(menuformat,charsmax(menuformat), "\wPoints\d =\y %i"points[id])
    
menu_addtext(iMenumenuformat0)
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_ALL)
    
menu_display(idiMenu0)

why the output is this

https://imgur.com/a/xTfiVli
?
and also, if i change this
PHP Code:
 for (new i=0i<2i++) 
with

PHP Code:
 for (new i=0i<sizeof(items); i++) 
i get index out of bounds in debug mode.

and how can i move that "Points" above items ? if i use addtext won't work

Last edited by lexzor; 01-24-2021 at 20:02.
lexzor is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-24-2021 , 21:46   Re: menu problems
Reply With Quote #2

items[][] - double brackets on both places + sizeof instead() of hardcoding.
Why are the prices strings?
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-25-2021 , 04:33   Re: menu problems
Reply With Quote #3

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

#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <nvault_array>
#include <fun>
#include <hamsandwich>

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

new const nVaultName[] = "nvaultarraytest"
new const tag[] = "^4[^3STATE3^4]^1"

static points[MAX_PLAYERS 1],
item[MAX_PLAYERS 1][33],
g_szAuthID[MAX_PLAYERS+1][33],
nVault

new items[][] = {
    
"Speed",
    
"Gravity",
    
"AWP"
}

new 
price[] = {
    
1500,
    
3500,
    
5000
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /give""give_points")
    
register_clcmd("say /menu""awesomemenu")
    
register_clcmd("say /reset""items_reset")
    
    
RegisterHam(Ham_Spawn"player""setitem"1
    
    
nVault nvault_open(nVaultName)
    
    if(
nVault == INVALID_HANDLE)
        
set_fail_state("[nVaultArray] Error!")
}

public 
client_authorized(idget_user_authid(idg_szAuthID[id], charsmax(g_szAuthID[]))

public 
give_points(id){ 
    
points[id] += 1000
}

public 
items_reset(id){
    for (new 
i=0i<sizeof(items); i++){
        
item[id][i] = 0
    
}
    
    
client_print_color(idprint_team_default"%s All items^4 has been reseted^1!"tag)
}

public 
awesomemenu(id){
    new 
iMenu menu_create("\r[STATE3]\y Test menu""awesomemenu_handler")
    new 
menuformat[1024]
    
    for (new 
i=0i<sizeof(items); i++){
        if(
item[id][i] == 0)
            
formatex(menuformatcharsmax(menuformat), "%s \d- \r[\y%d\r]"items[i], price[i])
        else if (
item[id][i] == || item[id][i] == 2)
            
formatex(menuformatcharsmax(menuformat), "%s \d- \y%s"items[i], item[id][i] == "\y[ON]" "\r[OFF]")
        
menu_additem(iMenumenuformat[i])
    }
    
    
formatex(menuformat,charsmax(menuformat), "\wPoints\d =\y %i"points[id])
    
menu_addtext(iMenumenuformat0)
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_ALL)
    
menu_display(idiMenu0)
}

public 
awesomemenu_handler(idiMenukey){
    switch(
key){
        case 
0:{
            if(
item[id][key] == 0){
                if(
points[id] < price[key]){
                
client_print_color(idprint_team_default"%s You can't buy^4 %s^1 because you need^4 %i Points^1!"tagitems[key], price[key] - points[id] )
                return 
PLUGIN_HANDLED
                
}else{
                    
points[id] -= price[key]
                    
item[id][key] = 1
                    client_print_color
(idprint_team_default"%s You just bought^4 %s^1!"tagitems[key])
                    
awesomemenu(id)    
                }
            }
            
            else if(
item[id][key] == 1)
                
item[id][key] = 2
            
            
else if (item[id][key] == 2)
                
item[id][key] = 1
            client_print_color
(idprint_team_default"%s You just %s^4 %s^1!"tagitem[id][key] == "disabled" "enabled"items[key])
            
awesomemenu(id)    
            return 
PLUGIN_HANDLED
        
}
        
        case 
1:{
            if(
item[id][key] == 0){
                if(
points[id] < price[key]){
                
client_print_color(idprint_team_default"%s You can't buy^4 %s^1 because you need^4 %i Points^1!"tagitems[key], price[key] - points[id] )
                return 
PLUGIN_HANDLED
                
}else{
                    
points[id] -= price[key]
                    
item[id][key] = 1
                    client_print_color
(idprint_team_default"%s You just bought^4 %s^1!"tagitems[key])
                    
awesomemenu(id)    
                }
            }
            
            else if(
item[id][key] == 1)
                
item[id][key] = 2
            
            
else if (item[id][key] == 2)
                
item[id][key] = 1
            client_print_color
(idprint_team_default"%s You just %s^4 %s^1!"tagitem[id][key] == "disabled" "enabled"items[key])
            
awesomemenu(id)    
            return 
PLUGIN_HANDLED
        
}
        
        case 
2:{
            if(
item[id][key] == 0){
                if(
points[id] < price[key]){
                
client_print_color(idprint_team_default"%s You can't buy^4 %s^1 because you need^4 %i Points^1!"tagitems[key], price[key] - points[id] )
                return 
PLUGIN_HANDLED
                
}else{
                    
points[id] -= price[key]
                    
item[id][key] = 1
                    client_print_color
(idprint_team_default"%s You just bought^4 %s^1!"tagitems[key])
                    
awesomemenu(id)    
                }
            }
            
            else if(
item[id][key] == 1)
                
item[id][key] = 2
            
            
else if (item[id][key] == 2)
                
item[id][key] = 1
            client_print_color
(idprint_team_default"%s You just %s^4 %s^1!"tagitem[id][key] == "disabled" "enabled"items[key])
            
awesomemenu(id)    
            return 
PLUGIN_HANDLED
        
}
        
        case 
MENU_EXIT:{
            
menu_destroy(iMenu)
        }
    }
    return 
1;
}

public 
setitem(id){
    if(
is_user_alive(id)){
        switch(
item[id][0]){
            
            case 
2set_user_maxspeed(id550.0)
                
            case 
1client_print_color(idprint_team_default"%s You just disabled^4 Speed^1!"tag)
                
            default: 
client_print_color(idprint_team_default"%s You must buy^4 Speed^1!"tag)
        }
        
        switch(
item[id][1]){
            case 
2set_user_gravity(id0.6)
                
            case 
1client_print_color(idprint_team_default"%s You just disabled^4 Gravity^1!"tag)
                
            default: 
client_print_color(idprint_team_default"%s You must buy^4 Gravity^1!"tag)
        }
        
        switch(
item[id][2]){
            case 
2give_item(id"weapon_awp")
                
            case 
1client_print_color(idprint_team_default"%s You just disabled^4 AWP1!"tag)
                
            default: 
client_print_color(idprint_team_default"%s You must buy^4 AWP^1!"tag)
        }
    }

ok, thanks, but now it looks like this. https://imgur.com/a/WsY7gpN

i used sizeof and i changed items[] with items[][].

a question. can i do somethinglike this.
PHP Code:
switch(key){
        case 
0..100:{
            if(
item[id][key] == 0){
                if(
points[id] < price[key]){
                
client_print_color(idprint_team_default"%s You can't buy^4 %s^1 because you need^4 %i Points^1!"tagitems[key], price[key] - points[id] )
                return 
PLUGIN_HANDLED
                
}else{
                    
points[id] -= price[key]
                    
item[id][key] = 1
                    client_print_color
(idprint_team_default"%s You just bought^4 %s^1!"tagitems[key])
                    
awesomemenu(id)    
                }
            }
            
            else if(
item[id][key] == 1)
                
item[id][key] = 2
            
            
else if (item[id][key] == 2)
                
item[id][key] = 1
            client_print_color
(idprint_team_default"%s You just %s^4 %s^1!"tagitem[id][key] == "disabled" "enabled"items[key])
            
awesomemenu(id)    
            return 
PLUGIN_HANDLED
        

this is just a test plugin i want to learn how to use dd array and how i can save them using nvault array. also, i-m trying to get used with this new menus so, if i'm not doing smth right just show me how should i do

edit: should i use enum? i found this: https://forums.alliedmods.net/showpo...99&postcount=7

Last edited by lexzor; 01-25-2021 at 05:38.
lexzor is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-25-2021 , 07:07   Re: menu problems
Reply With Quote #4

Yes, you definitely should.

Code:
enum MenuData {     ItemName[32],     ItemPrice } new g_eMenu[][MenuData] for(new i; i < sizeof(g_eMenu); i++) {     formatex(szItem, charsmax(szItem), "%s [%i$]", g_eMenu[i][ItemName], g_eMenu[i][ItemPrice])     menu_additem(iMenu, szItem) }
__________________

Last edited by OciXCrom; 01-25-2021 at 07:09.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-25-2021 , 20:15   Re: menu problems
Reply With Quote #5

ok.. i tried but i really don't understand how this enum works. how can i save itemdata (item[id][0], item[id][1]... etc)

and also how can i resolve this: https://imgur.com/a/WsY7gpN

Last edited by lexzor; 01-25-2021 at 20:15.
lexzor is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-26-2021 , 01:38   Re: menu problems
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
Yes, you definitely should.

Code:
enum MenuData {     ItemName[32],     ItemPrice } new g_eMenu[][MenuData] for(new i; i < sizeof(g_eMenu); i++) {     formatex(szItem, charsmax(szItem), "%s [%i$]", g_eMenu[i][ItemName], g_eMenu[i][ItemPrice])     menu_additem(iMenu, szItem) }
See this OciXCrom's example and explain what you do not understand.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-26-2021 , 06:25   Re: menu problems
Reply With Quote #7

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

#include <amxmodx>
#include <amxmisc>

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

enum _:MenuItems{
    
ItemName[16]
    
ItemPrice
}

static 
g_iMenuAdd[][MenuItems]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /menu""awesomemenu")
}

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

ok, how i define itemname and itemprice ?
should i do in public awosomenu something like this?:
PHP Code:
g_iMenuAdd[0][ItemName] = "Speed"
g_iMenuAdd[1][ItemName] = "Gravity"
g_iMenuAdd[0][ItemPrice] = 1500
g_iMenuAdd
[1][ItemPrice] = 3000 
lexzor is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-26-2021 , 06:44   Re: menu problems
Reply With Quote #8

Quote:
Originally Posted by lexzor View Post
PHP Code:
okhow i define itemname and itemprice 
should i do in public awosomenu something like this?: 
According to your code:
PHP Code:
Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

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

enum _:MenuItems{
    
szItemName[16]
    
iItemPrice
}

new const 
g_iMenuAdd[][MenuItems] = 
{
    {
"Speed"1500},
    {
"Gravity"3000}
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /menu""awesomemenu")
}

public 
awesomemenu(id){
    new 
iMenu menu_create("\r[STATE3]\w Test Menu")
    static 
menudata[256]
    
    for ( new 
0sizeof(MenuItems); i++){
        
formatex(menudatacharsmax(menudata), "\w%s \d- \y[%i]"g_iMenuAdd[i][szItemName], g_iMenuAdd[i][iItemPrice])
        
menu_additem(iMenumenudata)
    }
    
    
menu_setprop(iMenuMPROP_EXITMEXIT_ALL)
    
menu_display(idiMenu0)

__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 01-26-2021 at 07:49. Reason: Edit, saw OciXCrom reply :)
Shadows Adi is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-26-2021 , 07:15   Re: menu problems
Reply With Quote #9

And before you say the menu doesn't show, check your spelling on the function's name.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-26-2021 , 08:47   Re: menu problems
Reply With Quote #10

Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < fun >

enum _:ListOfItems
{
	Name [ 16 ],
	Price
};

new const g_szMenuItems [ ] [ ListOfItems ] =
{
	{ "Speed", 1500 },
	{ "Gravity", 3000 }
};

public plugin_init ( )	register_clcmd ( "say /menu", "pEntityMenu" );
public pEntityMenu ( pEntity )
{
	new szData [ 64 ], i;
	new iMenu = menu_create ( "\r[STATE3]\w Test Menu", "FUNC_HANDLER" );

	for ( i = 0; i < sizeof g_szMenuItems; i++ )
	{
		formatex ( szData, charsmax ( szData ), "\w%s - \r%d", g_szMenuItems [ i ] [ Name ], g_szMenuItems [ i ] [ Price ] );
		menu_additem ( iMenu, szData );
	}

	menu_setprop ( iMenu, MPROP_EXIT, MEXIT_ALL );
	menu_display ( pEntity, iMenu, 0 );
}

public FUNC_HANDLER ( pEntity, iMenu, Key )
{
	if ( Key == MENU_EXIT )
	{
		menu_destroy ( iMenu );
		return 1;
	}

	if ( cs_get_user_money ( pEntity ) < g_szMenuItems [ Key ] [ Price ] )
	{
		client_print ( pEntity, print_chat, "[AMX] You don't have enought money" );
		return 1;
	}


	switch ( Key )
	{
		case 0:	set_user_maxspeed ( pEntity, 240.0 );
		case 1:	set_user_gravity ( pEntity, 0.5 );
	}

	client_print ( pEntity, print_chat, "[AMX] You bought %s", g_szMenuItems [ Key ] [ Name ] );
	cs_set_user_money ( pEntity, cs_get_user_money ( pEntity ) - g_szMenuItems [ Key ] [ Price ] );
	return 1;
}
Full example here, hope i helped you!
__________________

Last edited by LondoN; 01-26-2021 at 08:48.
LondoN 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 23:51.


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