1. My plugin uses OnPlayerAttack() to modify damage to 0.0 (friendly fire), which worked fine before the last Rust update of Oct 1st.

    After that update, melee damage cannot be modified and does full damage. OnPlayerAttack() still gets called when players do melee attacks, but damage is not modified. I use
    Code:
    hitInfo.damageTypes.ScaleAll(0.0)
    I've looked through the decompiled code (Assembly-CSharp.dll), found where OnPlayerAttack hook is detected (OnProjectileAttack). Seems like melee is not done through that anymore.

    Is there a new recommended method to modify attack damage?
     
  2. Wulf

    Wulf Community Admin

    Melee damage was never done from that location. It is done from the internal hook IOnMeleeAttack which is then wrapped by OnPlayerAttack. The hook hasn't changed though.

    b4f4bca5b5b456090406701b964f7cb1.png
     
  3. That explains why OnPlayerAttack() still gets called when doing a melee attack, but why would its damage not be modified?

    Here's how I use it, maybe I'm not using the best method:
    Code:
    private void OnPlayerAttack(BasePlayer player, HitInfo hitInfo)
            {
                Puts("OnPlayerAttack() called.");  //for debug purposes
                if (hitInfo.HitEntity is BasePlayer && hitInfo.Initiator is BasePlayer)
                {
                    var victimPlayer = (BasePlayer) hitInfo.HitEntity;
                    //float damageScale = 1.0f;
                    var sb = new StringBuilder();
                    if (player == null || hitInfo == null) return;
                    var attackerPlayer = (BasePlayer)hitInfo.Initiator;
                    var victimID = victimPlayer.userID;
                    var attackerID = attackerPlayer.userID;
                    if (playerTeam.ContainsKey(victimID) && playerTeam.ContainsKey(attackerID)) 
                    {
                        if (victimID != attackerID)  //Don't modify if attack is suicide
                        {
                            if (playerTeam[victimID] == playerTeam[attackerID]) // Modify damage if both attacker and victim are on same team
                            {
                                hitInfo.damageTypes.ScaleAll(damageScale);
                                sb.Append("Friendly Fire!");
                            }
                        }
                    }
                    SendReply(hitInfo.Initiator as BasePlayer, sb.ToString());
                }
            }
     
  4. If I remember correctly the damage is being set after the hook is called which pretty much reverts your changes to the damage.
     
  5. I think I figured it out...

    I used OnEntityTakeDamage() previously, and that correctly assigns damage scales.

    Then I changed it to OnPlayerAttack() and that doesnt work with melee.

    For Future Reference: For modiying attacks, use OnEntityTakeDamage().