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 useI'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.Code:hitInfo.damageTypes.ScaleAll(0.0)
Is there a new recommended method to modify attack damage?
Solved Modifying player attack damage
Discussion in 'Rust Development' started by BodyweightEnergy, Oct 4, 2015.
-
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.
-
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()); } }
-
-
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().