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

🔫 武器

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

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

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
-- Spawning a Weapon with an AK47 model
local new_weapon = Weapon(
Vector(-900, 185, 215),
Rotator(0, 0, 0),
"nanos-world::SK_AK47"
)

-- Configures Weapon Base Settings
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)

-- Configures how the Character Grabs and Aims the Weapon
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))

-- Configures Weapon Particles
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")

-- Configures Weapon Sounds
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")

-- Configures Weapon Animations
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")

-- Configures the Mesh to drop when reloading
new_weapon:SetMagazineMesh("nanos-world::SM_AK47_Mag_Empty")

-- Configures the Crosshair Material
new_weapon:SetCrosshairMaterial("nanos-world::MI_Crosshair_Regular")

Using the default-weapons Package to spawn an AK47:

Terminal
# install the default-weapons package
./NanosWorldServer.exe --cli install package default-weapons
Server/Index.lua
-- Loads the default-weapons (note: it's recommended to add it to your Package's packages_requirements instead)
Server.LoadPackage("default-weapons")

-- Spawning the AK47 from default-weapons package
local my_ak47 = AK47(Vector(1035, 154, 300), Rotator())

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

更多相关示例:

Prop Shootergetting-started/tutorials-and-examples/prop-shooter Weapon Scopegetting-started/tutorials-and-examples/weapon-scope Weapon Flashlightgetting-started/tutorials-and-examples/weapon-flashlight

🛠 构造函数

Default Constructor

No description provided

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

Parameters

TypeNameDefaultDescription
Vectorlocation Required parameter No description provided
Rotatorrotation Required parameter No description provided
SkeletalMesh Referenceasset Required parameter No description provided
CollisionTypecollision_typeCollisionType.AutoNo description provided
booleangravity_enabledtrueNo description provided
booleandefer_spawnfalse传入 true 以避免立即将该实体发送给客户端,从而在你想要通过设置多个配置来调整它时提高性能。最后必须调用 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完成生成过程,如果实体是通过 defer_spawn 生成的,则将实体发送给客户端
table of stringGetAllValuesKeys获取所有值键的列表
tableGetClass获取该实体的类
integerGetID获取该实体的全网通用网络 ID(在客户端和服务器上相同)
anyGetValue获取此实体上存储在给定键处的
booleanHasAuthority获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false)
booleanIsA递归检查此实体是否继承自某个类
booleanIsBeingDestroyed如果该实体正在被销毁,则返回 true
booleanIsValid如果该实体有效(即未被销毁且指向一个有效的实体),则返回 true
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() 设置)
table of Base ActorGetAttachedEntities获取附加到该 Actor 的所有 Actor
Base Actor or nilGetAttachedTo获取该 Actor 所附加到的父级 Actor
tableGetBounds获取该 Actor 的边界范围
CollisionTypeGetCollision获取该 Actor 的碰撞类型
integerGetDimension获取该 Actor 的维度
floatGetDistanceFromCamera获取该 Actor 距离相机的距离
VectorGetForce获取该 Actor 的持续外力(由 SetForce() 设置)
VectorGetLocation获取该 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 的维度
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设置此可拾取物的附加设置(即拾取时如何附加到角色上)
SetCanUse设置玩家在手持该可拾取物时是否可以使用它
SetCrosshairMaterial设置该可拾取物的准星材质
SetPickable设置玩家是否可以从地面上拾取该可拾取物
SetStaticMeshAttachedTransform设置已附加静态网格体的位置和旋转
ReturnsNameDescription
integerGetAmmoBag获取此武器后备弹药包中的弹药量
integerGetAmmoClip获取此武器弹夹内的弹药量
integerGetAmmoToReload获取完全装满弹药所需的弹药量
Animation ReferenceGetAnimationCharacterFireNo description provided
Animation ReferenceGetAnimationFireNo description provided
Animation ReferenceGetAnimationReload获取换弹动画
ColorGetBulletColorNo description provided
integerGetBulletCountNo description provided
floatGetCadenceNo description provided
booleanGetCanHoldUse获取是否可以通过长按使用按钮来连续使用该武器
integerGetClipCapacityNo description provided
integerGetDamageNo description provided
HandlingModeGetHandlingModeNo description provided
booleanGetHoldReleaseUse获取是否在释放使用按钮时触发/发射该武器
VectorGetLeftHandLocationNo description provided
RotatorGetLeftHandRotationNo description provided
StaticMesh ReferenceGetMagazineMeshNo description provided
Particle ReferenceGetParticlesBulletTrailNo description provided
Particle ReferenceGetParticlesShellsNo description provided
floatGetRecoilNo description provided
VectorGetRightHandOffsetNo description provided
floatGetSightFOVMultiplierNo description provided
VectorGetSightLocationNo description provided
RotatorGetSightRotationNo description provided
Sound ReferenceGetSoundAimNo description provided
Sound ReferenceGetSoundDryNo description provided
Sound ReferenceGetSoundFireNo description provided
Sound ReferenceGetSoundLoadNo description provided
Sound ReferenceGetSoundUnloadNo description provided
Sound ReferenceGetSoundZoomingNo description provided
floatGetSpreadNo description provided
PlayAnimation在此武器上播放动画
Reload强制此武器换弹
SetAmmoBag设置此武器在后备弹药包中的弹药量
SetAmmoClip设置此武器在弹夹内的弹药量
SetAmmoSettings用于设置和配置弹药的辅助函数
SetAnimationCharacterFire角色开火时播放的动画
SetAnimationFire武器开火时自身播放的动画
SetAnimationReload角色换弹时播放的动画
SetAutoReload设置当弹药耗尽时角色是否会自动换弹
SetBulletColor设置子弹颜色
SetBulletSettings用于设置和配置子弹的辅助函数
SetCadence射速
SetClipCapacity武器弹夹的容量
SetDamage设置武器的基础伤害
SetHandlingMode设置角色抓握此武器的方式
SetLeftHandTransform左手偏移量
SetMagazineMesh设置角色换弹时使用的弹夹网格体
SetParticlesBarrel枪口处的开火枪口火焰粒子
SetParticlesBulletTrail子弹飞行时的弹道拖尾粒子
SetParticlesShells射击时从武器中飞出的空弹壳粒子
SetRecoil武器的基础后坐力
SetRightHandOffset设置右手偏移量
SetSightFOVMultiplier开镜瞄准 (ADS) 时的视场角倍数
SetSightTransform用于使玩家头部与武器瞄具对齐的偏移量,以及开镜瞄准时应用在武器上的旋转
SetSoundAim瞄准时的声音
SetSoundDry武器没有子弹并尝试射击时的声音
SetSoundFire射击时的声音
SetSoundFireLastBullets当弹夹内仅剩 X 发子弹开火时的声音
SetSoundLoad装入弹夹时的声音
SetSoundUnload卸下弹夹时的声音
SetSoundZooming缩放变焦时的声音
SetSpread武器的基础散射度
SetUsageSettings设置武器是否可以按住持续射击,以及是否需要松开按键才触发射击
SetWallbangSettings设置子弹如何穿透墙壁

Optimal

GetAmmoBag

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

Returns

TypeDescription
integerammo_bag

See also SetAmmoBag.


Optimal

GetAmmoClip

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

Returns

TypeDescription
integerammo_clip

See also SetAmmoClip.


Slow

GetAmmoToReload

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

Returns

TypeDescription
integerammo_to_reload

Optimal

GetAnimationCharacterFire

local animation_character_fire_path = my_weapon:GetAnimationCharacterFire()

Returns

TypeDescription
Animation Referenceanimation_character_fire_path

See also SetAnimationCharacterFire.


Optimal

GetAnimationFire

local animation_fire_path = my_weapon:GetAnimationFire()

Returns

TypeDescription
Animation Referenceanimation_fire_path

See also SetAnimationFire.


Optimal

GetAnimationReload

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

Returns

TypeDescription
Animation Referencereload_animation_path

See also SetAnimationReload.


Optimal

GetBulletColor

local bullet_color = my_weapon:GetBulletColor()

Returns

TypeDescription
Colorbullet_color

See also SetBulletColor.


Optimal

GetBulletCount

local bullet_count = my_weapon:GetBulletCount()

Returns

TypeDescription
integerbullet_count

Optimal

GetCadence

local cadence = my_weapon:GetCadence()

Returns

TypeDescription
floatcadence

See also SetCadence.


Optimal

GetCanHoldUse

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

Returns

TypeDescription
booleancan_hold_use

Optimal

GetClipCapacity

local clip = my_weapon:GetClipCapacity()

Returns

TypeDescription
integerclip

See also SetClipCapacity.


Optimal

GetDamage

local damage = my_weapon:GetDamage()

Returns

TypeDescription
integerdamage

See also SetDamage.


Optimal

GetHandlingMode

local handling_mode = my_weapon:GetHandlingMode()

Returns

TypeDescription
HandlingModehandling_mode

See also SetHandlingMode.


Optimal

GetHoldReleaseUse

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

Returns

TypeDescription
booleanhold_release_use

Optimal

GetLeftHandLocation

local left_hand_location = my_weapon:GetLeftHandLocation()

Returns

TypeDescription
Vectorleft_hand_location

Optimal

GetLeftHandRotation

local left_hand_rotation = my_weapon:GetLeftHandRotation()

Returns

TypeDescription
Rotatorleft_hand_rotation

Optimal

GetMagazineMesh

local magazine_mesh = my_weapon:GetMagazineMesh()

Returns

TypeDescription
StaticMesh Referencemagazine_mesh

See also SetMagazineMesh.


Optimal

GetParticlesBulletTrail

local particle_bullet_trail_asset_path = my_weapon:GetParticlesBulletTrail()

Returns

TypeDescription
Particle Referenceparticle_bullet_trail_asset_path

See also SetParticlesBulletTrail.


Optimal

GetParticlesShells

local particle_shells_asset_path = my_weapon:GetParticlesShells()

Returns

TypeDescription
Particle Referenceparticle_shells_asset_path

See also SetParticlesShells.


Optimal

GetRecoil

local recoil = my_weapon:GetRecoil()

Returns

TypeDescription
floatrecoil

See also SetRecoil.


Optimal

GetRightHandOffset

local right_hand_offset = my_weapon:GetRightHandOffset()

Returns

TypeDescription
Vectorright_hand_offset

See also SetRightHandOffset.


Optimal

GetSightFOVMultiplier

local sight_fov_multiplier = my_weapon:GetSightFOVMultiplier()

Returns

TypeDescription
floatsight_fov_multiplier

See also SetSightFOVMultiplier.


Optimal

GetSightLocation

local sight_location = my_weapon:GetSightLocation()

Returns

TypeDescription
Vectorsight_location

Optimal

GetSightRotation

local sight_rotation = my_weapon:GetSightRotation()

Returns

TypeDescription
Rotatorsight_rotation

Optimal

GetSoundAim

local sound_aim_asset_path = my_weapon:GetSoundAim()

Returns

TypeDescription
Sound Referencesound_aim_asset_path

See also SetSoundAim.


Optimal

GetSoundDry

local sound_dry_asset_path = my_weapon:GetSoundDry()

Returns

TypeDescription
Sound Referencesound_dry_asset_path

See also SetSoundDry.


Optimal

GetSoundFire

local sound_fire_asset_path = my_weapon:GetSoundFire()

Returns

TypeDescription
Sound Referencesound_fire_asset_path

See also SetSoundFire.


Slow

GetSoundLoad

local sound_load_asset_path = my_weapon:GetSoundLoad()

Returns

TypeDescription
Sound Referencesound_load_asset_path

See also SetSoundLoad.


Slow

GetSoundUnload

local sound_unload_asset_path = my_weapon:GetSoundUnload()

Returns

TypeDescription
Sound Referencesound_unload_asset_path

See also SetSoundUnload.


Optimal

GetSoundZooming

local sound_zooming_asset_path = my_weapon:GetSoundZooming()

Returns

TypeDescription
Sound Referencesound_zooming_asset_path

See also SetSoundZooming.


Optimal

GetSpread

local spread = my_weapon:GetSpread()

Returns

TypeDescription
floatspread

See also SetSpread.


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 No description provided
stringslot_name?DefaultSlot
No description provided
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 No description provided

See also GetAmmoBag.


Optimal

SetAmmoClip

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

Parameters

TypeParameterDefaultDescription
integernew_ammo_clip Required parameter No description provided

See also GetAmmoClip.


Optimal

SetAmmoSettings

用于设置和配置弹药的辅助函数
my_weapon:SetAmmoSettings(ammo_clip, ammo_bag, ammo_to_reload?, clip_capacity?)

Parameters

TypeParameterDefaultDescription
integerammo_clip Required parameter No description provided
integerammo_bag Required parameter No description provided
integerammo_to_reload?ammo_clip
No description provided
integerclip_capacity?ammo_clip
No description provided

Slow

SetAnimationCharacterFire

角色开火时播放的动画
my_weapon:SetAnimationCharacterFire(animation_character_fire_path, play_rate?)

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_character_fire_path Required parameter No description provided
floatplay_rate?1
No description provided

See also GetAnimationCharacterFire.


Slow

SetAnimationFire

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

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_fire_path Required parameter No description provided
floatplay_rate?1
No description provided

See also GetAnimationFire.


Slow

SetAnimationReload

角色换弹时播放的动画
my_weapon:SetAnimationReload(reload_animation_path, play_rate?)

Parameters

TypeParameterDefaultDescription
Animation Referencereload_animation_path Required parameter No description provided
floatplay_rate?1
No description provided

See also GetAnimationReload.


Optimal

SetAutoReload

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

Parameters

TypeParameterDefaultDescription
booleanauto_reload Required parameter No description provided

Optimal

SetBulletColor

设置子弹颜色

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

Parameters

TypeParameterDefaultDescription
Colorbullet_color Required parameter No description provided

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 No description provided
integerbullet_velocity Required parameter 仅限视觉效果
Colorbullet_color Required parameter No description provided

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 No description provided

See also GetClipCapacity.


Optimal

SetDamage

武器的基础伤害值

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

Parameters

TypeParameterDefaultDescription
integerdamage Required parameter No description provided

See also GetDamage.


Optimal

SetHandlingMode

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

Parameters

TypeParameterDefaultDescription
HandlingModehandling_mode Required parameter No description provided

See also GetHandlingMode.


Optimal

SetLeftHandTransform

左手偏移量
my_weapon:SetLeftHandTransform(left_hand_location, left_hand_rotation)

Parameters

TypeParameterDefaultDescription
Vectorleft_hand_location Required parameter No description provided
Rotatorleft_hand_rotation Required parameter No description provided

Slow

SetMagazineMesh

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

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

Parameters

TypeParameterDefaultDescription
StaticMesh Referencemagazine_mesh Required parameter No description provided
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 No description provided

Slow

SetParticlesBulletTrail

子弹飞行时的弹道拖尾粒子
my_weapon:SetParticlesBulletTrail(particle_bullet_trail_asset_path)

Parameters

TypeParameterDefaultDescription
Particle Referenceparticle_bullet_trail_asset_path Required parameter No description provided

See also GetParticlesBulletTrail.


Slow

SetParticlesShells

射击时从武器中飞出的空弹壳粒子
my_weapon:SetParticlesShells(particle_shells_asset_path)

Parameters

TypeParameterDefaultDescription
Particle Referenceparticle_shells_asset_path Required parameter No description provided

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 No description provided

See also GetRightHandOffset.


Optimal

SetSightFOVMultiplier

开镜瞄准 (ADS) 时的视场角倍数
my_weapon:SetSightFOVMultiplier(sight_fov_multiplier)

Parameters

TypeParameterDefaultDescription
floatsight_fov_multiplier Required parameter No description provided

See also GetSightFOVMultiplier.


Optimal

SetSightTransform

用于使玩家头部与武器瞄具对齐的偏移量,以及开镜瞄准时应用在武器上的旋转
my_weapon:SetSightTransform(sight_location, sight_rotation)

Parameters

TypeParameterDefaultDescription
Vectorsight_location Required parameter No description provided
Rotatorsight_rotation Required parameter No description provided

Slow

SetSoundAim

瞄准时的声音
my_weapon:SetSoundAim(sound_aim_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_aim_asset_path Required parameter No description provided
floatvolume?1
No description provided
floatpitch?1
No description provided

See also GetSoundAim.


Slow

SetSoundDry

武器没有子弹并尝试射击时的声音
my_weapon:SetSoundDry(sound_dry_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_dry_asset_path Required parameter No description provided
floatvolume?1
No description provided
floatpitch?1
No description provided

See also GetSoundDry.


Slow

SetSoundFire

射击时的声音
my_weapon:SetSoundFire(sound_fire_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_fire_asset_path Required parameter No description provided
floatvolume?1
No description provided
floatpitch?1
No description provided

See also GetSoundFire.


Slow

SetSoundFireLastBullets

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

Parameters

TypeParameterDefaultDescription
Sound Referencesound_asset_path Required parameter No description provided
integerremaining_bullets_count?1
开始播放此声音所剩余的子弹数量

Slow

SetSoundLoad

装入弹夹时的声音
my_weapon:SetSoundLoad(sound_load_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_load_asset_path Required parameter No description provided
floatvolume?1
No description provided
floatpitch?1
No description provided

See also GetSoundLoad.


Slow

SetSoundUnload

卸下弹夹时的声音
my_weapon:SetSoundUnload(sound_unload_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_unload_asset_path Required parameter No description provided
floatvolume?1
No description provided
floatpitch?1
No description provided

See also GetSoundUnload.


Slow

SetSoundZooming

缩放变焦时的声音
my_weapon:SetSoundZooming(sound_zooming_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_zooming_asset_path Required parameter No description provided
floatvolume?1
No description provided
floatpitch?1
No description provided

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 No description provided
booleanhold_release_use Required parameter No description provided

Optimal

SetWallbangSettings

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

Parameters

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

🚀 事件

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 改变其维度时触发
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
WeaponselfNo description provided
integerold_ammo_bagNo description provided
integernew_ammo_bagNo description provided

AmmoClipChange

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

Arguments

TypeArgumentDescription
WeaponselfNo description provided
integerold_ammo_clipNo description provided
integernew_ammo_clipNo description provided

BulletHit

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

Arguments

TypeArgumentDescription
WeaponselfNo description provided
Vectorimpact_point子弹击中在世界空间中的位置
Vectorimpact_normal子弹击中在世界空间中的法线
integerdamage所施加的伤害值
Base Actor or nilactor_hit被击中的 Actor 实体(如果有)

Fire

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

Arguments

TypeArgumentDescription
WeaponselfNo description provided
CharactershooterNo description provided

Reload

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

Arguments

TypeArgumentDescription
WeaponselfNo description provided
CharactercharacterNo description provided
integerammo_to_reloadNo description provided