From ebf53e740c4ee7151a25fcd545db1ca534025102 Mon Sep 17 00:00:00 2001 From: BotoX Date: Tue, 10 Sep 2019 22:07:09 +0200 Subject: [PATCH] Add QuickSwitch and fix bugs --- .../scripting/AdvancedTargeting.sp | 9 ++- QuickSwitch/scripting/QuickSwitch.sp | 73 +++++++++++++++++++ TeamManager/scripting/TeamManager.sp | 1 - 3 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 QuickSwitch/scripting/QuickSwitch.sp diff --git a/AdvancedTargeting/scripting/AdvancedTargeting.sp b/AdvancedTargeting/scripting/AdvancedTargeting.sp index 6b644cab..3ee2ee1b 100644 --- a/AdvancedTargeting/scripting/AdvancedTargeting.sp +++ b/AdvancedTargeting/scripting/AdvancedTargeting.sp @@ -91,15 +91,18 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("ReadClientFriends", Native_ReadClientFriends); RegPluginLibrary("AdvancedTargeting"); + g_bLateLoad = late; + return APLRes_Success; +} + +public void OnAllPluginsLoaded() +{ g_Plugin_voiceannounce_ex = LibraryExists("voiceannounce_ex"); g_Extension_Voice = LibraryExists("Voice"); LogMessage("AdvancedTargeting capabilities:\nVoiceAnnounce: %s\nVoice: %s", (g_Plugin_voiceannounce_ex ? "loaded" : "not loaded"), (g_Extension_Voice ? "loaded" : "not loaded")); - - g_bLateLoad = late; - return APLRes_Success; } public Action Command_Admins(int client, int args) diff --git a/QuickSwitch/scripting/QuickSwitch.sp b/QuickSwitch/scripting/QuickSwitch.sp new file mode 100644 index 00000000..90b0ad72 --- /dev/null +++ b/QuickSwitch/scripting/QuickSwitch.sp @@ -0,0 +1,73 @@ +#pragma semicolon 1 +#pragma newdecls required + +#include +#include +#include + +ConVar g_Cvar_QuickSwitch_Knife; +float g_flNextAttack[MAXPLAYERS + 1] = {0.0, ...}; +bool g_bSetNextAttack[MAXPLAYERS + 1] = false; + +public Plugin myinfo = +{ + name = "Knife QuickSwitch", + author = "BotoX", + description = "Switching to knife without delay.", + version = "1.0", + url = "" +}; + +public void OnPluginStart() +{ + g_Cvar_QuickSwitch_Knife = CreateConVar("sm_quickswitch_knife", "1", "Enable Knife QuickSwitch.", 0, true, 0.0, true, 1.0); + + AutoExecConfig(true, "plugin.QuickSwitch"); + + /* Handle late load */ + for(int client = 1; client <= MaxClients; client++) + { + if(IsClientInGame(client)) + OnClientPutInServer(client); + } +} + +public void OnClientPutInServer(int client) +{ + g_flNextAttack[client] = 0.0; + g_bSetNextAttack[client] = false; + SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch); + SDKHook(client, SDKHook_WeaponSwitchPost, OnWeaponSwitchPost); +} + +public void OnWeaponSwitch(int client, int weapon) +{ + if(!g_Cvar_QuickSwitch_Knife.BoolValue || !IsPlayerAlive(client) || ZR_IsClientZombie(client)) + return; + + char sWeaponName[32]; + GetEdictClassname(weapon, sWeaponName, sizeof(sWeaponName)); + + if(!StrEqual(sWeaponName, "weapon_knife")) + return; + + float flNextPrimaryAttack = GetEntPropFloat(weapon, Prop_Data, "m_flNextPrimaryAttack"); + float flNextSecondaryAttack = GetEntPropFloat(weapon, Prop_Data, "m_flNextSecondaryAttack"); + + if(flNextPrimaryAttack > g_flNextAttack[client]) + g_flNextAttack[client] = flNextPrimaryAttack; + + if(flNextSecondaryAttack > g_flNextAttack[client]) + g_flNextAttack[client] = flNextSecondaryAttack; + + g_bSetNextAttack[client] = true; +} + +public void OnWeaponSwitchPost(int client, int weapon) +{ + if(g_bSetNextAttack[client]) + { + SetEntPropFloat(client, Prop_Send, "m_flNextAttack", g_flNextAttack[client]); + g_bSetNextAttack[client] = false; + } +} diff --git a/TeamManager/scripting/TeamManager.sp b/TeamManager/scripting/TeamManager.sp index e9906e22..5ec9873a 100644 --- a/TeamManager/scripting/TeamManager.sp +++ b/TeamManager/scripting/TeamManager.sp @@ -130,7 +130,6 @@ public void OnClientDisconnect(int client) public Action OnJoinTeamCommand(int client, const char[] command, int argc) { - LogMessage("OnJoinTeamCommand(%L, %s, %d)", client, command, argc); if(client < 1 || client >= MaxClients || !IsClientInGame(client)) return Plugin_Continue;