OnEntityTakeDamage
OxideCarbonEntityCalled when an entity take is damaged.
object OnEntityTakeDamage(ResourceEntity resourceEntity, HitInfo info)
object OnEntityTakeDamage(Rust.Ai.Gen2.LivestockAnimal livestockAnimal, HitInfo info)Works — the game method in this build is the one the hook was written for.
Parameters
- resourceEntity
- ResourceEntity
- info
- HitInfo
Return value
objectReturn non-null to cancel the game action.
Example
object — you can affect the game: return a value to change or cancel the action.
private object OnEntityTakeDamage(ResourceEntity resourceEntity, HitInfo info)
{
Puts("OnEntityTakeDamage");
// change nothing — the game continues as usual
return null;
// to affect the game:
// return false; // non-null cancels the game action
}Works in both Oxide and Carbon: Carbon loads Oxide plugins as is.
Where it is called
Oxide core (Oxide.Rust)
RustCore::IOnBaseCombatEntityHurt(BaseCombatEntity entity, HitInfo hitInfo)
Oxide core code — the hook is called from here
private object IOnBaseCombatEntityHurt(BaseCombatEntity entity, HitInfo hitInfo)
{
if (entity is BasePlayer || entity is LivestockAnimal)
{
return null;
}
return Interface.CallHook("OnEntityTakeDamage", entity, hitInfo);
}Where it is called
Oxide core (Oxide.Rust)
RustCore::IOnBasePlayerAttacked(BasePlayer basePlayer, HitInfo hitInfo)
Oxide core code — the hook is called from here
private object IOnBasePlayerAttacked(BasePlayer basePlayer, HitInfo hitInfo)
{
if (!serverInitialized || basePlayer == null || hitInfo == null || basePlayer.IsDead() || isPlayerTakingDamage || basePlayer is NPCPlayer)
{
return null;
}
if (Interface.CallHook("OnEntityTakeDamage", basePlayer, hitInfo) != null)
{
return true;
}
isPlayerTakingDamage = true;
try
{
basePlayer.OnAttacked(hitInfo);
// …Where it is called
Oxide core (Oxide.Rust)
RustCore::IOnBasePlayerHurt(BasePlayer basePlayer, HitInfo hitInfo)
Oxide core code — the hook is called from here
private object IOnBasePlayerHurt(BasePlayer basePlayer, HitInfo hitInfo)
{
return isPlayerTakingDamage ? null : Interface.CallHook("OnEntityTakeDamage", basePlayer, hitInfo);
}Injection point 1
Rust.opj (Oxide)
void ResourceEntity.OnAttacked(HitInfo)
Passes: ResourceEntity resourceEntity, HitInfo info
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll
Where it is called (this branch's game code)
public override void OnAttacked(HitInfo info)
{
if (!isServer || isKilled)
{
return;
}
if (Interface.CallHook("OnEntityTakeDamage", this, info) != null)
{
return;
}
if (resourceDispenser != null)
{
resourceDispenser.OnResourceDispenserAttacked(info);
}
if (!info.DidGather)
// …Injection point 2
Rust.opj (Oxide)
void Rust.Ai.Gen2.LivestockAnimal.Hurt(HitInfo)
Passes: Rust.Ai.Gen2.LivestockAnimal livestockAnimal, HitInfo info
WorksReturnBehavior: ExitWhenNonNullArgumentBehavior: AllAssembly-CSharp.dll
Where it is called (this branch's game code)
public override void Hurt(HitInfo info)
{
if (Interface.CallHook("OnEntityTakeDamage", this, info) != null)
{
return;
}
base.Hurt(info);
if (!InSafeZone())
{
if (IsLeading())
{
// …Sources: Rust.opj from OxideMod/Oxide.Rust (MIT) and hook metadata of the Carbon documentation (MIT). Method code is decompiled from this branch's server.