跳至正文
版本:bleeding-edge 🩸

🔫 Weapon

武器是具有开火、换弹和瞄准功能的实体。

它们支持完全自定义,武器的所有部件都可以更改,具备极大的创作空间。

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
-- 使用 AK47 模型生成武器
local new_weapon = Weapon(
Vector(-900, 185, 215),
Rotator(0, 0, 0),
"nanos-world::SK_AK47"
)

-- 配置武器基础设置
new_weapon:SetAmmoSettings(30, 1000)
new_weapon:SetDamage(30)
new_weapon:SetSpread(30)
new_weapon:SetRecoil(0.25)
new_weapon:SetBulletSettings(1, 20000, 20000, Color(100, 58, 0))
new_weapon:SetCadence(0.1)
new_weapon:SetWallbangSettings(50, 0.75)

-- 配置 Character 握持与瞄准武器的方式
new_weapon:SetHandlingMode(HandlingMode.DoubleHandedWeapon)
new_weapon:SetSightTransform(Vector(0, 0, -1), Rotator(-1.5, 0, 0))
new_weapon:SetLeftHandTransform(Vector(22, 0, 9), Rotator(0, 60, 90))
new_weapon:SetRightHandOffset(Vector(-10, 0, 0))

-- 配置武器粒子效果
new_weapon:SetParticlesBulletTrail("nanos-world::P_Bullet_Trail")
new_weapon:SetParticlesBarrel("nanos-world::P_Weapon_BarrelSmoke")
new_weapon:SetParticlesShells("nanos-world::P_Weapon_Shells_762x39")

-- 配置武器音效
new_weapon:SetSoundDry("nanos-world::A_Rifle_Dry")
new_weapon:SetSoundLoad("nanos-world::A_Rifle_Load")
new_weapon:SetSoundUnload("nanos-world::A_Rifle_Unload")
new_weapon:SetSoundZooming("nanos-world::A_AimZoom")
new_weapon:SetSoundAim("nanos-world::A_Rattle")
new_weapon:SetSoundFire("nanos-world::A_AK47_Shot")

-- 配置武器动画
new_weapon:SetAnimationFire("nanos-world::A_AK47_Fire")
new_weapon:SetAnimationCharacterFire("nanos-world::AM_Mannequin_Sight_Fire")
new_weapon:SetAnimationReload("nanos-world::AM_Mannequin_Reload_Rifle")

-- 配置换弹时掉落的网格体
new_weapon:SetMagazineMesh("nanos-world::SM_AK47_Mag_Empty")

-- 配置准星材质
new_weapon:SetCrosshairMaterial("nanos-world::MI_Crosshair_Regular")

Using the default-weapons Package to spawn an AK47. First add it to the packages_requirements of your Package.toml:

Package.toml
[script]
# ...
packages_requirements = [
"default-weapons",
]
Server/Index.lua
-- Spawning the AK47 from default-weapons package
local my_ak47 = AK47(Vector(200, 0, 100), Rotator())

-- Giving the Weapon to a Character
my_character:PickUp(my_ak47)

更多相关示例:

道具发射器getting-started/tutorials-and-examples/prop-shooter 武器瞄准镜getting-started/tutorials-and-examples/weapon-scope 武器手电筒getting-started/tutorials-and-examples/weapon-flashlight

🛠 构造函数​

Default Constructor​

No description provided

local my_weapon = Weapon(location, rotation, asset, collision_type?, gravity_enabled?, spawn_mode?)

Parameters

TypeNameDefaultDescription
Vectorlocation Required parameter 生成的世界坐标位置
Rotatorrotation Required parameter 生成的世界坐标旋转
SkeletalMesh Referenceasset Required parameter 要使用的资产
CollisionTypecollision_typeCollisionType.Auto此 Actor 的碰撞配置文件
booleangravity_enabledtrue重力是否影响此 Actor
SpawnModespawn_modeSpawnMode.Immediate传入 SpawnMode.AfterConstructor 或 SpawnMode.Manual 可避免立即将实体发送至客户端,在需要配置多项设置时使用此选项可提升性能。最后必须调用 FinishSpawn()

🗿 静态函数​

Inherited Entity Static Functions
Weapon 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
Weapon 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
Weapon 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
Weapon 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
Weapon 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
integerGetAmmoBag获取此武器后备弹药包中的弹药量
integerGetAmmoClip获取此武器弹夹内的弹药量
integerGetAmmoToReload获取完全装满弹药所需的弹药量
Animation ReferenceGetAnimationCharacterFire获取角色开火时播放的动画
Animation ReferenceGetAnimationFire获取武器开火时自身播放的动画
Animation ReferenceGetAnimationReload获取换弹动画
ColorGetBulletColor获取子弹弹道的颜色
integerGetBulletCount获取每次射击发射的子弹数量
floatGetCadence获取两次射击之间的间隔时间
booleanGetCanHoldUse获取是否可以通过长按使用按钮来连续使用该武器
integerGetClipCapacity获取弹夹的最大子弹容量
integerGetDamage获取此武器的基础伤害量
booleanGetHoldReleaseUse获取是否在释放使用按钮时触发/发射该武器
VectorGetLeftHandLocation获取左手的位置偏移量
RotatorGetLeftHandRotation获取左手的旋转偏移量
StaticMesh ReferenceGetMagazineMesh获取换弹时使用的弹匣静态网格体
Particle ReferenceGetParticlesBarrel获取枪口开火火焰的粒子效果
Particle ReferenceGetParticlesBulletTrail获取子弹弹道的粒子效果
Particle ReferenceGetParticlesShells获取抛壳弹壳的粒子效果
floatGetRecoil获取此武器的基础后坐力
VectorGetRightHandOffset获取右手相对于相机的位置偏移量
floatGetSightFOVMultiplier获取开镜喵准时应用的视场角乘数
VectorGetSightLocation获取开镜瞄准时使用的照准位置偏移量
RotatorGetSightRotation获取开镜瞄准时使用的照准旋转量
Sound ReferenceGetSoundAim获取瞄准时播放的音效
Sound ReferenceGetSoundDry获取弹夹为空并尝试开火时播放的音效
Sound ReferenceGetSoundFire获取开火时播放的音效
Sound ReferenceGetSoundLoad获取装填弹匣时播放的音效
Sound ReferenceGetSoundUnload获取卸下弹匣时播放的音效
Sound ReferenceGetSoundZooming获取变焦时播放的音效
floatGetSpread获取此武器的基础弹道散布程度
floatGetWallbangDamageMultiplier获取子弹穿墙时应用的伤害乘数
floatGetWallbangMaxDistance获取子弹允许穿墙的最大距离
PlayAnimation在此武器上播放动画
Reload强制此武器换弹
SetAmmoBag设置此武器在后备弹药包中的弹药量
SetAmmoClip设置此武器在弹夹内的弹药量
SetAmmoSettings一次性设置弹药数量和弹夹容量
SetAnimationCharacterFire设置角色使用此武器开火时播放的动画
SetAnimationFire设置武器在开火时自身播放的动画
SetAnimationReload设置角色装填此武器时播放的动画
SetAutoReload设置当弹夹为空时角色是否会自动换弹
SetBulletColor设置子弹颜色
SetBulletSettings设置单次射击发出的子弹数量,以及子弹的外观和飞行方式
SetCadence设置两次射击之间的间隔时间
SetClipCapacity设置此武器弹夹可容纳的最大子弹数
SetDamage设置武器的基础伤害
SetHandlingMode设置角色抓握此武器的方式
SetLeftHandTransform设置角色左手持握此武器的位置,相对于武器本身
SetMagazineMesh设置角色换弹时使用的弹夹网格体
SetParticlesBarrel设置枪口开火火焰的粒子效果
SetParticlesBulletTrail设置子弹弹道的粒子效果
SetParticlesShells设置开火时抛出的空弹壳的粒子效果
SetRecoil设置此武器的基础后坐力
SetRightHandOffset设置右手偏移量
SetSightFOVMultiplier设置开镜瞄准时应用的视场角乘数
SetSightTransform设置开镜瞄准时使玩家视角与武器照准线对齐的偏移量
SetSoundAim设置开始瞄准时播放的音效
SetSoundDry设置弹夹为空并尝试开火时播放的音效
SetSoundFire设置开火时播放的音效
SetSoundFireLastBullets当弹夹内仅剩 X 发子弹开火时的声音
SetSoundLoad设置装填弹匣时播放的音效
SetSoundUnload设置卸下弹匣时播放的音效
SetSoundZooming设置变焦时播放的音效
SetSpread设置此武器的基础弹道散布程度
SetUsageSettings设置武器是否可以按住持续射击,以及是否需要松开按键才触发射击
SetWallbangSettings设置子弹如何穿透墙壁
StopAnimation停止在此武器上播放的动画蒙太奇

Optimal

GetAmmoBag​

获取此武器后备弹药包中的弹药量
local ammo_bag = my_weapon:GetAmmoBag()

Returns

TypeDescription
integer此武器的弹药包

See also SetAmmoBag.


Optimal

GetAmmoClip​

获取此武器弹夹内的弹药量
local ammo_clip = my_weapon:GetAmmoClip()

Returns

TypeDescription
integer此武器的弹夹弹药

See also SetAmmoClip.


Slow

GetAmmoToReload​

获取完全装满弹药所需的弹药量
local ammo_to_reload = my_weapon:GetAmmoToReload()

Returns

TypeDescription
integer完全换弹所需的弹药量

Optimal

GetAnimationCharacterFire​

获取角色开火时播放的动画
local animation_character_fire_path = my_weapon:GetAnimationCharacterFire()

Returns

TypeDescription
Animation Reference动画资产

See also SetAnimationCharacterFire.


Optimal

GetAnimationFire​

获取武器开火时自身播放的动画
local animation_fire_path = my_weapon:GetAnimationFire()

Returns

TypeDescription
Animation Reference动画资产

See also SetAnimationFire.


Optimal

GetAnimationReload​

获取换弹动画
local reload_animation_path = my_weapon:GetAnimationReload()

Returns

TypeDescription
Animation Reference换弹动画

See also SetAnimationReload.


Optimal

GetBulletColor​

获取子弹弹道的颜色
local bullet_color = my_weapon:GetBulletColor()

Returns

TypeDescription
Color子弹弹道颜色

See also SetBulletColor.


Optimal

GetBulletCount​

获取每次射击发射的子弹数量
local bullet_count = my_weapon:GetBulletCount()

Returns

TypeDescription
integer每次射击的子弹数

Optimal

GetCadence​

获取两次射击之间的间隔时间
local cadence = my_weapon:GetCadence()

Returns

TypeDescription
float射击间隔秒数

See also SetCadence.


Optimal

GetCanHoldUse​

获取是否可以通过长按使用按钮来连续使用该武器
local can_hold_use = my_weapon:GetCanHoldUse()

Returns

TypeDescription
boolean按住使用键时是否可以连续使用该武器

Optimal

GetClipCapacity​

获取弹夹的最大子弹容量
local clip = my_weapon:GetClipCapacity()

Returns

TypeDescription
integer弹夹容量

See also SetClipCapacity.


Optimal

GetDamage​

获取此武器的基础伤害量
local damage = my_weapon:GetDamage()

Returns

TypeDescription
integer基础伤害

See also SetDamage.


Optimal

GetHoldReleaseUse​

获取是否在释放使用按钮时触发/发射该武器
local hold_release_use = my_weapon:GetHoldReleaseUse()

Returns

TypeDescription
boolean释放使用键时是否会触发/发射该武器

Optimal

GetLeftHandLocation​

获取左手的位置偏移量
local left_hand_location = my_weapon:GetLeftHandLocation()

Returns

TypeDescription
Vector左手位置偏移量

Optimal

GetLeftHandRotation​

获取左手的旋转偏移量
local left_hand_rotation = my_weapon:GetLeftHandRotation()

Returns

TypeDescription
Rotator左手旋转偏移量

Optimal

GetMagazineMesh​

获取换弹时使用的弹匣静态网格体
local magazine_mesh = my_weapon:GetMagazineMesh()

Returns

TypeDescription
StaticMesh Reference静态网格体资产

See also SetMagazineMesh.


Optimal

GetParticlesBarrel​

获取枪口开火火焰的粒子效果
local particle_asset_path = my_weapon:GetParticlesBarrel()

Returns

TypeDescription
Particle Reference枪口处的开火枪口火焰粒子

See also SetParticlesBarrel.


Optimal

GetParticlesBulletTrail​

获取子弹弹道的粒子效果
local particle_bullet_trail_asset_path = my_weapon:GetParticlesBulletTrail()

Returns

TypeDescription
Particle Reference粒子资产

See also SetParticlesBulletTrail.


Optimal

GetParticlesShells​

获取抛壳弹壳的粒子效果
local particle_shells_asset_path = my_weapon:GetParticlesShells()

Returns

TypeDescription
Particle Reference粒子资产

See also SetParticlesShells.


Optimal

GetRecoil​

获取此武器的基础后坐力
local recoil = my_weapon:GetRecoil()

Returns

TypeDescription
float基础后坐力,0 表示无后坐力

See also SetRecoil.


Optimal

GetRightHandOffset​

获取右手相对于相机的位置偏移量
local right_hand_offset = my_weapon:GetRightHandOffset()

Returns

TypeDescription
Vector右手偏移量

See also SetRightHandOffset.


Optimal

GetSightFOVMultiplier​

获取开镜喵准时应用的视场角乘数
local sight_fov_multiplier = my_weapon:GetSightFOVMultiplier()

Returns

TypeDescription
floatFOV 乘数

See also SetSightFOVMultiplier.


Optimal

GetSightLocation​

获取开镜瞄准时使用的照准位置偏移量
local sight_location = my_weapon:GetSightLocation()

Returns

TypeDescription
Vector照准位置偏移量

Optimal

GetSightRotation​

获取开镜瞄准时使用的照准旋转量
local sight_rotation = my_weapon:GetSightRotation()

Returns

TypeDescription
Rotator照准旋转量

Optimal

GetSoundAim​

获取瞄准时播放的音效
local sound_aim_asset_path = my_weapon:GetSoundAim()

Returns

TypeDescription
Sound Reference音效资产

See also SetSoundAim.


Optimal

GetSoundDry​

获取弹夹为空并尝试开火时播放的音效
local sound_dry_asset_path = my_weapon:GetSoundDry()

Returns

TypeDescription
Sound Reference音效资产

See also SetSoundDry.


Optimal

GetSoundFire​

获取开火时播放的音效
local sound_fire_asset_path = my_weapon:GetSoundFire()

Returns

TypeDescription
Sound Reference音效资产

See also SetSoundFire.


Slow

GetSoundLoad​

获取装填弹匣时播放的音效
local sound_load_asset_path = my_weapon:GetSoundLoad()

Returns

TypeDescription
Sound Reference音效资产

See also SetSoundLoad.


Slow

GetSoundUnload​

获取卸下弹匣时播放的音效
local sound_unload_asset_path = my_weapon:GetSoundUnload()

Returns

TypeDescription
Sound Reference音效资产

See also SetSoundUnload.


Optimal

GetSoundZooming​

获取变焦时播放的音效
local sound_zooming_asset_path = my_weapon:GetSoundZooming()

Returns

TypeDescription
Sound Reference音效资产

See also SetSoundZooming.


Optimal

GetSpread​

获取此武器的基础弹道散布程度
local spread = my_weapon:GetSpread()

Returns

TypeDescription
float基础散布值,数值越高精准度越低

See also SetSpread.


Optimal

GetWallbangDamageMultiplier​

获取子弹穿墙时应用的伤害乘数
local damage_multiplier = my_weapon:GetWallbangDamageMultiplier()

Returns

TypeDescription
float子弹穿墙时应用的伤害乘数

Optimal

GetWallbangMaxDistance​

获取子弹允许穿墙的最大距离
local max_distance = my_weapon:GetWallbangMaxDistance()

Returns

TypeDescription
float子弹可穿墙的最大距离

Slow

PlayAnimation​

在此武器上播放动画
my_weapon:PlayAnimation(animation_path, slot_name?, loop_indefinitely?, blend_in_time?, blend_out_time?, play_rate?, stop_all_montages?)

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_path Required parameter 要播放的动画资产
stringslot_name?DefaultSlot
用于播放动画的动画插槽
booleanloop_indefinitely?false
此参数仅在武器具有动画蓝图时使用
floatblend_in_time?0.25
此参数仅在武器具有动画蓝图时使用
floatblend_out_time?0.25
此参数仅在武器具有动画蓝图时使用
floatplay_rate?1.0
此参数仅在武器具有动画蓝图时使用
booleanstop_all_montages?false
停止来自同一组的所有运行中的蒙太奇。此参数仅在武器具有动画蓝图时使用

Moderate

Reload​

强制此武器换弹(仅当由角色持有操作时有效)
my_weapon:Reload()

Optimal

SetAmmoBag​

设置此武器在后备弹药包中的弹药量
my_weapon:SetAmmoBag(new_ammo_bag)

Parameters

TypeParameterDefaultDescription
integernew_ammo_bag Required parameter 弹药包中的新弹药数量

See also GetAmmoBag.


Optimal

SetAmmoClip​

设置此武器在弹夹内的弹药量
my_weapon:SetAmmoClip(new_ammo_clip)

Parameters

TypeParameterDefaultDescription
integernew_ammo_clip Required parameter 弹夹中的新弹药数量

See also GetAmmoClip.


Optimal

SetAmmoSettings​

一次性设置弹药数量和弹夹容量
my_weapon:SetAmmoSettings(ammo_clip, ammo_bag, ammo_to_reload?, clip_capacity?)

Parameters

TypeParameterDefaultDescription
integerammo_clip Required parameter 当前已装填在弹夹中的子弹数
integerammo_bag Required parameter 携带的备用子弹数,在换弹时使用
integerammo_to_reload?ammo_clip
每次换弹动作装填的子弹数量,适用于霰弹枪等一次装填一发子弹的武器。默认为弹夹容量
integerclip_capacity?ammo_clip
弹夹可容纳的最大子弹数

Slow

SetAnimationCharacterFire​

设置角色使用此武器开火时播放的动画
my_weapon:SetAnimationCharacterFire(animation_character_fire_path, play_rate?)

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_character_fire_path Required parameter 要在角色上播放的动画资产
floatplay_rate?1
动画的速度乘数

See also GetAnimationCharacterFire.


Slow

SetAnimationFire​

设置武器在开火时自身播放的动画
my_weapon:SetAnimationFire(animation_fire_path, play_rate?)

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_fire_path Required parameter 要在武器网格体上播放的动画资产
floatplay_rate?1
动画的速度乘数

See also GetAnimationFire.


Slow

SetAnimationReload​

设置角色装填此武器时播放的动画
my_weapon:SetAnimationReload(reload_animation_path, play_rate?)

Parameters

TypeParameterDefaultDescription
Animation Referencereload_animation_path Required parameter 要在角色上播放的动画资产
floatplay_rate?1
动画的速度乘数

See also GetAnimationReload.


Optimal

SetAutoReload​

设置当弹药耗尽时角色是否会自动换弹。默认为 true
my_weapon:SetAutoReload(auto_reload)

Parameters

TypeParameterDefaultDescription
booleanauto_reload Required parameter 是否自动换弹

Optimal

SetBulletColor​

设置子弹颜色

仅在使用子弹拖尾粒子 P_Bullet_Trail 或你的粒子包含 Color 参数时生效
my_weapon:SetBulletColor(bullet_color)

Parameters

TypeParameterDefaultDescription
Colorbullet_color Required parameter 新的子弹颜色

See also GetBulletColor.


Optimal

SetBulletSettings​

设置单次射击发出的子弹数量,以及子弹的外观和飞行方式
my_weapon:SetBulletSettings(bullet_count, bullet_max_distance, bullet_velocity, bullet_color)

Parameters

TypeParameterDefaultDescription
integerbullet_count Required parameter 普通武器为 1
霰弹枪则 > 1
integerbullet_max_distance Required parameter 子弹飞行的最大距离(单位,1 单位 = 1 厘米)
integerbullet_velocity Required parameter 仅限视觉效果
Colorbullet_color Required parameter 子弹弹道颜色

Optimal

SetCadence​

设置两次射击之间的间隔时间
my_weapon:SetCadence(cadence)

Parameters

TypeParameterDefaultDescription
floatcadence Required parameter 每 cadence 秒发射 1 发子弹

See also GetCadence.


Optimal

SetClipCapacity​

设置此武器弹夹可容纳的最大子弹数
my_weapon:SetClipCapacity(clip)

Parameters

TypeParameterDefaultDescription
integerclip Required parameter 新的弹夹容量

See also GetClipCapacity.


Optimal

SetDamage​

武器的基础伤害值

在击中特定骨骼时,此数值会乘以相应的倍数系数
my_weapon:SetDamage(damage)

Parameters

TypeParameterDefaultDescription
integerdamage Required parameter 新的武器基础伤害量

See also GetDamage.


Optimal

SetHandlingMode​

设置角色抓握此武器的方式
my_weapon:SetHandlingMode(handling_mode)

Parameters

TypeParameterDefaultDescription
HandlingModehandling_mode Required parameter 新的角色握持模式

Optimal

SetLeftHandTransform​

设置角色左手持握此武器的位置,相对于武器本身
my_weapon:SetLeftHandTransform(left_hand_location, left_hand_rotation)

Parameters

TypeParameterDefaultDescription
Vectorleft_hand_location Required parameter 左手的位置偏移量
Rotatorleft_hand_rotation Required parameter 左手的旋转偏移量

Slow

SetMagazineMesh​

设置角色换弹时使用的弹夹网格体。

该网格体在掉落时会作为一个动画效果显示。
my_weapon:SetMagazineMesh(magazine_mesh, magazine_mesh_hide_bone?)

Parameters

TypeParameterDefaultDescription
StaticMesh Referencemagazine_mesh Required parameter 弹匣的静态网格体,在换弹过程中会生成在角色手中
stringmagazine_mesh_hide_bone?b_gun_mag
换弹时需要隐藏的武器骨骼名称

See also GetMagazineMesh.


Slow

SetParticlesBarrel​

设置枪口开火火焰的粒子效果
my_weapon:SetParticlesBarrel(particle_asset_path)

Parameters

TypeParameterDefaultDescription
Particle Referenceparticle_asset_path Required parameter 开火时要在枪口位置生成的粒子资产

See also GetParticlesBarrel.


Slow

SetParticlesBulletTrail​

设置子弹弹道的粒子效果
my_weapon:SetParticlesBulletTrail(particle_bullet_trail_asset_path)

Parameters

TypeParameterDefaultDescription
Particle Referenceparticle_bullet_trail_asset_path Required parameter 为每发子弹生成的粒子资产

See also GetParticlesBulletTrail.


Slow

SetParticlesShells​

设置开火时抛出的空弹壳的粒子效果
my_weapon:SetParticlesShells(particle_shells_asset_path)

Parameters

TypeParameterDefaultDescription
Particle Referenceparticle_shells_asset_path Required parameter 抛壳时要生成的粒子资产

See also GetParticlesShells.


Optimal

SetRecoil​

设置此武器的基础后坐力
my_weapon:SetRecoil(recoil)

Parameters

TypeParameterDefaultDescription
floatrecoil Required parameter 0 表示无后坐力,默认为 1

See also GetRecoil.


Optimal

SetRightHandOffset​

设置右手偏移量。用于调整相对于相机的位置。
my_weapon:SetRightHandOffset(right_hand_offset)

Parameters

TypeParameterDefaultDescription
Vectorright_hand_offset Required parameter 右手的新偏移量

See also GetRightHandOffset.


Optimal

SetSightFOVMultiplier​

设置开镜瞄准时应用的视场角乘数
my_weapon:SetSightFOVMultiplier(sight_fov_multiplier)

Parameters

TypeParameterDefaultDescription
floatsight_fov_multiplier Required parameter 小于 1 的数值会放大视角,例如瞄准镜设为 0.5

See also GetSightFOVMultiplier.


Optimal

SetSightTransform​

设置开镜瞄准时使玩家视角与武器照准线对齐的偏移量
my_weapon:SetSightTransform(sight_location, sight_rotation)

Parameters

TypeParameterDefaultDescription
Vectorsight_location Required parameter 相机与照准线之间的偏移量
Rotatorsight_rotation Required parameter 瞄准时应用给武器的旋转量

Slow

SetSoundAim​

设置开始瞄准时播放的音效
my_weapon:SetSoundAim(sound_aim_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_aim_asset_path Required parameter 要播放的音效资产
floatvolume?1
音量倍率
floatpitch?1
音高倍率

See also GetSoundAim.


Slow

SetSoundDry​

设置弹夹为空并尝试开火时播放的音效
my_weapon:SetSoundDry(sound_dry_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_dry_asset_path Required parameter 要播放的音效资产
floatvolume?1
音量倍率
floatpitch?1
音高倍率

See also GetSoundDry.


Slow

SetSoundFire​

设置开火时播放的音效
my_weapon:SetSoundFire(sound_fire_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_fire_asset_path Required parameter 要播放的音效资产
floatvolume?1
音量倍率
floatpitch?1
音高倍率

See also GetSoundFire.


Slow

SetSoundFireLastBullets​

当弹夹内仅剩 X 发子弹开火时的声音,适用于最后一发子弹的“叮”声或弹药不足时的声音
my_weapon:SetSoundFireLastBullets(sound_asset_path, remaining_bullets_count?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_asset_path Required parameter 要播放的音效资产
integerremaining_bullets_count?1
开始播放此声音所剩余的子弹数量

Slow

SetSoundLoad​

设置装填弹匣时播放的音效
my_weapon:SetSoundLoad(sound_load_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_load_asset_path Required parameter 要播放的音效资产
floatvolume?1
音量倍率
floatpitch?1
音高倍率

See also GetSoundLoad.


Slow

SetSoundUnload​

设置卸下弹匣时播放的音效
my_weapon:SetSoundUnload(sound_unload_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_unload_asset_path Required parameter 要播放的音效资产
floatvolume?1
音量倍率
floatpitch?1
音高倍率

See also GetSoundUnload.


Slow

SetSoundZooming​

设置变焦时播放的音效
my_weapon:SetSoundZooming(sound_zooming_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_zooming_asset_path Required parameter 要播放的音效资产
floatvolume?1
音量倍率
floatpitch?1
音高倍率

See also GetSoundZooming.


Optimal

SetSpread​

设置此武器的基础弹道散布程度
my_weapon:SetSpread(spread)

Parameters

TypeParameterDefaultDescription
floatspread Required parameter 数值越高精度越低 - 推荐值:20

See also GetSpread.


Optimal

SetUsageSettings​

设置武器是否可以按住持续射击,以及是否需要松开按键才触发射击
my_weapon:SetUsageSettings(can_hold_use, hold_release_use)

Parameters

TypeParameterDefaultDescription
booleancan_hold_use Required parameter 按住开火键是否持续射击(自动武器)
booleanhold_release_use Required parameter 是否仅在释放开火键时才进行射击(例如弓)

Optimal

SetWallbangSettings​

设置子弹如何穿透墙壁
my_weapon:SetWallbangSettings(max_distance, damage_multiplier)

Parameters

TypeParameterDefaultDescription
integermax_distance Required parameter 可以穿透墙壁的最大距离
floatdamage_multiplier Required parameter 穿墙击中时所施加的伤害

Optimal

StopAnimation​

停止在此武器上播放的动画蒙太奇
my_weapon:StopAnimation(animation_asset?)

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_asset?
留空以停止所有蒙太奇

🚀 事件​

Inherited Entity Events
Weapon 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
Weapon 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
Weapon 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
AmmoBagChange当后备弹药包中的弹药量因换弹或脚本手动设置而发生改变时
AmmoClipChange当弹夹内的弹药量因换弹、射击或脚本手动设置而发生改变时
BulletHit当子弹击中目标时触发(每发子弹击中都会触发一次)
Fire当武器射击时触发(每发子弹射击都会触发一次)
Reload当武器换弹时,可选由某个角色触发

AmmoBagChange​

当后备弹药包中的弹药量因换弹或脚本手动设置而发生改变时
Weapon.Subscribe("AmmoBagChange", function(self, old_ammo_bag, new_ammo_bag)
-- AmmoBagChange was called
end)

Arguments

TypeArgumentDescription
Weaponself触发该事件的武器
integerold_ammo_bag先前的弹药包弹药量
integernew_ammo_bag新的弹药包弹药量

AmmoClipChange​

当弹夹内的弹药量因换弹、射击或脚本手动设置而发生改变时
Weapon.Subscribe("AmmoClipChange", function(self, old_ammo_clip, new_ammo_clip)
-- AmmoClipChange was called
end)

Arguments

TypeArgumentDescription
Weaponself触发该事件的武器
integerold_ammo_clip先前的弹夹弹药量
integernew_ammo_clip新的弹夹弹药量

BulletHit​

当子弹击中目标时触发(每发子弹击中都会触发一次)
Weapon.Subscribe("BulletHit", function(self, impact_point, impact_normal, damage, actor_hit)
-- BulletHit was called
end)

Arguments

TypeArgumentDescription
Weaponself触发该事件的武器
Vectorimpact_point子弹击中在世界空间中的位置
Vectorimpact_normal子弹击中在世界空间中的法线
integerdamage所施加的伤害值
Base Actor or nilactor_hit被击中的 Actor 实体(如果有)

Fire​

当武器射击时触发(每发子弹射击都会触发一次)
Weapon.Subscribe("Fire", function(self, shooter)
-- Fire was called
end)

Arguments

TypeArgumentDescription
Weaponself触发该事件的武器
Charactershooter持握该武器的角色(若有)

Reload​

当武器换弹时,可选由某个角色触发
Weapon.Subscribe("Reload", function(self, character, ammo_to_reload)
-- Reload was called
end)

Arguments

TypeArgumentDescription
Weaponself触发该事件的武器
Charactercharacter角色
integerammo_to_reload已装填的子弹数量