Skip to main content
Version: latest - a1.156.0 โš–๏ธ

Base Damageable

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

๐Ÿ‘ชBase Class
This is a Base Class, an abstract definition that shares common methods and events with it's child classes. You cannot spawn it, and you cannot call anything on the Base Class name itself. Use any class that inherits it.

Classes that share methods and events from this Base Class: Character, CharacterSimple, VehicleWheeled, VehicleWater.

๐Ÿฆ ย Functionsโ€‹

ReturnsNameDescription
integerApplyDamageDo damage to this entity
floatGetDamageMultiplierGets the Damage Multiplier of a bone
integerGetHealthGets the current health
integerGetMaxHealthGets the Max Health
booleanIsDeadReturns if the entity is dead
RespawnRespawns the Entity, filling its Health and moving it to its Initial Location
SetDamageMultiplierChanges how much damage this entity takes on specific bones
SetHealthSets the Health of this Entity
SetMaxHealthSets the MaxHealth of this Entity

Moderate

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
local ret = my_damageable:ApplyDamage(damage, bone_name?, damage_type?, from_direction?, instigator?, causer?)

Parameters

TypeParameterDefaultDescription
integerdamage Required parameter Amount of damage
stringbone_name?
Name of the bone or socket
DamageTypedamage_type?DamageType.Shot
Type of the damage, used for effects and in the damage events
Vectorfrom_direction?Vector(0, 0, 0)
Direction the damage came from
Playerinstigator?nil
The player which caused the damage
anycauser?nil
The object which caused the damage

Returns

TypeDescription
integerthe damage applied

Optimal

GetDamageMultiplierโ€‹

Gets the Damage Multiplier of a bone
local multiplier = my_damageable:GetDamageMultiplier(bone_name)

Parameters

TypeParameterDefaultDescription
stringbone_name Required parameter Name of the bone or socket

Returns

TypeDescription
floatthe damage multiplier of the bone

See also SetDamageMultiplier.


Optimal

GetHealthโ€‹

Gets the current health
local health = my_damageable:GetHealth()

Returns

TypeDescription
integerCurrent health

See also SetHealth.


Optimal

GetMaxHealthโ€‹

Gets the Max Health
local max_health = my_damageable:GetMaxHealth()

Returns

TypeDescription
integerMax Health

See also SetMaxHealth.


Optimal

IsDeadโ€‹

Returns if the entity is dead
local is_dead = my_damageable:IsDead()

Returns

TypeDescription
booleanWhether the entity is dead

Moderate

Respawnโ€‹

Respawns the Entity, filling its Health and moving it to its Initial Location
my_damageable:Respawn(location?, rotation?)

Parameters

TypeParameterDefaultDescription
Vectorlocation?initial location
If not passed will use the initial location passed when the Entity spawned
Rotatorrotation?Rotator(0, 0, 0)
Rotation to respawn with

Optimal

SetDamageMultiplierโ€‹

Changes how much damage this entity takes on specific bones
my_damageable:SetDamageMultiplier(bone_name, multiplier)

Parameters

TypeParameterDefaultDescription
stringbone_name Required parameter Name of the bone or socket
floatmultiplier Required parameter Damage multiplier for that bone, 1 is the default

See also GetDamageMultiplier.


Optimal

SetHealthโ€‹

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

Parameters

TypeParameterDefaultDescription
integernew_health Required parameter The new Health of this Entity

See also GetHealth.


Optimal

SetMaxHealthโ€‹

Sets the MaxHealth of this Entity
my_damageable:SetMaxHealth(max_health)

Parameters

TypeParameterDefaultDescription
integermax_health Required parameter The new MaxHealth of this Entity

See also GetMaxHealth.

๐Ÿš€ย Eventsโ€‹

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

Deathโ€‹

When Entity Dies
<AnyDamageableClass>.Subscribe("Death", function(self, last_damage_taken, last_bone_damaged, damage_type_reason, hit_from_direction, instigator, causer)
-- Death was called
end)

Arguments

TypeArgumentDescription
Base DamageableselfThe Damageable that triggered the event
integerlast_damage_takenDamage of the hit that killed it
stringlast_bone_damagedBone hit by the last damage
DamageTypedamage_type_reasonType of the damage that killed it
Vectorhit_from_directionDirection the last damage came from
Player or nilinstigatorThe Player responsible for the death, if any
Base Actor or nilcauserThe object which caused the damage

HealthChangeโ€‹

When Entity has its Health changed, or because took damage or manually set through scripting or respawning
<AnyDamageableClass>.Subscribe("HealthChange", function(self, old_health, new_health)
-- HealthChange was called
end)

Arguments

TypeArgumentDescription
Base DamageableselfThe Damageable that triggered the event
integerold_healthHealth before the change
integernew_healthHealth after the change

Respawnโ€‹

When Entity Respawns
<AnyDamageableClass>.Subscribe("Respawn", function(self)
-- Respawn was called
end)

Arguments

TypeArgumentDescription
Base DamageableselfThe Damageable that triggered the event

TakeDamageโ€‹

Triggered when this Entity takes damage

Return the multiplier to the final damage. Return 0 to cancel the damage (will still display animations, particles and apply impact forces). The default 1.0.
<AnyDamageableClass>.Subscribe("TakeDamage", function(self, damage, bone, type, from_direction, instigator, causer)
-- TakeDamage was called
return 1.0
end)

Arguments

TypeArgumentDescription
Base DamageableselfThe Damageable that triggered the event
integerdamageAmount of damage taken
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