[CODE] Players menu

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1327
Gender:
United States of America

[CODE] Players menu

Post by Archive-Poster »

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.

Code: Select all

    /*   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_menu, source[]="fal", itemAccess=0, getPlayersFlags[]="ch")
{
    new players[32], player, plyrCnt
    new sz_name[32], sz_info[8]
    get_players(players, plyrCnt, getPlayersFlags)
    
    for(new i=0; i<plyrCnt; i++)
    {
        player = players[i]
        get_user_name(player, sz_name, charsmax(sz_name) )
        formatex(sz_info, charsmax(sz_info), "%s;%d", source, player)
        menu_additem(p_menu, sz_name, sz_info, itemAccess)
    }
    
    menu_setprop(p_menu, MPROP_EXIT, MEXIT_ALL)
    return plyrCnt
} 
User avatar
Archive-Poster
Posts: 1327
Gender:
United States of America

Re: [CODE] Players menu

Post by Archive-Poster »

Made this some time ago :

Code: Select all

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

    new iPlayers[32], iNum, iPlayer, szPlayerName[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(iPlayers, iNum, szFlags)

    for(--iNum; iNum>=0; iNum--)
    {
        iPlayer = iPlayers[iNum]
        get_user_name(iPlayer, szPlayerName, charsmax(szPlayerName))

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

    return iMenu
}

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

    new szUserId[32], szPlayerName[32], iPlayer
    menu_item_getinfo(iMenu, iItem, iCRAP, szUserId, charsmax(szUserId), szPlayerName, charsmax(szPlayerName), iPlayer /* tip */)

    if( (iPlayer = find_player("k", str_to_num(szUserId)))  )
    {
        new szName[32]
        get_user_name(iPlayer, szName, charsmax(szName))
        client_print(id, print_chat, "You have chosen #%s %s %s", szUserId, szPlayerName, szName)
    }
    else
    {
        client_print(id, print_chat, "Player %s<%s> seems to be disconnected", szPlayerName, szAuthid)
    }
    menu_destroy(iMenu)
    return PLUGIN_HANDLED
} 
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests