1. {QaD}Lurch

    {QaD}Lurch Naked Wanderer

    So I wrote the following test code to see what I can get from the game engine when damage is taken by a player. Works great for zombie attacks, but something's not right - it doesn't trigger when there's a deliberate player -vs- player attack.
    Code (Text):
    private void OnEntityTakeDamage(EntityAlive _entity, DamageSource _source)
            {
                if(_entity.IsClientControlled())
                {
                    string txt = string.Empty;
                    ClientInfo attackerInfo;
                    try
                    {
                        var srcEnt = _source.getEntityId();
                     
                        // Get all entity types, players and critters
                        var attacker = ConsoleHelper.ParseParamEntityIdToEntity(srcEnt.ToString(), false);

                        if (attacker.entityType == EntityType.Player)
                        {
                            attackerInfo = ConsoleHelper.ParseParamEntityIdToClientInfo(attacker.entityId.ToString());
                            txt = string.Format("PvP-> {0} just attacked {1} [hlth:{2}]", attackerInfo.playerName, _entity.EntityName, _entity.Health);
                            SendPublicChatMessage(chatColors["Teal"], txt);
                        }

                        txt = string.Format("Ouch! {0} was just hit by a {1} via {2} [hlth:{3}]", _entity.EntityName, attacker.entityType, _source.GetName(), _entity.Health);
                        SendPublicChatMessage(chatColors["Lime"], txt);
                    }
                    catch(Exception ex)
                    {
                        txt = string.Format("Entity damage trap: {0}", ex.Message);
                        SendPublicChatMessage(chatColors["Red"], txt);
                    }
                }
            }
    I'm looking into it some more - someone suggested that there is a server side setting, but since the players are able to induce damage to each other, this hook should be triggering.
     
  2. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    I'll take a look when I am able to test.
     
  3. {QaD}Lurch

    {QaD}Lurch Naked Wanderer

    So far, short of committing suicide in testing, it does not appear that the event hook is triggered for any of the other damage types enumerated within
    Code (Text):
    EnumDamageSourceType
    other than Melee.

    Spikes, block falling (mining accidents) - none of these trigger the event as one might otherwise expect.
     
  4. {QaD}Lurch

    {QaD}Lurch Naked Wanderer

    Update: It triggers on damage you do to yourself (explosively at least.)
     
  5. {QaD}Lurch

    {QaD}Lurch Naked Wanderer

    Have you been able to test?

    *Pushes beer his way*
     
  6. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Not yet, I checked this when I was mobile I think and lost it. I'll try to check soon.
     
  7. {QaD}Lurch

    {QaD}Lurch Naked Wanderer

    Observations to date:

    It does not hook for any other damage other than explosive damage types when Player -v- Player. This is the only time you will see the hook called. Typical scenario is when you have a crossbow with exploding bolts and pop one too close to someone. It will hook when the damage occurs between you and another player, or when you're abusing yourself.

    Otherwise, bullets, arrows, punches / melee, hatchets, sledgehammers etc don't appear to execute through this hook.
     
    Wulf likes this.
  8. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    I've been testing it, all appear to be working fine. Pretty much all of the game's damage the entities goes through the location we hook, so there's no chance much (if anything) is getting missed.
     
  9. Rakeki

    Rakeki Naked Wanderer

    I cant second this issue, im trying to capture block damage.

    I can** second this issue,
     
    Last edited by a moderator: Oct 17, 2016
  10. Rakeki

    Rakeki Naked Wanderer

    Literally have the below.

    Code (Text):
    void OnEntityTakeDamage(EntityAlive entity, DamageSource source)
    {
        Puts("OnEntityTakeDamage works!");
    }
    Nothing appears in logs etc when any blocks take damage?
     
  11. Rakeki

    Rakeki Naked Wanderer

    Is there something im missing?
     
  12. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    I'll take a look once I get a chance. I've been reviewing all of the hooks for each game we support, this one may need an overhaul.