基础可伤害物
所有可受损实体的基类。它提供了与生命值和伤害相关的的方法和事件。
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 | No description provided |
| string | bone_name? | | No description provided |
| DamageType | damage_type? | DamageType.Shot | No description provided |
| Vector | from_direction? | Vector(0, 0, 0) | No description provided |
| 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 | No description provided |
Returns
| Type | Description |
|---|---|
| float | 该骨骼的伤害系数 |
See also SetDamageMultiplier.
Optimal

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

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

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

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

SetDamageMultiplier
更改该实体在特定骨骼上受到的伤害大小
my_damageable:SetDamageMultiplier(bone_name, multiplier)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | bone_name | Required parameter | No description provided |
| float | multiplier | Required parameter | No description provided |
See also GetDamageMultiplier.
Optimal

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

SetMaxHealth
设置该实体的最大生命值
my_damageable:SetMaxHealth(max_health)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | max_health | Required parameter | No description provided |
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 | No description provided |
| integer | last_damage_taken | No description provided |
| string | last_bone_damaged | No description provided |
| DamageType | damage_type_reason | No description provided |
| Vector | hit_from_direction | No description provided |
| Player or nil | instigator | No description provided |
| 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 | No description provided |
| integer | old_health | No description provided |
| integer | new_health | No description provided |

Respawn
当实体重生时
<AnyDamageableClass>.Subscribe("Respawn", function(self)
-- Respawn was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Base Damageable | self | No description provided |

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 | No description provided |
| integer | damage | No description provided |
| string | bone | 受损的骨骼 |
| DamageType | type | 伤害类型 |
| Vector | from_direction | 伤害相对于受伤 Actor 的方向 |
| Player | instigator | 造成伤害的玩家 |
| any | causer | 造成伤害的对象 |

