Raised This Month: $ Target: $400
 0% 

How can I restrict specific menu options?


Post New Thread Reply   
 
Thread Tools Display Modes
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-22-2023 , 13:02   Re: How can I restrict specific menu options?
Reply With Quote #11

well i guess v_m4a1 is already preloaded. no need to add to the list, and in OnSelectM4, do the preliminary checks to avoid errors, sort of like this.
__________________
mlibre is offline
Tote
Senior Member
Join Date: Jul 2023
Old 08-22-2023 , 13:11   Re: How can I restrict specific menu options?
Reply With Quote #12

Quote:
Originally Posted by mlibre View Post
well i guess v_m4a1 is already preloaded. no need to add to the list, and in OnSelectM4, do the preliminary checks to avoid errors, sort of like this.
smth like this? not needed to check if item is m4a1 cause RegisterHam(Ham_Item_Deploy, "weapon_m4a1", "OnSelectM4", 1) already when item that is deployed is m4a1

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

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

#define ACCESS_FLAG ADMIN_LEVEL_H

new const M4Models[][] =
{
    
"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] = 0
                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] = 1
                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] = 2
                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] = 3
                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] = 4
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
    }
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;
}

public 
OnSelectM4(id)
{
    if(!
is_valid_ent(id) || !is_user_alive(id))
        return 
HAM_IGNORED;
    
    if(
m4[id] >= 1// using >= 1 to check whether the skin id is 1 or above because 0 is default skin
    
{
        
set_pev(idpev_viewmodel2M4Models[m4[id]])
    }
    return 
HAM_IGNORED;


Last edited by Tote; 08-23-2023 at 04:56.
Tote is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-22-2023 , 13:35   Re: How can I restrict specific menu options?
Reply With Quote #13

at the moment it will not compile, because it requires to include the engine, it uses EV_SZ_viewmodel, and in the end it has to return HAM_IGNORED, the compiler will prompt you with warnings.
__________________
mlibre is offline
Tote
Senior Member
Join Date: Jul 2023
Old 08-22-2023 , 15:00   Re: How can I restrict specific menu options?
Reply With Quote #14

Quote:
Originally Posted by mlibre View Post
at the moment it will not compile, because it requires to include the engine, it uses EV_SZ_viewmodel, and in the end it has to return HAM_IGNORED, the compiler will prompt you with warnings.
There were no warnings. It compiled without any errors, but you're right I need to make it return ham ignored at the end, will do that when I'm back
Tote is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-22-2023 , 15:34   Re: How can I restrict specific menu options?
Reply With Quote #15

oh really? It's quite rare that it compiles since this "is_valid_ent" only exists in the engine and you use fakemeta, that's why I say it
__________________
mlibre is offline
Tote
Senior Member
Join Date: Jul 2023
Old 08-23-2023 , 04:12   Re: How can I restrict specific menu options?
Reply With Quote #16

Quote:
Originally Posted by mlibre View Post
oh really? It's quite rare that it compiles since this "is_valid_ent" only exists in the engine and you use fakemeta, that's why I say it
My bad I thought i included engine, but I didnt. Updated my post, fixed the ham_ignore error & compilation include missing problem.

Last edited by Tote; 08-23-2023 at 04:56.
Tote is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 08-24-2023 , 12:01   Re: How can I restrict specific menu options?
Reply With Quote #17

change

PHP Code:
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] = 0
                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] = 1
                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] = 2
                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] = 3
                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] = 4
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
    }
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;

with this
Code:
public menu_handler( id, menu, item ) {     menu_destroy( menu );     if(~get_user_flags(id) & ACCESS_FLAG)     {         client_print(id, print_chat, "Sorry, You do not have access to this m4 skin!");         return     }         m4[id] = item     client_print(id, print_chat, "You selected m4 skin: %s", SkinNames[item])     return }

Last edited by lexzor; 08-24-2023 at 12:02.
lexzor is offline
jesusaliso
Member
Join Date: Aug 2013
Location: Venezuela
Old 08-24-2023 , 12:11   Re: How can I restrict specific menu options?
Reply With Quote #18

Guys when I get back from work, I'm going to try the code! thank you so much!
jesusaliso is offline
Send a message via Skype™ to jesusaliso
Tote
Senior Member
Join Date: Jul 2023
Old 08-24-2023 , 12:39   Re: How can I restrict specific menu options?
Reply With Quote #19

Quote:
Originally Posted by lexzor View Post
change

PHP Code:
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] = 0
                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] = 1
                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] = 2
                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] = 3
                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] = 4
                client_print
(idprint_chat"You selected m4 skin: %s"SkinNames[m4[id]])
            }
        }
    }
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;

with this
Code:
public menu_handler( id, menu, item ) {     menu_destroy( menu );     if(~get_user_flags(id) & ACCESS_FLAG)     {         client_print(id, print_chat, "Sorry, You do not have access to this m4 skin!");         return     }         m4[id] = item     client_print(id, print_chat, "You selected m4 skin: %s", SkinNames[item])     return }
it will restrict all menu items for all players who dont have this access.
he wants to make specific item restrict for player who dont have the required access

Quote:
Originally Posted by jesusaliso View Post
Guys when I get back from work, I'm going to try the code! thank you so much!
welcome, you can try the code which i sent above

Last edited by Tote; 08-24-2023 at 12:41.
Tote is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-25-2023 , 01:42   Re: How can I restrict specific menu options?
Reply With Quote #20

No, using callbacks as shown in the example I linked to is the most efficient way to do this. There is no reason to waste a player's time by having him think he can select an option when he can't actually select it and then having to re-open the menu.
__________________
fysiks 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 15:35.


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