From 3f8126949b4c10ca05ac3a1b7dde9960fb0b1bbd Mon Sep 17 00:00:00 2001 From: soft as HELL Date: Mon, 26 Feb 2024 19:03:37 +0200 Subject: [PATCH] Reset plugin state on player spawn or round start --- scripting/nt_tachifix.sp | 56 ++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/scripting/nt_tachifix.sp b/scripting/nt_tachifix.sp index 9e3cbd4..b9d9b2c 100644 --- a/scripting/nt_tachifix.sp +++ b/scripting/nt_tachifix.sp @@ -1,10 +1,14 @@ #include +#include +#include #include #pragma semicolon 1 #pragma newdecls required #define PLUGIN_VERSION "0.1.0" +#define FIREMODE_DELAY 0.5 +#define DEBUG 0 public Plugin myinfo = { @@ -16,12 +20,35 @@ public Plugin myinfo = } -bool g_bAttack2Held[NEO_MAXPLAYERS + 1]; float g_fLastFireModeChange[NEO_MAXPLAYERS + 1]; public void OnPluginStart() { CreateConVar("sm_nt_tachifix_version", PLUGIN_VERSION, "NEOTOKYO° Tachi fix version", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY); + + HookEvent("game_round_start", OnRoundStart, EventHookMode_Post); + HookEvent("player_spawn", OnPlayerSpawn, EventHookMode_Pre); +} + +public void OnPlayerSpawn(Handle event, const char[] name, bool dontBroadcast) +{ + #if DEBUG > 0 + PrintToServer("[nt_tachifix] OnPlayerSpawn %d", GetGameTime() - FIREMODE_DELAY); + #endif + + g_fLastFireModeChange[GetEventInt(event, "userid")] = GetGameTime() - FIREMODE_DELAY; +} + +public void OnRoundStart(Handle event, const char[] name, bool dontBroadcast) +{ + #if DEBUG > 0 + PrintToServer("[nt_tachifix] OnRoundStart %d", GetGameTime() - FIREMODE_DELAY); + #endif + + for(int client = 1; client <= NEO_MAXPLAYERS; client++) + { + g_fLastFireModeChange[client] = GetGameTime() - FIREMODE_DELAY; + } } public Action OnPlayerRunCmd(int client, int &buttons) @@ -29,33 +56,40 @@ public Action OnPlayerRunCmd(int client, int &buttons) if(!IsPlayerAlive(client)) return Plugin_Continue; - if((buttons & IN_ATTACK2) == IN_ATTACK2 && !g_bAttack2Held[client]) + #if DEBUG > 2 + PrintToServer("[nt_tachifix] %d m_bFreezePeriod %b %b", client, GameRules_GetProp("m_bFreezePeriod"), (GetGameTime() - g_fLastFireModeChange[client] >= FIREMODE_DELAY)); + #endif + + if((buttons & IN_ATTACK2) == IN_ATTACK2 && (GetGameTime() - g_fLastFireModeChange[client] >= FIREMODE_DELAY)) { if(!GameRules_GetProp("m_bFreezePeriod")) return Plugin_Continue; - if(GetGameTime() - g_fLastFireModeChange[client] < 0.5) - return Plugin_Continue; - - g_bAttack2Held[client] = true; - int activeweapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon"); if (!activeweapon) { + #if DEBUG > 0 + PrintToServer("[nt_tachifix] No weapon???"); + #endif return Plugin_Continue; } char classname[32]; if(GetEntityClassname(activeweapon, classname, 32) && StrEqual(classname, "weapon_tachi")) { + #if DEBUG > 0 + PrintToServer("[nt_tachifix] %d change firemode", client, !GetEntProp(activeweapon, Prop_Send, "m_iFireMode")); + #endif SetEntProp(activeweapon, Prop_Send, "m_iFireMode", !GetEntProp(activeweapon, Prop_Send, "m_iFireMode")); buttons &= ~IN_ATTACK2; g_fLastFireModeChange[client] = GetGameTime(); } - } - else - { - g_bAttack2Held[client] = false; + else + { + #if DEBUG > 0 + PrintToServer("[nt_tachifix] No tachi???"); + #endif + } } return Plugin_Continue;