This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[CODE] Players menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-09-2012 , 14:28   [CODE] Players menu
Reply With Quote #1

Here is a function i wrote to put a list of players into a certain menu. Its just to get you somewhere if you need to put a player list into your menu. The data it puts to each item is [source];[playerID]
You can pass "" as the source to this function if you don't need it. Separate your data by the ; delimiter in whatever manner you see fit.

@RETURN: amount of players in the list
@ PARAMETER:
p_menu: pointer to the menu in which to put the list
source[]: data to pass to the item signifying where the menu came from
itemAccess: Admin access to utilize this menu
getPlayersFlags[]: Flags to use in the getPlayers() function
@NOTE: feel free to remove the semicolon from the formatex statement if you don't use the source parameter.

PHP Code:
    /*   THIS FUNCTION AUTOMATICALLY SETS THE EXIT (creates a useable menu)
       p_menu is a pointer to the menu that we're going to add the players list to
       source[] is the source menu to keep track of what's going on internally
       itemAccess is the "access" paramater for menu_additem
       getPlayersFlags[] is a string of flags for the get_players command 
       RETURNS: number of players in the list */
mhlp_getPlayerMenu(&p_menusource[]="fal"itemAccess=0getPlayersFlags[]="ch")
{
    new 
players[32], playerplyrCnt
    
new sz_name[32], sz_info[8]
    
get_players(playersplyrCntgetPlayersFlags)
    
    for(new 
i=0i<plyrCnti++)
    {
        
player players[i]
        
get_user_name(playersz_namecharsmax(sz_name) )
        
formatex(sz_infocharsmax(sz_info), "%s;%d"sourceplayer)
        
menu_additem(p_menusz_namesz_infoitemAccess)
    }
    
    
menu_setprop(p_menuMPROP_EXITMEXIT_ALL)
    return 
plyrCnt

__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-09-2012 , 19:28   Re: [CODE] Players menu
Reply With Quote #2

Made this some time ago :

PHP Code:
USERID_MakePlayerMenu(id, const szMenuTitle[], const szMenuHandler[], iFlags PLMENU_OBEY_IMMUNITY)
{
    new 
iMenu menu_create(szMenuTitleszMenuHandler)
    new 
bool:bIsSuperAdmin
    
if( iFlags PLMENU_OBEY_IMMUNITY )
    {
        
bIsSuperAdmin = !!(get_user_flags(id) & ADMIN_RCON)
    }

    new 
iPlayers[32], iNumiPlayerszPlayerName[32], szUserId[32]
    new 
szFlags[4] = "h"
    
if( iFlags PLMENU_ONLY_ALIVE )
    {
        
szFlags[++iNum] = 'a'
    
}
    if( 
flags PLMENU_NO_BOTS )
    {
        
szFlags[++iNum] = 'c'
    
}

    
get_players(iPlayersiNumszFlags)

    for(--
iNumiNum>=0iNum--)
    {
        
iPlayer iPlayers[iNum]
        
get_user_name(iPlayerszPlayerNamecharsmax(szPlayerName))

        if(    
iFlags PLMENU_OBEY_IMMUNITY && !bIsSuperAdmin
        
&&    ( (get_user_flags(iPlayer) & ADMIN_IMMUNITY) && 
            ((
iFlags PLMENU_ALLOW_SELF) ? (id != iPlayer) : true) )    )
        {
            
menu_addtext(iMenuszPlayerName)
        }
        else
        {
            
formatex(szUserIdcharsmax(szUserId), "%d"get_user_userid(iPlayer))
            
menu_additem(iMenuszPlayerNameszUserId0)
        }
    }

    return 
iMenu
}

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

    new 
szUserId[32], szPlayerName[32], iPlayer
    menu_item_getinfo
(iMenuiItemiCRAPszUserIdcharsmax(szUserId), szPlayerNamecharsmax(szPlayerName), iPlayer /* tip */)

    if( (
iPlayer find_player("k"str_to_num(szUserId)))  )
    {
        new 
szName[32]
        
get_user_name(iPlayerszNamecharsmax(szName))
        
client_print(idprint_chat"You have chosen #%s %s %s"szUserIdszPlayerNameszName)
    }
    else
    {
        
client_print(idprint_chat"Player %s<%s> seems to be disconnected"szPlayerNameszAuthid)
    }
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 06-11-2012 , 12:39   Re: [CODE] Players menu
Reply With Quote #3

What means this !!(get_user_flags(id)) & ADMIN_RCON) should not it be only one exclamation symbol?
__________________
Steam: stickp0le
StickP0le is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-11-2012 , 12:42   Re: [CODE] Players menu
Reply With Quote #4

Quote:
Originally Posted by StickP0le View Post
What means this !!(get_user_flags(id)) & ADMIN_RCON) should not it be only one exclamation symbol?
It converts any value other than 0 to 1.
If the value is 0, then !!0 = 0.

Basically converts any value to a proper boolean value.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 06-11-2012 , 12:59   Re: [CODE] Players menu
Reply With Quote #5

It means that if the returned value is 2 or higher it Will convert into 1 and if it returned 0 it Will be 0 ?
__________________
Steam: stickp0le
StickP0le is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-11-2012 , 13:08   Re: [CODE] Players menu
Reply With Quote #6

Quote:
Originally Posted by StickP0le View Post
It means that if the returned value is 2 or higher it Will convert into 1 and if it returned 0 it Will be 0 ?
Yes, but don't forget that negative values will also be 1.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 06-11-2012 , 13:32   Re: [CODE] Players menu
Reply With Quote #7

Thanks!
__________________
Steam: stickp0le
StickP0le 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 17:26.


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