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

admin menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 07-15-2023 , 21:38   admin menu
Reply With Quote #1

I have a doubt here how do I display only the other player's dispenser and ignore the admin dispensers
code is working correctly but all dispensers appear including the admin itself, I want to know how to remove only from the admin

PHP Code:
public xMenuDispenser(id)
{
    new 
pMenu menu_create("Menu Dispenser""xMenuDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(!
pev_valid(iEnt))
        {
            
iOwner != id && is_user_admin(id)

            if(
iOwner != id && is_user_admin(id))
                continue;
        }
        
iLevel  pev(iEntDISPENSER_LEVEL);
        
iHealth pev(iEntpev_health);
        
iOwner  pev(iEntDISPENSER_OWNER);
        
num_to_str(iEntsEntIdcharsmax(sEntId));

        
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
    } 
    
menu_display(idpMenu0);

yagami is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-15-2023 , 22:39   Re: admin menu
Reply With Quote #2

You're adding items to the menu unconditionally when the entity is valid. Also, you're using the variable iOwner before you even assign it a value.

For people new to programming, I generally recommend that you most often use positive logic with if statements instead of trying to do negated conditions and/or things like "continue". Sometimes, these can be added in later, after your logic is working, when you refactor for optimization (but note that it's not always an optimization to use some of these tricks and also often make it harder to understand the code and should just be left alone).

Try something more like this:

PHP Code:
    while((iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if( 
pev_valid(iEnt) )
        {
            
iLevel  pev(iEntDISPENSER_LEVEL);
            
iHealth pev(iEntpev_health);
            
iOwner  pev(iEntDISPENSER_OWNER);

            if( 
/* should add to the menu */ )
            {
                
num_to_str(iEntsEntIdcharsmax(sEntId));
                
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
            }
        }
    } 
__________________
fysiks is offline
yagami
Senior Member
Join Date: Jan 2021
Old 07-16-2023 , 07:01   Re: admin menu
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
You're adding items to the menu unconditionally when the entity is valid. Also, you're using the variable iOwner before you even assign it a value.

For people new to programming, I generally recommend that you most often use positive logic with if statements instead of trying to do negated conditions and/or things like "continue". Sometimes, these can be added in later, after your logic is working, when you refactor for optimization (but note that it's not always an optimization to use some of these tricks and also often make it harder to understand the code and should just be left alone).

Try something more like this:

PHP Code:
    while((iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if( 
pev_valid(iEnt) )
        {
            
iLevel  pev(iEntDISPENSER_LEVEL);
            
iHealth pev(iEntpev_health);
            
iOwner  pev(iEntDISPENSER_OWNER);

            if( 
/* should add to the menu */ )
            {
                
num_to_str(iEntsEntIdcharsmax(sEntId));
                
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
            }
        }
    } 
How does it look now?
This part here is only for admins where they can destroy any dispenser, but I don't want another admin's dispenser or his own to appear.

PHP Code:
public xMenuAdminDispenser(id)
{
    new 
pMenu menu_create("Menu Dispenser""xMenuAdminDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(!
pev_valid(iEnt))
        {
            
iLevel  pev(iEntDISPENSER_LEVEL);
            
iHealth pev(iEntpev_health);
            
iOwner  pev(iEntDISPENSER_OWNER);
            
num_to_str(iEntsEntIdcharsmax(sEntId));

            if(
iOwner != id && is_user_admin(id))
            {
                
num_to_str(iEntsEntIdcharsmax(sEntId));
                
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
            }
        }
    }
}

public 
xMenuAdminDispenserHandler(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return;
    }

    new 
szData[6], szName[64], accesscallback;
    
menu_item_getinfo(menuitemaccessszDatacharsmax(szData), szNamecharsmax(szName), callback);

    new 
ent str_to_num(szData)  

    if(
pev_valid(ent))
    {
        new 
iOwner pev(entDISPENSER_OWNER);

        if(
is_user_admin(id) && id != iOwner)
        {
            
client_print_color(0print_team_default"%s ^3Admin %n destroyed his ^4Dispenser^3"PREFIX_CHATiOwner);
            
g_DispPlayerCount[iOwner]--;
            
xLimitGlobal[cs_get_user_team(iOwner)]--
            
isEnt[ent] = false
            xRemoveEntFix
(ent);
        }
    }

yagami is offline
yagami
Senior Member
Join Date: Jan 2021
Old 07-16-2023 , 09:21   Re: admin menu
Reply With Quote #4

Quote:
Originally Posted by yagami View Post
How does it look now?
This part here is only for admins where they can destroy any dispenser, but I don't want another admin's dispenser or his own to appear.

PHP Code:
public xMenuAdminDispenser(id)
{
    new 
pMenu menu_create("Menu Dispenser""xMenuAdminDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(!
pev_valid(iEnt))
        {
            
iLevel  pev(iEntDISPENSER_LEVEL);
            
iHealth pev(iEntpev_health);
            
iOwner  pev(iEntDISPENSER_OWNER);
            
num_to_str(iEntsEntIdcharsmax(sEntId));

            if(
iOwner != id && is_user_admin(id))
            {
                
num_to_str(iEntsEntIdcharsmax(sEntId));
                
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
            }
        }
    }
}

public 
xMenuAdminDispenserHandler(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return;
    }

    new 
szData[6], szName[64], accesscallback;
    
menu_item_getinfo(menuitemaccessszDatacharsmax(szData), szNamecharsmax(szName), callback);

    new 
ent str_to_num(szData)  

    if(
pev_valid(ent))
    {
        new 
iOwner pev(entDISPENSER_OWNER);

        if(
is_user_admin(id) && id != iOwner)
        {
            
client_print_color(0print_team_default"%s ^3Admin %n destroyed his ^4Dispenser^3"PREFIX_CHATiOwner);
            
g_DispPlayerCount[iOwner]--;
            
xLimitGlobal[cs_get_user_team(iOwner)]--
            
isEnt[ent] = false
            xRemoveEntFix
(ent);
        }
    }

L 07/16/2023 - 10:20:43: Invalid menu id 0(0)
L 07/16/2023 - 10:20:43: [AMXX] Displaying debug trace (plugin "testedispenser.amxx", version "1.5")
L 07/16/2023 - 10:20:43: [AMXX] Run time error 10: native error (native "menu_item_getinfo")
L 07/16/2023 - 10:20:43: [AMXX] [0] testedispenser.sma:MenuAdminDispenserHandle r (line 1710)
yagami is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 07-16-2023 , 10:13   Re: admin menu
Reply With Quote #5

I don't have a lot of experience on stuff like this, but to me it seems you should check if the dispenser is one of another admin. Loop through all players and check for admins and set a bool to true for all the admins with a dispenser of their own. Then your check should look something like this:

PHP Code:
if(is_user_admin(id) && iOwner && iAdmin[iPlayers]) // use get_players() 
After you've done this, you should be able to filter out the remaining dispensers which are not your own or not one of any other admin.

Correct me if i'm wrong here, just trying to help out.
__________________

Last edited by Napoleon_be; 07-16-2023 at 10:15.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
yagami
Senior Member
Join Date: Jan 2021
Old 07-16-2023 , 12:17   Re: admin menu
Reply With Quote #6

Quote:
Originally Posted by Napoleon_be View Post
I don't have a lot of experience on stuff like this, but to me it seems you should check if the dispenser is one of another admin. Loop through all players and check for admins and set a bool to true for all the admins with a dispenser of their own. Then your check should look something like this:

PHP Code:
if(is_user_admin(id) && iOwner && iAdmin[iPlayers]) // use get_players() 
After you've done this, you should be able to filter out the remaining dispensers which are not your own or not one of any other admin.

Correct me if i'm wrong here, just trying to help out.
PHP Code:
public xMenuDispenser(id)
{
    new 
pMenu menu_create("Menu Dispenser""xMenuDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(!
pev_valid(iEnt))
        {
            
iOwner != id && is_user_admin(id)

            if(
iOwner != id && is_user_admin(id))
                continue;
        }
        
iLevel  pev(iEntDISPENSER_LEVEL);
        
iHealth pev(iEntpev_health);
        
iOwner  pev(iEntDISPENSER_OWNER);
        
num_to_str(iEntsEntIdcharsmax(sEntId));

        
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rVida:\w[%d]"iLeveliHealth), sEntId)
    } 
    
menu_display(idpMenu0);
}

public 
xMenuDispenserHandler(idmenuitem)

    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return;
    }

    new 
szData[6], szName[64], accesscallback;
    
menu_item_getinfo(menuitemaccessszDatacharsmax(szData), szNamecharsmax(szName), callback);

    new 
ent str_to_num(szData)  

    if(
pev_valid(ent))
    {
        
client_print_color(0print_team_default"%s ^3Voce destruiu seu ^4Dispenser^3"PREFIX_CHAT)
        
g_DispPlayerCount[id]--;
        
xLimitGlobal[cs_get_user_team(id)]--
        
isEnt[ent] = false    
        xRemoveEntFix
(ent);
        
xGiveMoneyDisp(id);
    }
}

public 
xMenuAdminDispenser(id)
{
    if(!
is_user_connected(id))
        return 
PLUGIN_HANDLED
        
    
new pMenu menu_create("Menu Dispenser""xMenuAdminDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(!
pev_valid(iEnt))
        {
            
iLevel  pev(iEntDISPENSER_LEVEL);
            
iHealth pev(iEntpev_health);
            
iOwner  pev(iEntDISPENSER_OWNER);
            
num_to_str(iEntsEntIdcharsmax(sEntId));

            if(
iOwner != id && is_user_admin(id))
            {
                
num_to_str(iEntsEntIdcharsmax(sEntId));
                
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
            }
        }
        
menu_display(idpMenu0)
    }
    return 
PLUGIN_HANDLED
}

public 
xMenuAdminDispenserHandler(idmenuitem)
{
    new 
szData[6], szName[64], accesscallback;
    
menu_item_getinfo(menuitemaccessszDatacharsmax(szData), szNamecharsmax(szName), callback);

    new 
ent str_to_num(szData)  

    if(
pev_valid(ent))
    {
        new 
iOwner pev(entDISPENSER_OWNER);

        if(!
is_user_admin(id) && iOwner)
        {
            
client_print_color(0print_team_default"%s ^3Admin %n destroyed his ^4Dispenser^3"PREFIX_CHATiOwner);
            
g_DispPlayerCount[iOwner]--;
            
xLimitGlobal[cs_get_user_team(iOwner)]--
            
isEnt[ent] = false
            xRemoveEntFix
(ent);
        }
    }
    

menu is not even opening
L 07/16/2023 - 13:17:28: Invalid menu id 0(0)
L 07/16/2023 - 13:17:28: [AMXX] Displaying debug trace (plugin "testedispenser.amxx", version "1.5")
L 07/16/2023 - 13:17:28: [AMXX] Run time error 10: native error (native "menu_item_getinfo")
L 07/16/2023 - 13:17:28: [AMXX] [0] testedispenser.sma:MenuAdminDispenserHandle r (line 1711)
L 07/16/2023 - 13:17:28: [testedispenser.amxx] performance issue. Function xMenuAdminDispenserHandler executed more than 38.1ms.
yagami is offline
yagami
Senior Member
Join Date: Jan 2021
Old 07-16-2023 , 13:51   Re: admin menu
Reply With Quote #7

Quote:
Originally Posted by yagami View Post
PHP Code:
public xMenuDispenser(id)
{
    new 
pMenu menu_create("Menu Dispenser""xMenuDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(!
pev_valid(iEnt))
        {
            
iOwner != id && is_user_admin(id)

            if(
iOwner != id && is_user_admin(id))
                continue;
        }
        
iLevel  pev(iEntDISPENSER_LEVEL);
        
iHealth pev(iEntpev_health);
        
iOwner  pev(iEntDISPENSER_OWNER);
        
num_to_str(iEntsEntIdcharsmax(sEntId));

        
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rVida:\w[%d]"iLeveliHealth), sEntId)
    } 
    
menu_display(idpMenu0);
}

public 
xMenuDispenserHandler(idmenuitem)

    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return;
    }

    new 
szData[6], szName[64], accesscallback;
    
menu_item_getinfo(menuitemaccessszDatacharsmax(szData), szNamecharsmax(szName), callback);

    new 
ent str_to_num(szData)  

    if(
pev_valid(ent))
    {
        
client_print_color(0print_team_default"%s ^3Voce destruiu seu ^4Dispenser^3"PREFIX_CHAT)
        
g_DispPlayerCount[id]--;
        
xLimitGlobal[cs_get_user_team(id)]--
        
isEnt[ent] = false    
        xRemoveEntFix
(ent);
        
xGiveMoneyDisp(id);
    }
}

public 
xMenuAdminDispenser(id)
{
    if(!
is_user_connected(id))
        return 
PLUGIN_HANDLED
        
    
new pMenu menu_create("Menu Dispenser""xMenuAdminDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(!
pev_valid(iEnt))
        {
            
iLevel  pev(iEntDISPENSER_LEVEL);
            
iHealth pev(iEntpev_health);
            
iOwner  pev(iEntDISPENSER_OWNER);
            
num_to_str(iEntsEntIdcharsmax(sEntId));

            if(
iOwner != id && is_user_admin(id))
            {
                
num_to_str(iEntsEntIdcharsmax(sEntId));
                
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
            }
        }
        
menu_display(idpMenu0)
    }
    return 
PLUGIN_HANDLED
}

public 
xMenuAdminDispenserHandler(idmenuitem)
{
    new 
szData[6], szName[64], accesscallback;
    
menu_item_getinfo(menuitemaccessszDatacharsmax(szData), szNamecharsmax(szName), callback);

    new 
ent str_to_num(szData)  

    if(
pev_valid(ent))
    {
        new 
iOwner pev(entDISPENSER_OWNER);

        if(!
is_user_admin(id) && iOwner)
        {
            
client_print_color(0print_team_default"%s ^3Admin %n destroyed his ^4Dispenser^3"PREFIX_CHATiOwner);
            
g_DispPlayerCount[iOwner]--;
            
xLimitGlobal[cs_get_user_team(iOwner)]--
            
isEnt[ent] = false
            xRemoveEntFix
(ent);
        }
    }
    

menu is not even opening
L 07/16/2023 - 13:17:28: Invalid menu id 0(0)
L 07/16/2023 - 13:17:28: [AMXX] Displaying debug trace (plugin "testedispenser.amxx", version "1.5")
L 07/16/2023 - 13:17:28: [AMXX] Run time error 10: native error (native "menu_item_getinfo")
L 07/16/2023 - 13:17:28: [AMXX] [0] testedispenser.sma:MenuAdminDispenserHandle r (line 1711)
L 07/16/2023 - 13:17:28: [testedispenser.amxx] performance issue. Function xMenuAdminDispenserHandler executed more than 38.1ms.

PHP Code:
public xMenuAdminDispenser(id)
{
    new 
pMenu menu_create("Menu Dispenser""xMenuAdminDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(
pev_valid(iEnt))
        {
            
iLevel  pev(iEntDISPENSER_LEVEL);
            
iHealth pev(iEntpev_health);
            
iOwner  pev(iEntDISPENSER_OWNER);
            
num_to_str(iEntsEntIdcharsmax(sEntId));

            if(
iOwner && is_user_admin(id))
            {
                
num_to_str(iEntsEntIdcharsmax(sEntId));
                
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
            }
        }
    }
    
menu_display(idpMenu0);
}

public 
xMenuAdminDispenserHandler(idpMenuitem)
{
    if(
item == MENU_EXIT)
        
menu_destroy(pMenu);

    new 
szData[6], szName[64], accesscallback;
    
menu_item_getinfo(pMenuitemaccessszDatacharsmax(szData), szNamecharsmax(szName), callback);

    new 
ent str_to_num(szData)  

    if(
pev_valid(ent))
    {
        new 
iOwner pev(entDISPENSER_OWNER);

        if(!
is_user_admin(id) && iOwner)
        {
            
client_print_color(0print_team_default"%s ^3Admin %n destroyed his ^4Dispenser^3"PREFIX_CHATiOwner);
            
g_DispPlayerCount[iOwner]--;
            
xLimitGlobal[cs_get_user_team(iOwner)]--
            
isEnt[ent] = false
            xRemoveEntFix
(ent);
        }
    }

I just did code and it's still the same thing
yagami is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-16-2023 , 17:37   Re: admin menu
Reply With Quote #8

You made several posts with different code that it's hard to know what's going on. Don't make a new post if you're still the latest post, simply edit your last post to add information.

In this last version of the code that you posted, replace "iOwner && is_user_admin(id)" with "true" and verify that the menu is showing them all. Then, try replacing "true" with something like this: !(is_user_admin(iOwner) && id != iOwner)
__________________
fysiks is offline
yagami
Senior Member
Join Date: Jan 2021
Old 07-16-2023 , 17:49   Re: admin menu
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
You made several posts with different code that it's hard to know what's going on. Don't make a new post if you're still the latest post, simply edit your last post to add information.

In this last version of the code that you posted, replace "iOwner && is_user_admin(id)" with "true" and verify that the menu is showing them all. Then, try replacing "true" with something like this: !(is_user_admin(iOwner) && id != iOwner)
About the error I already found out what it was, I was putting the handle on when I pulled menu in init

this here is the final code but I don't know if it's working as I said, when an admin opens this menu, dispenser from other admins can't appear in the list so I did it this way

PHP Code:
public xMenuAdminDispenser(id)
{
    new 
pMenu menu_create("Menu Dispenser""xMenuAdminDispenserHandler")

    new 
iEnt = -1;
    new 
iLeveliHealthiOwnersEntId[6];

    while((
iEnt find_ent_by_class(iEntdispenser_classname)))
    {
        if(
pev_valid(iEnt))
        {
            
iLevel  pev(iEntDISPENSER_LEVEL);
            
iHealth pev(iEntpev_health);
            
iOwner  pev(iEntDISPENSER_OWNER);
            
num_to_str(iEntsEntIdcharsmax(sEntId));

            if(
is_user_admin(id) && iOwner)
            {
                
num_to_str(iEntsEntIdcharsmax(sEntId));
                
menu_additem(pMenufmt("\rLevel:\w[%d] \y|| \rLife:\w[%d] || \rOwner:\w[%d]"iLeveliHealthiOwner), sEntId)
            }
        }
    }
    
menu_display(idpMenu0);
}

public 
xMenuAdminDispenserHandler(idpMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(pMenu); 
        return;
    }

    new 
szData[6], szName[64], accesscallback;
    
menu_item_getinfo(pMenuitemaccessszDatacharsmax(szData), szNamecharsmax(szName), callback);

    new 
ent str_to_num(szData)  

    if(
pev_valid(ent))
    {
        new 
iOwner pev(entDISPENSER_OWNER);

        
client_print_color(0print_team_default"%s ^3Admin %n destroyed his ^4Dispenser^3"PREFIX_CHATiOwner);
        
g_DispPlayerCount[iOwner]--;
        
xLimitGlobal[cs_get_user_team(iOwner)]--
        
isEnt[ent] = false
        xRemoveEntFix
(ent);

    }

yagami is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-16-2023 , 18:26   Re: admin menu
Reply With Quote #10

I have no idea what you're saying. Checking is_user_admin(id) doesn't make any sense because this entire menu is only accessible by admins (according to you) so that will always be true.

If you're not going to try my suggestions, I'm going to have to stop trying to help.
__________________
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 09:28.


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