Raised This Month: $51 Target: $400
 12% 

[CS:GO] How to work with Entities?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Pavelas
Junior Member
Join Date: Oct 2016
Old 12-07-2020 , 23:21   [CS:GO] How to work with Entities?
Reply With Quote #1

Hello AlliedModders,

I just started to work with entities and I am feeling a bit lost, maybe you will be able to help me. At the moment I am working with entities on the map (prop_dynamic), I have the following code.

PHP Code:
void GetEntity()
{
    
int target GetClientAimTarget(clientfalse);

    if (
target == -1) {
        return;
    }

    
// Trying to work with entities

I have the following questions:
  1. Is Entity's Index static?
    In other words, how to identify entities if they have the same Class Name but do not have m_iName? Can I use just index and store it in the database?
  2. How to find Entity's Properties?
    For example, I found that I can use property m_bShouldGlow, it makes the entity glowing, where I can find all those properties and possible values?
  3. How to change Glow Color?
    As I mentioned before, I managed to make entity glow, is it possible to change the color of glow?
  4. How to make Client -> Entity relationship?
    For example, is it possible to apply effects (glow and others) only for some clients, not for everyone?
Thank you in advance for any replies, if you know any plugins or resources where I can learn more about entities, please let me know.

Last edited by Pavelas; 12-07-2020 at 23:24.
Pavelas is offline
Balimbanana
Member
Join Date: Jan 2017
Old 12-09-2020 , 01:23   Re: [CS:GO] How to work with Entities?
Reply With Quote #2

I don't have too much experience working with the glow functions of CS:GO, but from other games, it should be similar.

As answers to the questions:
1: No, indexes are automatically adjusted when entities are created/deleted. After an entity has been created, it will be the same index until destroyed, and events such as round_end or round_start will usually delete all entities and re-create them per map.

2: sm_dump_datamaps csgodatamaps.xml and sm_dump_netprops_xml csgonetprops.xml
it will create these files in csgo/filename.xml
For the most part, the netprops will be Prop_Send, and the datamaps will be Prop_Data.
For possible values, it depends on the property, most properties that start with m_b are bool, m_fl float, m_i integer, m_h entity handle, m_vec vector, m_sz string, but it is game/mod dependent.

3: There are multiple plugins out there for glow management for CS:GO, I would recommend looking in to some of them such as https://forums.alliedmods.net/showthread.php?p=2590299

4: Most of the plugins out there deal with the SetTransmit hook for sending glow to certain players. Just know that using it on a lot of entities will be fairly intensive on the server and could cause jitter or lag with a lot active at the same time (depending on hardware).
Balimbanana is offline
Pavelas
Junior Member
Join Date: Oct 2016
Old 12-09-2020 , 19:33   Re: [CS:GO] How to work with Entities?
Reply With Quote #3

Thank you very much for your answer, I learned a lot in the past few days, but I can't solve one problem. I made a simple plugin, where you can spawn an entity and then toggle entities display, everything works fine but I found a bug and I can't find the solution.

Problem: After entity is being spawned and I am trying to disable entities display for myself (Using SetTransmit SDK Hook), entity disappears but glow remains.

How to reproduce the bug?


Plugin source:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls required

#define MODEL_CHICKEN "models/chicken/chicken.mdl"

bool g_clientEntityDisplay[MAXPLAYERS 1] = { true, ... };
int g_clientEntityRef[MAXPLAYERS 1] = { INVALID_ENT_REFERENCE, ... };

public 
Plugin myinfo =
{
    
name "Entities Test",
    
author "Pavelas",
    
description "Spawn a Chicken, add Glow Effect, use Transmit",
    
version "1.0.0"
}

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_spawn"Command_Spawn);
    
RegConsoleCmd("sm_destroy"Command_Destroy);
    
RegConsoleCmd("sm_toggle"Command_Toggle);
}

public 
void OnMapStart()
{
    
PrecacheModel(MODEL_CHICKENtrue);
}

public 
void OnPluginEnd()
{
    for (
int i 0sizeof(g_clientEntityRef); i++) {
        
DestroyEntity(i);
    }
}

public 
Action Command_Spawn(int clientint args)
{
    
DestroyEntity(client);
    
CreateEntity(client);

    return 
Plugin_Handled;
}

public 
Action Command_Destroy(int clientint args)
{
    if (
g_clientEntityRef[client] == INVALID_ENT_REFERENCE) {
        
PrintToChat(client"[ENTITIES]: You do not have any spawned entities.");

        return 
Plugin_Handled;
    }

    
DestroyEntity(client);

    return 
Plugin_Handled;
}

public 
Action Command_Toggle(int clientint args)
{
    
g_clientEntityDisplay[client] = !g_clientEntityDisplay[client];

    
PrintToChat(client"[ENTITIES]: Display entities option changed: %s"g_clientEntityDisplay[client] ? "Display" "Hide");

    return 
Plugin_Handled;
}

public 
Action Event_OnSetTransmit(int entityint client)
{
    if (
g_clientEntityDisplay[client]) {
        return 
Plugin_Continue;
    }

    return 
Plugin_Handled;
}

void CreateEntity(int client)
{
    if (!
IsPlayerAlive(client)) {
        return;
    }

    
// Get client aim origin in order to spawn an entity there
    
float origin[3];
    
GetAimOrigin(clientorigin);

    
// Trying to create an entity
    
int entity CreateEntityByName("prop_dynamic_glow");

    if (!
IsValidEntity(entity)) {
        return;
    }

    
// Set transmit entity
    
if (!SDKHookEx(entitySDKHook_SetTransmitEvent_OnSetTransmit)) {
        return;
    }

    
// Entity properties
    
DispatchKeyValue(entity"model"MODEL_CHICKEN); // Add chicken model path
    
DispatchKeyValue(entity"solid""6");
    
DispatchKeyValue(entity"glowstyle""0");
    
DispatchKeyValue(entity"glowdist""10000.0");
    
DispatchKeyValue(entity"glowcolor""255 0 0");
    
DispatchKeyValue(entity"glowenabled""1");
    
DispatchSpawn(entity);
    
TeleportEntity(entityoriginNULL_VECTORNULL_VECTOR);

    
// Attach this entity to the client
    
g_clientEntityRef[client] = EntIndexToEntRef(entity);
}

void DestroyEntity(int client)
{
    if (
g_clientEntityRef[client] == INVALID_ENT_REFERENCE) {
        return;
    }

    
int entity EntRefToEntIndex(g_clientEntityRef[client]);

    if (!
IsValidEntity(entity)) {
        
PrintToChat(client"[ENTITIES]: Impossible to destroy invalid entity: %d"entity);

        return;
    }

    
// Unhook set transmit
    
SDKUnhook(entitySDKHook_SetTransmitEvent_OnSetTransmit);

    
// Destroy the entity
    
AcceptEntityInput(entity"Kill");

    
// Detach entity from the client
    
g_clientEntityRef[client] = INVALID_ENT_REFERENCE;
}

public 
bool TraceEntityFilterPlayer(int entityint contentsMask
{
    return 
entity MaxClients;
}

stock void GetAimOrigin(int clientfloat origin[3])
{
    
float pos[3], angles[3];
    
GetClientEyePosition(clientpos);
    
GetClientEyeAngles(clientangles);

    
Handle trace TR_TraceRayFilterEx(posanglesMASK_SHOTRayType_InfiniteTraceEntityFilterPlayer);

    if (
TR_DidHit(trace)) {
        
TR_GetEndPosition(origintrace);
    }

    
CloseHandle(trace);

Pavelas is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:20.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode