I'm seeing this hook get called twice for when animals are hit. And then sometimes once when the shot kills them. Anyone seem similar behavior? It's only for animals, not regular scientist NPC's, Bradleys, Heli's etc - just animals.
It's really messing things up.
OnEntityTakeDamage() weirdness
The only way it would be called twice is if they are taking damage twice. Maybe they are taking damage from the initial attack and then taking bleeding damage or something? Have you tried logging the damage types to try and find out?

0x89A
The only way it would be called twice is if they are taking damage twice. Maybe they are taking damage from the initial attack and then taking bleeding damage or something? Have you tried logging the damage types to try and find out?
Respect your knowledge of the innards, but it is indeed calling the OnEntityTakeDamage() hook TWICE for all animals, and the damage type is 'Bullet.'
Interestingly, the second call is for 1/2 the original damage. So for LR300 shots, I'm seeing 40HP of bullet damage, then on the second call, I see 20HP of bullet damage.
I've had to put in a hack-a-round to put an end to the double call polluting my statsitics engine plugin. (I use a simple TimeSpan check between calls to the hook, and if same player is getting it and it's less time than the fastest automatic weapon shot time, I ignore it...but I shouldn't need to do this nasty fix.)
It'd be nice if I knew why it's doing this (and why just animals!?), or at least if it's an Oxide thing or a FacePunch thing.
Merged post
Update:
So far, I'm only seeing this for BaseAnimalNPC types. It's not doing it for the ridable horses. I've unloaded every other plugin and am not running other mods. It's my dev server, so pretty much whatever FacePunch throws out there is what's on this box. Here's part of the code that I'm seeing the double-pump happen and what I use to trap the events in OnEntityTakeDamage():
//
// Player -vs- animal
if (entity is BaseAnimalNPC || (entity is BaseRidableAnimal && damage > 0))
{
// Un-comment to demo the double call of this hook for Animal Damage (Doesnt do it for Ridable critters)
//Instance.Puts($"Animal hit by: {damageType}:{damage}HP");
if (null != aps)
aps.AddHit(PlayerStats.TargetType.Animal, PlayerStats.HitType.Outgoing, distance);
return null;
}
try this option
entity.health - info.damageTypes.Total() Also had the same issue two weeks ago when was testing my stats plugin, didn't solve it yet
FurxFolf
Also had the same issue two weeks ago when was testing my stats plugin, didn't solve it yet
Hey bud - I don't think it's widely known, and certainly doesn't have much of an impact on the bulk of plugins out there that I've seen. It's likely one of those 'fringe' cases (that we in development LOVE to hate) that has slipped through the cracks all this time because unless you're attempting to write a plugin that counts EVERY hit / damage point, you probably won't ever notice it.
That said, I'm still open to it being my fault or from something I'm doing / not doing on my server. I'm relatively new to Rust Plugins, but not to development and engineering.
My stats plugin is also catching some other weirdness, but I have been busy this week with regular work. Will be posting an update with additional findings. I reckon the poor guys supporting Oxide are probably flat out with so much other stuff to do that something like this that has REALLY low impact wont make their radar - and who could blame them? More later.
Merged post
Further testing:
Added the current system TICK to the print-out in OnEntityTakeDamage() hook:
So looking at these numbers, we can convert the tick-time between the bullet strike for 50HP on the bear, and the second call to the same hook for what we'll just call a 'shadow hit' for half of the original, or 25HP, and see that it is around 2 milliseconds each time.
Note that the fastest firing guns in the game currently have shots spaced at around 85ms (Both the Custom SMG and the Prototype 17 have similar numbers, with the pistol being a little faster.)
I tested with more weapons today and have found a couple of interesting facts. The first is that when animals are struck by multiple pellets from a shotgun or Eokas, the OnEntityTakeDamage() hook is called for each and every pellet strike. And you guessed it, the timing between these separate calls is the same - around 2ms each.
What's interesting is that the shadow hits do not appear for all single-projectile weapons.
I see shadow hits for: M39, AK-47, LR300, L96, HMLMG, M2, Pump and SPAS-12 when firing slugs and the Semi-automatic rifle
No shadow hits for : Nail gun, Python, M92, Revolver, Semi-automatic pistol, MP5A2, Thompson, or any of the Bows.
There are no shadow hits when the original projectile strike kills the animal.
To me, these tests show an inconsistent call behavior if we just assume that the shadow hitting weapons are a single projectile. The observations today show that _some_ single-shot weapons have the shadow hit, while others do not.
Merged post
Mr.Blue suggested in a post on Discord channel RAC on #Oxide channel that I might check the Bone being hit. This was added tonight and there's some compelling evidence to suggest a new hypothesis which may perhaps make some sense and is worth further looking into.
What I noticed is that for the bulk of shadow-hits registered, the Bone ID (from HitInfo) is different from the first bullet strike. This suggests that a second bone is being struck inside of the animal. In my test case, I used a bear to try to keep some consistency of results. This suggests that they are not "stopping" the calculation of bullet trajectory once the bullet has entered the animal's hitbox, and are instead continuing to find collisions with other parts. We can see this behavior sometimes by shooting barrels that are in close proximity and "lined up" for a shot -- both barrels will break.
Further, when using the "ai.move false" command from the console and spawning in additional bears, I noticed that if I lined up a shot to the bear's head from either side (left or right) I only see the one bullet hit - there are no shadow hits registering for a side-on head strike.
What seems to remain an un-answered question and casts doubts on the validity of this idea is that about 20% of the shadow hits are registering with an identical bone ID.
I would welcome anyone doing similar tests to post results here for the benefit of other developers down the road.
Merged post
SUMMARY:
To me as a new plugin developer, there are some consistencies here worth noting in light of my last entry and Mr. Blue's suggestion to check the Bone ID - the first is that from the weapons I listed, you could summarize that any weapon that shoots the rifle round appears to have the ability to get shadow hits. Pistol rounds and arrows do not. This is an interesting game dynamic and seems to follow what some other game engines do (e.g. Scum.)
Note that side-on head shots don't register shadow hits.
While about 20% of my tests (on stationary bears) revealed identical bone ID's being hit, it's possible:
A) That they are causing an internal ricochet inside the animal's hitbox - this agrees with some real-world bullet strikes.
or
B) Bullet is passing through second hit-box and striking same bone (e.g. spine) between hitbox boundaries.
Hope this helps someone else down the road.