Last active
December 25, 2016 21:23
-
-
Save fakuivan/e665cce72e99cae36df5be945bab7b30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma semicolon 1 | |
#pragma newdecls required | |
#include <sourcemod> | |
#include <sdktools> | |
#include <events> | |
#define PLUGIN_VERSION "0.7" | |
public Plugin myinfo = | |
{ | |
name = "Spectator Kill Fix", | |
author = "fakuivan", | |
description = "Fixes an exploit related to projectiles and entities not being kill on team switch", | |
version = PLUGIN_VERSION, | |
url = "https://forums.alliedmods.net/member.php?u=264797" | |
}; | |
public void OnPluginStart() | |
{ | |
//CreateConVar("sm__version", PLUGIN_VERSION, "Version of ", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY); | |
HookEvent("player_team", Event_OnClientChangeTeam, EventHookMode_Pre); | |
RegAdminCmd("sm_trigger_distroy_me", Trigger, ADMFLAG_RCON); | |
} | |
char gs_prop_ents[][][] = | |
{ | |
{"tf_projectile_energy_ball" , "m_hOwnerEntity"}, | |
{"tf_projectile_rocket" , "m_hOwnerEntity"}, | |
{"tf_projectile_pipe" , "m_hThrower"}, | |
{"tf_projectile_pipe_remote" , "m_hThrower"}, | |
{"obj_sentrygun" , "m_hBuilder"}, | |
{"obj_dispenser" , "m_hBuilder"}, | |
{"obj_teleporter" , "m_hBuilder"} | |
}; | |
public Action Trigger(int i_client, int i_args) | |
{ | |
CleanParented(i_client, gs_prop_ents, sizeof(gs_prop_ents)); | |
} | |
public void Event_OnClientChangeTeam(Event h_event, const char[] s_name, bool b_dontBroadcast) | |
{ | |
char s_client_name[MAX_NAME_LENGTH]; | |
int i_userid = GetEventInt(h_event, "userid"); | |
int i_team = GetEventInt(h_event, "team"); | |
int i_old_team = GetEventInt(h_event, "oldteam"); | |
bool b_disconnect = GetEventBool(h_event, "disconnect"); | |
GetEventString(h_event, "name", s_client_name, sizeof(s_client_name)); | |
PrintToServer("[SPECTATOR HOTFIX] Player %N changed team", GetClientOfUserId(i_userid)); | |
if (b_disconnect || i_team == i_old_team) | |
{ | |
return; | |
} | |
PrintToServer("[SPECTATOR HOTFIX] Killing player %N's things", GetClientOfUserId(i_userid)); | |
CleanParented(GetClientOfUserId(i_userid), gs_prop_ents, sizeof(gs_prop_ents)); | |
} | |
void CleanParented(int i_client, char[][][] s_ent_prop_names, int i_entnum) | |
{ | |
int i_entity; | |
for (int i = 0; i < i_entnum; i++) | |
{ | |
while ((i_entity = FindEntityByClassname(i_entity, s_ent_prop_names[i][0])) != INVALID_ENT_REFERENCE) | |
{ | |
int i_owner = GetEntPropEnt(i_entity, Prop_Send, s_ent_prop_names[i][1]); | |
if (i_owner == i_client) | |
{ | |
AcceptEntityInput(i_entity, "Kill"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment