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

Solved menu_additem flag


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 03-17-2023 , 21:12   menu_additem flag
Reply With Quote #1

Hello, I have a question
If I add a flag to menu_additem
How do I add a message of no access to it?
__________________

Last edited by amirwolf; 02-17-2024 at 12:34.
amirwolf is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 03-18-2023 , 00:06   Re: menu_additem flag
Reply With Quote #2

Using paccess param from menu_additem will disable item from being pressed if you don't have specified access.
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define VIP_FLAG "t"
#define _VIP_FLAG ADMIN_LEVEL_H

public plugin_init()
    
register_clcmd("say test""run_test")

public 
run_test(id){
    new 
menu menu_create("My menu""menu_handler")
    
menu_additem(menu"Item 1", .paccess=_VIP_FLAG)
    
menu_additem(menufmt("%sItem 2"has_flag(idVIP_FLAG) ? "" "\d"))
    
menu_display(idmenu)
}

public 
menu_handler(idmenuitem){
    switch (
item) {
        case 
0client_print(idprint_chat"Item 1")
        case 
1client_print(idprint_chat"%s"has_flag(idVIP_FLAG) ? "Item 2" "You don't have permission")
    }

    
menu_destroy(menu)

__________________
bigdaddy424 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-18-2023 , 00:25   Re: menu_additem flag
Reply With Quote #3

If you add a flag in the "paccess" argument of menu_additem(), the item is automatically greyed out and disabled in the menu if the player does not have that access flag. Nothing else is needed.

EDIT: Looks like someone posted since I first opened the thread (had to leave for a while).
__________________

Last edited by fysiks; 03-18-2023 at 00:27.
fysiks is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 03-18-2023 , 08:26   Re: menu_additem flag
Reply With Quote #4

For example, I have this
No access message?
PHP Code:
#include <amxmodx>
#include <cstrike>

enum _:Models
{
    
Name[20],
    
NameModel[20],
    
RUTA[126],
    
FlagAdmin
}

new const 
g_eModels[][Models] =
{
    { 
"hutao""hutao""models/player/hutao/hutao.mdl" ADMIN_ALL},
    { 
"spiderman""admin_spiderman""models/player/donald/admin_spiderman.mdl"ADMIN_SLAY},
    { 
"woailuo""flash_woailuo""models/player/donald/flash_woailuo.mdl"ADMIN_LEVEL_B}
}

public 
plugin_init()
{
    
register_clcmd("say /test""ModelMenu")
}

public 
plugin_precache()
{
    for(new 
isizeof(g_eModels); i++)
        
precache_generic(g_eModels[i][RUTA])
}

public 
ModelMenu(id)
{
    new 
iMenu menu_create("Models Menu""ModelsHandler")
    
    for(new 
isizeof(g_eModels); i++)
        
menu_additem(iMenug_eModels[i][Name], ""g_eModels[i][FlagAdmin])
    
menu_display(idiMenu0)
    
    return 
PLUGIN_HANDLED
}

public 
ModelsHandler(idiMenuiItem){
    if(
iItem == MENU_EXIT)
    {
        
menu_destroy(iMenu);
        return 
PLUGIN_HANDLED;
    }
    
cs_set_user_model(idg_eModels[iItem][NameModel])
    
client_print(idprint_chat"Selected Model: %s"g_eModels[iItem][Name])
    return 
PLUGIN_HANDLED

__________________
amirwolf is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 03-18-2023 , 11:45   Re: menu_additem flag
Reply With Quote #5

if you want a chat message you can pass the flag as a string and check in menu callback if the user has the specified flag or flags

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

enum _:Models
{
    
Name[20],
    
NameModel[20],
    
RUTA[126],
    
FlagAdmin[6]
}

new const 
g_eModels[][Models] =
{
    
//changed the flag as a string (you must use read_flags to transform it in bytes and use get_user_flags)
    
"hutao""hutao""models/player/hutao/hutao.mdl" "a" },
    { 
"spiderman""admin_spiderman""models/player/donald/admin_spiderman.mdl""b"},
    { 
"woailuo""flash_woailuo""models/player/donald/flash_woailuo.mdl""c"}
}

public 
plugin_init()
{
    
register_clcmd("say /test""ModelMenu")
}

public 
plugin_precache()
{
    for(new 
isizeof(g_eModels); i++)
    {
        
//better check if the model exists so the server won't crash
        //doesn't make any sense here but it s a good practice
        
if(file_exists(g_eModels[i][RUTA]))
        {
            
precache_generic(g_eModels[i][RUTA])
        }
        else 
        {
            
log_amx("Model ^"%s^" does not exists"g_eModels[i][RUTA])
        }
    }
}

public 
ModelMenu(id)
{
    new 
iMenu menu_create("Models Menu""ModelsHandler")
    
    for(new 
isizeof(g_eModels); i++)
    {
        
// i'm just passing the flag from the global var as string data
        
menu_additem(iMenug_eModels[i][Name], g_eModels[i][FlagAdmin])
    }

    
menu_display(idiMenu0)
    
    return 
PLUGIN_HANDLED
}

public 
ModelsHandler(idiMenuiItem){
    if(
iItem == MENU_EXIT)
    {
        
menu_destroy(iMenu);
        return 
PLUGIN_HANDLED;
    }

    new 
szModelName[64], szFlag[6]
    
menu_item_getinfo(iMenuiItem_szFlagcharsmax(szFlag), szModelNamecharsmax(szModelName))

    if(!(
get_user_flags(id) & read_flags(szFlag)))
    {
        
client_print(idprint_chat"You don't have the access to use ^"%s^" model"szModelName)
        
ModelMenu(id)
        return 
PLUGIN_HANDLED
    
}

    
cs_set_user_model(idg_eModels[iItem][NameModel])
    
client_print(idprint_chat"Selected Model: %s"g_eModels[iItem][Name])
    
    return 
PLUGIN_HANDLED

lexzor is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 03-18-2023 , 11:59   Re: menu_additem flag
Reply With Quote #6

I already tried using menu_item_getinfo
But it didn't work, I think the reason was the incorrect use of flags
Thanks, now I understand the problem
Edit
But still not what I was looking for
__________________

Last edited by amirwolf; 03-18-2023 at 12:10.
amirwolf is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 03-18-2023 , 12:13   Re: menu_additem flag
Reply With Quote #7

what are you looking for? don't understand
lexzor is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 03-18-2023 , 16:30   Re: menu_additem flag
Reply With Quote #8

you need something like this but keep in mind that the folder name must match player model name.
for eg. elastigirl/elastigirl.mdl and not extra/elastigirl.mdl

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <hamsandwich>

enum _:Models
{
    
Name[20],
    
NameModel[20],
    
RUTA[126],
    
FlagAdmin
}

new const 
g_eModels[][Models] =
{
    { 
"hutao""hutao""models/player/hutao/hutao.mdl" ADMIN_ALL},
    { 
"spiderman""admin_spiderman""models/player/donald/admin_spiderman.mdl"ADMIN_SLAY},
    { 
"woailuo""flash_woailuo""models/player/donald/flash_woailuo.mdl"ADMIN_LEVEL_B
}

new 
my_model[MAX_PLAYERS 1]

public 
plugin_init()
{
    
register_clcmd("say /test""ModelMenu")
    
RegisterHam(Ham_Spawn"player""HookSpawn"1)
}

public 
plugin_precache()
{
    for(new 
isizeof(g_eModels); i++)
        
precache_generic(g_eModels[i][RUTA])
}

public 
client_putinserver(id)
    
my_model[id] = 0

public HookSpawn(id)
    
cs_set_user_model(idg_eModels[my_model[id]][NameModel])

public 
ModelMenu(id)
{
    new 
iMenu menu_create("Models Menu""ModelsHandler")
    
    for(new 
isizeof(g_eModels); i++)
        
menu_additem(iMenug_eModels[i][Name])
    
menu_display(idiMenu0)
    
    return 
PLUGIN_HANDLED
}

public 
ModelsHandler(idiMenuiItem){
    if (
iItem MENU_MORE){
        if (
access(idg_eModels[iItem][FlagAdmin])){
            
my_model[id] = iItem
            cs_set_user_model
(idg_eModels[my_model[id]][NameModel])
            
client_print(idprint_chat"Selected Model: %s"g_eModels[my_model[id]][Name])
            
        }
        
        else
            
client_print(idprint_chat"You don't have permission")
    }

    
menu_destroy(iMenu)

__________________

Last edited by bigdaddy424; 03-18-2023 at 18:01.
bigdaddy424 is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 03-18-2023 , 16:55   Re: menu_additem flag
Reply With Quote #9

Thanks to both of you
Another question, if I want the model to be reloaded after each Spawn
How to connect the selected model?
If a person has not chosen a model, I will choose a specific model for him
__________________
amirwolf is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 03-18-2023 , 18:02   Re: menu_additem flag
Reply With Quote #10

i edited my prev post, i think it should work just fine
__________________
bigdaddy424 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 14:26.


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