Code:
#pragma semicolon 1
#define PLUGIN_VERSION "1.0"
#include <sourcemod>
#include <sdktools>
#include <multicolors>
#include <warden>
#define SPRITE_PATH_VMT "materials/sprites/bombaci/warden.vmt"
#define SPRITE_PATH_VTF "materials/sprites/bombaci/warden.vtf"
#define SPRITE_SCALE "0.7"
#define SPRITE_HEIGHT 90.0
#define SPRITE_DUCK_DIFF 20.0
int g_iSpriteEntRef[MAXPLAYERS+1] = {INVALID_ENT_REFERENCE,...};
public Plugin myinfo =
{
name = "",
author = "",
description = "",
version = "",
url = ""
};
public void OnPluginStart()
{
HookEvent("player_death", Event_PlayerDeath);
}
public void OnMapStart()
{
AddFileToDownloadsTable(SPRITE_PATH_VMT);
AddFileToDownloadsTable(SPRITE_PATH_VTF);
PrecacheModel(SPRITE_PATH_VMT, true);
CreateTimer(0.1, Timer_Update, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
public void OnClientConnected(int client)
{
g_iSpriteEntRef[client] = INVALID_ENT_REFERENCE;
}
public void OnClientDisconnect(int client)
{
ResetSprite(client);
}
public void warden_OnWardenCreated(int client)
{
CreateSprite(client);
}
public void warden_OnWardenRemoved(int client)
{
ResetSprite(client);
}
public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if(!client || !IsClientInGame(client))
return Plugin_Continue;
ResetSprite(client);
return Plugin_Continue;
}
public void ResetSprite(int client)
{
if(g_iSpriteEntRef[client] == INVALID_ENT_REFERENCE)
return;
int m_unEnt = EntRefToEntIndex(g_iSpriteEntRef[client]);
g_iSpriteEntRef[client] = INVALID_ENT_REFERENCE;
if(m_unEnt == INVALID_ENT_REFERENCE)
return;
AcceptEntityInput(m_unEnt, "Kill");
}
public void CreateSprite(int client)
{
if(g_iSpriteEntRef[client] != INVALID_ENT_REFERENCE)
ResetSprite(client);
int sprite = CreateEntityByName("env_sprite_oriented");
if(sprite != -1)
{
DispatchKeyValue(sprite, "classname", "env_sprite_oriented");
DispatchKeyValue(sprite, "spawnflags", "1");
DispatchKeyValue(sprite, "scale", SPRITE_SCALE);
DispatchKeyValue(sprite, "rendermode", "1");
DispatchKeyValue(sprite, "rendercolor", "255 255 255");
DispatchKeyValue(sprite, "model", SPRITE_PATH_VMT);
DispatchSpawn(sprite);
float fPos[3];
GetClientAbsOrigin(client, fPos);
fPos[2] += SPRITE_HEIGHT;
if(GetClientButtons(client) & IN_DUCK)
fPos[2] -= SPRITE_DUCK_DIFF;
TeleportEntity(sprite, fPos, NULL_VECTOR, NULL_VECTOR);
SetVariantString("!activator");
AcceptEntityInput(sprite, "SetParent", client);
}
g_iSpriteEntRef[client] = EntIndexToEntRef(sprite);
}
public Action Timer_Update(Handle timer, any data)
{
for (int i = 1; i <= MaxClients; i++)
{
if(!IsClientInGame(i))
continue;
if(!IsPlayerAlive(i))
continue;
if(IsFakeClient(i))
continue;
if(!warden_iswarden(i))
continue;
CreateSprite(i);
}
return Plugin_Continue;
}
Working .#Zipcore