跳至正文
版本:最新版 - a1.156.0 ⚖️

🔪 Melee

Melee 代表一个可以被角色捡起的实体,并可用于近战攻击。角色可以用预定义的持握模式双手持握它。

Server Only🔁Auto-Distributed🧑‍💻API Source
👪Inheritance
This class shares methods and events from Base Entity, Base Actor, Base Paintable, Base Pickable.

🎒 示例​

Server/Index.lua
local crowbar = Melee(
Vector(-900, 185, 215),
Rotator(0, 90, 90),
"nanos-world::SM_Crowbar_01",
CollisionType.Normal,
true,
HandlingMode.SingleHandedMelee,
""
)

crowbar:SetScale(Vector(1.5, 1.5, 1.5))
crowbar:AddAnimationCharacterUse("nanos-world::AM_Mannequin_Melee_Slash_Attack")
crowbar:SetDamageSettings(0.3, 0.5)
crowbar:SetCooldown(1.0)
crowbar:SetBaseDamage(40)

🛠 构造函数​

Default Constructor​

No description provided

local my_melee = Melee(location, rotation, asset, collision_type?, gravity_enabled?, handling_mode?, crosshair_material?, can_use?, spawn_mode?)

Parameters

TypeNameDefaultDescription
Vectorlocation Required parameter 生成的世界坐标位置
Rotatorrotation Required parameter 生成的世界坐标旋转
StaticMesh Referenceasset Required parameter 要使用的资产
CollisionTypecollision_typeCollisionType.Auto此 Actor 的碰撞配置文件
booleangravity_enabledtrue重力是否影响此 Actor
HandlingModehandling_modeHandlingMode.Torch角色手持它的方式
Material Referencecrosshair_material十字准星材质
booleancan_usetrue拾取后是否可直接使用(攻击)
SpawnModespawn_modeSpawnMode.Immediate传入 SpawnMode.AfterConstructor 或 SpawnMode.Manual 可避免立即将实体发送至客户端,在需要配置多项设置时使用此选项可提升性能。最后必须调用 FinishSpawn()

🗿 静态函数​

Inherited Entity Static Functions
Melee inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
table of Base EntityGetAll返回一个包含调用此方法的类中所有实体的表
Base EntityGetByIndex返回该类中指定索引处的特定实体
integerGetCount返回该类当前存在的实体数量
table of tableGetInheritedClasses获取使用 继承系统 创建的、直接继承自该类的所有子类列表
iteratorGetPairs返回一个包含该类所有实体的迭代器,用于 pairs() 循环
table or nilGetParentClass如果该类是使用 继承系统 创建的,则获取其父类
tableInherit使用 继承系统 继承此类
booleanIsChildOf如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类
functionSubscribe为该类的所有实体订阅一个 事件
functionSubscribeRemote订阅从服务器调用的自定义远程事件
Unsubscribe退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调

This class doesn't have own static functions.

🦠 函数​

Inherited Entity Functions
Melee inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
BroadcastRemoteEvent直接在此实体上向所有玩家调用自定义远程事件
BroadcastRemoteInRadiusEvent直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家
CallRemoteEvent直接在此实体上向特定玩家调用自定义远程事件
CallRemoteEvent直接在此实体上调用自定义远程事件
CallRemotePlayersEvent直接在此实体上调用自定义远程事件,并将事件传递给玩家列表
Destroy销毁该实体
FinishSpawn如果此实体是以延迟 spawn_mode 生成的,则完成生成过程并将该实体发送至客户端
table of stringGetAllValuesKeys获取所有存储值的键名列表
tableGetClass获取该实体的类
integerGetID获取该实体的全网通用网络 ID(在客户端和服务器上相同)
anyGetValue获取此实体上存储在给定键处的 值
booleanHasAuthority获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false)
booleanIsA递归检查此实体是否继承自某个类
booleanIsBeingDestroyed如果该实体正在被销毁,则返回 true
booleanIsSpawned获取此实体是否已完成生成
booleanIsValid如果该实体有效(即未被销毁且指向一个有效的实体),则返回 true
SetSpawnMode从继承类的构造函数中覆盖此实体完成生成的时间点
SetValue在此实体中设置一个值
functionSubscribe在这个特定实体上订阅一个事件
functionSubscribeRemote在这个特定实体上订阅一个从服务器调用的自定义远程事件
Unsubscribe退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调
Inherited Actor Functions
Melee inherits from Base Actor Class, sharing it's methods and functions:
Base Actorscripting-reference/classes/base-classes/actor
ReturnsNameDescription
AddActorTag向该 Actor 添加一个虚幻 Actor 标签
AddAngularImpulse向该 Actor 添加角冲量。适用于单次瞬间爆发
AddImpulse向该 Actor 添加冲量。适用于单次瞬间爆发
booleanAttachTo将该 Actor 附加到任何其他 Actor 上,可选择附加在特定骨骼处
Detach将该 Actor 从其附加的 Actor 上分离
table of stringGetActorTags获取该 Actor 上的所有虚幻 Actor 标签
VectorGetAngularForce获取该 Actor 的角外力(由 SetAngularForce() 设置)
floatGetAngularVelocity返回此 Actor 的角速度
table of Base ActorGetAttachedEntities获取附加到该 Actor 的所有 Actor
Base Actor or nilGetAttachedTo获取该 Actor 所附加到的父级 Actor
stringGetAttachedToSocket获取此 Actor 所附加到的骨骼或插槽名称
tableGetBounds获取此 Actor 的包围盒,便于计算其在世界中的尺寸
CollisionTypeGetCollision获取该 Actor 的碰撞类型
integerGetDimension获取该 Actor 的维度
floatGetDistanceFromCamera获取该 Actor 距离相机的距离
VectorGetForce获取该 Actor 的持续外力(由 SetForce() 设置)
floatGetLifeSpan获取此 Actor 被销毁前剩余的时间(秒)
VectorGetLocation获取该 Actor 在游戏世界中的位置
floatGetMass返回此 Actor 的质量
Player or nilGetNetworkAuthority获取该 Actor 的网络主控玩家
VectorGetRelativeLocation如果该 Actor 已附加,获取其相对位置
RotatorGetRelativeRotation如果该 Actor 已附加,获取其相对旋转
RotatorGetRotation获取该 Actor 在游戏世界中的角度值
VectorGetScale获取该 Actor 的缩放比例
floatGetScreenPercentage获取该 Actor 在屏幕中所占尺寸的百分比
tableGetSocketTransform在给定骨骼或插槽名称的情况下,获取世界空间中的插槽变换
VectorGetVelocity获取该 Actor 当前的速度
booleanHasNetworkAuthority如果本地玩家当前是该 Actor 的网络主控(Network Authority),则返回 true
booleanIsGravityEnabled如果该 Actor 启用了重力,则返回 true
booleanIsInWater如果该 Actor 处于水中,则返回 true
booleanIsNetworkDistributed如果该 Actor 当前处于网络分配状态,则返回 true
booleanIsVisible如果该 Actor 可见,则返回 true
RemoveActorTag从该 Actor 中移除一个虚幻 Actor 标签
RotateTo在一定时间内平滑旋转该 Actor 到指定角度
SetAngularForce向该 Actor 添加一个永久的角外力,设为 Vector(0, 0, 0) 可以取消
SetCastShadow设置该 Actor 是否投射阴影
SetCollision设置该 Actor 的碰撞类型
SetDimension设置此 Actor 的维度。Actor 仅能看见并与处于同一维度中的实体进行交互
SetDistanceOptimizationMultiplier设置此 Actor 的距离优化系数
SetForce向该 Actor 添加一个永久的外力,设为 Vector(0, 0, 0) 可以取消
SetGravityEnabled设置该 Actor 是否启用重力
SetHighlightEnabled设置该 Actor 是否启用高亮显示,以及使用哪个高亮索引值
SetLifeSpan设置该 Actor 被销毁前的生存时间(秒)。经过这段时间后,Actor 将被自动销毁。
SetLocation设置该 Actor 在游戏世界中的位置
SetNetworkAuthority设置某个玩家拥有此 Actor 的网络主控
SetNetworkAuthorityAutoDistributed设置该 Actor 是否在玩家之间自动分配网络主控
SetOutlineEnabled设置该 Actor 是否启用描边,以及使用哪个描边索引值
SetRelativeLocation在局部空间中设置该 Actor 的相对位置(仅在此 Actor 已附加时生效)
SetRelativeRotation在局部空间中设置该 Actor 的相对旋转(仅在此 Actor 已附加时生效)
SetRenderCullDistance设置该 Actor 的渲染剔除距离
SetRotation设置该 Actor 在游戏世界中的旋转
SetScale设置该 Actor 的缩放比例
SetVisibility设置该 Actor 是否可见
TranslateTo在一定时间内平滑地将该 Actor 移动到某个位置
booleanWasRecentlyRendered获取该 Actor 最近是否在屏幕上被渲染过
Inherited Paintable Functions
Melee inherits from Base Paintable Class, sharing it's methods and functions:
Base Paintablescripting-reference/classes/base-classes/paintable
ReturnsNameDescription
ColorGetMaterialColorParameter从该 Actor 的材质中获取 Color 参数
floatGetMaterialScalarParameter从该 Actor 的材质中获取 Scalar 参数
stringGetMaterialTextureParameter从该 Actor 的材质中获取 Texture 参数
VectorGetMaterialVectorParameter从该 Actor 的材质中获取 Vector 参数
ResetMaterial将指定索引处的材质重置为原始材质
SetMaterial设置该 Actor 指定索引处的材质
SetMaterialColorParameter设置该 Actor 材质中的 Color 参数
SetMaterialFromCanvas将该 Actor 指定索引处的材质设为 Canvas 对象
SetMaterialFromSceneCapture将该 Actor 指定索引处的材质设为 SceneCapture 对象
SetMaterialFromWebUI将该 Actor 指定索引处的材质设为 WebUI 对象
SetMaterialScalarParameter设置该 Actor 材质中的 Scalar 参数
SetMaterialTextureParameter将该 Actor 材质中的纹理参数设为一张图像
SetMaterialVectorParameter设置该 Actor 材质中的 Vector 参数
SetPhysicalMaterial使用新的物理材质覆盖该 Actor 的物理材质
Inherited Pickable Functions
Melee inherits from Base Pickable Class, sharing it's methods and functions:
Base Pickablescripting-reference/classes/base-classes/pickable
ReturnsNameDescription
AddSkeletalMeshAttached附加一个骨骼网格体作为该实体的骨骼主姿态
AddStaticMeshAttached附加一个静态网格体到此实体
table of stringGetAllSkeletalMeshAttached获取附加到此实体的所有骨骼网格体
table of stringGetAllStaticMeshAttached获取附加到此实体的所有静态网格体
Character or nilGetHandler获取当前正手持该可拾取物的角色(如果存在)
HandlingModeGetHandlingMode获取该可拾取物的手持模式
SkeletalMesh ReferenceGetMesh获取该可拾取物使用的资产名称
PullUse拉取该可拾取物的使用状态(如果这是武器,将开始开火)
ReleaseUse释放该可拾取物的使用状态(如果这是武器,将停止开火)
RemoveAllSkeletalMeshesAttached移除所有已附加的骨骼网格体
RemoveAllStaticMeshesAttached移除所有已附加的静态网格体
RemoveSkeletalMeshAttached根据自定义 ID 移除此可拾取物上已存在的骨骼网格体(如果存在)
RemoveStaticMeshAttached根据自定义 ID 移除此可拾取物上已存在的静态网格体(如果存在)
SetAttachmentSettings设置此可拾取物的附加设置(即拾取时如何附加到角色上)
SetBuoyancyPontoons设置水体模拟所使用的浮筒
SetBuoyancySettings设置该实体在水中的行为
SetCanUse设置玩家在手持该可拾取物时是否可以使用它
SetCrosshairMaterial设置该可拾取物的准星材质
SetPickable设置玩家是否可以从地面上拾取该可拾取物
SetStaticMeshAttachedTransform设置已附加静态网格体的位置和旋转
ReturnsNameDescription
AddAnimationCharacterUse设置攻击时的动画
ClearAnimationsCharacterUse清除角色的攻击动画列表
table of Animation ReferenceGetAnimationsCharacterUse获取角色使用该武器时的动画
integerGetBaseDamage获取基础伤害
floatGetCooldown获取两次使用之间的冷却时间
Sound ReferenceGetSoundUse获取角色使用该武器时的声音
SetBaseDamage设置基础伤害
SetCooldown设置攻击之间的冷却时间
SetDamageSettings设置开始应用伤害和结束伤害的时间
SetImpactSound设置击中物体时的声音
SetSoundUse设置攻击时的声音

Slow

AddAnimationCharacterUse​

设置攻击时的动画

你可以添加多个动画,攻击时将随机选择其中一个动画
my_melee:AddAnimationCharacterUse(asset_path, play_rate?, slot_type?)

Parameters

TypeParameterDefaultDescription
Animation Referenceasset_path Required parameter 攻击时使用的动画
floatplay_rate?1.0
动画播放速率
AnimationSlotTypeslot_type?AnimationSlotType.UpperBody
是在上半身播放还是全身播放

Optimal

ClearAnimationsCharacterUse​

清除角色的攻击动画列表
my_melee:ClearAnimationsCharacterUse()

Moderate

GetAnimationsCharacterUse​

获取角色使用该武器时的动画
local ret = my_melee:GetAnimationsCharacterUse()

Returns

TypeDescription
table of Animation Reference角色使用它时的动画

Optimal

GetBaseDamage​

获取基础伤害
local damage = my_melee:GetBaseDamage()

Returns

TypeDescription
integer基础伤害

See also SetBaseDamage.


Optimal

GetCooldown​

获取两次使用之间的冷却时间
local cooldown = my_melee:GetCooldown()

Returns

TypeDescription
float两次使用之间的冷却时间

See also SetCooldown.


Optimal

GetSoundUse​

获取角色使用该武器时的声音
local asset_path = my_melee:GetSoundUse()

Returns

TypeDescription
Sound Reference角色使用它时的声音

See also SetSoundUse.


Optimal

SetBaseDamage​

设置基础伤害
my_melee:SetBaseDamage(damage)

Parameters

TypeParameterDefaultDescription
integerdamage Required parameter 基础伤害值

See also GetBaseDamage.


Optimal

SetCooldown​

设置攻击之间的冷却时间
my_melee:SetCooldown(cooldown)

Parameters

TypeParameterDefaultDescription
floatcooldown Required parameter 两次攻击之间新的冷却时间

See also GetCooldown.


Optimal

SetDamageSettings​

设置开始应用伤害和结束伤害的时间。在此期间,近战武器的碰撞将被启用,如果击中物体则会应用伤害
my_melee:SetDamageSettings(damage_start_time, damage_duration_time)

Parameters

TypeParameterDefaultDescription
floatdamage_start_time Required parameter 开始应用伤害的初始时间
floatdamage_duration_time Required parameter 停止应用伤害的持续时间

Slow

SetImpactSound​

设置击中物体时的声音
my_melee:SetImpactSound(surface_type, asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
SurfaceTypesurface_type Required parameter 应用声音的表面。使用 SurfaceType.Default 作为所有未定义表面的默认设置。注:Water 和 Flesh 表面已有默认声音,必须显式覆盖
Sound Referenceasset_path Required parameter 攻击时使用的声音
floatvolume?1.0
音量倍率
floatpitch?1.0
音高倍率

Slow

SetSoundUse​

设置攻击时的声音
my_melee:SetSoundUse(asset_path)

Parameters

TypeParameterDefaultDescription
Sound Referenceasset_path Required parameter 攻击时使用的声音

See also GetSoundUse.

🚀 事件​

Inherited Entity Events
Melee inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/entity
NameDescription
ClassRegister当使用 继承系统 注册一个新类时触发
Destroy当实体被销毁时触发
Spawn当实体被生成/创建时触发
ValueChange当实体通过 :SetValue() 改变了值时触发
Inherited Actor Events
Melee inherits from Base Actor Class, sharing it's events:
Base Actorscripting-reference/classes/base-classes/actor
NameDescription
DimensionChange当 Actor 改变其维度时触发
EnterWater当 Actor 进入水体时触发
LeaveWater当 Actor 离开水体时触发
NetworkAuthorityChange当 Actor 更改其网络主控玩家时触发
NetworkAuthorityChange当本地玩家获得或失去对此 Actor 的网络主控时触发
Inherited Pickable Events
Melee inherits from Base Pickable Class, sharing it's events:
Base Pickablescripting-reference/classes/base-classes/pickable
NameDescription
Drop当角色丢弃该可拾取物时
Hit当该可拾取物撞击到某种物体时触发
Interact当角色与该可拾取物交互时触发(即尝试将其拾取)
PickUp当 Character 拾取该物品时触发
PullUse当角色按下该可拾取物的使用键时触发(即在装备此物品时单击鼠标左键)
ReleaseUse当角色松开该可拾取物的使用键时触发(即在装备此物品时松开鼠标左键)
NameDescription
Attack当角色有效地使用该近战武器进行攻击时触发

Attack​

当角色有效地使用该近战武器进行攻击时触发
Melee.Subscribe("Attack", function(self, handler)
-- Attack was called
end)

Arguments

TypeArgumentDescription
Meleeself触发该事件的近战武器
Characterhandler发起攻击的角色