diff --git a/src/zr/cookies.inc b/src/zr/cookies.inc
index 7997b0b..64ccbec 100644
--- a/src/zr/cookies.inc
+++ b/src/zr/cookies.inc
@@ -31,6 +31,8 @@
CookiesInit()
{
// Forward event to modules.
+ ClassOnCookiesCreate();
+ WeaponsOnCookiesCreate();
ZHPOnCookiesCreate();
}
diff --git a/src/zr/event.inc b/src/zr/event.inc
index 9400637..4146b19 100644
--- a/src/zr/event.inc
+++ b/src/zr/event.inc
@@ -106,7 +106,6 @@ public Action:EventRoundStart(Handle:event, const String:name[], bool:dontBroadc
public Action:EventRoundStartPost(Handle:timer, any:index)
{
// Forward event to modules.
- WeaponsOnRoundStartPost();
}
/**
@@ -139,7 +138,6 @@ public Action:EventRoundEnd(Handle:event, const String:name[], bool:dontBroadcas
new reason = GetEventInt(event, "reason");
// Forward event to modules.
- WeaponsOnRoundEnd();
RoundEndOnRoundEnd(reason);
InfectOnRoundEnd();
SEffectsOnRoundEnd();
@@ -224,6 +222,7 @@ public Action:EventPlayerSpawnPost(Handle:timer, any:index)
}
// Forward event to modules.
+ WeaponsOnClientSpawnPost(index);
SpawnProtectOnClientSpawnPost(index);
}
diff --git a/src/zr/overlays.inc b/src/zr/overlays.inc
index 79fa079..d7860e2 100644
--- a/src/zr/overlays.inc
+++ b/src/zr/overlays.inc
@@ -236,8 +236,11 @@ OverlaysChannel:OverlaysClientFindChannel(client)
*
* @param client The client index.
* @param channel The channel to change state of.
- * @param toggle Set to true to toggle state, false to use value param.
+ * @param update (Optional) Update the overlay when this function is called.
+ * @param toggle (Optional) Set to true to toggle state, false to use value param.
* @param value (Optional) New value of the state, only used if toggle is false.
+ * @param reset (Optional) Clears the overlay from client's screen.
+ * @return The overlay's new state.
*/
bool:OverlaysClientSetChannelState(client, OverlaysChannel:channel, bool:update = false, bool:toggle = true, bool:value = false, bool:reset = false)
{
diff --git a/src/zr/playerclasses/classevents.inc b/src/zr/playerclasses/classevents.inc
index 3772f88..cf74ffa 100644
--- a/src/zr/playerclasses/classevents.inc
+++ b/src/zr/playerclasses/classevents.inc
@@ -17,6 +17,24 @@
* ------------------------------------
*/
+/**
+ * Create class-related cookies here.
+ */
+ClassOnCookiesCreate()
+{
+ // Forward event to sub-modules.
+ ClassOverlayOnCookiesCreate();
+}
+
+/**
+ * Called when all modules are done loading.
+ */
+ClassOnModulesLoaded()
+{
+ // Set default classes on all player slots.
+ ClassClientSetDefaultIndexes();
+}
+
/**
* Called when a client connects to the server (OnClientPutInServer).
*/
@@ -35,15 +53,6 @@ ClassClientInit(client)
ClassOverlayClientInit(client);
}
-/**
- * Called when all modules are done loading.
- */
-ClassOnModulesLoaded()
-{
- // Set default classes on all player slots.
- ClassClientSetDefaultIndexes();
-}
-
/**
* Called a client disconnects.
*/
diff --git a/src/zr/playerclasses/clientoverlays.inc b/src/zr/playerclasses/clientoverlays.inc
index 1605fce..a7014e3 100644
--- a/src/zr/playerclasses/clientoverlays.inc
+++ b/src/zr/playerclasses/clientoverlays.inc
@@ -33,26 +33,16 @@
/**
* @endsection
*/
-
-/**
- * Array to store default class overlay enable flag.
- */
-new bool:h_bClassOverlay[MAXPLAYERS + 1];
/**
- * Client is joining the server.
- *
- * @param client The client index.
+ * Name of the cookie for toggle state the class overlay.
*/
-ClassOverlayClientInit(client)
-{
- // Get overlay toggle cvar values.
- new bool:overlaytoggle = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE]);
- new bool:overlaydefault = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_DEFAULT]);
-
- // Apply default value if toggle is enabled, default to true if toggle is disabled.
- h_bClassOverlay[client] = overlaytoggle ? overlaydefault : true;
-}
+#define CLASSOVERLAY_COOKIE_ENABLED "zr_overlay"
+
+/**
+ * Cookie handle for the toggle state of an overlay.
+ */
+new Handle:g_hOverlayEnabledCookie = INVALID_HANDLE;
/**
* Hook commands related to overlay here.
@@ -78,6 +68,43 @@ ClassOverlayOnCommandsHook()
}
}
+/**
+ * Create class overlay-related cookies here.
+ */
+ClassOverlayOnCookiesCreate()
+{
+ // If cookie doesn't already exist, then create it.
+ g_hOverlayEnabledCookie = FindClientCookie(CLASSOVERLAY_COOKIE_ENABLED);
+ if (g_hOverlayEnabledCookie == INVALID_HANDLE)
+ {
+ g_hOverlayEnabledCookie = RegClientCookie(CLASSOVERLAY_COOKIE_ENABLED, "The toggle state of the class overlay.", CookieAccess_Public);
+ }
+}
+
+/**
+ * Client is joining the server.
+ *
+ * @param client The client index.
+ */
+ClassOverlayClientInit(client)
+{
+ // Get overlay toggle cvar values.
+ new bool:overlaytoggle = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE]);
+ new bool:overlaydefault = GetConVarBool(g_hCvarsList[CVAR_CLASSES_OVERLAY_DEFAULT]);
+
+ // Get ZHP enabled cookie value.
+ decl String:overlayenabled[8];
+ GetClientCookie(client, g_hOverlayEnabledCookie, overlayenabled, sizeof(overlayenabled));
+
+ // If the cookie is empty, then set the default value.
+ if (!overlayenabled[0])
+ {
+ // Set cookie to default value from cvar.
+ new bool:overlayvalue = overlaytoggle ? overlaydefault : true;
+ CookiesSetClientCookieBool(client, g_hOverlayEnabledCookie, overlayvalue);
+ }
+}
+
/**
* Client is spawning into the game.
*
@@ -152,7 +179,7 @@ ClassOverlayInitialize(client, const String:overlay[])
// Display class overlays.
OverlaysClientSetChannelPath(client, OVERLAYS_CHANNEL_CLASSES, overlay);
- OverlaysClientSetChannelState(client, OVERLAYS_CHANNEL_CLASSES, true, false, h_bClassOverlay[client]);
+ OverlaysClientSetChannelState(client, OVERLAYS_CHANNEL_CLASSES, true, false, CookiesGetClientCookieBool(client, g_hOverlayEnabledCookie));
}
/**
@@ -171,6 +198,7 @@ public Action:ClassOverlayEnableCommand(client, argc)
return;
}
- // Toggle current overlay channel, and retrieve new value.
- h_bClassOverlay[client] = OverlaysClientSetChannelState(client, OVERLAYS_CHANNEL_CLASSES, true, true);
+ // 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);
}
diff --git a/src/zr/steamidcache.inc b/src/zr/steamidcache.inc
index aa2700d..ad7c173 100644
--- a/src/zr/steamidcache.inc
+++ b/src/zr/steamidcache.inc
@@ -1,96 +1,96 @@
-/*
- * ============================================================================
- *
- * Zombie:Reloaded
- *
- * File: steamidcache.inc
- * Type: Core
- * Description: A SteamID caching API.
- *
- * 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 .
- *
- * ============================================================================
- */
-
-/**
- * The maximum length of a SteamID
- */
-#define STEAMIDCACHE_MAX_LENGTH 16
-
-/**
- * Creates a steamid cache.
- *
- * @return Handle to SteamID cache.
- */
-stock Handle:SteamidCacheCreate()
-{
- // Return steamid cache handle.
- return CreateArray(STEAMIDCACHE_MAX_LENGTH);
-}
-
-/**
- * Add client serial number to the SteamID cache.
- *
- * @param steamidcache The SteamID cache to add client to.
- * @param client The client index.
- * @return True if the client was added successfully, false if the client already exists.
- */
-stock bool:SteamidCacheAddClient(Handle:steamidcache, client)
-{
- // Check if client is in the cache.
- if (SteamidCacheClientExists(steamidcache, client))
- {
- return false;
- }
-
- // Get client's SteamID.
- decl String:steamid[STEAMIDCACHE_MAX_LENGTH];
- GetClientAuthString(client, steamid, sizeof(steamid));
-
- // Push SteamID into the SteamID cache.
- PushArrayString(steamidcache, steamid);
-
- // Client added successfully.
- return true;
-}
-
-/**
- * Check if a client is in the SteamID cache.
- *
- * @param steamidcache The SteamID cache to check in.
- * @param client The client index.
- * @return True if the client exists, false otherwise.
- */
-stock bool:SteamidCacheClientExists(Handle:steamidcache, client)
-{
- // Get client's SteamID.
- decl String:steamid[STEAMIDCACHE_MAX_LENGTH];
- GetClientAuthString(client, steamid, sizeof(steamid));
-
- // Return true if client was found, false otherwise.
- return (FindStringInArray(steamidcache, steamid) != -1);
-}
-
-/**
- * Reset SteamID cache.
- *
- * @param steamidcache The SteamID cache to reset.
- */
-stock SteamidCacheReset(Handle:steamidcache)
-{
- // Clear array.
- ClearArray(steamidcache);
-}
+/*
+ * ============================================================================
+ *
+ * Zombie:Reloaded
+ *
+ * File: steamidcache.inc
+ * Type: Core
+ * Description: A SteamID caching API.
+ *
+ * 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 .
+ *
+ * ============================================================================
+ */
+
+/**
+ * The maximum length of a SteamID
+ */
+#define STEAMIDCACHE_MAX_LENGTH 16
+
+/**
+ * Creates a steamid cache.
+ *
+ * @return Handle to SteamID cache.
+ */
+stock Handle:SteamidCacheCreate()
+{
+ // Return steamid cache handle.
+ return CreateArray(STEAMIDCACHE_MAX_LENGTH);
+}
+
+/**
+ * Add client serial number to the SteamID cache.
+ *
+ * @param steamidcache The SteamID cache to add client to.
+ * @param client The client index.
+ * @return True if the client was added successfully, false if the client already exists.
+ */
+stock bool:SteamidCacheAddClient(Handle:steamidcache, client)
+{
+ // Check if client is in the cache.
+ if (SteamidCacheClientExists(steamidcache, client))
+ {
+ return false;
+ }
+
+ // Get client's SteamID.
+ decl String:steamid[STEAMIDCACHE_MAX_LENGTH];
+ GetClientAuthString(client, steamid, sizeof(steamid));
+
+ // Push SteamID into the SteamID cache.
+ PushArrayString(steamidcache, steamid);
+
+ // Client added successfully.
+ return true;
+}
+
+/**
+ * Check if a client is in the SteamID cache.
+ *
+ * @param steamidcache The SteamID cache to check in.
+ * @param client The client index.
+ * @return True if the client exists, false otherwise.
+ */
+stock bool:SteamidCacheClientExists(Handle:steamidcache, client)
+{
+ // Get client's SteamID.
+ decl String:steamid[STEAMIDCACHE_MAX_LENGTH];
+ GetClientAuthString(client, steamid, sizeof(steamid));
+
+ // Return true if client was found, false otherwise.
+ return (FindStringInArray(steamidcache, steamid) != -1);
+}
+
+/**
+ * Reset SteamID cache.
+ *
+ * @param steamidcache The SteamID cache to reset.
+ */
+stock SteamidCacheReset(Handle:steamidcache)
+{
+ // Clear array.
+ ClearArray(steamidcache);
+}
diff --git a/src/zr/weapons/restrict.inc b/src/zr/weapons/restrict.inc
index 17c07cc..1b71e42 100644
--- a/src/zr/weapons/restrict.inc
+++ b/src/zr/weapons/restrict.inc
@@ -581,8 +581,8 @@ public ZRTools_Action:RestrictCanUse(client, weapon)
return ZRTools_Handled;
}
- // Forward event to modules. (item pickup)
- WeaponAlphaOnItemPickup(client, weapon);
+ // Forward event to weapons module.
+ WeaponsOnItemPickup(client, weapon);
// Allow pickup.
return ZRTools_Continue;
diff --git a/src/zr/weapons/weaponalpha.inc b/src/zr/weapons/weaponalpha.inc
index 3f33240..0485092 100644
--- a/src/zr/weapons/weaponalpha.inc
+++ b/src/zr/weapons/weaponalpha.inc
@@ -35,11 +35,6 @@
*/
new g_iWeaponDropHookID[MAXPLAYERS + 1] = {-1, ...};
-/**
- * Global variable that stops render mode modifying
- */
-new bool:g_bWeaponAlpha;
-
/**
* Client is joining the server.
*
@@ -66,40 +61,14 @@ WeaponAlphaOnClientDisconnect(client)
}
}
-/**
- * The round is starting.
- */
-WeaponAlphaOnRoundStartPost()
-{
- // Allow weapon render mode to be modified.
- g_bWeaponAlpha = true;
-}
-
-/**
- * The round is ending.
- *
- * @param reason Reason the round has ended.
- */
-WeaponAlphaOnRoundEnd()
-{
- // Disallow weapon render mode to be modified.
- g_bWeaponAlpha = false;
-}
-
/**
* Client has just picked up a weapon.
*
* @param client The client index.
* @param weapon The weapon index.
*/
-WeaponAlphaOnItemPickup(client, weapon)
+WeaponAlphaOnItemPickupPost(client, weapon)
{
- // If weapon alpha updating is disabled, then stop.
- if (!g_bWeaponAlpha)
- {
- return;
- }
-
// Get client's current alpha.
new alpha = ToolsGetEntityAlpha(client);
@@ -116,12 +85,6 @@ WeaponAlphaOnItemPickup(client, weapon)
*/
public ZRTools_Action:WeaponAlphaDrop(client, weapon)
{
- // If weapon alpha updating is disabled, then stop.
- if (!g_bWeaponAlpha)
- {
- return;
- }
-
// If weapon isn't a valid entity, then stop.
if (weapon < MaxClients)
{
diff --git a/src/zr/weapons/weapons.inc b/src/zr/weapons/weapons.inc
index 1b5c6db..a92374b 100644
--- a/src/zr/weapons/weapons.inc
+++ b/src/zr/weapons/weapons.inc
@@ -121,6 +121,15 @@ WeaponsOnCommandsCreate()
ZMarketOnCommandsCreate();
}
+/**
+ * Create weapon-related cookies here.
+ */
+WeaponsOnCookiesCreate()
+{
+ // Forward event to sub-modules.
+ ZMarketOnCookiesCreate();
+}
+
/**
* Loads weapon data from file.
*/
@@ -303,27 +312,67 @@ WeaponsOnClientSpawn(client)
{
// Forward event to sub-modules.
RestrictOnClientSpawn(client);
- ZMarketOnClientSpawn(client);
}
/**
- * The round is starting.
- */
-WeaponsOnRoundStartPost()
-{
- // Forward event to sub-modules
- WeaponAlphaOnRoundStartPost();
-}
-
-/**
- * The round is ending.
+ * Client is spawning into the game. *Post
*
- * @param reason Reason the round has ended.
+ * @param client The client index.
*/
-WeaponsOnRoundEnd()
+WeaponsOnClientSpawnPost(client)
{
- // Forward event to sub-modules
- WeaponAlphaOnRoundEnd();
+ // Forward event to sub-modules.
+ ZMarketOnClientSpawnPost(client);
+}
+
+/**
+ * Called when a client picks up an item.
+ *
+ * @param client The client index.
+ * @param weapon The weapon index.
+ */
+WeaponsOnItemPickup(client, weapon)
+{
+ // Forward event to sub-modules.
+
+ // Fire post OnItemPickup event.
+
+ // Fill datapack with event information.
+ new Handle:eventinfo = CreateDataPack();
+ WritePackCell(eventinfo, client);
+ WritePackCell(eventinfo, weapon);
+
+ // Create post delay timer.
+ CreateTimer(0.0, WeaponsOnItemPickupPost, eventinfo);
+}
+
+/**
+ * Called when a client picks up an item. *Post
+ *
+ * @param client The client index.
+ * @param weapon The weapon index.
+ */
+public Action:WeaponsOnItemPickupPost(Handle:timer, Handle:eventinfo)
+{
+ // Get event info.
+ ResetPack(eventinfo);
+ new client = ReadPackCell(eventinfo);
+ new weapon = ReadPackCell(eventinfo);
+
+ // If client isn't in the game anymore, then stop.
+ if (!IsClientInGame(client))
+ {
+ return;
+ }
+
+ // If the weapon entity isn't valid anymore, then stop.
+ if (!IsValidEdict(weapon))
+ {
+ return;
+ }
+
+ // Forward event to sub-modules.
+ WeaponAlphaOnItemPickupPost(client, weapon);
}
/**
diff --git a/src/zr/weapons/zmarket.inc b/src/zr/weapons/zmarket.inc
index 5d0123d..69f715e 100644
--- a/src/zr/weapons/zmarket.inc
+++ b/src/zr/weapons/zmarket.inc
@@ -25,6 +25,15 @@
* ============================================================================
*/
+/**
+ * @section Name of the cookies for ZMarket rebuy/auto-rebuy data.
+ */
+#define ZMARKET_COOKIE_AUTOREBUY "zr_zmarket_autorebuy"
+#define ZMARKET_COOKIE_REBUY "zr_zmarket_rebuy"
+/**
+ * @endsection
+ */
+
/**
* Variable to store buyzone offset value.
*/
@@ -41,14 +50,9 @@ new g_iZMarketCurType[MAXPLAYERS + 1];
new Handle:g_hZMarketPurchaseCount[MAXPLAYERS + 1];
/**
- * Array to store a weapon of each type last purchased from ZMarket.
+ * Cookie handle for auti-rebuy.
*/
-new String:g_strZMarketLastWeapon[MAXPLAYERS + 1][WeaponsSlot][WEAPONS_MAX_LENGTH];
-
-/**
- * Array to store clients' auto-rebuy setting.
- */
-new bool:g_bZMarketAutoRebuy[MAXPLAYERS + 1];
+new Handle:g_hZMarketAutoRebuyCookie = INVALID_HANDLE;
/**
* Create commands specific to ZMarket.
@@ -59,6 +63,30 @@ ZMarketOnCommandsCreate()
RegConsoleCmd(SAYHOOKS_KEYWORD_ZMARKET, ZMarketCommand, "Opens custom buymenu.");
}
+ZMarketOnCookiesCreate()
+{
+ // If auto-rebuy cookie doesn't already exist, then create all ZMarket cookies.
+ g_hZMarketAutoRebuyCookie = FindClientCookie(ZMARKET_COOKIE_AUTOREBUY);
+ if (g_hZMarketAutoRebuyCookie == INVALID_HANDLE)
+ {
+ g_hZMarketAutoRebuyCookie = RegClientCookie(ZMARKET_COOKIE_AUTOREBUY, "The toggle state of auto-rebuy.", CookieAccess_Public);
+
+ decl String:rebuycookiename[32];
+ decl String:rebuycookiedesc[64];
+
+ // x = Weapon slot.
+ for (new x = 0; x < WEAPONS_SLOTS_MAX; x++)
+ {
+ // Format cookie name and description.
+ Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, x);
+ Format(rebuycookiedesc, sizeof(rebuycookiedesc), "Current loadout weapon for slot %d", x);
+
+ // Register client cookie.
+ RegClientCookie(rebuycookiename, rebuycookiedesc, CookieAccess_Public);
+ }
+ }
+}
+
/**
* Find ZMarket-specific offsets here.
*/
@@ -89,7 +117,15 @@ ZMarketClientInit(client)
g_hZMarketPurchaseCount[client] = CreateTrie();
// Initialize auto-rebuy data.
- g_bZMarketAutoRebuy[client] = false;
+ decl String:zmarketautorebuy[8];
+ GetClientCookie(client, g_hZMarketAutoRebuyCookie, zmarketautorebuy, sizeof(zmarketautorebuy));
+
+ // If the cookie is empty, then set the default value.
+ if (!zmarketautorebuy[0])
+ {
+ // Set cookie to false.
+ CookiesSetClientCookieBool(client, g_hZMarketAutoRebuyCookie, false);
+ }
}
/**
@@ -114,13 +150,19 @@ ZMarketOnClientDisconnect(client)
*
* @param client The client index.
*/
-ZMarketOnClientSpawn(client)
+ZMarketOnClientSpawnPost(client)
{
// Reset purchase counts for client.
ZMarketResetPurchaseCount(client);
+ // If client hasn't spawned into the game yet, then stop.
+ if (!IsPlayerAlive(client))
+ {
+ return;
+ }
+
// If auto-rebuy is enabled, then force client to rebuy weapons.
- if (g_bZMarketAutoRebuy[client])
+ if (CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie))
{
ZMarketRebuy(client, true);
}
@@ -222,7 +264,7 @@ bool:ZMarketMenuMain(client)
// Get auto-rebuy setting.
decl String:rebuyautosetting[8];
- ConfigBoolToSetting(g_bZMarketAutoRebuy[client], rebuyautosetting, sizeof(rebuyautosetting));
+ ConfigBoolToSetting(CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie), rebuyautosetting, sizeof(rebuyautosetting));
// Format menu options.
Format(getloadout, sizeof(getloadout), "%t", "Weapons menu zmarket main get loadout");
@@ -290,7 +332,8 @@ public ZMarketMenuMainHandle(Handle:menu_zmarket_main, MenuAction:action, client
case 3:
{
// Toggle rebuy.
- g_bZMarketAutoRebuy[client] = !g_bZMarketAutoRebuy[client];
+ new bool:autorebuyenabled = CookiesGetClientCookieBool(client, g_hZMarketAutoRebuyCookie);
+ CookiesSetClientCookieBool(client, g_hZMarketAutoRebuyCookie, !autorebuyenabled);
// Resend menu.
ZMarketMenuMain(client);
@@ -341,12 +384,16 @@ bool:ZMarketMenuLoadout(client)
decl String:projectileweapon[WEAPONS_MAX_LENGTH];
decl String:explosiveweapon[WEAPONS_MAX_LENGTH];
+ // Transfer cookie values into an array.
+ new String:rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH];
+ ZMarketCookiesToArray(client, rebuyweapons, WEAPONS_SLOTS_MAX, sizeof(rebuyweapons[]));
+
// Return the display name for all the client's weapon classname's.
- WeaponsClassnameToDisplay(g_strZMarketLastWeapon[client][Slot_Primary], sizeof(g_strZMarketLastWeapon), primaryweapon, sizeof(primaryweapon));
- WeaponsClassnameToDisplay(g_strZMarketLastWeapon[client][Slot_Secondary], sizeof(g_strZMarketLastWeapon), secondaryweapon, sizeof(secondaryweapon));
- WeaponsClassnameToDisplay(g_strZMarketLastWeapon[client][Slot_Melee], sizeof(g_strZMarketLastWeapon), meleeweapon, sizeof(meleeweapon));
- WeaponsClassnameToDisplay(g_strZMarketLastWeapon[client][Slot_Projectile], sizeof(g_strZMarketLastWeapon), projectileweapon, sizeof(projectileweapon));
- WeaponsClassnameToDisplay(g_strZMarketLastWeapon[client][Slot_Explosive], sizeof(g_strZMarketLastWeapon), explosiveweapon, sizeof(explosiveweapon));
+ WeaponsClassnameToDisplay(rebuyweapons[Slot_Primary], sizeof(rebuyweapons[]), primaryweapon, sizeof(primaryweapon));
+ WeaponsClassnameToDisplay(rebuyweapons[Slot_Secondary], sizeof(rebuyweapons[]), secondaryweapon, sizeof(secondaryweapon));
+ WeaponsClassnameToDisplay(rebuyweapons[Slot_Melee], sizeof(rebuyweapons[]), meleeweapon, sizeof(meleeweapon));
+ WeaponsClassnameToDisplay(rebuyweapons[Slot_Projectile], sizeof(rebuyweapons[]), projectileweapon, sizeof(projectileweapon));
+ WeaponsClassnameToDisplay(rebuyweapons[Slot_Explosive], sizeof(rebuyweapons[]), explosiveweapon, sizeof(explosiveweapon));
// Get the empty translation.
decl String:empty[64];
@@ -685,7 +732,7 @@ public ZMarketMenuTypeWeaponsHandle(Handle:menu_zmarket_typeweapons, MenuAction:
* Equip a weapon on a client.
*
* @param client The client index.
- * @param weapon The weapon to equip (must be in weapons config file)
+ * @param weapon The weapon to equip. (must be in weapons config file)
* @param rebuy (Optional) If client is rebuying, ammo will be ignored.
*/
stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
@@ -792,8 +839,8 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
// Give client the weapon.
GivePlayerItem(client, weaponentity);
- // Copy weapon to array for this slot.
- strcopy(g_strZMarketLastWeapon[client][slot], sizeof(g_strZMarketLastWeapon), weapon);
+ // Update cookie with new weapon.
+ ZMarketSetRebuyCookie(client, slot, weapon);
// Add 1 to the client's purchase count.
ZMarketSetPurchaseCount(client, weapon, 1, true);
@@ -858,7 +905,7 @@ bool:ZMarketGetCurrentLoadout(client)
if (weapons[x] == -1)
{
// Empty rebuy slot.
- strcopy(g_strZMarketLastWeapon[client][x], sizeof(g_strZMarketLastWeapon), "");
+ ZMarketSetRebuyCookie(client, WeaponsSlot:x, "");
continue;
}
@@ -867,7 +914,7 @@ bool:ZMarketGetCurrentLoadout(client)
ReplaceString(weaponname, sizeof(weaponname), "weapon_", "");
// Copy the name to the rebuy cache.
- strcopy(g_strZMarketLastWeapon[client][x], sizeof(g_strZMarketLastWeapon), weaponname);
+ ZMarketSetRebuyCookie(client, WeaponsSlot:x, weaponname);
}
// Tell client their loadout has been updated.
@@ -876,12 +923,80 @@ bool:ZMarketGetCurrentLoadout(client)
return true;
}
+/**
+ * Transfer array values to rebuy cookies.
+ *
+ * @param client The client index.
+ * @param rebuyweapons The string array to copy results from.
+ * @param maxweapons The max amount of weapons in the array.
+ * @param maxlen The max length of each cookie result.
+ */
+stock ZMarketArrayToCookies(client, String:rebuyweapons[WeaponsSlot][], maxweapons, maxlen)
+{
+ decl String:rebuycookiename[32];
+ new Handle:rebuycookie;
+
+ // x = Weapon slot.
+ for (new x = 0; x < maxweapons; x++)
+ {
+ // Format cookie name.
+ Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, x);
+
+ // Find cookie handle, and retrieve its value.
+ rebuycookie = FindClientCookie(rebuycookiename);
+ SetClientCookie(client, rebuycookie, rebuyweapons[x]);
+ }
+}
+
+/**
+ * Transfer rebuy cookies to an array for easier access.
+ *
+ * @param client The client index.
+ * @param rebuyweapons The string array to copy results to
+ * @param maxweapons The max amount of weapons in the array.
+ * @param maxlen The max length of each cookie result.
+ */
+stock ZMarketCookiesToArray(client, String:rebuyweapons[WeaponsSlot][], maxweapons, maxlen)
+{
+ decl String:rebuycookiename[32];
+ new Handle:rebuycookie;
+
+ // x = Weapon slot.
+ for (new x = 0; x < maxweapons; x++)
+ {
+ // Format cookie name.
+ Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, x);
+
+ // Find cookie handle, and retrieve its value.
+ rebuycookie = FindClientCookie(rebuycookiename);
+ GetClientCookie(client, rebuycookie, rebuyweapons[x], maxlen);
+ }
+}
+
+/**
+ * Set a weapon slot cookie given the slot and value.
+ *
+ * @param client The client index.
+ * @param slot The weapon slot to set value to.
+ * @param value The value (weaponname) of the slot.
+ */
+stock ZMarketSetRebuyCookie(client, WeaponsSlot:slot, const String:value[])
+{
+ // Format cookie name.
+ decl String:rebuycookiename[32];
+ Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, _:slot);
+
+ // Find cookie handle, and retrieve its value.
+ new Handle:rebuycookie = FindClientCookie(rebuycookiename);
+ SetClientCookie(client, rebuycookie, value);
+}
+
/**
* Force a client to rebuy their weapons.
*
* @param client The client index.
*/
-ZMarketRebuy(client, bool:rebuy = false)
+ZMarketRebuy(client, bool:autorebuy = false)
{
// If client is a zombie, then stop.
if (InfectIsClientInfected(client))
@@ -891,23 +1006,24 @@ ZMarketRebuy(client, bool:rebuy = false)
}
new bool:zmarketbuyzone = GetConVarBool(g_hCvarsList[CVAR_WEAPONS_ZMARKET_BUYZONE]);
- if (!rebuy && zmarketbuyzone && !ZMarketIsClientInBuyZone(client))
+ if (!autorebuy && zmarketbuyzone && !ZMarketIsClientInBuyZone(client))
{
TranslationPrintToChat(client, "Weapons zmarket buyzone");
return;
}
+ // Transfer cookie values into an array.
+ new String:rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH];
+ ZMarketCookiesToArray(client, rebuyweapons, WEAPONS_SLOTS_MAX, sizeof(rebuyweapons[]));
+
// x = Weapon slot.
for (new x = 0; x < WEAPONS_SLOTS_MAX; x++)
{
- new bool:equipped = ZMarketEquip(client, g_strZMarketLastWeapon[client][x], true);
-
- // Remove weapon from last weapons.
- if (!equipped)
- {
- strcopy(g_strZMarketLastWeapon[client][x], sizeof(g_strZMarketLastWeapon), "");
- }
+ ZMarketEquip(client, rebuyweapons[x], true);
}
+
+ // Copy values back to cookies.
+ ZMarketArrayToCookies(client, rebuyweapons, WEAPONS_SLOTS_MAX, sizeof(rebuyweapons));
}
/**
diff --git a/src/zr/zhp.inc b/src/zr/zhp.inc
index 40ba370..bba4cd5 100644
--- a/src/zr/zhp.inc
+++ b/src/zr/zhp.inc
@@ -58,7 +58,7 @@ ZHPOnCookiesCreate()
g_hZHPEnabledCookie = FindClientCookie(ZHP_COOKIE_ENABLED);
if (g_hZHPEnabledCookie == INVALID_HANDLE)
{
- g_hZHPEnabledCookie = RegClientCookie(ZHP_COOKIE_ENABLED, "The toggle state of ZHP", CookieAccess_Public);
+ g_hZHPEnabledCookie = RegClientCookie(ZHP_COOKIE_ENABLED, "The toggle state of ZHP.", CookieAccess_Public);
}
}
@@ -191,12 +191,15 @@ bool:ZHPToggle(client)
// Get the cookie value.
new bool:zhpstate = CookiesGetClientCookieBool(client, g_hZHPEnabledCookie);
- // If ZHP is enabled, then tell client it's being disabled.
+ // Toggle the value.
+ CookiesSetClientCookieBool(client, g_hZHPEnabledCookie, !zhpstate);
+
+ // If ZHP was enabled, then tell client it has been disabled.
if (zhpstate)
{
TranslationPrintToChat(client, "ZHP disable");
}
- // If ZHP is disabled, then tell client it's being enabled.
+ // If ZHP was disabled, then tell client it has been enabled.
else
{
TranslationPrintToChat(client, "ZHP enable");
@@ -205,9 +208,6 @@ bool:ZHPToggle(client)
ZHPUpdateHUD(client);
}
- // Toggle the value.
- CookiesSetClientCookieBool(client, g_hZHPEnabledCookie, !zhpstate);
-
return true;
}