2009-06-22 06:08:26 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-06-22 06:08:26 +02:00
|
|
|
*
|
|
|
|
* File: zcookies.inc
|
|
|
|
* Type: Module
|
|
|
|
* Description: ZCookies module, allows clients to modify their ZR cookies via menu.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create commands specific to ZHP.
|
|
|
|
*/
|
|
|
|
ZCookiesOnCommandsCreate()
|
|
|
|
{
|
|
|
|
// Register ZCookies command.
|
|
|
|
RegConsoleCmd(SAYHOOKS_KEYWORD_ZCOOKIES, ZCookiesCommand, "Toggle all ZR cookies here.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show ZCookies menu to client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZCookiesMenuMain(client)
|
|
|
|
{
|
|
|
|
// Create menu handle.
|
|
|
|
new Handle:zcookies_menu_main = CreateMenu(ZCookiesMenuMainHandle);
|
|
|
|
|
|
|
|
// Make client global translations target.
|
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
2009-12-17 03:13:35 +01:00
|
|
|
decl String:autorebuyenabled[MENU_LINE_SMALL_LENGTH];
|
|
|
|
decl String:zhpenabled[MENU_LINE_SMALL_LENGTH];
|
|
|
|
decl String:overlayenabled[MENU_LINE_SMALL_LENGTH];
|
2009-06-22 06:08:26 +02:00
|
|
|
|
|
|
|
// Get the current toggle state of the cookies.
|
2009-08-03 23:55:50 +02:00
|
|
|
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie), autorebuyenabled, sizeof(autorebuyenabled), false, client);
|
|
|
|
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZHPEnabledCookie), zhpenabled, sizeof(zhpenabled), false, client);
|
|
|
|
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hOverlayEnabledCookie), overlayenabled, sizeof(overlayenabled), false, client);
|
2009-06-22 06:08:26 +02:00
|
|
|
|
2009-07-28 02:02:49 +02:00
|
|
|
decl String:title[MENU_LINE_TITLE_LENGTH];
|
2009-07-27 22:25:23 +02:00
|
|
|
decl String:autorebuy[MENU_LINE_REG_LENGTH];
|
|
|
|
decl String:zhp[MENU_LINE_REG_LENGTH];
|
|
|
|
decl String:overlay[MENU_LINE_REG_LENGTH];
|
|
|
|
decl String:zmarket[MENU_LINE_REG_LENGTH];
|
2009-06-22 06:08:26 +02:00
|
|
|
|
|
|
|
// Translate each line into client's language.
|
2009-07-28 02:02:49 +02:00
|
|
|
Format(title, sizeof(title), "%t\n ", "ZCookies Menu main title");
|
2009-06-22 06:08:26 +02:00
|
|
|
Format(autorebuy, sizeof(autorebuy), "%t", "ZCookies menu main auto-rebuy", autorebuyenabled);
|
|
|
|
Format(zhp, sizeof(zhp), "%t", "ZCookies menu main zhp", zhpenabled);
|
|
|
|
Format(overlay, sizeof(overlay), "%t", "ZCookies menu main overlay", overlayenabled);
|
2009-07-24 00:40:39 +02:00
|
|
|
Format(zmarket, sizeof(zmarket), "%t", "ZCookies zmarket loadout");
|
2009-06-22 06:08:26 +02:00
|
|
|
|
|
|
|
// Get conditional values for each option.
|
|
|
|
new bool:weapons = GetConVarBool(g_hCvarsList[CVAR_WEAPONS]); // For auto-rebuy.
|
|
|
|
new bool:zmarketrebuyauto = GetConVarBool(g_hCvarsList[CVAR_WEAPONS_ZMARKET_REBUY_AUTO]); // For auto-rebuy.
|
2009-07-24 00:40:39 +02:00
|
|
|
new bool:zhpcvar = GetConVarBool(g_hCvarsList[CVAR_ZHP]); // For ZHP.
|
2009-06-22 06:08:26 +02:00
|
|
|
new bool:overlaytoggle = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE]); // For class overlay.
|
2009-07-24 00:40:39 +02:00
|
|
|
new bool:zmarketenabled = GetConVarBool(g_hCvarsList[CVAR_WEAPONS_ZMARKET]); // For ZMarket loadout.
|
2009-06-22 06:08:26 +02:00
|
|
|
|
|
|
|
// Add items to menu.
|
2009-07-28 02:02:49 +02:00
|
|
|
SetMenuTitle(zcookies_menu_main, title);
|
2009-06-22 06:08:26 +02:00
|
|
|
AddMenuItem(zcookies_menu_main, "autorebuy", autorebuy, MenuGetItemDraw(weapons && zmarketrebuyauto));
|
|
|
|
AddMenuItem(zcookies_menu_main, "zhp", zhp, MenuGetItemDraw(zhpcvar));
|
|
|
|
AddMenuItem(zcookies_menu_main, "overlay", overlay, MenuGetItemDraw(overlaytoggle));
|
2009-07-24 00:40:39 +02:00
|
|
|
AddMenuItem(zcookies_menu_main, "zmarket", zmarket, MenuGetItemDraw(zmarketenabled));
|
2009-06-22 06:08:26 +02:00
|
|
|
|
|
|
|
// Create a "Back" button to the main menu.
|
|
|
|
SetMenuExitBackButton(zcookies_menu_main, true);
|
|
|
|
|
|
|
|
// Display menu to client.
|
|
|
|
DisplayMenu(zcookies_menu_main, client, MENU_TIME_FOREVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Menu callback (main)
|
|
|
|
* Toggles client cookies.
|
|
|
|
*
|
|
|
|
* @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)
|
|
|
|
*/
|
|
|
|
public ZCookiesMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
|
|
|
|
{
|
|
|
|
// Client selected an option.
|
|
|
|
if (action == MenuAction_Select)
|
|
|
|
{
|
2009-07-24 00:40:39 +02:00
|
|
|
new bool:resend = true;
|
|
|
|
|
2009-06-22 06:08:26 +02:00
|
|
|
switch(slot)
|
|
|
|
{
|
|
|
|
// Toggled auto-rebuy
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
// Toggle the auto-rebuy cookie.
|
|
|
|
ZMarketToggleAutoRebuy(client);
|
|
|
|
}
|
|
|
|
// Toggled ZHP.
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
ZHPToggle(client);
|
|
|
|
}
|
|
|
|
// Toggled class overlay.
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
// If overlay toggle is disabled, then stop.
|
|
|
|
new bool:overlaytoggle = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE]);
|
|
|
|
if (overlaytoggle)
|
|
|
|
{
|
|
|
|
// Toggle current overlay channel, retrieve new value, and update cookie.
|
|
|
|
new bool:overlayenabled = OverlaysClientSetChannelState(client, OVERLAYS_CHANNEL_CLASSES, true, true);
|
|
|
|
CookiesSetClientCookieBool(client, g_hOverlayEnabledCookie, overlayenabled);
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 00:40:39 +02:00
|
|
|
// Opened ZMarket loadout.
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
// Show a client their current loadout.
|
|
|
|
ZMarketMenuLoadout(client);
|
|
|
|
|
|
|
|
// Don't resend ZCookies.
|
|
|
|
resend = false;
|
|
|
|
}
|
2009-06-22 06:08:26 +02:00
|
|
|
}
|
|
|
|
|
2009-07-24 00:40:39 +02:00
|
|
|
if (resend)
|
|
|
|
{
|
|
|
|
// Re-send menu.
|
|
|
|
ZCookiesMenuMain(client);
|
|
|
|
}
|
2009-06-22 06:08:26 +02:00
|
|
|
}
|
|
|
|
// Client closed the menu.
|
|
|
|
if (action == MenuAction_Cancel)
|
|
|
|
{
|
|
|
|
// Client hit "Back" button.
|
|
|
|
if (slot == MenuCancel_ExitBack)
|
|
|
|
{
|
|
|
|
// Re-open main menu.
|
|
|
|
ZMenuMain(client);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Client exited menu.
|
|
|
|
if (action == MenuAction_End)
|
|
|
|
{
|
|
|
|
CloseHandle(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Command callback (zcookies)
|
|
|
|
* Toggle all ZR cookies here.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param argc Argument count.
|
|
|
|
*/
|
|
|
|
public Action:ZCookiesCommand(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 ZCookies menu.
|
|
|
|
ZCookiesMenuMain(client);
|
|
|
|
|
|
|
|
// This stops the "Unknown command" message in client's console.
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|