AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [Question] Entity Index (https://forums.alliedmods.net/showthread.php?t=318268)

Halt 08-22-2019 13:46

[Question] Entity Index
 
Curious if anyone here has ever played with grenades in CSGO. I know the grenade in your inventory and the entity created once you throw it are two different entities. Anyone know how to get the index of the "thrown" grenade entity? Please enlighten me.

backwards 08-22-2019 14:12

Re: [Question] Entity Index
 
use the onentitycreate callback and check if it's a grenade_projectile type. Then SDKHook its spawnpost function where you will check the netprop m_hThrower. Use EntRefToEntIndex to get the players index that threw the grenade projectile.

Halt 08-22-2019 14:13

Re: [Question] Entity Index
 
Quote:

Originally Posted by 1337norway (Post 2664250)
use the onentitycreate callback and check if it's a grenade_projectile type. Then SDKHook its spawnpost function where you will check the netprop m_hThrower. Use EntRefToEntIndex to get the players index that threw the grenade projectile.

Thanks! Exactly what I was looking for.

Halt 08-22-2019 14:40

Re: [Question] Entity Index
 
Now I don't want any code, I just want to know if I'm on the right track & what I might do to better improve it.

PLEASE DONT GIVE ME FINISHED CODE

PHP Code:

#include <sourcemod>
#include <sdkhooks>

public void OnPluginStart()
{
  
HookEvent("OnEntityCreated"Event_EntityCreated);
}

public 
Action Event_EntityCreated(Handle eventint iEntity, const char[] EntityName)
{
  if (
iEntity == "grenade_projectile"
  {
    
int iGrenadeUser GetEntProp(iEntityProp_Data"m_hThrower"); //Gets user for killfeed
    
SetEntProp(iEntity"color""255 0 0"); //Sets Smoke Grenade to Red
  
}



TheDS1337 08-22-2019 14:48

Re: [Question] Entity Index
 
Quote:

Originally Posted by Halt (Post 2664256)
Now I don't want any code, I just want to know if I'm on the right track & what I might do to better improve it.

PLEASE DONT GIVE ME FINISHED CODE

PHP Code:

#include <sourcemod>
#include <sdkhooks>

public void OnPluginStart()
{
  
HookEvent("OnEntityCreated"Event_EntityCreated);
}

public 
Action Event_EntityCreated(Handle eventint iEntity, const char[] EntityName)
{
  if (
iEntity == "grenade_projectile"
  {
    
int iGrenadeUser GetEntProp(iEntityProp_Data"m_hThrower"); //Gets user for killfeed
    
SetEntProp(iEntity"color""255 0 0"); //Sets Smoke Grenade to Red
  
}



iEntity is an integer (entity index), "grenade_projectile" is a string (entity classname)

You should use GetEntityClassname EntityName and see if it's equal to grenade_projectile using StrEqual function.

You cannot check for m_hThrower at entity creation because it's not set, it is set only after it's spawned and this is where SDKHook comes to to play.

Also, I think m_hThrower is a sendprop so you should use Prop_Send, with the function GetEntPropEnt because it's checking for an entity of the thrower (a player). basically any m_h* is a handle to an entity.

Halt 08-22-2019 15:00

Re: [Question] Entity Index
 
*facepalm* I know better than to try and store a string in an int variable. Silly me. Thank you for the explination, here is what I got, with some help from the Discord. (Domino)

PHP Code:

public void OnEntityCreated(int entity, const char[] classname)
{
    if (
StrContains(classname"grenade_projectile"false) > -1)
    {
        
SDKHook(entitySDKHook_SpawnPostOnSpawnPost);
    }
}

public 
void OnSpawnPost(int entity)
{
    
int iThrower GetEntPropEnt(entityProp_Send"m_hThrower");
    
bRestrictCommand[iThrower] == true;
    
CreateTimer(30.0CommandRestrictiThrower);
}

public 
Action CommandRestrict(Handle timerdata any)
{
  
bRestrictCommand[iThrower] == false;



backwards 08-22-2019 15:05

Re: [Question] Entity Index
 
grenade_projectile isn't the real name btw, it depends on the grenade type you want, flashgrenade_projectile, hegrenade_projectile, stuff like this. although i'm not sure exactly what the names are

Halt 08-22-2019 15:15

Re: [Question] Entity Index
 
Well specifically I'm looking for smoke. How would I go about making a debug that prints created entities in chat?

backwards 08-22-2019 15:21

Re: [Question] Entity Index
 
public void OnEntityCreated(int entity, const char[] classname)
{
PrintToChatAll(classname);
}

TheDS1337 08-22-2019 16:05

Re: [Question] Entity Index
 
smokegrenade_projectile, hegrenade_projectile, flashbang_projectile, decoy_projectile, molotov_projectile, incgrenade_projectile, tagrenade_projectile and breachcharge for the breach charge added in Danger Zone.


All times are GMT -4. The time now is 19:39.

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