基础可伤害物
所有可受损实体的基类。它提供了与生命值和伤害相关的的方法和事件。
Base ClassAPI Source
👪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.
Classes that share methods and events from this Base Class: Character, CharacterSimple, VehicleWheeled, VehicleWater.
🦠 函数
| Returns | Name | Description | |
|---|---|---|---|
| integer | ApplyDamage | 对该实体造成伤害 | |
| float | GetDamageMultiplier | 获取特定骨骼的伤害系数 | |
| integer | GetHealth | 获取当前生命值 | |
| integer | GetMaxHealth | 获取最大生命值 | |
| boolean | IsDead | 返回该实体是否已死亡 | |
Respawn | 重生该实体,恢复其生命值并将其移动到初始位置 | ||
SetDamageMultiplier | 更改该实体在特定骨骼上受到的伤害大小 | ||
SetHealth | 设置该实体的生命值 | ||
SetMaxHealth | 设置该实体的最大生命值 |
Moderate

ApplyDamage
对该实体造成伤害,将触发所有相关事件并根据骨骼应用修改后的伤害。如果是重度爆炸,还会应用冲量
local ret = my_damageable:ApplyDamage(damage, bone_name?, damage_type?, from_direction?, instigator?, causer?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | damage | Required parameter | 伤害量 |
| string | bone_name? | | 骨骼或插槽的名称 |
| DamageType | damage_type? | DamageType.Shot | 伤害类型,用于效果及伤害事件中 |
| Vector | from_direction? | Vector(0, 0, 0) | 伤害来源方向 |
| Player | instigator? | nil | 造成伤害的玩家 |
| any | causer? | nil | 造成伤害的对象 |
Returns
| Type | Description |
|---|---|
| integer | 施加的伤害值 |
Optimal

GetDamageMultiplier
获取特定骨骼的伤害系数
local multiplier = my_damageable:GetDamageMultiplier(bone_name)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | bone_name | Required parameter | 骨骼或插槽的名称 |
Returns
| Type | Description |
|---|---|
| float | 该骨骼的伤害系数 |
See also SetDamageMultiplier.
Optimal

GetHealth
获取当前生命值
local health = my_damageable:GetHealth()
Returns
| Type | Description |
|---|---|
| integer | 当前生命值 |
See also SetHealth.
Optimal

GetMaxHealth
获取最大生命值
local max_health = my_damageable:GetMaxHealth()
Returns
| Type | Description |
|---|---|
| integer | 最大生命值 |
See also SetMaxHealth.
Optimal

IsDead
返回该实体是否已死亡
local is_dead = my_damageable:IsDead()
Returns
| Type | Description |
|---|---|
| boolean | 该实体是否已死亡 |
Moderate

Respawn
重生该实体,恢复其生命值并将其移动到初始位置
my_damageable:Respawn(location?, rotation?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | location? | initial location | 如果未传入,将使用实体生成时传入的初始位置 |
| Rotator | rotation? | Rotator(0, 0, 0) | 重生时的旋转 |
Optimal

SetDamageMultiplier
更改该实体在特定骨骼上受到的伤害大小
my_damageable:SetDamageMultiplier(bone_name, multiplier)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | bone_name | Required parameter | 骨骼或插槽的名称 |
| float | multiplier | Required parameter | 该骨骼的伤害系数,默认为 1 |
See also GetDamageMultiplier.
Optimal

SetHealth
设置该实体的生命值。只能在存活的实体上调用(先调用 Respawn)
my_damageable:SetHealth(new_health)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | new_health | Required parameter | 此实体的新生命值 |
See also GetHealth.
Optimal

SetMaxHealth
设置该实体的最大生命值
my_damageable:SetMaxHealth(max_health)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | max_health | Required parameter | 此实体的新最大生命值 |
See also GetMaxHealth.
🚀 事件
| Name | Description | |
|---|---|---|
Death | 当实体死亡时 | |
HealthChange | 当实体的生命值发生改变时,无论是由于受到伤害,还是通过脚本或重生进行手动设置 | |
Respawn | 当实体重生时 | |
TakeDamage | 当此实体受到伤害时触发 |

Death
当实体死亡时
<AnyDamageableClass>.Subscribe("Death", function(self, last_damage_taken, last_bone_damaged, damage_type_reason, hit_from_direction, instigator, causer)
-- Death was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Base Damageable | self | 触发该事件的可受损物 |
| integer | last_damage_taken | 致死击的伤害值 |
| string | last_bone_damaged | 最后一次受伤被击中的骨骼 |
| DamageType | damage_type_reason | 导致死亡的伤害类型 |
| Vector | hit_from_direction | 最后一次伤害的来源方向 |
| Player or nil | instigator | 造成死亡的玩家(如果有) |
| Base Actor or nil | causer | 造成伤害的对象 |

HealthChange
当实体的生命值发生改变时,无论是由于受到伤害,还是通过脚本或重生进行手动设置
<AnyDamageableClass>.Subscribe("HealthChange", function(self, old_health, new_health)
-- HealthChange was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Base Damageable | self | 触发该事件的可受损物 |
| integer | old_health | 更改前的生命值 |
| integer | new_health | 更改后的生命值 |

Respawn
当实体重生时
<AnyDamageableClass>.Subscribe("Respawn", function(self)
-- Respawn was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Base Damageable | self | 触发该事件的可受损物 |

TakeDamage
当此实体受到伤害时触发
返回最终伤害的系数。返回0可取消伤害(但仍会显示动画、粒子效果并应用冲击力)。默认值为1.0。
<AnyDamageableClass>.Subscribe("TakeDamage", function(self, damage, bone, type, from_direction, instigator, causer)
-- TakeDamage was called
return 1.0
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Base Damageable | self | 触发该事件的可受损物 |
| integer | damage | 承受的伤害量 |
| string | bone | 受损的骨骼 |
| DamageType | type | 伤害类型 |
| Vector | from_direction | 伤害相对于受伤 Actor 的方向 |
| Player | instigator | 造成伤害的玩家 |
| any | causer | 造成伤害的对象 |

