Skip to main content
Version: latest - a1.172.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โ€‹

ApplyDamage: integerDo damage to this entity
GetDamageMultiplier: floatGets the Damage Multiplier of a bone
GetHealth: integerGets the current health
GetMaxHealth: integerGets the Max Health
IsDead: booleanReturns 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

ApplyDamageModerateโ€‹

Do damage to this entity

It triggers all the related events and modifies the damage based on the bone. A heavy explosion also applies an impulse

local ret = my_damageable:ApplyDamage(damage, bone_name?, damage_type?, from_direction?, instigator?, causer?)
Parameters
NameTypeDescription
damageintegerAmount of damage
bone_name?stringName of the bone or socket Default
damage_type?DamageTypeType of the damage, used for effects and in the damage events Default DamageType.Shot
from_direction?VectorDirection the damage came from Default Vector(0, 0, 0)
instigator?PlayerThe player which caused the damage Default nil
causer?anyThe object which caused the damage Default nil
Returns
TypeDescription
integerthe damage applied

GetDamageMultiplierOptimalโ€‹

Gets the Damage Multiplier of a bone

local multiplier = my_damageable:GetDamageMultiplier(bone_name)
Parameters
NameTypeDescription
bone_namestringName of the bone or socket
Returns
TypeDescription
floatthe damage multiplier of the bone

See also SetDamageMultiplier.

GetHealthOptimalโ€‹

Gets the current health

local health = my_damageable:GetHealth()
Returns
TypeDescription
integerCurrent health

See also SetHealth.

GetMaxHealthOptimalโ€‹

Gets the Max Health

local max_health = my_damageable:GetMaxHealth()
Returns
TypeDescription
integerMax Health

See also SetMaxHealth.

IsDeadOptimalโ€‹

Returns if the entity is dead

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

RespawnModerateโ€‹

Respawns the Entity, filling its Health and moving it to its Initial Location

my_damageable:Respawn(location?, rotation?)
Parameters
NameTypeDescription
location?VectorIf not passed will use the initial location passed when the Entity spawned Default initial location
rotation?RotatorRotation to respawn with Default Rotator(0, 0, 0)

SetDamageMultiplierOptimalโ€‹

Changes how much damage this entity takes on specific bones

my_damageable:SetDamageMultiplier(bone_name, multiplier)
Parameters
NameTypeDescription
bone_namestringName of the bone or socket
multiplierfloatDamage multiplier for that bone, 1 is the default

See also GetDamageMultiplier.

SetHealthOptimalโ€‹

Sets the Health of this Entity

You can only call it on alive Entities (call Respawn first)

my_damageable:SetHealth(new_health)
Parameters
NameTypeDescription
new_healthintegerThe new Health of this Entity

See also GetHealth.

SetMaxHealthOptimalโ€‹

Sets the MaxHealth of this Entity

my_damageable:SetMaxHealth(max_health)
Parameters
NameTypeDescription
max_healthintegerThe new MaxHealth of this Entity

See also GetMaxHealth.

๐Ÿš€ Eventsโ€‹

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
NameTypeDescription
selfBase DamageableThe Damageable that triggered the event
last_damage_takenintegerDamage of the hit that killed it
last_bone_damagedstringBone hit by the last damage
damage_type_reasonDamageTypeType of the damage that killed it
hit_from_directionVectorDirection the last damage came from
instigatorPlayer or nilThe Player responsible for the death, if any
causerBase Actor or nilThe 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
NameTypeDescription
selfBase DamageableThe Damageable that triggered the event
old_healthintegerHealth before the change
new_healthintegerHealth after the change

Respawnโ€‹

When Entity Respawns

<AnyDamageableClass>.Subscribe("Respawn", function(self)
-- Respawn was called
end)
Arguments
NameTypeDescription
selfBase DamageableThe Damageable that triggered the event

TakeDamageโ€‹

Triggered when this Entity takes damage

<AnyDamageableClass>.Subscribe("TakeDamage", function(self, damage, bone, type, from_direction, instigator, causer)
-- TakeDamage was called
return 1.0
end)
Arguments
NameTypeDescription
selfBase DamageableThe Damageable that triggered the event
damageintegerAmount of damage taken
bonestringDamaged bone
typeDamageTypeDamage Type
from_directionVectorDirection of the damage relative to the damaged actor
instigatorPlayerThe player which caused the damage
causeranyThe object which caused the damage
Returns
TypeDescription
numberReturn 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