#pragma semicolon 1
#pragma newdecls required
#include <sdktools_functions>
#include <sdktools_entinput>
int iReplaces;
char sReplace[32];
public void OnPluginStart()
{
ConVar cvar;
(cvar = CreateConVar("sm_awp_replace", "weapon_ssg08", "The item that will replace the AWP. Leave blank if you want to disable the plugin", FCVAR_NOTIFY|FCVAR_PRINTABLEONLY)).AddChangeHook(CVarChanged);
CVarChanged(cvar, NULL_STRING, NULL_STRING);
AutoExecConfig(true, "awp_replace");
}
public void CVarChanged(ConVar cvar, const char[] oldValue, const char[] newValue)
{
cvar.GetString(sReplace, sizeof(sReplace));
TrimString(sReplace);
int num = FindCharInString(sReplace, ' ');
if(num > 8) sReplace[num] = 0;
else if(num != -1) sReplace[0] = 0;
}
public void OnMapStart()
{
char map[8];
GetCurrentMap(map, sizeof(map));
bool hooked;
if(hooked == !StrContains(map, "awp_", false)) return;
if((hooked = !hooked))
HookEvent("round_freeze_end", Event_FreezeEnd, EventHookMode_PostNoCopy);
else UnhookEvent("round_freeze_end", Event_FreezeEnd, EventHookMode_PostNoCopy);
}
public void Event_FreezeEnd(Event event, const char[] name, bool dontBroadcast)
{
if(!sReplace[0]) return;
iReplaces = 0;
int ent = MaxClients + 1, wpn;
float pos[3], ang[3];
while((ent = FindEntityByClassname(ent, "weapon_awp")) > MaxClients + 1)
{
if(IsHaveOwner(ent)) continue;
GetEntPropVector(ent, Prop_Send, "m_vecOrigin", pos);
GetEntPropVector(ent, Prop_Data, "m_angRotation", ang);
AcceptEntityInput(ent, "Kill");
if((wpn = CreateEntityByName(sReplace)) == -1) continue;
if(!DispatchSpawn(wpn)) continue;
TeleportEntity(wpn, pos, ang, NULL_VECTOR);
iReplaces++;
}
PrintToServer("\n%i entities 'weapon_awp' changed by '%s'\n", iReplaces, sReplace);
}
stock bool IsHaveOwner(int ent)
{
static int owner;
owner = GetEntPropEnt(ent, Prop_Data, "m_hOwnerEntity");
if(owner > MaxClients || owner < 1 || !IsClientInGame(owner)) return false;
RemovePlayerItem(owner, ent);
AcceptEntityInput(ent, "Kill");
if(GivePlayerItem(owner, sReplace) > MaxClients) iReplaces++;
return true;
}