From 062a08b67ebc7b7a8eedc4e356d5798314468931 Mon Sep 17 00:00:00 2001 From: BotoX Date: Wed, 26 Oct 2016 22:46:10 +0200 Subject: [PATCH] Fix issues in a few plugins. --- AdminCheats/scripting/AdminCheats.sp | 4 +- AfkManager/scripting/AfkManager.sp | 6 +- .../{includes => include}/dhooks.inc | 0 ForceInputs/scripting/ForceInputs.sp | 19 ++++--- GlowColors/scripting/GlowColors.sp | 4 +- SelfMute/scripting/SelfMute.sp | 4 +- WeaponCleaner/scripting/WeaponCleaner.sp | 56 ++++++++++++------- 7 files changed, 56 insertions(+), 37 deletions(-) rename FixGameUI/scripting/{includes => include}/dhooks.inc (100%) diff --git a/AdminCheats/scripting/AdminCheats.sp b/AdminCheats/scripting/AdminCheats.sp index 4bac67f..b669e9f 100644 --- a/AdminCheats/scripting/AdminCheats.sp +++ b/AdminCheats/scripting/AdminCheats.sp @@ -99,7 +99,7 @@ public Action OnCheatCommand(int client, const char[] command, int argc) if(IsClientAuthorized(client) && CheckCommandAccess(client, "", ADMFLAG_CHEATS)) return Plugin_Continue; - PrintToConsole(client, "denied :^)"); + //PrintToConsole(client, "denied :^)"); return Plugin_Handled; } @@ -114,7 +114,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 if(IsClientAuthorized(client) && CheckCommandAccess(client, "", ADMFLAG_CHEATS)) return Plugin_Continue; - PrintToConsole(client, "denied :^)"); + //PrintToConsole(client, "denied :^)"); return Plugin_Handled; } diff --git a/AfkManager/scripting/AfkManager.sp b/AfkManager/scripting/AfkManager.sp index fc482a4..3d18386 100644 --- a/AfkManager/scripting/AfkManager.sp +++ b/AfkManager/scripting/AfkManager.sp @@ -94,9 +94,9 @@ public void OnPluginStart() AddCommandListener(Command_Say, "say"); AddCommandListener(Command_Say, "say_team"); - HookEvent("player_team", Event_PlayerTeamPost, EventHookMode_PostNoCopy); - HookEvent("player_spawn", Event_PlayerSpawnPost, EventHookMode_PostNoCopy); - HookEvent("player_death", Event_PlayerDeathPost, EventHookMode_PostNoCopy); + HookEvent("player_team", Event_PlayerTeamPost, EventHookMode_Post); + HookEvent("player_spawn", Event_PlayerSpawnPost, EventHookMode_Post); + HookEvent("player_death", Event_PlayerDeathPost, EventHookMode_Post); HookEvent("round_end", Event_RoundEnd, EventHookMode_Pre); HookEntityOutput("trigger_teleport", "OnEndTouch", Teleport_OnEndTouch); diff --git a/FixGameUI/scripting/includes/dhooks.inc b/FixGameUI/scripting/include/dhooks.inc similarity index 100% rename from FixGameUI/scripting/includes/dhooks.inc rename to FixGameUI/scripting/include/dhooks.inc diff --git a/ForceInputs/scripting/ForceInputs.sp b/ForceInputs/scripting/ForceInputs.sp index b98f461..412c8d8 100644 --- a/ForceInputs/scripting/ForceInputs.sp +++ b/ForceInputs/scripting/ForceInputs.sp @@ -71,11 +71,14 @@ public Action Command_ForceInputPlayer(int client, int args) for(int i = 0; i < TargetCount; i++) { - if (sArguments[2][0]) + if(!IsValidEntity(aTargetList[i])) + continue; + + if(sArguments[2][0]) SetVariantString(sArguments[2]); AcceptEntityInput(aTargetList[i], sArguments[1], aTargetList[i], aTargetList[i]); - ReplyToCommand(client, "[SM] Input succesfull."); + ReplyToCommand(client, "[SM] Input successful."); } return Plugin_Handled; @@ -103,7 +106,7 @@ public Action Command_ForceInput(int client, int args) SetVariantString(sArguments[2]); AcceptEntityInput(client, sArguments[1], client, client); - ReplyToCommand(client, "[SM] Input succesfull."); + ReplyToCommand(client, "[SM] Input successful."); } else if(StrEqual(sArguments[0], "!target")) { @@ -125,7 +128,7 @@ public Action Command_ForceInput(int client, int args) SetVariantString(sArguments[2]); AcceptEntityInput(entity, sArguments[1], client, client); - ReplyToCommand(client, "[SM] Input succesfull."); + ReplyToCommand(client, "[SM] Input successful."); } } else @@ -135,19 +138,19 @@ public Action Command_ForceInput(int client, int args) int entity = INVALID_ENT_REFERENCE; while((entity = FindEntityByClassname(entity, "*")) != INVALID_ENT_REFERENCE) { - char sClassname[64]; - char sTargetname[64]; + static char sClassname[64]; + static char sTargetname[64]; GetEntPropString(entity, Prop_Data, "m_iClassname", sClassname, sizeof(sClassname)); GetEntPropString(entity, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname)); if(strncmp(sClassname, sArguments[0], Wildcard, false) == 0 || strncmp(sTargetname, sArguments[0], Wildcard, false) == 0) { - if (sArguments[2][0]) + if(sArguments[2][0]) SetVariantString(sArguments[2]); AcceptEntityInput(entity, sArguments[1], client, client); - ReplyToCommand(client, "[SM] Input succesfull."); + ReplyToCommand(client, "[SM] Input successful."); } } } diff --git a/GlowColors/scripting/GlowColors.sp b/GlowColors/scripting/GlowColors.sp index f1da974..bbf27fa 100644 --- a/GlowColors/scripting/GlowColors.sp +++ b/GlowColors/scripting/GlowColors.sp @@ -41,8 +41,8 @@ public void OnPluginStart() RegAdminCmd("sm_rainbow", Command_Rainbow, ADMFLAG_CUSTOM1, "Enable rainbow glowcolors. sm_rainbow [frequency]"); - HookEvent("player_spawn", Event_ApplyGlowcolor, EventHookMode_PostNoCopy); - HookEvent("player_team", Event_ApplyGlowcolor, EventHookMode_PostNoCopy); + HookEvent("player_spawn", Event_ApplyGlowcolor, EventHookMode_Post); + HookEvent("player_team", Event_ApplyGlowcolor, EventHookMode_Post); LoadConfig(); diff --git a/SelfMute/scripting/SelfMute.sp b/SelfMute/scripting/SelfMute.sp index a3d3800..bace2f4 100644 --- a/SelfMute/scripting/SelfMute.sp +++ b/SelfMute/scripting/SelfMute.sp @@ -998,7 +998,7 @@ public void OnPlayerRadio(DataPack pack) } CloseHandle(pack); - Handle RadioText = StartMessage("RadioText", g_MsgPlayers, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS); + Handle RadioText = StartMessage("RadioText", g_MsgPlayers, playersNum, USERMSG_RELIABLE); if(g_bIsProtoBuf) { PbSetInt(RadioText, "msg_dst", g_MsgDest); @@ -1021,7 +1021,7 @@ public void OnPlayerRadio(DataPack pack) } EndMessage(); - Handle SendAudio = StartMessage("SendAudio", g_MsgPlayers, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS); + Handle SendAudio = StartMessage("SendAudio", g_MsgPlayers, playersNum, USERMSG_RELIABLE); if(g_bIsProtoBuf) PbSetString(SendAudio, "radio_sound", g_MsgRadioSound); else diff --git a/WeaponCleaner/scripting/WeaponCleaner.sp b/WeaponCleaner/scripting/WeaponCleaner.sp index 52023b0..85cfe2d 100644 --- a/WeaponCleaner/scripting/WeaponCleaner.sp +++ b/WeaponCleaner/scripting/WeaponCleaner.sp @@ -24,7 +24,7 @@ public Plugin myinfo = name = "WeaponCleaner", author = "BotoX", description = "Clean unneeded weapons", - version = "2.1", + version = "2.2", url = "" }; @@ -65,12 +65,12 @@ public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] n continue; // Kill it - AcceptEntityInput(G_WeaponArray[0][0], "Kill"); - // This implicitly calls OnEntityDestroyed() which calls RemoveWeapon() - - // Move index backwards (since the list was modified by removing it) - i--; - d--; + if(KillWeapon(G_WeaponArray[i][0])) + { + // Move index backwards (since the list was modified by removing it) + i--; + d--; + } } } g_MaxWeapons = StringToInt(newValue); @@ -129,7 +129,7 @@ public void OnEntityCreated(int entity, const char[] classname) public void OnEntityDestroyed(int entity) { - RemoveWeapon(entity); + RemoveWeapon(EntIndexToEntRef(EntRefToEntIndex(entity))); } public void OnWeaponSpawned(int entity) @@ -157,7 +157,7 @@ public Action OnWeaponEquip(int client, int entity) return; // Weapon should not be cleaned anymore - RemoveWeapon(entity); + RemoveWeapon(EntIndexToEntRef(entity)); } public Action OnWeaponDrop(int client, int entity) @@ -184,6 +184,8 @@ public Action OnWeaponDrop(int client, int entity) bool InsertWeapon(int entity) { + int entref = EntIndexToEntRef(entity); + // Try to find a free slot for(int i = 0; i < g_MaxWeapons; i++) { @@ -191,28 +193,27 @@ bool InsertWeapon(int entity) continue; // Found a free slot, add it here - G_WeaponArray[i][0] = entity; + G_WeaponArray[i][0] = entref; G_WeaponArray[i][1] = GetTime(); return true; } // No free slot found // Kill the first (oldest) item in the list - AcceptEntityInput(G_WeaponArray[0][0], "Kill"); - // This implicitly calls OnEntityDestroyed() which calls RemoveWeapon() + KillWeapon(G_WeaponArray[0][0]); // Add new weapon to the end of the list - G_WeaponArray[g_MaxWeapons - 1][0] = entity; + G_WeaponArray[g_MaxWeapons - 1][0] = entref; G_WeaponArray[g_MaxWeapons - 1][1] = GetTime(); return true; } -bool RemoveWeapon(int entity) +bool RemoveWeapon(int entref) { // Find the Weapon for(int i = 0; i < g_MaxWeapons; i++) { - if(G_WeaponArray[i][0] == entity) + if(G_WeaponArray[i][0] == entref) { G_WeaponArray[i][0] = 0; G_WeaponArray[i][1] = 0; @@ -243,16 +244,31 @@ bool CheckWeapons() if(g_MaxWeaponLifetime && GetTime() - G_WeaponArray[i][1] >= g_MaxWeaponLifetime) { // Kill it - AcceptEntityInput(G_WeaponArray[i][0], "Kill"); - // This implicitly calls OnEntityDestroyed() which calls RemoveWeapon() - - // Move index backwards (since the list was modified by removing it) - i--; + if(KillWeapon(G_WeaponArray[i][0])) + { + // Move index backwards (since the list was modified by removing it) + i--; + } } } return true; } +bool KillWeapon(int entref) +{ + if(!IsValidEntity(entref)) + return RemoveWeapon(entref); + + // This implicitly calls OnEntityDestroyed() on success which calls RemoveWeapon() + AcceptEntityInput(entref, "Kill"); + + // Not successful? + if(IsValidEntity(entref)) + return RemoveWeapon(entref); + + return true; +} + public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast) { for(int i = 0; i < MAX_WEAPONS; i++)