I'm currently working in a simple plugin that serve to put a simple sprite in the head of the players like this:
=============================
The plugin works fine sometimes, but the problem is, when the round starts some sprites disappear, and when a person who have the sprite in the head dies, the sprite DON'T dissapear, it stays in the site of the death person (static). You can test the plugin youself and see how it works.
I think there's something wrong with the Sprite entity, or i've made a bad way to kill the sprite. Can someone help me? thanks
Code:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
//#include <hl_gangs>
new g_unClientSprite[MAXPLAYERS+1]={INVALID_ENT_REFERENCE,...};
int g_iTimer;
public Plugin myinfo =
{
name = "Icons for Gangs",
author = "Nano",
description = "",
version = "2.1",
url = "http://steamcommunity.com/id/marianzet1"
};
public void OnPluginStart()
{
HookEvent("round_start", round_start);
HookEvent("player_death", Event_PlayerDeath);
// HookEvent("round_end", round_end);
}
public void OnMapStart()
{
AddFileToDownloadsTable("materials/decals/rage/pandilla.vtf");
AddFileToDownloadsTable("materials/decals/rage/pandilla.vmt");
PrecacheModel("materials/decals/rage/pandilla.vmt", true);
}
public void OnClientConnected(int client)
{
g_unClientSprite[client]=INVALID_ENT_REFERENCE;
}
public void OnClientDisconnect(int client)
{
ResetSprite(client);
}
public Action round_start(Event event, char[] name, bool dontBroadcast)
{
CreateTimer(1.0, Timer_SetSprite, _, TIMER_REPEAT);
}
public Action Timer_SetSprite(Handle timer)
{
if (g_iTimer <= 60)
{
for (int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetClientTeam(i) == CS_TEAM_T)
{
CreateSprite(i);
}
}
g_iTimer++;
return Plugin_Continue;
}
g_iTimer = 0;
return Plugin_Stop;
}
public Action Event_PlayerDeath(Event event, char[] name, bool dontBroadcast)
{
for (int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetClientTeam(i) == CS_TEAM_T)
{
ResetSprite(i);
}
}
}
//I've tested this too:
/*
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (client > 0 && IsValidClient(client))
{
ResetSprite(client);
}
return Plugin_Continue;
}
*/
public ResetSprite(client)
{
if(g_unClientSprite[client] == INVALID_ENT_REFERENCE)
return;
new m_unEnt = EntRefToEntIndex(g_unClientSprite[client]);
g_unClientSprite[client] = INVALID_ENT_REFERENCE;
if(m_unEnt == INVALID_ENT_REFERENCE)
return;
AcceptEntityInput(m_unEnt, "Kill");
}
public CreateSprite(client)
{
if(g_unClientSprite[client] != INVALID_ENT_REFERENCE)
return;
new m_unEnt = CreateEntityByName("env_sprite");
if (IsValidEntity(m_unEnt))
{
char iTarget[16], sTargetname[64];
GetEntPropString(client, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname));
Format(iTarget, sizeof(iTarget), "Client%d", client);
DispatchKeyValue(client, "targetname", iTarget);
float m_flPosition[3];
GetClientEyePosition(client, m_flPosition);
m_flPosition[2] += 20.0;
g_unClientSprite[client] = EntIndexToEntRef(m_unEnt);
DispatchKeyValue(m_unEnt, "model", "materials/decals/rage/pandilla.vmt");
DispatchKeyValue(m_unEnt, "classname", "env_sprite");
DispatchKeyValue(m_unEnt, "spawnflags", "1");
DispatchKeyValue(m_unEnt, "scale", "0.1");
DispatchKeyValue(m_unEnt, "rendermode", "1");
DispatchKeyValue(m_unEnt, "rendercolor", "255 255 255");
DispatchSpawn(m_unEnt);
TeleportEntity(m_unEnt, m_flPosition, NULL_VECTOR, NULL_VECTOR);
SetVariantString(iTarget);
AcceptEntityInput(m_unEnt, "SetParent", client, m_unEnt, 0);
DispatchKeyValue(client, "targetname", sTargetname);
}
}
bool IsValidClient(int client)
{
return (0 < client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client));
}
__________________