ZCookies module completed, added to the main menu, translations updated.

This commit is contained in:
Greyscale 2009-06-21 21:08:26 -07:00
parent ff7528f09f
commit b74bbe67ce
12 changed files with 301 additions and 32 deletions

View File

@ -405,31 +405,37 @@
"Menu main zclass"
{
"#format" "{1:s}"
"en" "ZClass - Configure your class settings.(Command: {1})"
"en" "ZClass - Configure your class settings. (Command: {1})"
}
"Menu main zcookies"
{
"#format" "{1:s}"
"en" "ZCookies - Toggle your personal ZR settings here. (Command: {1})"
}
"Menu main zspawn"
{
"#format" "{1:s}"
"en" "ZSpawn - Join late? Use this to spawn.(Command: {1})"
"en" "ZSpawn - Join late? Use this to spawn. (Command: {1})"
}
"Menu main ztele"
{
"#format" "{1:s}"
"en" "ZTele - Teleport back to your spawn location.(Command: {1})"
"en" "ZTele - Teleport back to your spawn location. (Command: {1})"
}
"Menu main zhp"
{
"#format" "{1:s}"
"en" "ZHP - Toggle real HP display when infected.(Command: {1})"
"en" "ZHP - Toggle real HP display when infected. (Command: {1})"
}
"Menu main zmarket"
{
"#format" "{1:s}"
"en" "ZMarket - Need a weapon? Buy them here.(Command: {1})"
"en" "ZMarket - Need a weapon? Buy them here. (Command: {1})"
}
// ===========================
@ -532,6 +538,16 @@
"en" "Weapon @green{1} @defaulthas a purchase limit of @green{2}@default. Wait until you respawn to try again."
}
"Weapons zmarket auto-rebuy toggle on"
{
"en" "Auto-rebuy has been enabled, your loadout will be automatically purchased for you each time you spawn."
}
"Weapons zmarket auto-rebuy toggle off"
{
"en" "Auto-rebuy has been disabled."
}
"Weapons zmarket updated loadout"
{
"en" "You are not able to purchase a weapon at this time, but your loadout has been updated with this weapon."
@ -727,6 +743,33 @@
"en" "Zombie protection ends in: {1} seconds."
}
// ===========================
// ZCookies (module)
// ===========================
"ZCookies Menu main title"
{
"en" "ZCookies\nSelect a Cookie:"
}
"ZCookies menu main auto-rebuy"
{
"#format" "{1:s}"
"en" "ZMarket Auto-Rebuy: {1}"
}
"ZCookies menu main zhp"
{
"#format" "{1:s}"
"en" "ZHP Display: {1}"
}
"ZCookies menu main overlay"
{
"#format" "{1:s}"
"en" "Human/Zombie Class Overlay: {1}"
}
// ===========================
// ZSpawn (module)
// ===========================

View File

@ -77,6 +77,7 @@
#include "zr/zspawn"
#include "zr/ztele"
#include "zr/zhp"
#include "zr/zcookies"
#include "zr/jumpboost"
#include "zr/volfeatures/volfeatures"

View File

@ -38,6 +38,7 @@ CommandsInit()
InfectOnCommandsCreate();
MenuOnCommandsCreate();
ZAdminOnCommandsCreate();
ZCookiesOnCommandsCreate();
ZSpawnOnCommandsCreate();
ZTeleOnCommandsCreate();
ZHPOnCommandsCreate();

View File

@ -892,21 +892,29 @@ stock bool:ConfigSettingToBool(const String:option[])
* @param bOption True/false value to be converted to "yes"/"no", respectively.
* @param option Destination string buffer to store "yes" or "no" in.
* @param maxlen Length of destination string buffer (wont't be more than 4).
* @param yesno When true, returns "yes/no", false returns "on/off."
*/
stock ConfigBoolToSetting(bool:bOption, String:option[], maxlen)
stock ConfigBoolToSetting(bool:bOption, String:option[], maxlen, bool:yesno = true)
{
// If option is true, then copy "yes" to return string.
if (bOption)
{
strcopy(option, maxlen, "yes");
yesno ? strcopy(option, maxlen, "Yes") : strcopy(option, maxlen, "On");
}
// If option is false, then copy "no" to return string.
else
{
strcopy(option, maxlen, "no");
yesno ? strcopy(option, maxlen, "No") : strcopy(option, maxlen, "Off");
}
}
/**
* Returns a "yes/no" string from config as a bool.
*
* @param kv The keyvalue handle.
* @param key The keyname the value is under.
* @param defaultvalue (Optional) Value to return if setting is missing.
*/
stock bool:ConfigKvGetStringBool(Handle:kv, const String:key[], const String:defaultvalue[] = "yes")
{
decl String:value[CONFIG_MAX_LENGTH];

View File

@ -5,7 +5,7 @@
*
* File: cookies.inc
* Type: Module
* Description: Client cookie API.
* Description: Extended client cookie API.
*
* Copyright (C) 2009 Greyscale, Richard Helgeby
*
@ -30,7 +30,7 @@
*/
CookiesInit()
{
// Forward event to modules.
// Forward "OnCookiesCreate" event to modules.
ClassOnCookiesCreate();
WeaponsOnCookiesCreate();
ZHPOnCookiesCreate();

View File

@ -51,7 +51,7 @@ public Action:ZMenuCommand(client, argc)
}
// Send main menu.
MenuMain(client);
ZMenuMain(client);
// This stops the "Unknown command" message in client's console.
return Plugin_Handled;
@ -62,10 +62,10 @@ public Action:ZMenuCommand(client, argc)
*
* @param client The client index.
*/
MenuMain(client)
ZMenuMain(client)
{
// Create menu handle.
new Handle:menu_main = CreateMenu(MenuMainHandle);
new Handle:menu_main = CreateMenu(ZMenuMainHandle);
// Make client global translations target.
SetGlobalTransTarget(client);
@ -83,6 +83,7 @@ MenuMain(client)
// Initialize menu lines.
decl String:zadmin[256];
decl String:zclass[256];
decl String:zcookies[256];
decl String:zspawn[256];
decl String:ztele[256];
decl String:zhp[256];
@ -91,6 +92,7 @@ MenuMain(client)
// Translate each line into client's language.
Format(zadmin, sizeof(zadmin), "%t", "Menu main zadmin", SAYHOOKS_KEYWORD_ZMENU);
Format(zclass, sizeof(zclass), "%t", "Menu main zclass", SAYHOOKS_KEYWORD_ZADMIN);
Format(zcookies, sizeof(zcookies), "%t", "Menu main zcookies", SAYHOOKS_KEYWORD_ZCOOKIES);
Format(zspawn, sizeof(zspawn), "%t", "Menu main zspawn", SAYHOOKS_KEYWORD_ZCLASS);
Format(ztele, sizeof(ztele), "%t", "Menu main ztele", SAYHOOKS_KEYWORD_ZTELE);
Format(zhp, sizeof(zhp), "%t", "Menu main zhp", SAYHOOKS_KEYWORD_ZHP);
@ -103,6 +105,7 @@ MenuMain(client)
AddMenuItem(menu_main, "zadmin", zadmin, MenuGetItemDraw(admin));
AddMenuItem(menu_main, "zclass", zclass);
AddMenuItem(menu_main, "zcookies", zcookies);
AddMenuItem(menu_main, "zspawn", zspawn);
AddMenuItem(menu_main, "ztele", ztele);
AddMenuItem(menu_main, "zhp", zhp);
@ -121,7 +124,7 @@ MenuMain(client)
* @param client The client index.
* @param slot The menu slot selected. (starting from 0)
*/
public MenuMainHandle(Handle:menu, MenuAction:action, client, slot)
public ZMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
{
// Client selected an option.
if (action == MenuAction_Select)
@ -131,41 +134,50 @@ public MenuMainHandle(Handle:menu, MenuAction:action, client, slot)
switch(slot)
{
// Selected zadmin.
// Selected ZAdmin.
case 0:
{
// Copy return to resend variable.
resend = !ZRAdminMenu(client);
}
// Select zclass.
// Select ZClass.
case 1:
{
// Send class menu
// Send ZClass menu
ClassMenuMain(client);
// Don't resend this menu.
resend = false;
}
// Select zspawn.
// Select ZCookies.
case 2:
{
// Send zspawn command from client.
// Send ZCookies menu
ZCookiesMenuMain(client);
// Don't resend this menu.
resend = false;
}
// Select ZSpawn.
case 3:
{
// Send ZSpawn command from client.
ZSpawnClient(client);
}
// Select ztele.
case 3:
// Select ZTele.
case 4:
{
// Copy return to resend variable.
resend = !ZTeleClient(client);
}
// Select zhp.
case 4:
// Select ZHP.
case 5:
{
// Toggle ZHP.
ZHPToggle(client);
}
// Select zmarket.
case 5:
// Select ZMarket.
case 6:
{
// Send ZMarket menu.
resend = !ZMarketMenuMain(client);
@ -175,7 +187,7 @@ public MenuMainHandle(Handle:menu, MenuAction:action, client, slot)
// Resend is still true, then resend menu.
if (resend)
{
MenuMain(client);
ZMenuMain(client);
}
}
// Client exited menu.

View File

@ -153,7 +153,7 @@ public ClassMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
{
if (slot == MenuCancel_ExitBack)
{
MenuMain(client);
ZMenuMain(client);
}
}
}

View File

@ -47,6 +47,7 @@
#define SAYHOOKS_KEYWORD_ZMENU "zmenu"
#define SAYHOOKS_KEYWORD_ZADMIN "zadmin"
#define SAYHOOKS_KEYWORD_ZCLASS "zclass"
#define SAYHOOKS_KEYWORD_ZCOOKIES "zcookies"
#define SAYHOOKS_KEYWORD_ZSPAWN "zspawn"
#define SAYHOOKS_KEYWORD_ZTELE "ztele"
#define SAYHOOKS_KEYWORD_ZHP "zhp"

View File

@ -102,6 +102,7 @@ public WeaponsMenuMainHandle(Handle:menu_weapons_main, MenuAction:action, client
if (slot == MenuCancel_ExitBack)
{
// Re-open admin menu.
ZRAdminMenu(client);
}
}
// Client hit "Exit" button.

View File

@ -331,9 +331,8 @@ public ZMarketMenuMainHandle(Handle:menu_zmarket_main, MenuAction:action, client
// Auto-rebuy.
case 3:
{
// Toggle rebuy.
new bool:autorebuyenabled = CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie);
CookiesSetClientCookieBool(client, g_hZMarketAutoRebuyCookie, !autorebuyenabled);
// Toggle the auto-rebuy cookie.
ZMarketToggleAutoRebuy(client);
// Resend menu.
ZMarketMenuMain(client);
@ -352,7 +351,7 @@ public ZMarketMenuMainHandle(Handle:menu_zmarket_main, MenuAction:action, client
// Client hit "Back" button.
if (slot == MenuCancel_ExitBack)
{
MenuMain(client);
ZMenuMain(client);
}
}
// Client hit "Exit" button.
@ -1042,6 +1041,38 @@ ZMarketRebuy(client, bool:autorebuy = false)
ZMarketArrayToCookies(client, rebuyweapons, WEAPONS_SLOTS_MAX, sizeof(rebuyweapons));
}
/**
* Toggle auto-rebuy on a client.
*
* @param client The client index.
*/
ZMarketToggleAutoRebuy(client)
{
// If auto-rebuy is disabled, then stop.
new bool:zmarketrebuyauto = GetConVarBool(g_hCvarsList[CVAR_WEAPONS_ZMARKET_REBUY_AUTO]);
if (!zmarketrebuyauto)
{
return;
}
// Get the cookie value.
new bool:autorebuystate = CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie);
// Toggle the value.
CookiesSetClientCookieBool(client, g_hZMarketAutoRebuyCookie, !autorebuystate);
// If auto-rebuy was enabled, then tell client it has been disabled.
if (autorebuystate)
{
TranslationPrintToChat(client, "Weapons zmarket auto-rebuy toggle off");
}
// If auto-rebuy was disabled, then tell client it has been enabled.
else
{
TranslationPrintToChat(client, "Weapons zmarket auto-rebuy toggle on");
}
}
/**
* Command callback (zmarket)
* Opens custom buymenu.

View File

@ -151,7 +151,7 @@ public ZRAdminMenuHandle(Handle:menu, MenuAction:action, client, slot)
if (slot == MenuCancel_ExitBack)
{
// Exit back to main menu.
MenuMain(client);
ZMenuMain(client);
}
}
else if (action == MenuAction_End)

171
src/zr/zcookies.inc Normal file
View File

@ -0,0 +1,171 @@
/*
* ============================================================================
*
* Zombie:Reloaded
*
* 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);
// Set menu title.
SetMenuTitle(zcookies_menu_main, "%t\n ", "ZCookies Menu main title");
decl String:autorebuyenabled[4];
decl String:zhpenabled[4];
decl String:overlayenabled[4];
// Get the current toggle state of the cookies.
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie), autorebuyenabled, sizeof(autorebuyenabled), false);
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZHPEnabledCookie), zhpenabled, sizeof(zhpenabled), false);
ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hOverlayEnabledCookie), overlayenabled, sizeof(overlayenabled), false);
decl String:autorebuy[64];
decl String:zhp[64];
decl String:overlay[64];
// Translate each line into client's language.
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);
// 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.
new bool:zhpcvar = GetConVarBool(g_hCvarsList[CVAR_ZHP]); // For ZHP.
new bool:overlaytoggle = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE]); // For class overlay.
// Add items to menu.
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));
// 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)
{
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);
}
}
}
// Re-send menu.
ZCookiesMenuMain(client);
}
// 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;
}