#pragma semicolon 1
#pragma newdecls required
#include <sdktools_entinput>
Handle
hTimer;
int
iOffset;
float
fTimer;
public Plugin myinfo =
{
name = "SM Weapon Cleanup",
author = "TechKnow & Palonez",
description = "Removes loose weapons droped",
version = "1.3.0 (rewritten by Grey83)",
url = "http://www.sourcemod.net/"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if((iOffset = FindSendPropInfo("CBaseCombatWeapon", "m_hOwnerEntity")) < 1)
{
FormatEx(error, err_max, "Can't find offset 'CBaseCombatWeapon::m_hOwnerEntity'!");
return APLRes_Failure;
}
return APLRes_Success;
}
public void OnPluginStart()
{
CreateConVar("sm_Weaponcleanup_version", "1.2.1", "WeaponCleanup version", FCVAR_DONTRECORD|FCVAR_NOTIFY|FCVAR_SPONLY);
ConVar cvar;
cvar = CreateConVar("Removeweapons_on", "1", "1 Removeweapons on 0 is off", _, true, _, true, 1.0);
cvar.AddChangeHook(CVarChange_Enable);
CVarChange_Enable(cvar, NULL_STRING, NULL_STRING);
cvar = CreateConVar("Removeweapons_Time", "10.0", "Cleanup every X seconds", _, true);
cvar.AddChangeHook(CVarChange_Timer);
CVarChange_Timer(cvar, NULL_STRING, NULL_STRING);
RegAdminCmd("sm_cleanup", Cmd_CleanUp, ADMFLAG_SLAY);
}
public void CVarChange_Enable(ConVar cvar, const char[] oldValue, const char[] newValue)
{
static bool hooked;
if(cvar.BoolValue == hooked) return;
if((hooked = !hooked))
{
HookEvent("player_death", Event_CleanUp, EventHookMode_PostNoCopy);
HookEvent("round_start", Event_CleanUp, EventHookMode_PostNoCopy);
}
else
{
UnhookEvent("player_death", Event_CleanUp, EventHookMode_PostNoCopy);
UnhookEvent("round_start", Event_CleanUp, EventHookMode_PostNoCopy);
}
}
public void CVarChange_Timer(ConVar cvar, const char[] oldValue, const char[] newValue)
{
fTimer = cvar.FloatValue;
OnMapEnd();
OnMapStart();
}
public void OnMapStart()
{
if(!hTimer && fTimer > 0.0) hTimer = CreateTimer(fTimer, Timer_CleanUp, TIMER_REPEAT);
}
public void OnMapEnd()
{
if(hTimer)
{
CloseHandle(hTimer);
hTimer = null;
}
}
public Action Cmd_CleanUp(int client, int args)
{
RemoveWeapons();
return Plugin_Handled;
}
public void Event_CleanUp(Event event, const char[] name, bool dontBroadcast)
{
RemoveWeapons();
}
public Action Timer_CleanUp(Handle timer)
{
RemoveWeapons();
return Plugin_Continue;
}
stock void RemoveWeapons()
{
int ent = MaxClients, max = GetMaxEntities();
char cls[10];
while(++ent < max)
{
if(IsValidEntity(ent) && GetEdictClassname(ent, cls, sizeof(cls)) && ((!strncmp(cls, "weapon_", 7, false) && strncmp(cls, "weapon_c4", 9, false)) || !strncmp(cls, "item_", 5, false)) && GetEntDataEnt2(ent, iOffset) == -1)
AcceptEntityInput(ent, "KillHierarchy");
}
}