1. Мизантроп

    Мизантроп Wood Hoarder

    Please, add this hook
     
  2. Loborl

    Loborl Naked Wanderer

    Hi All,

    I have functional Clan plugin but most of all I would like to do something like Frendly Fire.
    If it were possible to add a hook that would allow to control the damages to the players I would be very grateful.
    If you already have a similar implementation I am very grateful for the advice :)

    Thanks very much.
     
  3. Russo-turisto

    Russo-turisto Scavenger

    Pls, add.
    void OnPlayerDamage(PlayerSession player, PlayerSession target)
     
    LaserHydra likes this.
  4. AnonOps

    AnonOps Naked Wanderer

    Hey this message is for the oxide's devs.

    Just want to know if it's possible to add a new Hook "OnPlayerHealthChange". I think that can be a good hook to make a godmode or an anti teamkill and more..
    I try to find that on the github repos but only exist for rust and others games
     
    Russo-turisto likes this.
  5. Russo-turisto

    Russo-turisto Scavenger

    I think, need OnPlayerTakeDamage.
     
  6. AnonOps

    AnonOps Naked Wanderer

    Yeah, the name of the hook is not important, just need the hook ^^'
     
  7. Glumi Chan

    Glumi Chan Scavenger

    Push, why there is no answere to this?
     
  8. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Not everything is done instantly, it does take time and this hook isn't the only thing on the TODO list.
     
  9. Glumi Chan

    Glumi Chan Scavenger

    My post wasnt mean offending or something ^^

    I just thought cause the Post was from 2015 and no one said: "Yep recognized" or "Nope we dont do that" or something like that, that you maybe overseen this Post ^^
     
  10. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    I didn't take it as that, just saying that there are other things to do as well, but we will get around to it all when able. ;)
     
    Glumi Chan likes this.
  11. SouZa

    SouZa Master Researcher Plugin Developer

    Your awesome plugin developer ( who? Me! ) has discovered (maybe, still on test phase) a way to listen for player damage through oxide without using any kind of "OnTakeDamage" hook!

    If all goes right you can say hello to Friendly-Fire Off for Hurtworld soon : )
    If all goes wrong then sorry for getting your expectations high! xD

    Edit (4 july): Since it's still better to use a hook instead of this method to avoid performance issues (Thanks @Wulf), I've tried to find a hook damage and so I changed this topic title to: Damage Hook Discussion.
     
    Last edited: Jul 4, 2016
  12. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    For a hook placement, there's actually a thread for this already. Ideally you'd want a hook, trying to listen or constantly check would be a performance hog.
     
  13. SouZa

    SouZa Master Researcher Plugin Developer

    "without using any kind of "OnTakeDamage" hook!

    And damn, you answered like 10 seconds after I post >.<
     
  14. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    See my edited response.
     
  15. SouZa

    SouZa Master Researcher Plugin Developer

    PlayerSession.WorldPlayerEntity.GetComponent<PlayerStatManager>().EventStats.OnEventPublished += MyCustomOnEventPublishedListener();
     
  16. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Yeah, you'd still want a hook ideally.
     
  17. SouZa

    SouZa Master Researcher Plugin Developer

    Yes I understand a hook would be the best choice in performance wise. But a damage hook for hurtworld has been requested for some time now and wasn't made public yet. I tried to dig into the assembly to understand the damage code but gave up xD. Maybe my friend @Smeag could try dig into it! @Smeag !!
    Anyway I'll try to develop in this way and test on a populated server to check it.
     
  18. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    The project is open source, doesn't have to be only me contributing to it. ;)
     
  19. SouZa

    SouZa Master Researcher Plugin Developer

    I know, I know ;) Here is my contribution:

    So, I tried again and managed to find a hook for player damage using the OxidePatcher. I just wish there was a more direct and simple way, the one I found is a bit tricky.
    I hook the AddValue() method on the EntityFluidEffectProxy class like this:
    Code (Text):
    public float AddValue(float relativeValue, EntityEffectSourceData sourceData, bool applyImpactMultipliers = false, bool applyImpactOffsets = false)
    {
        object[] objArray = new object[] { this, relativeValue, sourceData, applyImpactMultipliers, applyImpactOffsets };
        object obj = Interface.CallHook("OnAddValue", objArray);
        if (obj is float)
        {
            return (float)obj;
        }
        ( ... )
    }
    so if the OnAddValue() is called on a plugin and returns a float, the damage won't be applied. If returns anything else the damage will be applied.

    The thing is, the sourceData will have information about where the damage is from (animal, explosion, ambient, player) and in case of the player it's possible to find the PlayerIdentity, so far so good. The problem is finding the Player who received the damage :(

    The only way I found out was to get the (private) OnEventPublished from EntityFluidEffectProxy through Reflection, loop the Delegates from the InvocationList, find the one which target type was EntityStats, get the (private) OnEventPublished this time from EntityStats through Reflection again, loop the Delegates, find the one which target type was PlayerStatManager and get the PlayerIdentity through there. So yeah a bit tricky.

    Debug damage Screenshot

    The idea would make this more generic to also catch CreatureToPlayer damage. But my question is if Reflection is heavy? Because this will be fired a lot on a populated server.
     
  20. SouZa

    SouZa Master Researcher Plugin Developer

    @Wulf like I said on previous post, I used the AddValue() method from EntityFluidEffectProxy to make the damage hook.

    I have modified the HurtworldCore locally to add and test the hook. Like I said, I used Reflection so I'm not sure if is performance-acceptable or if there is other way to accomplish this. Can you take a quick look whenever you have a couple of minutes free? ( Ctrl + F "IOnDamage" ).
     
    MonkeY12 likes this.