View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-05-2021 , 14:48   Re: Total weapons count on the map
Reply With Quote #5

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[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));

    
int m_hMyWeapons GetEntPropArraySize(clientProp_Send"m_hMyWeapons");
    
int entity;
    
char classname[64];

    for(
int x 0m_hMyWeaponsx++)
    {
        
entity GetEntPropEnt(clientProp_Send"m_hMyWeapons"x);
        
        if(
entity == -1) continue;

        
GetEntityClassname(entityclassnamesizeof(classname));

        
PrintToServer("m_hMyWeapons %i %i - %s %N %s",
                                            
entity,
                                            
EntIndexToEntRef(entity),
                                            
classname,
                                            
GetEntPropEnt(entityProp_Send"m_hOwnerEntity"),
                                            
state[GetEntProp(entityProp_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(nextframeEntIndexToEntRef(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(entityProp_Send"m_hOwnerEntity");
    
    if(
owner == -1) return;

    
char classname[64];
    
GetEntityClassname(entityclassnamesizeof(classname));

    
//PrintToServer("nextframe %N %s", owner, classname);
    
PrintToServer("nextframe %i %i - %s %N %s",
                                        
entity,
                                        
EntIndexToEntRef(entity),
                                        
classname,
                                        
owner,
                                        
state[GetEntProp(entityProp_Send"m_iState")]);

__________________
Do not Private Message @me
Bacardi is offline