Here is a very basic version of a player menu, completely ready to go, just add your commands to it, to do what you want when you select a player..
Study the code so you understand it, and then you can manipulate it, and notice that the menu displays dead players too (but grey) and you cannot select them from the menu.. that is optional, but I left the code there so you can see how that works.. it is easy to remove though..
Code:
#include <amxmodx>
#include <amxmisc>
#define MENU_SIZE 256
#define MENU_PLAYERS 8
new g_nMenuPosition
new g_nMenuPlayers[32]
public plugin_init()
{
register_clcmd( "player_menu", "PlayerMenu", ADMIN_LEVEL_A, "Shows The Player Menu" )
register_menucmd( register_menuid("\rPlayer Menu:"), 1023, "MenuAction" )
}
public PlayerMenu( id, lvl, cid )
{
if( cmd_access( id, lvl, cid, 0 ) )
ShowPlayerMenu( id, g_nMenuPosition = 0 )
return PLUGIN_HANDLED
}
public MenuAction( id, key )
{
switch( key )
{
case 8: ShowPlayerMenu( id, ++g_nMenuPosition )
case 9: ShowPlayerMenu( id, --g_nMenuPosition )
default:
{
new nPlayerID = g_nMenuPlayers[g_nMenuPosition * MENU_PLAYERS + key]
DoAction( id, nPlayerID )
// If you dont want to keep the menu Open after selecting a command,
// then simply remove the following line:
ShowPlayerMenu( id, g_nMenuPosition )
}
}
return PLUGIN_HANDLED
}
public ShowPlayerMenu( id, pos )
{
if( pos < 0 ) return
new i, iPlayerID
new szMenuBody[MENU_SIZE]
new nCurrKey = 0
new szUserName[32]
new nStart = pos * MENU_PLAYERS
new nNum
get_players( g_nMenuPlayers, nNum )
if( nStart >= nNum )
nStart = pos = g_nMenuPosition = 0
new nLen = format( szMenuBody, MENU_SIZE-1, "\rPlayer Menu:\R%d/%d^n\w^n", pos+1, (nNum / MENU_PLAYERS + ((nNum % MENU_PLAYERS) ? 1 : 0 )) )
new nEnd = nStart + MENU_PLAYERS
new nKeys = (1<<9)
if( nEnd > nNum )
nEnd = nNum
for( i = nStart; i < nEnd; i++ )
{
iPlayerID = g_nMenuPlayers[i]
get_user_name( iPlayerID, szUserName, 31 )
if( (get_user_flags(iPlayerID) & ADMIN_IMMUNITY) || !is_user_alive(iPlayerID) )
{
nCurrKey++
nLen += format( szMenuBody[nLen], (MENU_SIZE-1-nLen), "\d%d. %s^n\w", nCurrKey, szUserName )
}else
{
nKeys |= (1<<nCurrKey++)
nLen += format( szMenuBody[nLen], (MENU_SIZE-1-nLen), "%d. %s^n", nCurrKey, szUserName )
}
}
if( nEnd != nNum )
{
format( szMenuBody[nLen], (MENU_SIZE-1-nLen), "^n9. More...^n0. %s", pos ? "Back" : "Exit" )
nKeys |= (1<<8)
}
else
format( szMenuBody[nLen], (MENU_SIZE-1-nLen), "^n0. %s", pos ? "Back" : "Exit" )
show_menu( id, nKeys, szMenuBody, -1 )
return
}
public DoAction( nAdminID, nPlayerID )
{
// Do something to the selected player here using nPlayerID...
// nAdminID will be the ID of the Admin/User who ran the menu...
return PLUGIN_HANDLED
}