Raised This Month: $ Target: $400
 0% 

How can I restrict specific menu options?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jesusaliso
Member
Join Date: Aug 2013
Location: Venezuela
Old 08-20-2023 , 20:41   How can I restrict specific menu options?
Reply With Quote #1

Hey guys, I'm using this menu so that players can replace their weapon model. Could you help me optimize the code a bit to restrict an option for a vip/admin user, and if it is not, I will return a message.

If anyone knows any other plugin already optimized, please leave it here! or if you have something to suggest about the plugin or want to recommend something to me, I am attentive, thanks

PHP Code:
#include <amxmodx>
#include <cstrike>
#include <cromchat>

new const PLUGIN[] = "m4a1 Menu";
new const 
VERSION[] = "1.0";
new const 
AUTHOR[] = "RevCrew";

new const 
M4Models[][] =
{
    
"models/v_m4a1.mdl",
    
"models/armas_m4/v_m4a11.mdl",
    
"models/armas_m4/v_m4a12.mdl",
    
"models/armas_m4/v_m4a13.mdl",
    
"models/armas_m4/v_m4a14.mdl"
};

new const 
M4MenuNames[][] =
{
    
"M4a1 [DEFAUT]",
    
"M4a1 D'Cyan",
    
"M4a1 Golden'R",
    
"M4a1 Hyper Beast",
    
"M4a1 Howl"
};

new 
M4[33];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say /m4","M4Menu");
    
register_event("CurWeapon""CurentWeapon""be""1=1");
}

public 
plugin_precache() 

    for(new 
isizeof M4Modelsi++) 
    {
        
precache_model(M4Models[i]);
    }
}

public 
MenuM4(id)
{
    new 
menu menu_create("\y>>>>> \rM4a1 Menu \y<<<<<^n \dby >>\rRevCrew\d<<""M4Case")
    
    
menu_additem(menu"M4a1 \r[DEFAUT]^n""1"0)
    
menu_additem(menu"\wM4a1 \yD'Cyan""2"0)
    
menu_additem(menu"\wM4a1 \yGolden'R""3"0)
    
menu_additem(menu"\wM4a1 \yHyper Beast""4"0)
    
menu_additem(menu"\wM4a1 \yHowl""5"0)
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu);
    
    return 
1
}

public 
M4Case(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        return 
1;
    }
    new 
nick[33]; get_user_name(idnick32);
    
M4[id] = item;
    
CC_SendMessage(id"&x03%s &x01You Chouse &x04%s &x01as Your M4a1"nickM4MenuNames[item]);
    
    
menu_destroy (menu);
    return 
1;
}

public 
CurentWeapon(id
{
    if(
get_user_weapon(id) == CSW_M4A1
    {
        
set_pev(idpev_viewmodel2M4Models[M4[id]]);
    }
}

public 
M4Menu(id)
{
    if(
is_user_alive(id))
    {
        
MenuM4(id);
    }else{
        
MenuM4(id);
    }

jesusaliso is offline
Send a message via Skype™ to jesusaliso
Hakim Azizov
Member
Join Date: Mar 2023
Old 08-20-2023 , 21:01   Re: How can I restrict specific menu options?
Reply With Quote #2

change to :



PHP Code:
#include <amxmodx>
#include <cstrike>
#include <cromchat>

const ADMIN_OR_VIP ADMIN_LEVEL_H // Access level H players can use this menu

new const PLUGIN[] = "m4a1 Menu";
new const 
VERSION[] = "1.0";
new const 
AUTHOR[] = "RevCrew";

new const 
M4Models[][] =
{
    
"models/v_m4a1.mdl",
    
"models/armas_m4/v_m4a11.mdl",
    
"models/armas_m4/v_m4a12.mdl",
    
"models/armas_m4/v_m4a13.mdl",
    
"models/armas_m4/v_m4a14.mdl"
};

new const 
M4MenuNames[][] =
{
    
"M4a1 [DEFAUT]",
    
"M4a1 D'Cyan",
    
"M4a1 Golden'R",
    
"M4a1 Hyper Beast",
    
"M4a1 Howl"
};

new 
M4[33];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say /m4","M4Menu");
    
register_event("CurWeapon""CurentWeapon""be""1=1");
}

public 
plugin_precache() 

    for(new 
isizeof M4Modelsi++) 
    {
        
precache_model(M4Models[i]);
    }
}

public 
MenuM4(id)
{
    new 
menu menu_create("\y>>>>> \rM4a1 Menu \y<<<<<^n \dby >>\rRevCrew\d<<""M4Case")
    
    
menu_additem(menu"M4a1 \r[DEFAUT]^n""1"0)
    
menu_additem(menu"\wM4a1 \yD'Cyan""2"0)
    
menu_additem(menu"\wM4a1 \yGolden'R""3"0)
    
menu_additem(menu"\wM4a1 \yHyper Beast""4"0)
    
menu_additem(menu"\wM4a1 \yHowl""5"0)
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu);
    
    return 
1
}

public 
M4Case(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        return 
1;
    }
    new 
nick[33]; get_user_name(idnick32);
    
M4[id] = item;
    
CC_SendMessage(id"&x03%s &x01You Chouse &x04%s &x01as Your M4a1"nickM4MenuNames[item]);
    
    
menu_destroy (menu);
    return 
1;
}

public 
CurentWeapon(id
{
    if(
get_user_frags(id) & ADMIN_OR_VIP && get_user_weapon(id) == CSW_M4A1
    {
        
set_pev(idpev_viewmodel2M4Models[M4[id]]);
    }
}

public 
M4Menu(id)
{
    if (
get_user_frags(id) & ADMIN_OR_VIP)
    {
        
MenuM4(id);
    }else{
        
client_print(id,print_chat,"Menu only for vips or admins")
    }


Last edited by Hakim Azizov; 08-20-2023 at 21:02.
Hakim Azizov is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-20-2023 , 21:03   Re: How can I restrict specific menu options?
Reply With Quote #3

You can disable certain menu options for certain players by using menu callbacks, https://forums.alliedmods.net/showth...4#MenuCallback.

Try that out and see how far you get. If you have issues, post the new code that you tried.
__________________
fysiks is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-20-2023 , 21:47   Re: How can I restrict specific menu options?
Reply With Quote #4

If we talk about optimization, first of all we discard the CurWeapon to replace it with Ham_Item_Deploy
__________________
mlibre is offline
Tote
Senior Member
Join Date: Jul 2023
Old 08-21-2023 , 12:15   Re: How can I restrict specific menu options?
Reply With Quote #5

I made it from start, here you go:

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

#define PLUGIN "Gun Skins"
#define VERSION "1.0"
#define AUTHOR "Tote"

#define ACCESS_FLAG ADMIN_LEVEL_H

new SkinNames[][] =
{
"M4A1 [Default]",
"M4A1 [D'CYAT]",
"M4A1 [Golden'R]",
"M4A1 [Hyper Beast]",
"M4A1 [Howl]"
}

new m4[33];

public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)

register_clcmd("say /m4", "M4SKINS")
RegisterHam(Ham_Item_Deploy, "weapon_m4a1", "OnSelectM4", 1)

}

public M4SKINS( id )
{
new menu = menu_create( "\rM4A1 SKINS:", "menu_handler" );

menu_additem( menu, "\wM4A1 [DEFAULT]", "", 0 );
menu_additem( menu, "\wM4A1 D'Cyan", "", 0 );
menu_additem( menu, "\wM4A1 Golden'R", "", 0 );
menu_additem( menu, "\wM4A1 Hyper Beast", "", 0 );
menu_additem( menu, "\wM4A1 Howl", "", 0 );

menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );

menu_display( id, menu, 0 );

}

public menu_handler( id, menu, item )
{
switch( item )
{
case 0:
{
if(~get_user_flags(id) & ACCESS_FLAG)
{
client_print(id, print_chat, "Sorry, You do not have access to this m4 skin!");
return PLUGIN_HANDLED
}
else
{
m4[id] = 1
client_print(id, print_chat, "You selected m4 skin: %s", SkinNames[m4[id]])
}
}
case 1:
{
if(~get_user_flags(id) & ACCESS_FLAG)
{
client_print(id, print_chat, "Sorry, You do not have access to this m4 skin!");
return PLUGIN_HANDLED
}
else
{
m4[id] = 2
client_print(id, print_chat, "You selected m4 skin: %s", SkinNames[m4[id]])
}
}
case 2:
{
if(~get_user_flags(id) & ACCESS_FLAG)
{
client_print(id, print_chat, "Sorry, You do not have access to this m4 skin!");
return PLUGIN_HANDLED
}
else
{
m4[id] = 3
client_print(id, print_chat, "You selected m4 skin: %s", SkinNames[m4[id]])
}
}
case 3:
{
if(~get_user_flags(id) & ACCESS_FLAG)
{
client_print(id, print_chat, "Sorry, You do not have access to this m4 skin!");
return PLUGIN_HANDLED
}
else
{
m4[id] = 4
client_print(id, print_chat, "You selected m4 skin: %s", SkinNames[m4[id]])
}
}
case 4:
{
if(~get_user_flags(id) & ACCESS_FLAG)
{
client_print(id, print_chat, "Sorry, You do not have access to this m4 skin!");
return PLUGIN_HANDLED
}
else
{
m4[id] = 5
client_print(id, print_chat, "You selected m4 skin: %s", SkinNames[m4[id]])
}
}
}


menu_destroy( menu );
return PLUGIN_HANDLED;
}

public OnSelectM4(id)
{
if(m4[id] == 1)
{
set_pev(id, pev_viewmodel2, "models/v_m4a1.mdl")
}
else if(m4[id] == 2)
{
set_pev(id, pev_viewmodel2, "models/armas_m4/v_m4a11")
}
else if(m4[id] == 3)
{
set_pev(id, pev_viewmodel2, "models/armas_m4/v_m4a12")
}
else if(m4[id] == 4)
{
set_pev(id, pev_viewmodel2, "models/armas_m4/v_m4a13")
}
else if(m4[id] == 5)
{
set_pev(id, pev_viewmodel2, "models/armas_m4/v_m4a14")
}
}
Tote is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-21-2023 , 13:24   Re: How can I restrict specific menu options?
Reply With Quote #6

use php tags please
PHP Code:
code here 
__________________
mlibre is offline
jesusaliso
Member
Join Date: Aug 2013
Location: Venezuela
Old 08-21-2023 , 18:48   Re: How can I restrict specific menu options?
Reply With Quote #7

Hi guys, sorry for not responding soon, I'll try what you sent me and I'll let you know! really very grateful to you
jesusaliso is offline
Send a message via Skype™ to jesusaliso
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-21-2023 , 22:34   Re: How can I restrict specific menu options?
Reply With Quote #8

Quote:
Originally Posted by jesusaliso View Post
Hi guys, sorry for not responding soon, I'll try what you sent me and I'll let you know! really very grateful to you
Do not use the code posted by Tote. Also, I think there is confusion about your request because your original post was written in a confusing way. Are you trying to only allow admins/VIPs to open the menu or are you trying to prevent non-admins/VIP from using specific items in the menu?

Quote:
Originally Posted by Hakim Azizov View Post
change to :
This is the Scripting Help section so you should explain what you changed if you're going to try to help. It's not always clear what code you removed/added/changed at a glance and it's helpful to help people learn (which is what the Scripting Help section is meant for).

Quote:
Originally Posted by Tote View Post
I made it from start, here you go:
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Gun Skins"
#define VERSION "1.0"
#define AUTHOR "Tote"

#define ACCESS_FLAG ADMIN_LEVEL_H

new SkinNames[][] = 
{
    
"M4A1 [Default]",
    
"M4A1 [D'CYAT]",
    
"M4A1 [Golden'R]",
    
"M4A1 [Hyper Beast]",
    
"M4A1 [Howl]"
}

new 
m4[33];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /m4""M4SKINS")
    
RegisterHam(Ham_Item_Deploy"weapon_m4a1""OnSelectM4"1)
    
}

public 
M4SKINSid )
{
    new 
menu menu_create"\rM4A1 SKINS:""menu_handler" );
    
    
menu_additemmenu"\wM4A1 [DEFAULT]""");
    
menu_additemmenu"\wM4A1 D'Cyan""");
    
menu_additemmenu"\wM4A1 Golden'R""");
    
menu_additemmenu"\wM4A1 Hyper Beast""");
    
menu_additemmenu"\wM4A1 Howl""");
    
    
menu_setpropmenuMPROP_EXITMEXIT_ALL );
    
    
menu_displayidmenu);
    
}

public 
menu_handleridmenuitem )
{
    switch( 
item )
    {
        case 
0:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 1
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
        case 
1:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 2
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }    
        }
        case 
2:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 3
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
        case 
3:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 4
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
        case 
4:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 5
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
    }
    
    
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;
}

public 
OnSelectM4(id)
{
    if(
m4[id] == 1)
    {
        
set_pev(idpev_viewmodel2"models/v_m4a1.mdl")
    }
    else if(
m4[id] == 2)
    {
        
set_pev(idpev_viewmodel2"models/armas_m4/v_m4a11")
    }
    else if(
m4[id] == 3)
    {
        
set_pev(idpev_viewmodel2"models/armas_m4/v_m4a12")
    }
    else if(
m4[id] == 4)
    {
        
set_pev(idpev_viewmodel2"models/armas_m4/v_m4a13")
    }
    else if(
m4[id] == 5)
    {
        
set_pev(idpev_viewmodel2"models/armas_m4/v_m4a14")
    }

This a very poorly written plugin that is much worse that the original one in the OP. It seems that you need much more experience before trying to help others, especially in Scripting Help.
__________________
fysiks is offline
jesusaliso
Member
Join Date: Aug 2013
Location: Venezuela
Old 08-22-2023 , 08:48   Re: How can I restrict specific menu options?
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
Do not use the code posted by Tote. Also, I think there is confusion about your request because your original post was written in a confusing way. Are you trying to only allow admins/VIPs to open the menu or are you trying to prevent non-admins/VIP from using specific items in the menu?
i'm trying to prevent non-admins/VIP from using specific items in the menu.
jesusaliso is offline
Send a message via Skype™ to jesusaliso
Tote
Senior Member
Join Date: Jul 2023
Old 08-22-2023 , 11:30   Re: How can I restrict specific menu options?
Reply With Quote #10

Here ~

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Gun Skins"
#define VERSION "1.0"
#define AUTHOR "Tote"

#define ACCESS_FLAG ADMIN_LEVEL_H

new const M4Models[][] =
{
    
"models/v_m4a1.mdl",
    
"models/armas_m4/v_m4a11.mdl",
    
"models/armas_m4/v_m4a12.mdl",
    
"models/armas_m4/v_m4a13.mdl",
    
"models/armas_m4/v_m4a14.mdl"
};

new 
SkinNames[][] = 
{
    
"M4A1 [Default]",
    
"M4A1 [D'CYAT]",
    
"M4A1 [Golden'R]",
    
"M4A1 [Hyper Beast]",
    
"M4A1 [Howl]"
}

    new 
m4[33];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_clcmd("say /m4""M4SKINS")
    
RegisterHam(Ham_Item_Deploy"weapon_m4a1""OnSelectM4"1)

}

public 
plugin_precache() 

    for(new 
isizeof M4Modelsi++) 
    {
    
precache_model(M4Models[i]);
    }
}

public 
client_putinserver(id)
{
    
m4[id] = 0
}

public 
M4SKINSid )
{
    new 
menu menu_create"\rM4A1 SKINS:""menu_handler" );

    
menu_additemmenu"\wM4A1 [DEFAULT]""");
    
menu_additemmenu"\wM4A1 D'Cyan""");
    
menu_additemmenu"\wM4A1 Golden'R""");
    
menu_additemmenu"\wM4A1 Hyper Beast""");
    
menu_additemmenu"\wM4A1 Howl""");

    
menu_setpropmenuMPROP_EXITMEXIT_ALL );

    
menu_displayidmenu);

}

public 
menu_handleridmenuitem )
{
    switch( 
item )
    {
        case 
0:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 1
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
        case 
1:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 2
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }    
        }
        case 
2:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 3
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
        case 
3:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 4
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
        case 
4:
        {
            if(~
get_user_flags(id) & ACCESS_FLAG)
            {
                
client_print(idprint_chat"Sorry, You do not have access to this m4 skin!");
                return 
PLUGIN_HANDLED
            
}
            else
            {
                
m4[id] = 5
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
    }
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;
}

public 
OnSelectM4(id)
{
    if(
m4[id] >= 2// using >= 2 because the main models start after num 2. so no need to set model if it's 1 or 0 because its default on 1 & 0
    
{
        
set_pev(idpev_viewmodel2M4Models[m4[id]])
    }


Last edited by Tote; 08-22-2023 at 11:36.
Tote 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 20:08.


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