Raised This Month: $ Target: $400
 0% 

About player with immunity frag in menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GarbageBox
Senior Member
Join Date: Feb 2010
Old 01-03-2011 , 10:43   About player with immunity frag in menu
Reply With Quote #1

The code below here is I copy form this: https://forums.alliedmods.net/showth...6364#BasicMenu
But I want to know what else should add in the code then will disable to choose the player who have ADMIN_IMMUNITY frags.
I know my english is really bad, if you don't know what I'm say please look below.
1.Player1 < Normal player
2.Player2
3.Player3
4.Player4 < This player have ADMIN_IMMUNITY frag
5.Player5
Code:
 #include <amxmodx>
 #include <fun>

 public plugin_init()
 {
    //Register a way to get to your menu...
    register_clcmd( "my_player_menu","AwesomeMenu");
 }
 public AwesomeMenu(id)
 {
    //Create a variable to hold the menu
    new menu = menu_create("\rLook at this Player Menu!:", "menu_handler");

    //We will need to create some variables so we can loop through all the players
    new players[32], pnum, tempid;

    //Some variables to hold information about the players
    new szName[32], szTempid[10];

    //Fill players with available players
    get_players(players, pnum);

    //Start looping through all players
    for( new i; i<pnum; i++ )
    {
        //Save a tempid so we do not re-index
        tempid = players[i];

        //Get the players name and id as strings
        get_user_name(tempid, szName, 31);
        num_to_str(tempid, szTempid, 9);

        //Add the item for this player
        menu_additem(menu, szName, szTempid, 0);

    }

    //We now have all players in the menu, lets display the menu
    menu_display(id, menu, 0);
 }
 public menu_handler(id, menu, item)
 {
    if( item == MENU_EXIT )
    {
        menu_destroy(menu);
        return PLUGIN_HANDLED;
    }

    new data[6], iName[64];
    new access, callback;
    menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);

    //Get the id of the player that was selected
    new tempid = str_to_num(data);

    //If the player is alive
    if( is_user_alive(tempid) )
        //Set their health to 100
        set_user_health(tempid, 100);

    menu_destroy(menu);
    return PLUGIN_HANDLED;
 }
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-03-2011 , 14:21   Re: About player with immunity frag in menu
Reply With Quote #2

Use a callback function. In the call back function check if they have immunity. If they do then return ITEM_DISABLED otherwise return ITEM_ENABLED.

A callback example can be found in the New Menu Tutorial posted by Exolent.
__________________
fysiks is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 01-04-2011 , 11:35   Re: About player with immunity frag in menu
Reply With Quote #3

https://forums.alliedmods.net/showpo...0&postcount=95
I have look at this.
But I try to edit myself but still nothing change...
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-04-2011 , 21:03   Re: About player with immunity frag in menu
Reply With Quote #4

Quote:
Originally Posted by GarbageBox View Post
https://forums.alliedmods.net/showpo...0&postcount=95
I have look at this.
But I try to edit myself but still nothing change...
Show your code.
__________________
fysiks is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 01-05-2011 , 03:44   Re: About player with immunity frag in menu
Reply With Quote #5

Here I use if a player alive to do a return for check does it work, but nothing disable...
Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN	"Test Menu"
#define VERSION	"1.0"
#define AUTHOR	"..:)"

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_clcmd("amx_testmenu", "ShowMenu", ADMIN_ADMIN, "- display the Test Menu")
	
	return PLUGIN_CONTINUE
}

public ShowMenu( id )
{
	new menu = menu_create("\rTest Menu:", "MenuCommand")
	new callback = menu_makecallback("MenuCallback");

	new players[32], pnum, tempid

	new szName[32], szTempid[10]

	get_players(players, pnum)

	for( new i; i<pnum; i++ )
    {
		tempid = players[i];

		get_user_name(tempid, szName, 31)
		num_to_str(tempid, szTempid, 9)

		menu_additem(menu, szName, szTempid, callback)

    }

	menu_display(id, menu, 0);
}

public MenuCallback(id, menu, item)
{
	new data[6], iName[64];
	new access, callback;
	menu_item_getinfo(menu, item, access, data, 5, iName, 63, callback);

	new tempid = str_to_num(data);

	if( str_to_num(data) == 0 )
	{
		return is_user_alive(tempid) ? ITEM_ENABLED : ITEM_DISABLED;
	}

	return ITEM_ENABLED;
}

public MenuCommand(id, menu, item)
{
	if( item == MENU_EXIT )
	{
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}

	new data[6], iName[64];
	menu_item_getinfo(menu, item, access, data, 5, iName, 63, callback);

	new tempid = str_to_num(data);

	if( str_to_num(data) == 0 )
	{
		set_user_health(tempid, 100);
	}

	menu_destroy(menu);
	return PLUGIN_HANDLED;
}
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-05-2011 , 19:19   Re: About player with immunity frag in menu
Reply With Quote #6

PHP Code:
public MenuCallback(idmenuitem)
{
    new 
data[6], iName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata5iName63callback);

    new 
tempid str_to_num(data);

    return 
is_user_alive(tempid) ? ITEM_ENABLED ITEM_DISABLED;


__________________
fysiks is offline
GarbageBox
Senior Member
Join Date: Feb 2010
Old 01-06-2011 , 07:09   Re: About player with immunity frag in menu
Reply With Quote #7

Still no change in the menu.
What's the problem?
I replace the MenuCallback part of yours
__________________
You can be a SUPER coder but you Haven't to say such as "stupid, etc." words to the others
GarbageBox is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-06-2011 , 18:26   Re: About player with immunity frag in menu
Reply With Quote #8

Quote:
Originally Posted by GarbageBox View Post
Still no change in the menu.
What's the problem?
I replace the MenuCallback part of yours
Not sure. You will need to debug it and see what the value of tempid is (if it's not what it's supposed to be then you need to debug more). Better, yet, print all relevant variable and strings and see what they are when the callback gets called.
__________________
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 01:57.


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