Checking if attacked by player?
Hi,
what is the  best way to check if an entity was attacked by a player as oposed to a an AI?

If I hook into oxide with:
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
{
if(info !=null &&info.Initiator is BasePlayer){
#cannot be AI
}
}

Seems above is still registering the attack if the  attacker is an AI (Bear/Chicken/etc)
info.InitiatorPlayer != null

Many npcs inherit from baseplayer. Other way is to check if their userid.IsSteamId()
if (info.Initiator.GetType() == typeof(BasePlayer))
{
  // Do stuff
}


Should work only on real BasePlayers and not the entities that inherit from it.

Ok... I'm a moron.....

6 hours of why it won't work....... somehow on my setup the plugin double loaded...... (remember to unload plugins BEFORE snapshot)
A prior unmodified plugin was  sitting  under this one... and THAT one was letting thru the   NPC's....

But heads up  2CHEVSKI  for the  inheritance........ 
yep... the above code was just thrown together for a quick demo, I'm well aware of checking for nulls before using.

Also I had seen "userid.IsSteamId()"  but was not sure on how heavy it was  time wise...

New to C#  but a couple of decades in corporate Java...    the main issue is almost ZERO API information on  "Oxide" & "Rust"
I'm not a professional so I just put a ton of Puts() statements all over the code if I don't know what's going on.  =)
yep.....
but it's cleaning the crap up afterwards.. & having to put them back for debugging.....
That's the problem with having to relese this stuff "source" in a normal build environment a simple flag strips during compile.
Zugzwang
if (info.Initiator.GetType() == typeof(BasePlayer))
{
  // Do stuff
}

Should work only on real BasePlayers and not the entities that inherit from it.

Yes, but this is unnecessary reflection usage and trade up for this is performance.

razorfishsl
yep.....
but it's cleaning the crap up afterwards.. & having to put them back for debugging.....
That's the problem with having to relese this stuff "source" in a normal build environment a simple flag strips during compile.

You could make a debug output method which body is inside some #if preprocessor directive. So after you've finished debugging you just remove #define with this constant and method appears empty at the runtime.

5ba0b9633e817.png?uid=5ba0b9716c220 2CHEVSKII

Yes, but this is unnecessary reflection usage and trade up for this is performance.

Totally correct.  I failed to consider the performance impact.  Quicker to infer the type from a value check.  Going to have to change a couple of lines in my plugins, as it is best practice to do things as efficiently as possible.

Yep...
I could but that leaves it in the source..

I've been comparing C# on storage of lists/vectors and have to say many assumptions have been blown out of  water
Some of this stuff is 200% slower , so instead of something taking 5 ms , it takes 10-11ms and fixing it is just a case of deleting what might be considered "good programming practice",  MS must have some real garbage implemantations of base objects