Skip to main content

Base Damageable

Base class for all Damageable entities. It provides Health and Damage related methods and events.


info

This is a base class. You cannot spawn it directly.

Functions​

ReturnsNameDescription
integerApplyDamageDo damage to this entity
integerGetHealthGets the current health
integerGetMaxHealthGets the Max Health
RespawnRespawns the Entity, fullying it's Health and moving it to it's Initial Location
SetHealthSets the Health of this Entity
SetMaxHealthSets the MaxHealth of this Entity

ApplyDamage​

Do damage to this entity, will trigger all related events and apply modified damage based on bone. Also will apply impulse if it's a heavy explosion

— Returns integer (the damage applied).

local ret = my_damageable:ApplyDamage(damage, bone_name?, damage_type?, from_direction?, instigator?, causer?)
TypeParameterDefaultDescription
integerdamage
stringbone_name?
DamageTypedamage_type?DamageType.Shot
Vectorfrom_direction?Vector(0, 0, 0)
Playerinstigator?nilThe player which caused the damage
anycauser?nilThe object which caused the damage

GetHealth​

Gets the current health

— Returns integer.

local ret = my_damageable:GetHealth()

GetMaxHealth​

Gets the Max Health

— Returns integer.

local ret = my_damageable:GetMaxHealth()

Respawn​

Respawns the Entity, fullying it's Health and moving it to it's Initial Location

my_damageable:Respawn(location?, rotation?)
TypeParameterDefaultDescription
Vectorlocation?initial locationIf not passed will use the initial location passed when the Entity spawned
Rotatorrotation?Rotator(0, 0, 0)

SetHealth​

Sets the Health of this Entity. You can only call it on alive Entities (call Respawn first)

my_damageable:SetHealth(new_health)
TypeParameterDefaultDescription
integernew_health

SetMaxHealth​

Sets the MaxHealth of this Entity

my_damageable:SetMaxHealth(new_max_health)
TypeParameterDefaultDescription
integernew_max_health

Events​

NameDescription
HealthChangeWhen Entity has it's Health changed, or because took damage or manually set through scripting or respawning
RespawnWhen Entity Respawns
DeathWhen Entity Dies
TakeDamageTriggered when this Entity takes damage

HealthChange​

When Entity has it's Health changed, or because took damage or manually set through scripting or respawning
Damageable.Subscribe("HealthChange", function(self, old_health, new_health)
-- HealthChange was called
end)
TypeArgumentDescription
Damageableself
integerold_health
integernew_health

Respawn​

When Entity Respawns
Damageable.Subscribe("Respawn", function(self)
-- Respawn was called
end)
TypeArgumentDescription
Damageableself

Death​

When Entity Dies
Damageable.Subscribe("Death", function(self, last_damage_taken, last_bone_damaged, damage_type_reason, hit_from_direction, instigator, causer)
-- Death was called
end)
TypeArgumentDescription
Damageableself
integerlast_damage_taken
stringlast_bone_damaged
DamageTypedamage_type_reason
Vectorhit_from_direction
Player or nilinstigator
Base Actor or nilcauserThe object which caused the damage

TakeDamage​

Triggered when this Entity takes damage

Return false to cancel the damage (will still display animations, particles and apply impact forces)
Damageable.Subscribe("TakeDamage", function(self, damage, bone, type, from_direction, instigator, causer)
-- TakeDamage was called
end)
TypeArgumentDescription
Damageableself
integerdamage
stringboneDamaged bone
DamageTypetypeDamage Type
Vectorfrom_directionDirection of the damage relative to the damaged actor
PlayerinstigatorThe player which caused the damage
anycauserThe object which caused the damage