From 85c3400a62899e193c024d6e3b0958dc1406eb06 Mon Sep 17 00:00:00 2001 From: Greyscale Date: Fri, 26 Jun 2009 18:33:09 -0700 Subject: [PATCH] Fixed weapons bug for what.. the 4th time? Finally figured out the cause, reproduced, made fix, no more bug. Zombies no longer pick up weapons after the round. Fixed bug where disabling restrict/weapons module allowed zombies to get weapons. --- src/zr/event.inc | 1 + src/zr/tools_functions.inc | 14 ++++---- src/zr/weapons/restrict.inc | 68 +++++++++++++++++++++++++++++++++---- src/zr/weapons/weapons.inc | 18 ++++++++++ 4 files changed, 88 insertions(+), 13 deletions(-) diff --git a/src/zr/event.inc b/src/zr/event.inc index 2c609c7..d462b4a 100644 --- a/src/zr/event.inc +++ b/src/zr/event.inc @@ -138,6 +138,7 @@ public Action:EventRoundEnd(Handle:event, const String:name[], bool:dontBroadcas new reason = GetEventInt(event, "reason"); // Forward event to modules. + WeaponsOnRoundEnd(); RoundEndOnRoundEnd(reason); InfectOnRoundEnd(); SEffectsOnRoundEnd(); diff --git a/src/zr/tools_functions.inc b/src/zr/tools_functions.inc index 928c0c3..df9f9b8 100644 --- a/src/zr/tools_functions.inc +++ b/src/zr/tools_functions.inc @@ -33,7 +33,7 @@ * @param stack If modifying velocity, then true will stack new velocity onto the client's * current velocity, false will reset it. */ -ToolsClientVelocity(client, Float:vecVelocity[3], bool:apply = true, bool:stack = true) +stock ToolsClientVelocity(client, Float:vecVelocity[3], bool:apply = true, bool:stack = true) { // If retrieve if true, then get client's velocity. if (!apply) @@ -72,7 +72,7 @@ ToolsClientVelocity(client, Float:vecVelocity[3], bool:apply = true, bool:stack * @param client The client index. * @param value LMV value. (1.0 = default, 2.0 = double) */ -ToolsSetClientLMV(client, Float:fLMV) +stock ToolsSetClientLMV(client, Float:fLMV) { // Set lagged movement value of client. SetEntDataFloat(client, g_iToolsLMV, fLMV / 300.0, true); @@ -85,7 +85,7 @@ ToolsSetClientLMV(client, Float:fLMV) * @param ownership If true, enable will toggle the client's ownership of nightvision. * If false, enable will toggle the client's on/off state of the nightvision. */ -ToolsClientNightVision(client, bool:enable, bool:ownership = true) +stock ToolsClientNightVision(client, bool:enable, bool:ownership = true) { // If ownership is true, then toggle the ownership of nightvision on client. if (ownership) @@ -104,7 +104,7 @@ ToolsClientNightVision(client, bool:enable, bool:ownership = true) * @param client The client index. * @param FOV The field of vision of the client. */ -ToolsSetClientDefaultFOV(client, FOV) +stock ToolsSetClientDefaultFOV(client, FOV) { SetEntData(client, g_iToolsDefaultFOV, FOV, 1, true); } @@ -118,7 +118,7 @@ ToolsSetClientDefaultFOV(client, FOV) * @param value The value of the client's score or deaths. * @return The score or death count of the client, -1 if setting. */ -ToolsClientScore(client, bool:score = true, bool:apply = true, value = 0) +stock ToolsClientScore(client, bool:score = true, bool:apply = true, value = 0) { if (!apply) { @@ -156,7 +156,7 @@ ToolsClientScore(client, bool:score = true, bool:apply = true, value = 0) * @param alpha The alpha value to set client's alpha to. (0-255) * @param weapons Apply alpha to all client's weapons. */ -ToolsSetClientAlpha(client, alpha) +stock ToolsSetClientAlpha(client, alpha) { // Turn rendermode on, on the client. SetEntityRenderMode(client, RENDER_TRANSALPHA); @@ -174,7 +174,7 @@ ToolsSetClientAlpha(client, alpha) * @param client The client index. * @return The alpha value of the client. (0-255) */ -ToolsGetEntityAlpha(entity) +stock ToolsGetEntityAlpha(entity) { static bool:gotconfig = false; static String:prop[32]; diff --git a/src/zr/weapons/restrict.inc b/src/zr/weapons/restrict.inc index 1b71e42..7938f7a 100644 --- a/src/zr/weapons/restrict.inc +++ b/src/zr/weapons/restrict.inc @@ -43,6 +43,11 @@ enum RestrictData */ new g_iCanUseHookID[MAXPLAYERS + 1] = {-1, ...}; +/** + * Array to block any client from picking up weapons. + */ +new bool:g_bRestrictBlockWeapon[MAXPLAYERS + 1]; + /** * Array to store a list of different weapon groups */ @@ -134,6 +139,9 @@ RestrictClientInit(client) { // Hook "Weapon_CanUse" on client. g_iCanUseHookID[client] = ZRTools_HookWeapon_CanUse(client, RestrictCanUse); + + // Reset block weapons flag. + g_bRestrictBlockWeapon[client] = false; } /** @@ -161,6 +169,48 @@ RestrictOnClientSpawn(client) // Re-hook "canuse" on client. ZRTools_UnhookWeapon_CanUse(g_iCanUseHookID[client]); g_iCanUseHookID[client] = ZRTools_HookWeapon_CanUse(client, RestrictCanUse); + + // H4x. Unfortunately I can't disable this flag early enough for CS:S to give start USP/Glock. + // So I have to give BOOTLEG weapons. (Sorry Valve) + if (g_bRestrictBlockWeapon[client]) + { + // Reset block weapons flag. + g_bRestrictBlockWeapon[client] = false; + + if (ZRIsClientOnTeam(client, CS_TEAM_T)) + { + GivePlayerItem(client, WEAPONS_SPAWN_T_WEAPON); + } + else if (ZRIsClientOnTeam(client, CS_TEAM_CT)) + { + GivePlayerItem(client, WEAPONS_SPAWN_CT_WEAPON); + } + } +} + +/** + * The round is ending. + */ +RestrictOnRoundEnd() +{ + // x = Client index. + for (new x = 1; x <= MaxClients; x++) + { + // If client isn't in-game, then stop. + if (!IsClientInGame(x)) + { + continue; + } + + // If client is a human, then stop. + if (InfectIsClientHuman(x)) + { + continue; + } + + // Enable block weapon flag. + g_bRestrictBlockWeapon[x] = true; + } } /** @@ -545,6 +595,18 @@ public ZRTools_Action:RestrictCanUse(client, weapon) return ZRTools_Continue; } + // If the player is a zombie, then prevent pickup. + if (InfectIsClientInfected(client)) + { + return ZRTools_Handled; + } + + // If client is flagged for not picking up weapons, then stop. + if (g_bRestrictBlockWeapon[client]) + { + return ZRTools_Handled; + } + // If weapons module is disabled, then stop. new bool:weapons = GetConVarBool(g_hCvarsList[CVAR_WEAPONS]); if (!weapons) @@ -575,12 +637,6 @@ public ZRTools_Action:RestrictCanUse(client, weapon) return ZRTools_Handled; } - // If the player is a zombie, then prevent pickup. - if (InfectIsClientInfected(client)) - { - return ZRTools_Handled; - } - // Forward event to weapons module. WeaponsOnItemPickup(client, weapon); diff --git a/src/zr/weapons/weapons.inc b/src/zr/weapons/weapons.inc index 7c91fa1..658c577 100644 --- a/src/zr/weapons/weapons.inc +++ b/src/zr/weapons/weapons.inc @@ -35,6 +35,15 @@ */ #define WEAPONS_SLOTS_MAX 5 +/** + * @section CS:S start weapons. + */ +#define WEAPONS_SPAWN_T_WEAPON "weapon_glock" +#define WEAPONS_SPAWN_CT_WEAPON "weapon_usp" +/** + * @endsection + */ + /** * Weapon config data indexes. */ @@ -325,6 +334,15 @@ WeaponsOnClientSpawnPost(client) ZMarketOnClientSpawnPost(client); } +/** + * The round is ending. + */ +WeaponsOnRoundEnd() +{ + // Forward event to sub-modules. + RestrictOnRoundEnd(); +} + /** * Called when a client picks up an item. *