OnEntityTakeDamage
OnEntityTakeDamage is called before a BaseCombatEntity applies incoming damage, giving you the chance to inspect or modify the HitInfo or cancel the hit. It fires for players, animals, buildings and most other combat entities.
object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)Parameters
| Parameter | Type | Description |
|---|---|---|
entity | BaseCombatEntity | The BaseCombatEntity taking the damage. This is the hurt target, which can be a player, animal, building block, deployable, NPC or resource entity depending on what was hit. Null-check it and cast to the specific type you care about. |
hitInfo | HitInfo | The HitInfo describing the incoming damage: Initiator and InitiatorPlayer, damageTypes (DamageTypeList), isHeadshot, IsProjectile(), Weapon, HitPositionWorld and more. You can scale damage through hitInfo.damageTypes or cancel the hit entirely. |
Return value
Returning null lets the original damage path continue with the (possibly modified) HitInfo. Returning any non-null object stops the original code path at that call site, which effectively cancels the hit for entities that route through these injections, so use a non-null return to suppress damage you have fully handled yourself.
How it works
The hook fires from Oxide's own combat wrappers rather than a patched game method, so it runs for virtually everything that can be hurt. The main path is RustCore.IOnBaseCombatEntityHurt, which is invoked for any BaseCombatEntity that is not a BasePlayer. Player hits arrive through RustCore.IOnBasePlayerAttacked and IOnBasePlayerHurt, and two specialized paths exist for ResourceEntity.OnAttacked and Rust.Ai.Gen2.LivestockAnimal.Hurt.
entity is the receiver and hitInfo carries the damage type, the attacker (InitiatorPlayer, Initiator), projectile details and the damage list. Adjust hitInfo.damageTypes (for example Scale(Rust.DamageType.Bullet, 0.5f) or ScaleAll(0f)) to reshape the hit. Declaring a narrower parameter type such as BasePlayer makes Oxide skip calls where the argument is not that type, so you only handle the cases you care about. Because the hook fires constantly, never print to console inside it; cache decisions and keep the body cheap.
Other signatures
Oxide also calls OnEntityTakeDamage from other places in the game with these parameter types. Declare the overload you need, or several:
object OnEntityTakeDamage(ResourceEntity resourceEntity, HitInfo info)object OnEntityTakeDamage(Rust.Ai.Gen2.LivestockAnimal livestockAnimal, HitInfo info)object OnEntityTakeDamage(BasePlayer player, HitInfo hitInfo)
Example plugin: Reduce structure damage from explosives
using System.Collections.Generic;
using System;
using Newtonsoft.Json;
using Oxide.Core;
using Rust;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Explosive Building Damage", "RustPluginGenerator", "1.0.0")]
[Description("Scales explosion damage taken by buildings and deployables.")]
public class ExplosiveBuildingDamage : RustPlugin
{
private PluginConfig config;
private class PluginConfig
{
[JsonProperty("Explosion damage multiplier")]
public float Multiplier = 0.5f;
}
protected override void LoadDefaultConfig() => config = new PluginConfig();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<PluginConfig>();
if (config == null) throw new Exception();
}
catch
{
PrintWarning("Configuration file is invalid, using defaults");
LoadDefaultConfig();
}
if (config.Multiplier < 0f) config.Multiplier = 0f;
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(config);
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Reloaded"] = "Explosive damage multiplier is now {0}."
}, this);
}
private string Msg(string key, string userId = null, params object[] args) =>
string.Format(lang.GetMessage(key, this, userId), args);
private void Init()
{
Puts("ExplosiveBuildingDamage loaded with multiplier " + config.Multiplier);
}
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
{
if (entity == null || hitInfo == null || hitInfo.damageTypes == null) return null;
if (entity is BasePlayer) return null;
bool isBuilding = entity is BuildingBlock;
bool isOwned = entity.OwnerID != 0 && entity.GetBuildingPrivilege() != null;
if (!isBuilding && !isOwned) return null;
if (hitInfo.damageTypes.GetMajorityDamageType() != DamageType.Explosion) return null;
hitInfo.damageTypes.Scale(DamageType.Explosion, config.Multiplier);
return null;
}
}
}The plugin scales explosion damage against building blocks and deployables so raiding costs more on a custom server. OnEntityTakeDamage receives every hurt entity; the body first rejects anything that is not a BuildingBlock or a BaseEntity owned through a building privilege, then reads hitInfo.damageTypes.GetMajorityDamageType(). When the majority type is Explosion, it calls hitInfo.damageTypes.Scale(Rust.DamageType.Explosion, multiplier). Returning null keeps the modified HitInfo so the entity still takes the reduced damage. The multiplier is configurable and reloading config adjusts the behavior without restarting.
Common use cases
Explosion damage multiplier
Scale explosion damage up or down on buildings to tune raid cost without touching weapon configs. Check
hitInfo.damageTypes.GetMajorityDamageType()before scaling.Damage immunity zones
When the receiver is inside a protected area or event zone, call
hitInfo.damageTypes.ScaleAll(0f)or return a non-null value to block the hit. This also handles players if you narrow the parameter to BasePlayer.Headshot or weapon-specific tuning
Read
hitInfo.isHeadshotandhitInfo.Weaponto apply custom PvP damage curves, for example reducing bolt-action headshots against armored targets while leaving body shots untouched.
Pitfalls
Fires on almost every hit
This hook runs constantly during combat, so doing expensive lookups (team scans, container checks, permission queries) per call hurts server performance. Cache results or check cheap conditions like entity type first.
Mutating hitInfo.damageTypes before checks
GetMajorityDamageType()reflects the damage list you have already scaled. Read the majority type before applying scaling, otherwise subsequent checks against it can misclassify the hit.Narrow types skip unrelated entities
Declaring
BaseCombatEntityreceives everything, but declaringBasePlayeronly fires for players. Do not assume a single hook method catches resource or animal hits if you have narrowed the parameter.
Plugin recipes that use OnEntityTakeDamage
- How to make a Rust Bradley APC and patrol helicopter kill announcer pluginTracks damage dealt to the Bradley APC and patrol helicopter, then announces in chat which player did the most damage and the map grid where the boss died. Uses OnEntityTakeDamage and OnEntityDeath.
- How to make a Rust building protection plugin (PvE owner-only damage)Blocks and deployables only take damage from their owner or players authorized on the covering tool cupboard. Uses OnEntityTakeDamage with a BaseCombatEntity signature, ignoring decay and NPC sources.
- How to make a Rust clan plugin (tag, invite, friendly fire block)Adds a lightweight clan system with /clan create, invite, join, leave and info, stores clans in a data file, prefixes members' chat with their tag and blocks damage between clanmates via OnPlayerChat and OnEntityTakeDamage.
- How to make a Rust combat block plugin (block commands in combat)Tracks combat with the OnEntityTakeDamage hook and blocks a configurable list of chat commands while a player is in combat, using OnPlayerCommand to cancel them. Players see the remaining seconds in chat.
- How to make a Rust duels plugin (1v1 challenge system)Adds a player-vs-player duel system where /duel <player> sends a challenge, /duel accept starts it, and damage outside the duel pair is blocked. Uses OnEntityTakeDamage, OnEntityDeath and OnPlayerDisconnected.
- How to make a Rust explosive damage multiplier plugin (per-weapon raiding)Scales explosion damage against building blocks, deployables and other structures using per-weapon multipliers keyed by the attacker's weapon prefab short name. It uses OnEntityTakeDamage to intercept explosion hits and rewrites the damage amount.
- How to make a Rust friendly fire plugin (team damage blocker)Blocks damage between members of the same Rust team using OnEntityTakeDamage, with a permission whitelist and a /ff toggle for team leaders that persists per team across restarts.
- How to make a Rust god mode plugin (damage immunity + full needs)Adds a permission-gated /god toggle that blocks all damage through OnEntityTakeDamage and keeps health, food and water topped up from a repeating timer. State is dropped in OnPlayerDisconnected.
- How to make a Rust heli and Bradley loot lock plugin (PvE ownership)Tracks damage dealt to the Patrol Helicopter and Bradley APC per player and locks the crates they drop for a configurable time, allowing only the top damager and their team to loot. Uses OnEntityTakeDamage, OnEntityDeath, OnEntitySpawned and CanLootEntity.
- How to make a Rust home teleport plugin (warmup, cooldown, damage cancel)Adds /sethome, /home, /delhome and /homes with per-permission home limits, a warmup timer that is cancelled when the player takes damage, and a teleport cooldown. It uses OnEntityTakeDamage to break the warmup and a per-tick timer for the countdown.
- How to make a Rust new player protection plugin (raid protection)Blocks damage to buildings owned by players under a configurable playtime threshold, tracks playtime per player in oxide/data, and removes protection early when the protected player damages another player's base. Uses OnEntityTakeDamage and OnNewSave.
- How to make a Rust no fall damage plugin (permission based)Removes or scales fall damage in OnEntityTakeDamage for players, optionally only for holders of a permission, with a configurable multiplier and a short chat notice.
- How to make a Rust no vehicle decay plugin (per-type scaling)Scales or disables decay damage on minicopters, boats, horses and modular cars per vehicle type, optionally only while inside a tool cupboard radius. It uses OnEntityTakeDamage(BaseCombatEntity, HitInfo).
- How to make a Rust no-decay plugin (per-category multipliers)Scales or disables decay damage for building blocks by grade, deployables and vehicles using configurable multipliers. It hooks OnEntityTakeDamage, reads the damage type and the entity type, and returns null when decay should be cancelled.
- How to make a Rust NPC damage multiplier plugin (per-type overrides)Scales damage NPCs deal to players and damage players deal to NPCs independently, with per-NPC-type overrides, using Oxide's OnEntityTakeDamage(BaseCombatEntity, HitInfo) hook.
- How to make a Rust offline raid protection plugin (cupboard based)Scales damage to building blocks and deployables when every player authorized on the covering tool cupboard has been offline for a configurable delay. Uses OnEntityTakeDamage and OnPlayerDisconnected, with a repeating timer that turns protection on and off.
- How to make a Rust PvE raid hours plugin (weekly raid windows)Blocks player-versus-player damage and player damage to other players' buildings outside configured weekly raid windows, using OnEntityTakeDamage plus a /raidtime command that reports the next opening.
- How to make a Rust PvE server plugin (block PvP and foreign structure damage)A PvE ruleset plugin that cancels player-vs-player damage and damage dealt by players to buildings or deployables they do not own, while leaving NPC, animal and own-base damage untouched. It works through the OnEntityTakeDamage hook.
- How to make a Rust PvE traps plugin (traps ignore players)Makes auto turrets, flame turrets, shotgun traps and landmines skip players entirely: turrets drop the player as a target and any trap damage aimed at a player is cancelled. Uses OnTurretTarget and OnEntityTakeDamage.
- How to make a Rust PvP damage multiplier plugin (global, per-weapon, headshot)Scales damage players deal to other players using a global multiplier, per-weapon shortname overrides and an extra headshot factor. It runs in OnEntityTakeDamage(BasePlayer, HitInfo) and rewrites hitInfo.damageTypes before the hit is applied.
- How to make a Rust PvP toggle plugin (Oxide/Carbon)Adds a /pvp command that switches each player between PvP and PvE mode with a per-player cooldown, stores the choice in oxide/data, and blocks player-versus-player damage unless both sides have PvP enabled. It uses OnEntityTakeDamage(BasePlayer, HitInfo) to cancel damage.
- How to make a Rust PvP zones plugin (spherical zones, Oxide/Carbon)Blocks player-versus-player damage everywhere except inside named spherical zones defined in the config, using OnEntityTakeDamage to cancel damage between players outside those zones. Admins add, list and remove zones with console commands.
- How to make a Rust raid alert plugin (chat warnings for base owners)Chat-alerts online owners and tool cupboard authed players when explosives damage their building, with the attacker name and map grid, throttled to one alert per building per minute. It uses OnEntityTakeDamage and reads the building's BuildingPrivlidge list.
- How to make a Rust raid block plugin (block tpr/home after explosives)Places a temporary raid block on attackers and on the owner of a building that takes explosive damage, blocking configured chat commands such as /home and /tpr and printing the remaining time. Uses OnEntityTakeDamage to start the block and OnPlayerCommand to enforce it.
- How to make a Rust raid logger plugin (explosive hit tracking)Logs explosive damage on player buildings to oxide/data, merges nearby hits into single raid events, and lists them with /raids for admins. Uses OnEntityTakeDamage filtered to BuildingBlock hits with Explosion damage.
- How to make a Rust raid schedule plugin (raid hours)Blocks damage from players to player-built structures and deployables outside configured daily raid windows, using the OnEntityTakeDamage hook and a /raid status command.
- How to make a Rust safe PvE zones plugin (spherical, no damage)Creates configurable spherical safe zones where damage between players and to buildings is cancelled, with entry and exit chat notices checked on a repeating timer. It uses OnEntityTakeDamage plus a timer loop.
- How to make a Rust sleeper protection plugin (timed spawn protection)Gives sleeping players a configurable grace period after disconnect during which other players cannot damage them, and optionally blocks looting their body. It uses OnPlayerDisconnected to start the timer, OnEntityTakeDamage to block hits, and CanLootPlayer to deny looting.
- How to make a Rust sleeping bag teleport plugin (bag list, warmup, cooldown)Adds /bag, which lists the player's sleeping bags, beds and beach towels with grid references, and /bag <number> to teleport to one after a warmup timer with a per-player cooldown. It relies on the OnEntitySpawned and OnEntityKill hooks to keep an index of placed spawn points.
- How to make a Rust team teleport plugin (/tpteam)Adds a /tpteam <name> command that teleports a player to a teammate after a warmup, with a per-player cooldown and an opt-out toggle via /tpteam off. It compares Player.currentTeam on both players and drives the warmup with Oxide timers.
- How to make a Rust teleport requests plugin (TPR/TPA)A complete Oxide plugin that implements /tpr player-to-player teleport requests with /tpa, /tpc, request timeouts, a warmup before the move, a per-player cooldown and blocks for wounded, dead, mounted or swimming players. It uses OnPlayerTick and OnEntityTakeDamage to guard the warmup.
- How to make a Rust vanish plugin (admin invisibility)Adds a /vanish command that hides an admin from other players by stopping their network visibility, makes them immune to damage while hidden, draws a small CUI banner, and restores them on toggle off or disconnect. It uses OnEntityTakeDamage to block damage and OnPlayerDisconnected to clean up.
- How to make a Rust wipe raid cooldown plugin (block building damage after wipe)Stores the save timestamp on each new map save and blocks all damage dealt to building blocks, deployables and their building privilege range until N hours have passed. Uses OnNewSave to record the wipe and OnEntityTakeDamage to block the damage.
Build a plugin with OnEntityTakeDamage
Describe what should happen and get a compiled plugin that uses this hook.
Edit the prompt on the next screen. 2 free plugins a month, no card.
Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.
Build a plugin with OnEntityTakeDamage
Generate