跳至正文
版本:bleeding-edge 🩸

基础可伤害物

所有可受损实体的基类。它提供了与生命值和伤害相关的的方法和事件。

👪Base Class🧑‍💻API 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.

🦠 函数​

ReturnsNameDescription
integerApplyDamage对该实体造成伤害
floatGetDamageMultiplier获取特定骨骼的伤害系数
integerGetHealth获取当前生命值
integerGetMaxHealth获取最大生命值
booleanIsDead返回该实体是否已死亡
Respawn重生该实体,恢复其生命值并将其移动到初始位置
SetDamageMultiplier更改该实体在特定骨骼上受到的伤害大小
SetHealth设置该实体的生命值
SetMaxHealth设置该实体的最大生命值

Moderate

ApplyDamage​

对该实体造成伤害,将触发所有相关事件并根据骨骼应用修改后的伤害。如果是重度爆炸,还会应用冲量
local ret = my_damageable:ApplyDamage(damage, bone_name?, damage_type?, from_direction?, instigator?, causer?)

Parameters

TypeParameterDefaultDescription
integerdamage Required parameter 伤害量
stringbone_name?
骨骼或插槽的名称
DamageTypedamage_type?DamageType.Shot
伤害类型,用于效果及伤害事件中
Vectorfrom_direction?Vector(0, 0, 0)
伤害来源方向
Playerinstigator?nil
造成伤害的玩家
anycauser?nil
造成伤害的对象

Returns

TypeDescription
integer施加的伤害值

Optimal

GetDamageMultiplier​

获取特定骨骼的伤害系数
local multiplier = my_damageable:GetDamageMultiplier(bone_name)

Parameters

TypeParameterDefaultDescription
stringbone_name Required parameter 骨骼或插槽的名称

Returns

TypeDescription
float该骨骼的伤害系数

See also SetDamageMultiplier.


Optimal

GetHealth​

获取当前生命值
local health = my_damageable:GetHealth()

Returns

TypeDescription
integer当前生命值

See also SetHealth.


Optimal

GetMaxHealth​

获取最大生命值
local max_health = my_damageable:GetMaxHealth()

Returns

TypeDescription
integer最大生命值

See also SetMaxHealth.


Optimal

IsDead​

返回该实体是否已死亡
local is_dead = my_damageable:IsDead()

Returns

TypeDescription
boolean该实体是否已死亡

Moderate

Respawn​

重生该实体,恢复其生命值并将其移动到初始位置
my_damageable:Respawn(location?, rotation?)

Parameters

TypeParameterDefaultDescription
Vectorlocation?initial location
如果未传入,将使用实体生成时传入的初始位置
Rotatorrotation?Rotator(0, 0, 0)
重生时的旋转

Optimal

SetDamageMultiplier​

更改该实体在特定骨骼上受到的伤害大小
my_damageable:SetDamageMultiplier(bone_name, multiplier)

Parameters

TypeParameterDefaultDescription
stringbone_name Required parameter 骨骼或插槽的名称
floatmultiplier Required parameter 该骨骼的伤害系数,默认为 1

See also GetDamageMultiplier.


Optimal

SetHealth​

设置该实体的生命值。只能在存活的实体上调用(先调用 Respawn)
my_damageable:SetHealth(new_health)

Parameters

TypeParameterDefaultDescription
integernew_health Required parameter 此实体的新生命值

See also GetHealth.


Optimal

SetMaxHealth​

设置该实体的最大生命值
my_damageable:SetMaxHealth(max_health)

Parameters

TypeParameterDefaultDescription
integermax_health Required parameter 此实体的新最大生命值

See also GetMaxHealth.

🚀 事件​

NameDescription
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

TypeArgumentDescription
Base Damageableself触发该事件的可受损物
integerlast_damage_taken致死击的伤害值
stringlast_bone_damaged最后一次受伤被击中的骨骼
DamageTypedamage_type_reason导致死亡的伤害类型
Vectorhit_from_direction最后一次伤害的来源方向
Player or nilinstigator造成死亡的玩家(如果有)
Base Actor or nilcauser造成伤害的对象

HealthChange​

当实体的生命值发生改变时,无论是由于受到伤害,还是通过脚本或重生进行手动设置
<AnyDamageableClass>.Subscribe("HealthChange", function(self, old_health, new_health)
-- HealthChange was called
end)

Arguments

TypeArgumentDescription
Base Damageableself触发该事件的可受损物
integerold_health更改前的生命值
integernew_health更改后的生命值

Respawn​

当实体重生时
<AnyDamageableClass>.Subscribe("Respawn", function(self)
-- Respawn was called
end)

Arguments

TypeArgumentDescription
Base Damageableself触发该事件的可受损物

TakeDamage​

当此实体受到伤害时触发

返回最终伤害的系数。返回 0 可取消伤害(但仍会显示动画、粒子效果并应用冲击力)。默认值为 1.0。
<AnyDamageableClass>.Subscribe("TakeDamage", function(self, damage, bone, type, from_direction, instigator, causer)
-- TakeDamage was called
return 1.0
end)

Arguments

TypeArgumentDescription
Base Damageableself触发该事件的可受损物
integerdamage承受的伤害量
stringbone受损的骨骼
DamageTypetype伤害类型
Vectorfrom_direction伤害相对于受伤 Actor 的方向
Playerinstigator造成伤害的玩家
anycauser造成伤害的对象