C#:
namespace Oxide.Plugins;
[Info("Protect Animals", "&anhe", "1.0.2")]
[Description("Reflects damage back to players who hurt animals on foreign property.")]
public class ProtectAnimals : RustPlugin
{
private object OnEntityTakeDamage(BaseCombatEntity target, HitInfo info) =>
// Prevent if
(
// Target is an animal
target is BaseAnimalNPC &&
// Attacked by unauthorised player
(
// Attacked by player
(
info.InitiatorPlayer ??
BasePlayer.FindByID(info.Initiator?.OwnerID ?? 0)
) is BasePlayer attacker &&
// Not authorised
target.GetBuildingPrivilege(true)
?.IsAuthed(attacker) == false &&
// Not admin
!attacker.IsAdmin &&
// Reflect damage back to attacker
ReflectDamage(attacker, info)
)
)
? false : null;
#region Reflect damage
bool ReflectDamage(BasePlayer attacker, HitInfo info) {
attacker.Hurt(
info.damageTypes.Total(),
info.damageTypes.GetMajorityDamageType(),
attacker,
false
);
return true;
}
#endregion
}