🔫 武器
武器是具有开火、换弹和瞄准功能的实体。
它们支持完全自定义,武器的所有部件都可以更改,具备极大的创作空间。

🎒 示例
-- 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:
# install the default-weapons package
./NanosWorldServer.exe --cli install package default-weapons
-- 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
| Type | Name | Default | Description |
|---|---|---|---|
| Vector | location | Required parameter | No description provided |
| Rotator | rotation | Required parameter | No description provided |
| SkeletalMesh Reference | asset | Required parameter | No description provided |
| CollisionType | collision_type | CollisionType.Auto | No description provided |
| boolean | gravity_enabled | true | No description provided |
| boolean | defer_spawn | false | 传入 true 以避免立即将该实体发送给客户端,从而在你想要通过设置多个配置来调整它时提高性能。最后必须调用 FinishSpawn() |
🗿 静态函数
Inherited Entity Static Functions
Base Entityscripting-reference/classes/base-classes/entity
| Returns | Name | Description | |
|---|---|---|---|
| table of Base Entity | GetAll | 返回一个包含调用此方法的类中所有实体的表 | |
| Base Entity | GetByIndex | 返回该类中指定索引处的特定实体 | |
| integer | GetCount | 返回该类当前存在的实体数量 | |
| table of table | GetInheritedClasses | 获取使用 继承系统 创建的、直接继承自该类的所有子类列表 | |
| iterator | GetPairs | 返回一个包含该类所有实体的迭代器,用于 pairs() 循环 | |
| table or nil | GetParentClass | 如果该类是使用 继承系统 创建的,则获取其父类 | |
| table | Inherit | 使用 继承系统 继承此类 | |
| boolean | IsChildOf | 如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类 | |
| function | Subscribe | 为该类的所有实体订阅一个 事件 | |
| function | SubscribeRemote | 订阅从服务器调用的自定义远程事件 | |
Unsubscribe | 退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调 |
This class doesn't have own static functions.
🦠 函数
Inherited Entity Functions
Base Entityscripting-reference/classes/base-classes/entity
| Returns | Name | Description | |
|---|---|---|---|
BroadcastRemoteEvent | 直接在此实体上向所有玩家调用自定义远程事件 | ||
BroadcastRemoteInRadiusEvent | 直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家 | ||
CallRemoteEvent | 直接在此实体上向特定玩家调用自定义远程事件 | ||
CallRemoteEvent | 直接在此实体上调用自定义远程事件 | ||
CallRemotePlayersEvent | 直接在此实体上调用自定义远程事件,并将事件传递给玩家列表 | ||
Destroy | 销毁该实体 | ||
FinishSpawn | 完成生成过程,如果实体是通过 defer_spawn 生成的,则将实体发送给客户端 | ||
| table of string | GetAllValuesKeys | 获取所有值键的列表 | |
| table | GetClass | 获取该实体的类 | |
| integer | GetID | 获取该实体的全网通用网络 ID(在客户端和服务器上相同) | |
| any | GetValue | 获取此实体上存储在给定键处的 值 | |
| boolean | HasAuthority | 获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false) | |
| boolean | IsA | 递归检查此实体是否继承自某个类 | |
| boolean | IsBeingDestroyed | 如果该实体正在被销毁,则返回 true | |
| boolean | IsValid | 如果该实体有效(即未被销毁且指向一个有效的实体),则返回 true | |
SetValue | 在此实体中设置一个值 | ||
| function | Subscribe | 在这个特定实体上订阅一个事件 | |
| function | SubscribeRemote | 在这个特定实体上订阅一个从服务器调用的自定义远程事件 | |
Unsubscribe | 退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调 |
Inherited Actor Functions
Base Actorscripting-reference/classes/base-classes/actor
| Returns | Name | Description | |
|---|---|---|---|
AddActorTag | 向该 Actor 添加一个虚幻 Actor 标签 | ||
AddAngularImpulse | 向该 Actor 添加角冲量。适用于单次瞬间爆发 | ||
AddImpulse | 向该 Actor 添加冲量。适用于单次瞬间爆发 | ||
| boolean | AttachTo | 将该 Actor 附加到任何其他 Actor 上,可选择附加在特定骨骼处 | |
Detach | 将该 Actor 从其附加的 Actor 上分离 | ||
| table of string | GetActorTags | 获取该 Actor 上的所有虚幻 Actor 标签 | |
| Vector | GetAngularForce | 获取该 Actor 的角外力(由 SetAngularForce() 设置) | |
| table of Base Actor | GetAttachedEntities | 获取附加到该 Actor 的所有 Actor | |
| Base Actor or nil | GetAttachedTo | 获取该 Actor 所附加到的父级 Actor | |
| table | GetBounds | 获取该 Actor 的边界范围 | |
| CollisionType | GetCollision | 获取该 Actor 的碰撞类型 | |
| integer | GetDimension | 获取该 Actor 的维度 | |
| float | GetDistanceFromCamera | 获取该 Actor 距离相机的距离 | |
| Vector | GetForce | 获取该 Actor 的持续外力(由 SetForce() 设置) | |
| Vector | GetLocation | 获取该 Actor 在游戏世界中的位置 | |
| Player or nil | GetNetworkAuthority | 获取该 Actor 的网络主控玩家 | |
| Vector | GetRelativeLocation | 如果该 Actor 已附加,获取其相对位置 | |
| Rotator | GetRelativeRotation | 如果该 Actor 已附加,获取其相对旋转 | |
| Rotator | GetRotation | 获取该 Actor 在游戏世界中的角度值 | |
| Vector | GetScale | 获取该 Actor 的缩放比例 | |
| float | GetScreenPercentage | 获取该 Actor 在屏幕中所占尺寸的百分比 | |
| table | GetSocketTransform | 在给定骨骼或插槽名称的情况下,获取世界空间中的插槽变换 | |
| Vector | GetVelocity | 获取该 Actor 当前的速度 | |
| boolean | HasNetworkAuthority | 如果本地玩家当前是该 Actor 的网络主控(Network Authority),则返回 true | |
| boolean | IsGravityEnabled | 如果该 Actor 启用了重力,则返回 true | |
| boolean | IsInWater | 如果该 Actor 处于水中,则返回 true | |
| boolean | IsNetworkDistributed | 如果该 Actor 当前处于网络分配状态,则返回 true | |
| boolean | IsVisible | 如果该 Actor 可见,则返回 true | |
RemoveActorTag | 从该 Actor 中移除一个虚幻 Actor 标签 | ||
RotateTo | 在一定时间内平滑旋转该 Actor 到指定角度 | ||
SetAngularForce | 向该 Actor 添加一个永久的角外力,设为 Vector(0, 0, 0) 可以取消 | ||
SetCastShadow | 设置该 Actor 是否投射阴影 | ||
SetCollision | 设置该 Actor 的碰撞类型 | ||
SetDimension | 设置该 Actor 的维度 | ||
SetDistanceOptimizationMultiplier | 设置此 Actor 的距离优化系数 | ||
SetForce | Adds a permanent force to this Actor, set to Vector(0, 0, 0) to cancel | ||
SetGravityEnabled | Sets whether gravity is enabled on this Actor | ||
SetHighlightEnabled | Sets whether the highlight is enabled on this Actor, and which highlight index to use | ||
SetLifeSpan | Sets the time (in seconds) before this Actor is destroyed. After this time has passed, the actor will be automatically destroyed. | ||
SetLocation | Sets this Actor's location in the game world | ||
SetNetworkAuthority | Sets the Player to have network authority over this Actor | ||
SetNetworkAuthorityAutoDistributed | Sets if this Actor will auto distribute the network authority between players | ||
SetOutlineEnabled | Sets whether the outline is enabled on this Actor, and which outline index to use | ||
SetRelativeLocation | Sets this Actor's relative location in local space (only if this actor is attached) | ||
SetRelativeRotation | Sets this Actor's relative rotation in local space (only if this actor is attached) | ||
SetRenderCullDistance | Sets this Actor's render cull distance | ||
SetRotation | Sets this Actor's rotation in the game world | ||
SetScale | Sets this Actor's scale | ||
SetVisibility | Sets whether the actor is visible or not | ||
TranslateTo | Smoothly moves this actor to a location over a certain time | ||
| boolean | WasRecentlyRendered | Gets if this Actor was recently rendered on screen |
Inherited Paintable Functions
Base Paintablescripting-reference/classes/base-classes/paintable
| Returns | Name | Description | |
|---|---|---|---|
| Color | GetMaterialColorParameter | 从该 Actor 的材质中获取 Color 参数 | |
| float | GetMaterialScalarParameter | 从该 Actor 的材质中获取 Scalar 参数 | |
| string | GetMaterialTextureParameter | 从该 Actor 的材质中获取 Texture 参数 | |
| Vector | GetMaterialVectorParameter | 从该 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
Base Pickablescripting-reference/classes/base-classes/pickable
| Returns | Name | Description | |
|---|---|---|---|
AddSkeletalMeshAttached | 附加一个骨骼网格体作为该实体的骨骼主姿态 | ||
AddStaticMeshAttached | 附加一个静态网格体到此实体 | ||
| table of string | GetAllSkeletalMeshAttached | 获取附加到此实体的所有骨骼网格体 | |
| table of string | GetAllStaticMeshAttached | 获取附加到此实体的所有静态网格体 | |
| Character or nil | GetHandler | 获取当前正手持该可拾取物的角色(如果存在) | |
| HandlingMode | GetHandlingMode | 获取该可拾取物的手持模式 | |
| SkeletalMesh Reference | GetMesh | 获取该可拾取物使用的资产名称 | |
PullUse | 拉取该可拾取物的使用状态(如果这是武器,将开始开火) | ||
ReleaseUse | 释放该可拾取物的使用状态(如果这是武器,将停止开火) | ||
RemoveAllSkeletalMeshesAttached | 移除所有已附加的骨骼网格体 | ||
RemoveAllStaticMeshesAttached | 移除所有已附加的静态网格体 | ||
RemoveSkeletalMeshAttached | 根据自定义 ID 移除此可拾取物上已存在的骨骼网格体(如果存在) | ||
RemoveStaticMeshAttached | 根据自定义 ID 移除此可拾取物上已存在的静态网格体(如果存在) | ||
SetAttachmentSettings | 设置此可拾取物的附加设置(即拾取时如何附加到角色上) | ||
SetCanUse | 设置玩家在手持该可拾取物时是否可以使用它 | ||
SetCrosshairMaterial | 设置该可拾取物的准星材质 | ||
SetPickable | 设置玩家是否可以从地面上拾取该可拾取物 | ||
SetStaticMeshAttachedTransform | 设置已附加静态网格体的位置和旋转 |


GetAmmoBag
获取此武器后备弹药包中的弹药量
local ammo_bag = my_weapon:GetAmmoBag()
Returns
| Type | Description |
|---|---|
| integer | ammo_bag |
See also SetAmmoBag.


GetAmmoClip
获取此武器弹夹内的弹药量
local ammo_clip = my_weapon:GetAmmoClip()
Returns
| Type | Description |
|---|---|
| integer | ammo_clip |
See also SetAmmoClip.


GetAmmoToReload
获取完全装满弹药所需的弹药量
local ammo_to_reload = my_weapon:GetAmmoToReload()
Returns
| Type | Description |
|---|---|
| integer | ammo_to_reload |


GetAnimationCharacterFire
local animation_character_fire_path = my_weapon:GetAnimationCharacterFire()
Returns
| Type | Description |
|---|---|
| Animation Reference | animation_character_fire_path |
See also SetAnimationCharacterFire.


GetAnimationFire
local animation_fire_path = my_weapon:GetAnimationFire()
Returns
| Type | Description |
|---|---|
| Animation Reference | animation_fire_path |
See also SetAnimationFire.


GetAnimationReload
获取换弹动画
local reload_animation_path = my_weapon:GetAnimationReload()
Returns
| Type | Description |
|---|---|
| Animation Reference | reload_animation_path |
See also SetAnimationReload.


GetBulletColor
local bullet_color = my_weapon:GetBulletColor()
Returns
| Type | Description |
|---|---|
| Color | bullet_color |
See also SetBulletColor.


GetBulletCount
local bullet_count = my_weapon:GetBulletCount()
Returns
| Type | Description |
|---|---|
| integer | bullet_count |


GetCadence
local cadence = my_weapon:GetCadence()
Returns
| Type | Description |
|---|---|
| float | cadence |
See also SetCadence.


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


GetClipCapacity
local clip = my_weapon:GetClipCapacity()
Returns
| Type | Description |
|---|---|
| integer | clip |
See also SetClipCapacity.


GetDamage
local damage = my_weapon:GetDamage()
Returns
| Type | Description |
|---|---|
| integer | damage |
See also SetDamage.


GetHandlingMode
local handling_mode = my_weapon:GetHandlingMode()
Returns
| Type | Description |
|---|---|
| HandlingMode | handling_mode |
See also SetHandlingMode.


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


GetLeftHandLocation
local left_hand_location = my_weapon:GetLeftHandLocation()
Returns
| Type | Description |
|---|---|
| Vector | left_hand_location |


GetLeftHandRotation
local left_hand_rotation = my_weapon:GetLeftHandRotation()
Returns
| Type | Description |
|---|---|
| Rotator | left_hand_rotation |


GetMagazineMesh
local magazine_mesh = my_weapon:GetMagazineMesh()
Returns
| Type | Description |
|---|---|
| StaticMesh Reference | magazine_mesh |
See also SetMagazineMesh.


GetParticlesBulletTrail
local particle_bullet_trail_asset_path = my_weapon:GetParticlesBulletTrail()
Returns
| Type | Description |
|---|---|
| Particle Reference | particle_bullet_trail_asset_path |
See also SetParticlesBulletTrail.


GetParticlesShells
local particle_shells_asset_path = my_weapon:GetParticlesShells()
Returns
| Type | Description |
|---|---|
| Particle Reference | particle_shells_asset_path |
See also SetParticlesShells.


GetRecoil
local recoil = my_weapon:GetRecoil()
Returns
| Type | Description |
|---|---|
| float | recoil |
See also SetRecoil.


GetRightHandOffset
local right_hand_offset = my_weapon:GetRightHandOffset()
Returns
| Type | Description |
|---|---|
| Vector | right_hand_offset |
See also SetRightHandOffset.


GetSightFOVMultiplier
local sight_fov_multiplier = my_weapon:GetSightFOVMultiplier()
Returns
| Type | Description |
|---|---|
| float | sight_fov_multiplier |
See also SetSightFOVMultiplier.


GetSightLocation
local sight_location = my_weapon:GetSightLocation()
Returns
| Type | Description |
|---|---|
| Vector | sight_location |


GetSightRotation
local sight_rotation = my_weapon:GetSightRotation()
Returns
| Type | Description |
|---|---|
| Rotator | sight_rotation |


GetSoundAim
local sound_aim_asset_path = my_weapon:GetSoundAim()
Returns
| Type | Description |
|---|---|
| Sound Reference | sound_aim_asset_path |
See also SetSoundAim.


GetSoundDry
local sound_dry_asset_path = my_weapon:GetSoundDry()
Returns
| Type | Description |
|---|---|
| Sound Reference | sound_dry_asset_path |
See also SetSoundDry.


GetSoundFire
local sound_fire_asset_path = my_weapon:GetSoundFire()
Returns
| Type | Description |
|---|---|
| Sound Reference | sound_fire_asset_path |
See also SetSoundFire.


GetSoundLoad
local sound_load_asset_path = my_weapon:GetSoundLoad()
Returns
| Type | Description |
|---|---|
| Sound Reference | sound_load_asset_path |
See also SetSoundLoad.


GetSoundUnload
local sound_unload_asset_path = my_weapon:GetSoundUnload()
Returns
| Type | Description |
|---|---|
| Sound Reference | sound_unload_asset_path |
See also SetSoundUnload.


GetSoundZooming
local sound_zooming_asset_path = my_weapon:GetSoundZooming()
Returns
| Type | Description |
|---|---|
| Sound Reference | sound_zooming_asset_path |
See also SetSoundZooming.


GetSpread
local spread = my_weapon:GetSpread()
Returns
| Type | Description |
|---|---|
| float | spread |
See also SetSpread.


PlayAnimation
在此武器上播放动画
my_weapon:PlayAnimation(animation_path, slot_name?, loop_indefinitely?, blend_in_time?, blend_out_time?, play_rate?, stop_all_montages?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Animation Reference | animation_path | Required parameter | No description provided |
| string | slot_name? | DefaultSlot | No description provided |
| boolean | loop_indefinitely? | false | 此参数仅在武器具有动画蓝图时使用 |
| float | blend_in_time? | 0.25 | 此参数仅在武器具有动画蓝图时使用 |
| float | blend_out_time? | 0.25 | 此参数仅在武器具有动画蓝图时使用 |
| float | play_rate? | 1.0 | 此参数仅在武器具有动画蓝图时使用 |
| boolean | stop_all_montages? | false | 停止来自同一组的所有运行中的蒙太奇。此参数仅在武器具有动画蓝图时使用 |


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


SetAmmoBag
设置此武器在后备弹药包中的弹药量
my_weapon:SetAmmoBag(new_ammo_bag)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | new_ammo_bag | Required parameter | No description provided |
See also GetAmmoBag.


SetAmmoClip
设置此武器在弹夹内的弹药量
my_weapon:SetAmmoClip(new_ammo_clip)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | new_ammo_clip | Required parameter | No description provided |
See also GetAmmoClip.


SetAmmoSettings
用于设置和配置弹药的辅助函数
my_weapon:SetAmmoSettings(ammo_clip, ammo_bag, ammo_to_reload?, clip_capacity?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | ammo_clip | Required parameter | No description provided |
| integer | ammo_bag | Required parameter | No description provided |
| integer | ammo_to_reload? | ammo_clip | No description provided |
| integer | clip_capacity? | ammo_clip | No description provided |


SetAnimationCharacterFire
角色开火时播放的动画
my_weapon:SetAnimationCharacterFire(animation_character_fire_path, play_rate?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Animation Reference | animation_character_fire_path | Required parameter | No description provided |
| float | play_rate? | 1 | No description provided |
See also GetAnimationCharacterFire.


SetAnimationFire
武器开火时自身播放的动画
my_weapon:SetAnimationFire(animation_fire_path, play_rate?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Animation Reference | animation_fire_path | Required parameter | No description provided |
| float | play_rate? | 1 | No description provided |
See also GetAnimationFire.


SetAnimationReload
角色换弹时播放的动画
my_weapon:SetAnimationReload(reload_animation_path, play_rate?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Animation Reference | reload_animation_path | Required parameter | No description provided |
| float | play_rate? | 1 | No description provided |
See also GetAnimationReload.


SetAutoReload
设置当弹药耗尽时角色是否会自动换弹。默认为 true
my_weapon:SetAutoReload(auto_reload)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| boolean | auto_reload | Required parameter | No description provided |


SetBulletColor
设置子弹颜色
仅在使用子弹拖尾粒子 P_Bullet_Trail 或你的粒子包含 Color 参数时生效
my_weapon:SetBulletColor(bullet_color)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Color | bullet_color | Required parameter | No description provided |
See also GetBulletColor.


SetBulletSettings
用于设置和配置子弹的辅助函数
my_weapon:SetBulletSettings(bullet_count, bullet_max_distance, bullet_velocity, bullet_color)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | bullet_count | Required parameter | 普通武器为 1 霰弹枪则 > 1 |
| integer | bullet_max_distance | Required parameter | No description provided |
| integer | bullet_velocity | Required parameter | 仅限视觉效果 |
| Color | bullet_color | Required parameter | No description provided |


SetCadence
射速
my_weapon:SetCadence(cadence)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | cadence | Required parameter | 每 cadence 秒发射 1 发子弹 |
See also GetCadence.


SetClipCapacity
武器弹夹的容量
my_weapon:SetClipCapacity(clip)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | clip | Required parameter | No description provided |
See also GetClipCapacity.


SetDamage
武器的基础伤害值
在击中特定骨骼时,此数值会乘以相应的倍数系数
my_weapon:SetDamage(damage)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | damage | Required parameter | No description provided |
See also GetDamage.


SetHandlingMode
设置角色抓握此武器的方式
my_weapon:SetHandlingMode(handling_mode)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| HandlingMode | handling_mode | Required parameter | No description provided |
See also GetHandlingMode.


SetLeftHandTransform
左手偏移量
my_weapon:SetLeftHandTransform(left_hand_location, left_hand_rotation)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | left_hand_location | Required parameter | No description provided |
| Rotator | left_hand_rotation | Required parameter | No description provided |


SetMagazineMesh
设置角色换弹时使用的弹夹网格体。
该网格体在掉落时会作为一个动画效果显示。
my_weapon:SetMagazineMesh(magazine_mesh, magazine_mesh_hide_bone?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| StaticMesh Reference | magazine_mesh | Required parameter | No description provided |
| string | magazine_mesh_hide_bone? | b_gun_mag | 换弹时需要隐藏的武器骨骼名称 |
See also GetMagazineMesh.


SetParticlesBarrel
枪口处的开火枪口火焰粒子
my_weapon:SetParticlesBarrel(particle_asset_path)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Particle Reference | particle_asset_path | Required parameter | No description provided |


SetParticlesBulletTrail
子弹飞行时的弹道拖尾粒子
my_weapon:SetParticlesBulletTrail(particle_bullet_trail_asset_path)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Particle Reference | particle_bullet_trail_asset_path | Required parameter | No description provided |
See also GetParticlesBulletTrail.


SetParticlesShells
射击时从武器中飞出的空弹壳粒子
my_weapon:SetParticlesShells(particle_shells_asset_path)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Particle Reference | particle_shells_asset_path | Required parameter | No description provided |
See also GetParticlesShells.


SetRecoil
武器的基础后坐力
my_weapon:SetRecoil(recoil)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | recoil | Required parameter | 0 表示无后坐力,默认为 1 |
See also GetRecoil.


SetRightHandOffset
设置右手偏移量。用于调整相对于相机的位置。
my_weapon:SetRightHandOffset(right_hand_offset)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | right_hand_offset | Required parameter | No description provided |
See also GetRightHandOffset.


SetSightFOVMultiplier
开镜瞄准 (ADS) 时的视场角倍数
my_weapon:SetSightFOVMultiplier(sight_fov_multiplier)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | sight_fov_multiplier | Required parameter | No description provided |
See also GetSightFOVMultiplier.


SetSightTransform
用于使玩家头部与武器瞄具对齐的偏移量,以及开镜瞄准时应用在武器上的旋转
my_weapon:SetSightTransform(sight_location, sight_rotation)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | sight_location | Required parameter | No description provided |
| Rotator | sight_rotation | Required parameter | No description provided |


SetSoundAim
瞄准时的声音
my_weapon:SetSoundAim(sound_aim_asset_path, volume?, pitch?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Sound Reference | sound_aim_asset_path | Required parameter | No description provided |
| float | volume? | 1 | No description provided |
| float | pitch? | 1 | No description provided |
See also GetSoundAim.


SetSoundDry
武器没有子弹并尝试射击时的声音
my_weapon:SetSoundDry(sound_dry_asset_path, volume?, pitch?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Sound Reference | sound_dry_asset_path | Required parameter | No description provided |
| float | volume? | 1 | No description provided |
| float | pitch? | 1 | No description provided |
See also GetSoundDry.


SetSoundFire
射击时的声音
my_weapon:SetSoundFire(sound_fire_asset_path, volume?, pitch?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Sound Reference | sound_fire_asset_path | Required parameter | No description provided |
| float | volume? | 1 | No description provided |
| float | pitch? | 1 | No description provided |
See also GetSoundFire.


SetSoundFireLastBullets
当弹夹内仅剩 X 发子弹开火时的声音,适用于最后一发子弹的“叮”声或弹药不足时的声音
my_weapon:SetSoundFireLastBullets(sound_asset_path, remaining_bullets_count?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Sound Reference | sound_asset_path | Required parameter | No description provided |
| integer | remaining_bullets_count? | 1 | 开始播放此声音所剩余的子弹数量 |


SetSoundLoad
装入弹夹时的声音
my_weapon:SetSoundLoad(sound_load_asset_path, volume?, pitch?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Sound Reference | sound_load_asset_path | Required parameter | No description provided |
| float | volume? | 1 | No description provided |
| float | pitch? | 1 | No description provided |
See also GetSoundLoad.


SetSoundUnload
卸下弹夹时的声音
my_weapon:SetSoundUnload(sound_unload_asset_path, volume?, pitch?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Sound Reference | sound_unload_asset_path | Required parameter | No description provided |
| float | volume? | 1 | No description provided |
| float | pitch? | 1 | No description provided |
See also GetSoundUnload.


SetSoundZooming
缩放变焦时的声音
my_weapon:SetSoundZooming(sound_zooming_asset_path, volume?, pitch?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Sound Reference | sound_zooming_asset_path | Required parameter | No description provided |
| float | volume? | 1 | No description provided |
| float | pitch? | 1 | No description provided |
See also GetSoundZooming.


SetSpread
武器的基础散射度
my_weapon:SetSpread(spread)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | spread | Required parameter | 数值越高精度越低 - 推荐值:20 |
See also GetSpread.


SetUsageSettings
设置武器是否可以按住持续射击,以及是否需要松开按键才触发射击
my_weapon:SetUsageSettings(can_hold_use, hold_release_use)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| boolean | can_hold_use | Required parameter | No description provided |
| boolean | hold_release_use | Required parameter | No description provided |


SetWallbangSettings
设置子弹如何穿透墙壁
my_weapon:SetWallbangSettings(max_distance, damage_multiplier)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | max_distance | Required parameter | 可以穿透墙壁的最大距离 |
| float | damage_multiplier | Required parameter | 穿墙击中时所施加的伤害 |
🚀 事件
Inherited Entity Events
Base Entityscripting-reference/classes/base-classes/entity
| Name | Description | |
|---|---|---|
ClassRegister | 当使用 继承系统 注册一个新类时触发 | |
Destroy | 当实体被销毁时触发 | |
Spawn | 当实体被生成/创建时触发 | |
ValueChange | 当实体通过 :SetValue() 改变了值时触发 |
Inherited Actor Events
Base Actorscripting-reference/classes/base-classes/actor
| Name | Description | |
|---|---|---|
DimensionChange | 当 Actor 改变其维度时触发 |
Inherited Pickable Events
Base Pickablescripting-reference/classes/base-classes/pickable
| Name | Description | |
|---|---|---|
AmmoBagChange | 当后备弹药包中的弹药量因换弹或脚本手动设置而发生改变时 | |
AmmoClipChange | 当弹夹内的弹药量因换弹、射击或脚本手动设置而发生改变时 | |
BulletHit | 当子弹击中目标时触发(每发子弹击中都会触发一次) | |
Fire | Triggered when Weapon fires (this will be triggered for each shot) | |
Reload | When a Weapon is reloaded, optionally by a Character |

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

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

BulletHit
当子弹击中目标时触发(每发子弹击中都会触发一次)
Weapon.Subscribe("BulletHit", function(self, impact_point, impact_normal, damage, actor_hit)
-- BulletHit was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Weapon | self | No description provided |
| Vector | impact_point | 子弹击中在世界空间中的位置 |
| Vector | impact_normal | 子弹击中在世界空间中的法线 |
| integer | damage | 所施加的伤害值 |
| Base Actor or nil | actor_hit | 被击中的 Actor 实体(如果有) |

Fire
Triggered when Weapon fires (this will be triggered for each shot)
Weapon.Subscribe("Fire", function(self, shooter)
-- Fire was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Weapon | self | No description provided |
| Character | shooter | No description provided |

Reload
When a Weapon is reloaded, optionally by a Character
Weapon.Subscribe("Reload", function(self, character, ammo_to_reload)
-- Reload was called
end)