#include <amxmodx>
#include <amxmisc>
#include <reapi>
new const PLUGIN_VERSION[] = "1.0";
// Native from custom_weapon_ethereal.amxx plugin
native give_custom_weapon_ethereal(id, GiveType:givetype);
#if !defined MAX_MENU_LENGTH
#define MAX_MENU_LENGTH 512
#endif
/****************************************************************************************
****************************************************************************************/
#define ETHEREALMENU_KEYS (MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0)
const PLAYERS_PER_PAGE = 8;
/****************************************************************************************
****************************************************************************************/
new g_iAccess = ADMIN_IMMUNITY;
new g_iMenuPlayers[MAX_PLAYERS+1][MAX_PLAYERS], g_iMenuPosition[MAX_PLAYERS+1];
public plugin_init()
{
register_plugin("Ethereal Menu", PLUGIN_VERSION, "w0w");
register_dictionary("eth_menu.ini");
register_clcmd("eth_menu", "func_EthClCmd");
register_clcmd("say /ethmenu", "func_EthClCmd");
register_clcmd("say_team /ethmenu", "func_EthClCmd");
register_menu("func_EtherealMenu", ETHEREALMENU_KEYS, "func_EtherealMenu_Handler");
new pCvar = create_cvar("eth_menu_access", "a", FCVAR_NONE, "ETH_MENU_CVAR_ACCESS");
hook_cvar_change(pCvar, "hook_CvarChange_Access");
AutoExecConfig(true, "eth_menu");
}
public func_EthClCmd(id)
{
if(g_iAccess > 0 && !(get_user_flags(id) & g_iAccess))
return PLUGIN_HANDLED;
func_EtherealMenu(id, 0);
return PLUGIN_HANDLED;
}
public func_EtherealMenu(id, iPage)
{
if(iPage < 0)
return PLUGIN_HANDLED;
new iPlayerCount;
for(new i = 1; i <= MaxClients; i++)
{
if(!is_user_alive(i))
continue;
g_iMenuPlayers[id][iPlayerCount++] = i;
}
SetGlobalTransTarget(id);
new i = min(iPage * PLAYERS_PER_PAGE, iPlayerCount);
new iStart = i - (i % PLAYERS_PER_PAGE);
new iEnd = min(iStart + PLAYERS_PER_PAGE, iPlayerCount);
g_iMenuPosition[id] = iPage = iStart / PLAYERS_PER_PAGE;
new szMenu[MAX_MENU_LENGTH], iMenuItem, iKeys = (MENU_KEY_0), iPagesNum;
iPagesNum = (iPlayerCount / PLAYERS_PER_PAGE + ((iPlayerCount % PLAYERS_PER_PAGE) ? 1 : 0));
new iLen = formatex(szMenu, charsmax(szMenu), "\y%l \d\R%d/%d^n^n", "ETH_MENU_TITLE", iPage + 1, iPagesNum);
for(new a = iStart; a < iEnd; ++a)
{
iPlayer = g_iMenuPlayers[id][a];
iKeys |= (1<<iMenuItem);
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y%d. \w%n^n", ++iMenuItem, g_iMenuPlayers[id][a]);
}
if(iEnd != iPlayerCount)
{
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\y9. \w%l^n\y0. \w%l", "ETH_MENU_NEXT", iPage ? "ETH_MENU_BACK" : "ETH_MENU_EXIT");
iKeys |= (MENU_KEY_9);
}
else
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n\y0. \w%l", iPage ? "ETH_MENU_BACK" : "ETH_MENU_EXIT");
show_menu(id, iKeys, szMenu, -1, "func_EtherealMenu");
return PLUGIN_HANDLED;
}
public func_EtherealMenu_Handler(id, iKey)
{
switch(iKey)
{
case 8: func_EtherealMenu(id, ++g_iMenuPosition[id]);
case 9: func_EtherealMenu(id, --g_iMenuPosition[id]);
default:
{
new iTarget = g_iMenuPlayers[id][(g_iMenuPosition[id] * PLAYERS_PER_PAGE) + iKey];
if(!is_user_alive(id))
{
client_print_color(id, iTarget, "%l", "ETH_MENU_ERROR_DEAD");
return func_EtherealMenu(id, g_iMenuPosition[id]);
}
give_custom_weapon_ethereal(iTarget, GT_DROP_AND_REPLACE);
client_print_color(id, iTarget, "%l", "ETH_MENU_SUCCESS", iTarget);
func_EtherealMenu(id, g_iMenuPosition[id]);
}
}
return PLUGIN_HANDLED;
}
public hook_CvarChange_Access(pCvar, const szOldValue[], const szNewValue[])
{
g_iAccess = read_flags(szNewValue);
}