I made this. And tested.
PHP Code:
#include <sdktools>
// settings for m_takedamage
#define DAMAGE_NO 0
#define DAMAGE_EVENTS_ONLY 1 // Call damage functions, but don't modify health
#define DAMAGE_YES 2
#define DAMAGE_AIM 3
Handle timers[MAXPLAYERS+1];
public void OnPluginStart()
{
HookEventEx("player_activate", player_activate);
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
{
DataPack pack;
timers[i] = CreateDataTimer(0.8, player_timer, pack, TIMER_REPEAT);
pack.WriteCell(i);
pack.WriteCell(GetClientUserId(i));
pack.Reset();
}
}
}
public void player_activate(Event event, const char[] name, bool dontBroadcast)
{
int userid = event.GetInt("userid", 0);
int client = GetClientOfUserId(userid);
if(client > 0)
{
if(timers[client] != null)
{
delete timers[client];
}
DataPack pack;
timers[client] = CreateDataTimer(0.8, player_timer, pack, TIMER_REPEAT);
pack.WriteCell(client);
pack.WriteCell(userid);
pack.Reset();
}
}
public Action player_timer(Handle timer, DataPack pack)
{
static bool hint[MAXPLAYERS+1];
int client = pack.ReadCell();
int userid = pack.ReadCell();
pack.Reset();
if(timers[client] == null)
return Plugin_Stop;
if(timers[client] != timer)
return Plugin_Stop;
if(!IsClientConnected(client))
{
timers[client] = null;
hint[client] = false;
return Plugin_Stop;
}
if(!IsClientInGame(client))
{
hint[client] = false;
return Plugin_Continue;
}
if(IsFakeClient(client))
{
timers[client] = null;
hint[client] = false;
return Plugin_Stop;
}
int newuserid = GetClientUserId(client);
// timer match but not userid ? Something went wrong
if(userid != newuserid)
{
timers[client] = null;
hint[client] = false;
return Plugin_Stop;
}
float eyepos[3], eyeangle[3], startpos[3], endpos[3];
GetClientEyePosition(client, eyepos);
GetClientEyeAngles(client, eyeangle);
GetAngleVectors(eyeangle, startpos, NULL_VECTOR, NULL_VECTOR);
ScaleVector(startpos, 10.0);
AddVectors(startpos, eyepos, startpos);
GetAngleVectors(eyeangle, endpos, NULL_VECTOR, NULL_VECTOR);
ScaleVector(endpos, 160.0);
AddVectors(endpos, eyepos, endpos);
TR_TraceHullFilter(startpos, endpos, {-4.0,-4.0,-4.0}, {4.0,4.0,4.0}, MASK_SHOT_HULL, TraceFilter, client);
int entity = TR_GetEntityIndex();
if(entity < MaxClients)
{
if(hint[client])
{
hint[client] = false;
PrintCenterText(client, " ");
}
return Plugin_Continue;
}
char clsname[MAX_NAME_LENGTH];
GetEntityClassname(entity, clsname, sizeof(clsname));
//PrintToServer("clsname %s %i %i", clsname, GetEntProp(entity, Prop_Data, "m_takedamage"), entity);
if(!HasEntProp(entity, Prop_Data, "m_takedamage")
|| GetEntProp(entity, Prop_Data, "m_takedamage") <= DAMAGE_NO
|| !HasEntProp(entity, Prop_Data, "m_iHealth")
|| GetEntProp(entity, Prop_Data, "m_iHealth") <= 0)
{
if(hint[client])
{
hint[client] = false;
PrintCenterText(client, " ");
}
return Plugin_Continue;
}
hint[client] = true;
PrintCenterText(client , "HEALTH\n %d" , GetEntProp(entity, Prop_Data, "m_iHealth"));
return Plugin_Continue;
}
public bool TraceFilter(int entity, int contentsMask, any data)
{
return (entity != data);
}