2009-04-29 01:58:41 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2008-10-04 22:59:11 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-29 01:58:41 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: menu.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Base menu functions for the plugin.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-29 01:58:41 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
|
|
|
|
2009-06-17 23:32:46 +02:00
|
|
|
/**
|
|
|
|
* Create commands specific to ZMenu.
|
|
|
|
*/
|
|
|
|
MenuOnCommandsCreate()
|
|
|
|
{
|
|
|
|
// Register ZMenu command.
|
|
|
|
RegConsoleCmd(SAYHOOKS_KEYWORD_ZMENU, ZMenuCommand, "Opens ZR's main menu.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Command callback (zmenu)
|
|
|
|
* Opens ZR's main menu.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param argc Argument count.
|
|
|
|
*/
|
|
|
|
public Action:ZMenuCommand(client, argc)
|
|
|
|
{
|
|
|
|
// If client is console, then stop and tell them this feature is for players only.
|
|
|
|
if (ZRIsConsole(client))
|
|
|
|
{
|
|
|
|
TranslationPrintToServer("Must be player");
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send main menu.
|
2009-06-22 06:08:26 +02:00
|
|
|
ZMenuMain(client);
|
2009-06-17 23:32:46 +02:00
|
|
|
|
|
|
|
// This stops the "Unknown command" message in client's console.
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
/**
|
|
|
|
* Show main menu to client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-06-22 06:08:26 +02:00
|
|
|
ZMenuMain(client)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
// Create menu handle.
|
2009-06-22 06:08:26 +02:00
|
|
|
new Handle:menu_main = CreateMenu(ZMenuMainHandle);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Make client global translations target.
|
2008-10-04 22:59:11 +02:00
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
2009-06-17 23:32:46 +02:00
|
|
|
decl String:publictrigger[4];
|
|
|
|
decl String:silenttrigger[4];
|
|
|
|
|
|
|
|
// Get public/silent chat triggers.
|
|
|
|
SayHooksGetPublicChatTrigger(publictrigger, sizeof(publictrigger));
|
|
|
|
SayHooksGetSilentChatTrigger(silenttrigger, sizeof(silenttrigger));
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Set menu title.
|
2009-06-17 23:32:46 +02:00
|
|
|
SetMenuTitle(menu_main, "%t\n ", "Menu main title", publictrigger, silenttrigger);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Initialize menu lines.
|
2009-06-17 23:32:46 +02:00
|
|
|
decl String:zadmin[256];
|
|
|
|
decl String:zclass[256];
|
2009-06-22 06:08:26 +02:00
|
|
|
decl String:zcookies[256];
|
2009-06-17 23:32:46 +02:00
|
|
|
decl String:zspawn[256];
|
|
|
|
decl String:ztele[256];
|
|
|
|
decl String:zhp[256];
|
|
|
|
decl String:zmarket[256];
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Translate each line into client's language.
|
2009-06-29 21:33:20 +02:00
|
|
|
Format(zadmin, sizeof(zadmin), "%t", "Menu main zadmin", SAYHOOKS_KEYWORD_ZADMIN);
|
|
|
|
Format(zclass, sizeof(zclass), "%t", "Menu main zclass", SAYHOOKS_KEYWORD_ZCLASS);
|
2009-06-22 06:08:26 +02:00
|
|
|
Format(zcookies, sizeof(zcookies), "%t", "Menu main zcookies", SAYHOOKS_KEYWORD_ZCOOKIES);
|
2009-06-29 21:33:20 +02:00
|
|
|
Format(zspawn, sizeof(zspawn), "%t", "Menu main zspawn", SAYHOOKS_KEYWORD_ZSPAWN);
|
2009-05-08 04:57:21 +02:00
|
|
|
Format(ztele, sizeof(ztele), "%t", "Menu main ztele", SAYHOOKS_KEYWORD_ZTELE);
|
|
|
|
Format(zhp, sizeof(zhp), "%t", "Menu main zhp", SAYHOOKS_KEYWORD_ZHP);
|
|
|
|
Format(zmarket, sizeof(zmarket), "%t", "Menu main zmarket", SAYHOOKS_KEYWORD_ZMARKET);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Add items to menu.
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Disable option if client isn't an admin.
|
|
|
|
new bool:admin = ZRIsClientAdmin(client);
|
|
|
|
AddMenuItem(menu_main, "zadmin", zadmin, MenuGetItemDraw(admin));
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
AddMenuItem(menu_main, "zclass", zclass);
|
2009-06-22 06:08:26 +02:00
|
|
|
AddMenuItem(menu_main, "zcookies", zcookies);
|
2008-10-04 22:59:11 +02:00
|
|
|
AddMenuItem(menu_main, "zspawn", zspawn);
|
|
|
|
AddMenuItem(menu_main, "ztele", ztele);
|
|
|
|
AddMenuItem(menu_main, "zhp", zhp);
|
2009-05-29 08:43:15 +02:00
|
|
|
AddMenuItem(menu_main, "zmarket", zmarket);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Display menu to client.
|
2008-10-04 22:59:11 +02:00
|
|
|
DisplayMenu(menu_main, client, MENU_TIME_FOREVER);
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
/**
|
|
|
|
* Menu callback (main)
|
|
|
|
* Redirects client to selected option's handle code.
|
|
|
|
*
|
|
|
|
* @param menu The menu handle.
|
|
|
|
* @param action Action client is doing in menu.
|
|
|
|
* @param client The client index.
|
|
|
|
* @param slot The menu slot selected. (starting from 0)
|
|
|
|
*/
|
2009-06-22 06:08:26 +02:00
|
|
|
public ZMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
// Client selected an option.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (action == MenuAction_Select)
|
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
// Create variable to possible resend menu later.
|
|
|
|
new bool:resend = true;
|
|
|
|
|
2008-10-04 22:59:11 +02:00
|
|
|
switch(slot)
|
|
|
|
{
|
2009-06-22 06:08:26 +02:00
|
|
|
// Selected ZAdmin.
|
2009-04-15 23:40:45 +02:00
|
|
|
case 0:
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
// Copy return to resend variable.
|
2009-06-26 02:03:34 +02:00
|
|
|
resend = !ZAdminMenu(client);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-06-22 06:08:26 +02:00
|
|
|
// Select ZClass.
|
2009-04-15 23:40:45 +02:00
|
|
|
case 1:
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-06-22 06:08:26 +02:00
|
|
|
// Send ZClass menu
|
2009-04-15 23:40:45 +02:00
|
|
|
ClassMenuMain(client);
|
2009-04-29 01:58:41 +02:00
|
|
|
|
|
|
|
// Don't resend this menu.
|
|
|
|
resend = false;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-06-22 06:08:26 +02:00
|
|
|
// Select ZCookies.
|
2009-04-15 23:40:45 +02:00
|
|
|
case 2:
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-06-22 06:08:26 +02:00
|
|
|
// Send ZCookies menu
|
|
|
|
ZCookiesMenuMain(client);
|
|
|
|
|
|
|
|
// Don't resend this menu.
|
|
|
|
resend = false;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-06-22 06:08:26 +02:00
|
|
|
// Select ZSpawn.
|
2009-04-30 07:36:57 +02:00
|
|
|
case 3:
|
2009-06-22 06:08:26 +02:00
|
|
|
{
|
|
|
|
// Send ZSpawn command from client.
|
|
|
|
ZSpawnClient(client);
|
|
|
|
}
|
|
|
|
// Select ZTele.
|
|
|
|
case 4:
|
2009-03-29 22:04:47 +02:00
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
// Copy return to resend variable.
|
2009-05-05 06:56:34 +02:00
|
|
|
resend = !ZTeleClient(client);
|
2009-03-29 22:04:47 +02:00
|
|
|
}
|
2009-06-22 06:08:26 +02:00
|
|
|
// Select ZHP.
|
|
|
|
case 5:
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-16 01:18:08 +02:00
|
|
|
// Toggle ZHP.
|
|
|
|
ZHPToggle(client);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-06-22 06:08:26 +02:00
|
|
|
// Select ZMarket.
|
|
|
|
case 6:
|
2009-04-30 07:36:57 +02:00
|
|
|
{
|
2009-06-05 05:58:48 +02:00
|
|
|
// Send ZMarket menu.
|
2009-06-19 05:41:54 +02:00
|
|
|
resend = !ZMarketMenuMain(client);
|
2009-04-30 07:36:57 +02:00
|
|
|
}
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-04-29 01:58:41 +02:00
|
|
|
|
|
|
|
// Resend is still true, then resend menu.
|
|
|
|
if (resend)
|
|
|
|
{
|
2009-06-22 06:08:26 +02:00
|
|
|
ZMenuMain(client);
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-04-29 01:58:41 +02:00
|
|
|
// Client exited menu.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (action == MenuAction_End)
|
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
CloseHandle(menu);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
|
|
|
|
2009-06-26 02:03:34 +02:00
|
|
|
/**
|
|
|
|
* Shows a list of all clients to a client, different handlers can be used for this, as well as title.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param handler The menu handler.
|
|
|
|
* @param any Title is a translations phrase.
|
|
|
|
*/
|
|
|
|
stock MenuClientList(client, MenuHandler:handler, any:...)
|
|
|
|
{
|
|
|
|
// Create menu handle.
|
|
|
|
new Handle:menu_clients = CreateMenu(handler);
|
|
|
|
|
|
|
|
// Set client as translation target.
|
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
|
|
|
// Translate phrase.
|
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CHAT];
|
|
|
|
VFormat(translation, sizeof(translation), "%t", 3);
|
|
|
|
|
|
|
|
// Set menu title to the translated phrase.
|
|
|
|
SetMenuTitle(menu_clients, translation);
|
|
|
|
|
|
|
|
decl String:clientoption[MAX_NAME_LENGTH];
|
|
|
|
decl String:clientuserid[8];
|
|
|
|
|
|
|
|
// x = Client index.
|
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get client info.
|
|
|
|
GetClientName(x, clientoption, sizeof(clientoption));
|
|
|
|
IntToString(GetClientUserId(x), clientuserid, sizeof(clientuserid));
|
|
|
|
|
|
|
|
// Add option to menu.
|
|
|
|
AddMenuItem(menu_clients, clientuserid, clientoption);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a "Back" button to the main admin menu.
|
|
|
|
SetMenuExitBackButton(menu_clients, true);
|
|
|
|
|
|
|
|
// Send menu.
|
|
|
|
DisplayMenu(menu_clients, client, MENU_TIME_FOREVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the client index of the selected client in the menu.
|
|
|
|
*
|
|
|
|
* @param menu The menu handle.
|
|
|
|
* @param slot The menu slot that was selected.
|
|
|
|
* @return The client index, 0 if the selected client is no longer in the server.
|
|
|
|
*/
|
|
|
|
stock MenuGetClientIndex(Handle:menu, slot)
|
|
|
|
{
|
|
|
|
// Get menu slot's information.
|
|
|
|
decl String:clientuserid[8];
|
|
|
|
GetMenuItem(menu, slot, clientuserid, sizeof(clientuserid));
|
|
|
|
|
|
|
|
// Return the targetted client through their userid which was set into the menu slot's info param.
|
|
|
|
return GetClientOfUserId(StringToInt(clientuserid));
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
/**
|
|
|
|
* Return itemdraw flag for SM menus.
|
|
|
|
*
|
|
|
|
* @param condition If this is true, item will be drawn normally.
|
|
|
|
*/
|
2009-06-26 02:03:34 +02:00
|
|
|
stock MenuGetItemDraw(bool:condition)
|
2009-04-29 01:58:41 +02:00
|
|
|
{
|
|
|
|
return condition ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|