Raised This Month: $344 Target: $400
 86%   Almost there!

[Question] Entity Index


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-22-2019 , 13:46   [Question] Entity Index
Reply With Quote #1

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.
Halt is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 08-22-2019 , 14:12   Re: [Question] Entity Index
Reply With Quote #2

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.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-22-2019 , 14:13   Re: [Question] Entity Index
Reply With Quote #3

Quote:
Originally Posted by 1337norway View Post
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 is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-22-2019 , 14:40   Re: [Question] Entity Index
Reply With Quote #4

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
  
}


Last edited by Halt; 08-22-2019 at 14:40.
Halt is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 08-22-2019 , 14:48   Re: [Question] Entity Index
Reply With Quote #5

Quote:
Originally Posted by Halt View Post
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.

Last edited by TheDS1337; 08-22-2019 at 14:50.
TheDS1337 is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-22-2019 , 15:00   Re: [Question] Entity Index
Reply With Quote #6

*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;

Halt is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 08-22-2019 , 15:05   Re: [Question] Entity Index
Reply With Quote #7

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
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-22-2019 , 15:15   Re: [Question] Entity Index
Reply With Quote #8

Well specifically I'm looking for smoke. How would I go about making a debug that prints created entities in chat?
Halt is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 08-22-2019 , 15:21   Re: [Question] Entity Index
Reply With Quote #9

public void OnEntityCreated(int entity, const char[] classname)
{
PrintToChatAll(classname);
}
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 08-22-2019 , 16:05   Re: [Question] Entity Index
Reply With Quote #10

smokegrenade_projectile, hegrenade_projectile, flashbang_projectile, decoy_projectile, molotov_projectile, incgrenade_projectile, tagrenade_projectile and breachcharge for the breach charge added in Danger Zone.
TheDS1337 is offline
Reply


Thread Tools
Display Modes

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 12:30.


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