sry double post
I don't fully understand OP question.
So I throw some things what you can try.
Do you want track specific entity ?
- Use
EntIndexToEntRef(entity) <->
EntRefToEntIndex(ref)
- This work like clients
userid, if you not get valid entity index by using
ref id then it is deleted.
Some other examples.
PHP Code:
#include <sdktools>
#include <sdkhooks>
// Weapon m_iState
#define WEAPON_NOT_CARRIED 0 // Weapon is on the ground
#define WEAPON_IS_CARRIED_BY_PLAYER 1 // This client is carrying this weapon.
#define WEAPON_IS_ACTIVE 2 // This client is carrying this weapon and it's the currently held weapon
char state[][] = {
"WEAPON_NOT_CARRIED",
"WEAPON_IS_CARRIED_BY_PLAYER",
"WEAPON_IS_ACTIVE"
};
public void OnPluginStart()
{
HookEventEx("player_spawn", player_spawn);
}
// Moment when player spawn
// + Player get default spawn weapons, after death or game restart (cs:s = pistol, knife)
// + Player is carrying weapons from previous rounds
// - Player not pick weapon at this moment (cs:s = c4 or weapons on ground)
//
public void player_spawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
int m_hMyWeapons = GetEntPropArraySize(client, Prop_Send, "m_hMyWeapons");
int entity;
char classname[64];
for(int x = 0; x < m_hMyWeapons; x++)
{
entity = GetEntPropEnt(client, Prop_Send, "m_hMyWeapons", x);
if(entity == -1) continue;
GetEntityClassname(entity, classname, sizeof(classname));
PrintToServer("m_hMyWeapons %i %i - %s %N %s",
entity,
EntIndexToEntRef(entity),
classname,
GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity"),
state[GetEntProp(entity, Prop_Send, "m_iState")]);
}
}
// Moment, entity created
// + all weapons created on map (cs:s = round restart)
//
public void OnEntityCreated(int entity, const char[] classname)
{
if(StrContains(classname, "weapon_", true) != 0) return;
RequestFrame(nextframe, EntIndexToEntRef(entity));
}
// Moment, entity created -> next frame delay
// + weapon created and player owns/carrying it (cs:s = c4 at round start, weapon buy, give weapon_*)
// - Player not pick weapon from ground at this moment
//
public void nextframe(int ref)
{
int entity = EntRefToEntIndex(ref);
if(!IsValidEntity(entity)) return;
int owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
if(owner == -1) return;
char classname[64];
GetEntityClassname(entity, classname, sizeof(classname));
//PrintToServer("nextframe %N %s", owner, classname);
PrintToServer("nextframe %i %i - %s %N %s",
entity,
EntIndexToEntRef(entity),
classname,
owner,
state[GetEntProp(entity, Prop_Send, "m_iState")]);
}
__________________