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

Solved TF2 Get entity of fired projectile


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cieniu97
Junior Member
Join Date: Sep 2021
Location: Poland
Old 10-10-2021 , 08:45   TF2 Get entity of fired projectile
Reply With Quote #1

Hello there!

Context:
I'm coding SDK OnTakeDamage event. There is provided inflictor and attacker.
Determining weapon for hitscan weapons is easy. Projectiles is where I am stuck. I have made distinction from those using GetEntClassName.

Question:
How to get entity index of weapon that fired projectile having only projectile entity?

Last edited by Cieniu97; 10-10-2021 at 12:22.
Cieniu97 is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 10-10-2021 , 10:40   Re: TF2 Get entity of fired projectile
Reply With Quote #2

Try using GetEntPropEnt with m_hOwnerEntity on the projectile.
xerox8521 is offline
Cieniu97
Junior Member
Join Date: Sep 2021
Location: Poland
Old 10-10-2021 , 10:57   Re: TF2 Get entity of fired projectile
Reply With Quote #3

I have already tried that. It returns player entity.
Getting players active weapon also doesnt work for following reason:
If you shoot rocket from far and then change weapon before rocket hits, then returned weapon will be your new active weapon. So even if you hit with rocket it will display shovel
Cieniu97 is offline
Cieniu97
Junior Member
Join Date: Sep 2021
Location: Poland
Old 10-10-2021 , 12:22   Re: TF2 Get entity of fired projectile
Reply With Quote #4

After digging into this hot mess of netprops i found this

SOLUTION:
PHP Code:
int launcherEnt GetEntPropEnt(projectileEntProp_Send"m_hLauncher");
int originalLauncherEnt GetEntPropEnt(projectileEntProp_Send"m_hOriginalLauncher"); 
Both of them seems to work. Both return entity index of weapon that fired projectile.
I don't know the difference between those two so step carefully future readers.
Cieniu97 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-10-2021 , 12:23   Re: TF2 Get entity of fired projectile
Reply With Quote #5

*edit
nvm

...first idea, is you look:
- SDKHooks OnEntityCreated, check entity projectile classname
- Take entity ref value https://sm.alliedmods.net/new-api/ha...tIndexToEntRef
and past it on next frame https://sm.alliedmods.net/new-api/fu...s/RequestFrame

- On next frame callback, find entity again with ref value does it exist. https://sm.alliedmods.net/new-api/ha...tRefToEntIndex
- Look projectile owner and take owner active weapon.

At this point, you have:
- projectile ref value to find projectile entity index
- owner client index
- owner weapon index.

Create array to store these and look those when ontakedamage happens.
Either adt_array or adt_trie dynamic array.

Hope you understand this mumble.
__________________
Do not Private Message @me

Last edited by Bacardi; 10-10-2021 at 12:23. Reason: nvm
Bacardi is offline
Cieniu97
Junior Member
Join Date: Sep 2021
Location: Poland
Old 10-10-2021 , 12:32   Re: TF2 Get entity of fired projectile
Reply With Quote #6

@Bacardi
I was familiar with those workarounds, but this is just an overkill. I figured that tf2 has to know which weapon fired certain projectile, and it did :> . I had to do this with just blindly getting netprops from TFProjectile class.
I wish there was ANY documentation what values in netprops and datamaps mean and do.
Thanks anyway!
Cieniu97 is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 10-11-2021 , 19:51   Re: TF2 Get entity of fired projectile
Reply With Quote #7

Quote:
Originally Posted by Cieniu97 View Post
After digging into this hot mess of netprops i found this

SOLUTION:
PHP Code:
int launcherEnt GetEntPropEnt(projectileEntProp_Send"m_hLauncher");
int originalLauncherEnt GetEntPropEnt(projectileEntProp_Send"m_hOriginalLauncher"); 
Both of them seems to work. Both return entity index of weapon that fired projectile.
I don't know the difference between those two so step carefully future readers.
m_hOriginalLauncher is for the original entity that fired the weapon, while m_hLauncher may be modified in cases of projectile deflects (Pyro's airblast).
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 10-13-2021 , 13:30   Re: TF2 Get entity of fired projectile
Reply With Quote #8

Quote:
Originally Posted by Cieniu97 View Post
I have already tried that. It returns player entity.
Getting players active weapon also doesnt work for following reason:
If you shoot rocket from far and then change weapon before rocket hits, then returned weapon will be your new active weapon. So even if you hit with rocket it will display shovel
To remedy that u could use GetPlayerWeaponSlot(client, 0); I assume slot0 is the rocket launchers slot.
Which will return the entity in that slot...the only reason it wouldn't work in this scenario is if you dropped or replaced the weapon in that slot between the long range shot.

int originalLauncherEnt = GetEntPropEnt(projectileEnt, Prop_Send, "m_hOriginalLauncher");

using this should work fine however for efficiencies sake where are you getting the netprop from. If it's a repetitive place then doing so is ineffecient and the best method would be to do as bacardi said, get the projectile from onentitycreated, hook the entity spawnpost in onentitycreated and using that netprop from there. I would not use a next frame hook from onentitycreated, i've seen at times where netprops are not fully set by nextframe, it is guaranteed from spawnpost...Just my 2 cents...

Last edited by MasterMind420; 10-13-2021 at 13:33.
MasterMind420 is offline
Cieniu97
Junior Member
Join Date: Sep 2021
Location: Poland
Old 10-13-2021 , 16:21   Re: TF2 Get entity of fired projectile
Reply With Quote #9

Quote:
Originally Posted by MasterMind420 View Post
...the only reason it wouldn't work in this scenario is if you dropped or replaced the weapon in that slot between the long range shot.
Yes, and this is not uncommon for people to maniacally switch their weapons. Also there are other projectiles like for example sticky bomb which is not on slot 0.
OriginalLauncher works the best, but I had to add
PHP Code:
HasEntProp(inflictorProp_Send"m_hOriginalLauncher"
To make it more foolproof.

I am using netprops in OnTakeDamage event, so its used frequently. Is there some trouble with that? I am unfamiliar with specific functions efficiency.
Cieniu97 is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 10-13-2021 , 17:07   Re: TF2 Get entity of fired projectile
Reply With Quote #10

Quote:
Originally Posted by Cieniu97 View Post
Yes, and this is not uncommon for people to maniacally switch their weapons. Also there are other projectiles like for example sticky bomb which is not on slot 0.
OriginalLauncher works the best, but I had to add
PHP Code:
HasEntProp(inflictorProp_Send"m_hOriginalLauncher"
To make it more foolproof.

I am using netprops in OnTakeDamage event, so its used frequently. Is there some trouble with that? I am unfamiliar with specific functions efficiency.
hmm, if you are using that netprop on the projectile that is shot out, to get the weapon it was shot from as I understand it, correct me if i'm wrong...then I would use onentitycreated then a spawnpost hook from there and within spawn post check that netprop to get the entity it was shot from...doing so from spawn post of the projectile should guarantee that the netprop is set and allow you to get that netprop. That way it will only check when needed which is when the projectile first exists rather than when damage is done. You should be able to get any info you need from the projectile the moment it is created, Who shot it, what weapon fired it...etc. From all the netprops for said projectile entity...I can see in ontakedamage the potential for the check to fire more often than needed. if you run into any issues you can PM me and I can help with the code.

Last edited by MasterMind420; 10-13-2021 at 17:11.
MasterMind420 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 00:17.


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