Skip to main content
Version: latest - a1.172.0 โš–๏ธ

๐Ÿ”ซ Weapon

Weapons are entities with firing, reloading and aiming functionalities.

They are fully customizable, all pieces of the weapon can be changed with immense possibility of creation

Server Only๐Ÿ”Auto-Distributed๐Ÿง‘โ€๐Ÿ’ปAPI Source
๐Ÿ‘ชInheritance
This class shares methods and events from Base Entity, Base Actor, Base Paintable, Base Pickable.

๐ŸŽ’ Examplesโ€‹

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. 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)

More related examples:

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

๐Ÿ›  Constructorsโ€‹

Default Constructorโ€‹

No description provided

local my_weapon = Weapon(location, rotation, asset, collision_type?, gravity_enabled?, spawn_mode?)
Parameters
NameTypeDescription
locationVectorWorld location to spawn at
rotationRotatorWorld rotation to spawn with
assetSkeletalMesh ReferenceThe asset to use
collision_type?CollisionTypeCollision profile of this Actor Default CollisionType.Auto
gravity_enabled?booleanWhether gravity affects this Actor Default true
spawn_mode?SpawnModePass SpawnMode.AfterConstructor or SpawnMode.Manual to avoid immediately sending the entity to clients and improve performance when you want to configure it by setting several configs. Must call FinishSpawn() after all Default SpawnMode.Immediate

๐Ÿ—ฟ Static Functionsโ€‹

This class doesn't have own static functions.

Inherited static functions

๐Ÿฆ  Functionsโ€‹

Ammunition
GetAmmoBag: integerGets this Weapon's Ammo Bag
GetAmmoClip: integerGets this Weapon's Ammo Clip
GetAmmoToReload: integerGets the amount of ammo needed to fully reload
GetClipCapacity: integerGets the max number of bullets the clip can hold
Reload: booleanForces this Weapon to reload
SetAmmoBagSets this Weapon's Ammo in the Bag
SetAmmoClipSets this Weapon's Ammo in the Clip
SetAmmoSettingsSets the ammo counts and the clip capacity at once
SetAutoReloadSets if the Character will reload automatically when the clip is empty
SetClipCapacitySets the max number of bullets the Weapon's clip can hold
Animation
GetAnimationCharacterFire: Animation ReferenceGets the Animation played by the Character when firing
GetAnimationFire: Animation ReferenceGets the Animation played by the Weapon when firing
GetAnimationReload: Animation ReferenceGets the reload animation
PlayAnimationPlays an Animation on this Weapon
SetAnimationCharacterFireSets the Animation played by the Character when firing this Weapon
SetAnimationFireSets the Animation played by the Weapon itself when firing
SetAnimationReloadSets the Animation played by the Character when reloading this Weapon
StopAnimationStops an Animation Montage on this Weapon
Audio
GetSoundAim: Sound ReferenceGets the Sound played when aiming
GetSoundDry: Sound ReferenceGets the Sound played when firing with an empty clip
GetSoundFire: Sound ReferenceGets the Sound played when firing
GetSoundLoad: Sound ReferenceGets the Sound played when loading a magazine
GetSoundUnload: Sound ReferenceGets the Sound played when unloading a magazine
GetSoundZooming: Sound ReferenceGets the Sound played when zooming
SetSoundAimSets the Sound played when starting to aim
SetSoundDrySets the Sound played when trying to fire with an empty clip
SetSoundFireSets the Sound played when firing
SetSoundFireLastBulletsSound when firing with only having X remaining bullets in the magazine
SetSoundLoadSets the Sound played when loading a magazine
SetSoundUnloadSets the Sound played when unloading a magazine
SetSoundZoomingSets the Sound played when zooming
Combat
GetBulletCount: integerGets how many bullets are fired per shot
GetCadence: floatGets the time between shots
GetCanHoldUse: booleanGets if the weapon can be used continuously by holding the use button
GetDamage: integerGets the base damage of this Weapon
GetHoldReleaseUse: booleanGets if the weapon is triggered/fired when releasing the use button
GetSpread: floatGets the base spread of this Weapon
GetWallbangDamageMultiplier: floatGets the damage multiplier applied when a bullet passes through a wall
GetWallbangMaxDistance: floatGets the max distance a bullet can pass through walls
SetBulletSettingsSets how many bullets are fired per shot and how they look and travel
SetCadenceSets the time between shots
SetDamageSet the Base Weapon's Damage
SetSpreadSets the base spread of this Weapon
SetUsageSettingsSets if the Weapon can hold to keep firing and if it needs to release to fire
SetWallbangSettingsSets how the bullet will pass through walls
Effects
GetBulletColor: ColorGets the color of the bullet trail
GetMagazineMesh: StaticMesh ReferenceGets the magazine Static Mesh used when reloading
GetParticlesBarrel: Particle ReferenceGets the Particle of the Fire Blast in the muzzle
GetParticlesBulletTrail: Particle ReferenceGets the Particle of the bullet trail
GetParticlesShells: Particle ReferenceGets the Particle of the ejected shells
SetBulletColorSet the Bullet Color
SetMagazineMeshSet the mesh used when the Character reloads the weapon
SetParticlesBarrelSets the Particle of the fire blast at the muzzle
SetParticlesBulletTrailSets the Particle of the bullet trail
SetParticlesShellsSets the Particle of the empty shells ejected when firing
Handling
GetLeftHandLocation: VectorGets the location offset of the left hand
GetLeftHandRotation: RotatorGets the rotation offset of the left hand
GetRecoil: floatGets the base recoil of this Weapon
GetRightHandOffset: VectorGets the offset of the right hand, relative to the camera
GetSightFOVMultiplier: floatGets the Field of View multiplier applied when aiming down sights
GetSightLocation: VectorGets the sight location offset used when aiming down sights
GetSightRotation: RotatorGets the sight rotation used when aiming down sights
SetHandlingModeSets how the Character grabs this Weapon
SetLeftHandTransformSets where the Character's left hand holds this Weapon, relative to the Weapon
SetRecoilSets the base recoil of this Weapon
SetRightHandOffsetSet the offset of Right Hand
SetSightFOVMultiplierSets the Field of View multiplier applied when aiming down sights
SetSightTransformSets the offset that aligns the Player's view with the Weapon's sight when aiming down sights

Inherited functions

Ammunitionfunctionsโ€‹

GetAmmoBagOptimalโ€‹

Gets this Weapon's Ammo Bag

local ammo_bag = my_weapon:GetAmmoBag()
Returns
TypeDescription
integerThis Weapon's Ammo Bag

See also SetAmmoBag.

GetAmmoClipOptimalโ€‹

Gets this Weapon's Ammo Clip

local ammo_clip = my_weapon:GetAmmoClip()
Returns
TypeDescription
integerThis Weapon's Ammo Clip

See also SetAmmoClip.

GetAmmoToReloadSlowโ€‹

Gets the amount of ammo needed to fully reload

local ammo_to_reload = my_weapon:GetAmmoToReload()
Returns
TypeDescription
integerAmount of ammo needed to fully reload

GetClipCapacityOptimalโ€‹

Gets the max number of bullets the clip can hold

local clip = my_weapon:GetClipCapacity()
Returns
TypeDescription
integerThe clip capacity

See also SetClipCapacity.

ReloadModerateโ€‹

Forces this Weapon to reload

It only works while a Character is handling the Weapon, the Ammo Bag is not empty and the Clip is not full. Returning true means the reload was requested, it can still be cancelled by the Character's AttemptReload event or interrupted. Use the Reload event to know how many bullets were actually reloaded

local reload_requested = my_weapon:Reload()
Returns
TypeDescription
booleanWhether the reload was requested

SetAmmoBagOptimalโ€‹

Sets this Weapon's Ammo in the Bag

my_weapon:SetAmmoBag(new_ammo_bag)
Parameters
NameTypeDescription
new_ammo_bagintegerThe new Ammo in the Bag

See also GetAmmoBag.

SetAmmoClipOptimalโ€‹

Sets this Weapon's Ammo in the Clip

my_weapon:SetAmmoClip(new_ammo_clip)
Parameters
NameTypeDescription
new_ammo_clipintegerThe new Ammo in the Clip

See also GetAmmoClip.

SetAmmoSettingsOptimalโ€‹

Sets the ammo counts and the clip capacity at once

my_weapon:SetAmmoSettings(ammo_clip, ammo_bag, ammo_to_reload?, clip_capacity?)
Parameters
NameTypeDescription
ammo_clipintegerBullets currently loaded in the clip
ammo_bagintegerSpare bullets carried, used when reloading
ammo_to_reload?integerBullets loaded on each reload, useful for shotguns that load one shell at a time. Defaults to the clip capacity Default ammo_clip
clip_capacity?integerMax bullets the clip can hold Default ammo_clip

SetAutoReloadOptimalโ€‹

Sets if the Character will reload automatically when the clip is empty

If the Character will reload automatically when ammo empties. Default is true

my_weapon:SetAutoReload(auto_reload)
Parameters
NameTypeDescription
auto_reloadbooleanWhether to reload automatically

SetClipCapacityOptimalโ€‹

Sets the max number of bullets the Weapon's clip can hold

my_weapon:SetClipCapacity(clip)
Parameters
NameTypeDescription
clipintegerThe new clip capacity

See also GetClipCapacity.

Animationfunctionsโ€‹

GetAnimationCharacterFireOptimalโ€‹

Gets the Animation played by the Character when firing

local animation_character_fire_path = my_weapon:GetAnimationCharacterFire()
Returns
TypeDescription
Animation ReferenceThe Animation asset

See also SetAnimationCharacterFire.

GetAnimationFireOptimalโ€‹

Gets the Animation played by the Weapon when firing

local animation_fire_path = my_weapon:GetAnimationFire()
Returns
TypeDescription
Animation ReferenceThe Animation asset

See also SetAnimationFire.

GetAnimationReloadOptimalโ€‹

Gets the reload animation

local reload_animation_path = my_weapon:GetAnimationReload()
Returns
TypeDescription
Animation ReferenceReload animation

See also SetAnimationReload.

PlayAnimationSlowโ€‹

Plays an Animation on this Weapon

my_weapon:PlayAnimation(animation_path, slot_name?, loop_indefinitely?, blend_in_time?, blend_out_time?, play_rate?, stop_all_montages?)
Parameters
NameTypeDescription
animation_pathAnimation ReferenceThe Animation asset to play
slot_name?stringThe Animation Slot to play it on Default DefaultSlot
loop_indefinitely?booleanThis parameter is only used if the Weapon has an Animation Blueprint Default false
blend_in_time?floatThis parameter is only used if the Weapon has an Animation Blueprint Default 0.25
blend_out_time?floatThis parameter is only used if the Weapon has an Animation Blueprint Default 0.25
play_rate?floatThis parameter is only used if the Weapon has an Animation Blueprint Default 1.0
stop_all_montages?booleanStops all running Montages from the same Group. This parameter is only used if the Weapon has an Animation Blueprint Default false

SetAnimationCharacterFireSlowโ€‹

Sets the Animation played by the Character when firing this Weapon

my_weapon:SetAnimationCharacterFire(animation_character_fire_path, play_rate?)
Parameters
NameTypeDescription
animation_character_fire_pathAnimation ReferenceThe Animation asset to play on the Character
play_rate?floatSpeed multiplier of the animation Default 1

See also GetAnimationCharacterFire.

SetAnimationFireSlowโ€‹

Sets the Animation played by the Weapon itself when firing

my_weapon:SetAnimationFire(animation_fire_path, play_rate?)
Parameters
NameTypeDescription
animation_fire_pathAnimation ReferenceThe Animation asset to play on the Weapon mesh
play_rate?floatSpeed multiplier of the animation Default 1

See also GetAnimationFire.

SetAnimationReloadSlowโ€‹

Sets the Animation played by the Character when reloading this Weapon

my_weapon:SetAnimationReload(reload_animation_path, play_rate?)
Parameters
NameTypeDescription
reload_animation_pathAnimation ReferenceThe Animation asset to play on the Character
play_rate?floatSpeed multiplier of the animation Default 1

See also GetAnimationReload.

StopAnimationOptimalโ€‹

Stops an Animation Montage on this Weapon

my_weapon:StopAnimation(animation_asset?)
Parameters
NameTypeDescription
animation_asset?Animation ReferenceLeave empty to stop all Montages Default

Audiofunctionsโ€‹

GetSoundAimOptimalโ€‹

Gets the Sound played when aiming

local sound_aim_asset_path = my_weapon:GetSoundAim()
Returns
TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundAim.

GetSoundDryOptimalโ€‹

Gets the Sound played when firing with an empty clip

local sound_dry_asset_path = my_weapon:GetSoundDry()
Returns
TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundDry.

GetSoundFireOptimalโ€‹

Gets the Sound played when firing

local sound_fire_asset_path = my_weapon:GetSoundFire()
Returns
TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundFire.

GetSoundLoadSlowโ€‹

Gets the Sound played when loading a magazine

local sound_load_asset_path = my_weapon:GetSoundLoad()
Returns
TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundLoad.

GetSoundUnloadSlowโ€‹

Gets the Sound played when unloading a magazine

local sound_unload_asset_path = my_weapon:GetSoundUnload()
Returns
TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundUnload.

GetSoundZoomingOptimalโ€‹

Gets the Sound played when zooming

local sound_zooming_asset_path = my_weapon:GetSoundZooming()
Returns
TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundZooming.

SetSoundAimSlowโ€‹

Sets the Sound played when starting to aim

my_weapon:SetSoundAim(sound_aim_asset_path?, volume?, pitch?)
Parameters
NameTypeDescription
sound_aim_asset_path?Sound ReferenceThe Sound asset to play, pass nil or an empty string for no sound Default nil
volume?floatVolume multiplier Default 1
pitch?floatPitch multiplier Default 1

See also GetSoundAim.

SetSoundDrySlowโ€‹

Sets the Sound played when trying to fire with an empty clip

my_weapon:SetSoundDry(sound_dry_asset_path?, volume?, pitch?)
Parameters
NameTypeDescription
sound_dry_asset_path?Sound ReferenceThe Sound asset to play, pass nil or an empty string for no sound Default nil
volume?floatVolume multiplier Default 1
pitch?floatPitch multiplier Default 1

See also GetSoundDry.

SetSoundFireSlowโ€‹

Sets the Sound played when firing

my_weapon:SetSoundFire(sound_fire_asset_path?, volume?, pitch?)
Parameters
NameTypeDescription
sound_fire_asset_path?Sound ReferenceThe Sound asset to play, pass nil or an empty string for no sound Default nil
volume?floatVolume multiplier Default 1
pitch?floatPitch multiplier Default 1

See also GetSoundFire.

SetSoundFireLastBulletsSlowโ€‹

Sound when firing with only having X remaining bullets in the magazine

Useful for a last shot 'ping' or a sound when low on bullets

my_weapon:SetSoundFireLastBullets(sound_asset_path?, remaining_bullets_count?)
Parameters
NameTypeDescription
sound_asset_path?Sound ReferenceThe Sound asset to play, pass nil or an empty string for no sound Default nil
remaining_bullets_count?integerThe amount of remaining bullet to start playing this sound Default 1

SetSoundLoadSlowโ€‹

Sets the Sound played when loading a magazine

my_weapon:SetSoundLoad(sound_load_asset_path?, volume?, pitch?)
Parameters
NameTypeDescription
sound_load_asset_path?Sound ReferenceThe Sound asset to play, pass nil or an empty string for no sound Default nil
volume?floatVolume multiplier Default 1
pitch?floatPitch multiplier Default 1

See also GetSoundLoad.

SetSoundUnloadSlowโ€‹

Sets the Sound played when unloading a magazine

my_weapon:SetSoundUnload(sound_unload_asset_path?, volume?, pitch?)
Parameters
NameTypeDescription
sound_unload_asset_path?Sound ReferenceThe Sound asset to play, pass nil or an empty string for no sound Default nil
volume?floatVolume multiplier Default 1
pitch?floatPitch multiplier Default 1

See also GetSoundUnload.

SetSoundZoomingSlowโ€‹

Sets the Sound played when zooming

my_weapon:SetSoundZooming(sound_zooming_asset_path?, volume?, pitch?)
Parameters
NameTypeDescription
sound_zooming_asset_path?Sound ReferenceThe Sound asset to play, pass nil or an empty string for no sound Default nil
volume?floatVolume multiplier Default 1
pitch?floatPitch multiplier Default 1

See also GetSoundZooming.

Combatfunctionsโ€‹

GetBulletCountOptimalโ€‹

Gets how many bullets are fired per shot

local bullet_count = my_weapon:GetBulletCount()
Returns
TypeDescription
integerBullets per shot

GetCadenceOptimalโ€‹

Gets the time between shots

local cadence = my_weapon:GetCadence()
Returns
TypeDescription
floatSeconds between shots

See also SetCadence.

GetCanHoldUseOptimalโ€‹

Gets if the weapon can be used continuously by holding the use button

local can_hold_use = my_weapon:GetCanHoldUse()
Returns
TypeDescription
booleanWhether the weapon can be used continuously by holding the use button

GetDamageOptimalโ€‹

Gets the base damage of this Weapon

local damage = my_weapon:GetDamage()
Returns
TypeDescription
integerThe base damage

See also SetDamage.

GetHoldReleaseUseOptimalโ€‹

Gets if the weapon is triggered/fired when releasing the use button

local hold_release_use = my_weapon:GetHoldReleaseUse()
Returns
TypeDescription
booleanWhether the weapon is triggered/fired when releasing the use button

GetSpreadOptimalโ€‹

Gets the base spread of this Weapon

local spread = my_weapon:GetSpread()
Returns
TypeDescription
floatThe base spread, higher means less precision

See also SetSpread.

GetWallbangDamageMultiplierOptimalโ€‹

Gets the damage multiplier applied when a bullet passes through a wall

local damage_multiplier = my_weapon:GetWallbangDamageMultiplier()
Returns
TypeDescription
floatDamage multiplier applied when a bullet passes through a wall

GetWallbangMaxDistanceOptimalโ€‹

Gets the max distance a bullet can pass through walls

local max_distance = my_weapon:GetWallbangMaxDistance()
Returns
TypeDescription
floatMax distance a bullet can pass through walls

SetBulletSettingsOptimalโ€‹

Sets how many bullets are fired per shot and how they look and travel

my_weapon:SetBulletSettings(bullet_count, bullet_max_distance, bullet_velocity, bullet_color)
Parameters
NameTypeDescription
bullet_countinteger1 for common weapons
> 1 for shotguns
bullet_max_distanceintegerMax distance the bullet travels (in units, 1 unit = 1 cm)
bullet_velocityintegerVisuals only
bullet_colorColorColor of the bullet trail

SetCadenceOptimalโ€‹

Sets the time between shots

my_weapon:SetCadence(cadence)
Parameters
NameTypeDescription
cadencefloat1 shot at each cadence second

See also GetCadence.

SetDamageOptimalโ€‹

Set the Base Weapon's Damage

Base Weapon's Damage

This will be multiplied by multiplier factors when hitting specific bones

my_weapon:SetDamage(damage)
Parameters
NameTypeDescription
damageintegerThe new Base Weapon's Damage

See also GetDamage.

SetSpreadOptimalโ€‹

Sets the base spread of this Weapon

my_weapon:SetSpread(spread)
Parameters
NameTypeDescription
spreadfloatthe higher the less precision - recommended value: 20

See also GetSpread.

SetUsageSettingsOptimalโ€‹

Sets if the Weapon can hold to keep firing and if it needs to release to fire

my_weapon:SetUsageSettings(can_hold_use, hold_release_use)
Parameters
NameTypeDescription
can_hold_usebooleanWhether holding the fire button keeps firing (automatic weapons)
hold_release_usebooleanWhether it only fires when the fire button is released (e.g. bows)

SetWallbangSettingsOptimalโ€‹

Sets how the bullet will pass through walls

my_weapon:SetWallbangSettings(max_distance, damage_multiplier)
Parameters
NameTypeDescription
max_distanceintegerMax distance to pass through another wall
damage_multiplierfloatDamage given if wallbangged

Effectsfunctionsโ€‹

GetBulletColorOptimalโ€‹

Gets the color of the bullet trail

local bullet_color = my_weapon:GetBulletColor()
Returns
TypeDescription
ColorThe bullet trail color

See also SetBulletColor.

GetMagazineMeshOptimalโ€‹

Gets the magazine Static Mesh used when reloading

local magazine_mesh = my_weapon:GetMagazineMesh()
Returns
TypeDescription
StaticMesh ReferenceThe Static Mesh asset

See also SetMagazineMesh.

GetParticlesBarrelOptimalโ€‹

Gets the Particle of the Fire Blast in the muzzle

local particle_asset_path = my_weapon:GetParticlesBarrel()
Returns
TypeDescription
Particle ReferenceParticle of the Fire Blast in the muzzle

See also SetParticlesBarrel.

GetParticlesBulletTrailOptimalโ€‹

Gets the Particle of the bullet trail

local particle_bullet_trail_asset_path = my_weapon:GetParticlesBulletTrail()
Returns
TypeDescription
Particle ReferenceThe Particle asset

See also SetParticlesBulletTrail.

GetParticlesShellsOptimalโ€‹

Gets the Particle of the ejected shells

local particle_shells_asset_path = my_weapon:GetParticlesShells()
Returns
TypeDescription
Particle ReferenceThe Particle asset

See also SetParticlesShells.

SetBulletColorOptimalโ€‹

Set the Bullet Color

Only has effect if using Bullet Trail particle P_Bullet_Trail or if you particle has the Color parameter

my_weapon:SetBulletColor(bullet_color)
Parameters
NameTypeDescription
bullet_colorColorThe new Bullet Color

See also GetBulletColor.

SetMagazineMeshSlowโ€‹

Set the mesh used when the Character reloads the weapon

Will drop this Mesh as an animation effect

my_weapon:SetMagazineMesh(magazine_mesh, magazine_mesh_hide_bone?)
Parameters
NameTypeDescription
magazine_meshStaticMesh ReferenceThe Static Mesh of the magazine, spawned in the Character's hand during the reload
magazine_mesh_hide_bone?stringWeapon bone to hide when reloading it Default b_gun_mag

See also GetMagazineMesh.

SetParticlesBarrelSlowโ€‹

Sets the Particle of the fire blast at the muzzle

my_weapon:SetParticlesBarrel(particle_asset_path?)
Parameters
NameTypeDescription
particle_asset_path?Particle ReferenceThe Particle asset to spawn at the muzzle when firing, pass nil or an empty string for no particle Default nil

See also GetParticlesBarrel.

SetParticlesBulletTrailSlowโ€‹

Sets the Particle of the bullet trail

my_weapon:SetParticlesBulletTrail(particle_bullet_trail_asset_path?)
Parameters
NameTypeDescription
particle_bullet_trail_asset_path?Particle ReferenceThe Particle asset to spawn for each bullet, pass nil or an empty string for no particle Default nil

See also GetParticlesBulletTrail.

SetParticlesShellsSlowโ€‹

Sets the Particle of the empty shells ejected when firing

my_weapon:SetParticlesShells(particle_shells_asset_path?)
Parameters
NameTypeDescription
particle_shells_asset_path?Particle ReferenceThe Particle asset to spawn when ejecting a shell, pass nil or an empty string for no particle Default nil

See also GetParticlesShells.

Handlingfunctionsโ€‹

GetLeftHandLocationOptimalโ€‹

Gets the location offset of the left hand

local left_hand_location = my_weapon:GetLeftHandLocation()
Returns
TypeDescription
VectorThe left hand location offset

GetLeftHandRotationOptimalโ€‹

Gets the rotation offset of the left hand

local left_hand_rotation = my_weapon:GetLeftHandRotation()
Returns
TypeDescription
RotatorThe left hand rotation offset

GetRecoilOptimalโ€‹

Gets the base recoil of this Weapon

local recoil = my_weapon:GetRecoil()
Returns
TypeDescription
floatThe base recoil, 0 means no recoil

See also SetRecoil.

GetRightHandOffsetOptimalโ€‹

Gets the offset of the right hand, relative to the camera

local right_hand_offset = my_weapon:GetRightHandOffset()
Returns
TypeDescription
VectorThe right hand offset

See also SetRightHandOffset.

GetSightFOVMultiplierOptimalโ€‹

Gets the Field of View multiplier applied when aiming down sights

local sight_fov_multiplier = my_weapon:GetSightFOVMultiplier()
Returns
TypeDescription
floatThe FOV multiplier

See also SetSightFOVMultiplier.

GetSightLocationOptimalโ€‹

Gets the sight location offset used when aiming down sights

local sight_location = my_weapon:GetSightLocation()
Returns
TypeDescription
VectorThe sight location offset

GetSightRotationOptimalโ€‹

Gets the sight rotation used when aiming down sights

local sight_rotation = my_weapon:GetSightRotation()
Returns
TypeDescription
RotatorThe sight rotation

SetHandlingModeOptimalโ€‹

Sets how the Character grabs this Weapon

my_weapon:SetHandlingMode(handling_mode)
Parameters
NameTypeDescription
handling_modeHandlingModeThe new how the Character grabs this Weapon

SetLeftHandTransformOptimalโ€‹

Sets where the Character's left hand holds this Weapon, relative to the Weapon

my_weapon:SetLeftHandTransform(left_hand_location, left_hand_rotation)
Parameters
NameTypeDescription
left_hand_locationVectorLocation offset of the left hand
left_hand_rotationRotatorRotation offset of the left hand

SetRecoilOptimalโ€‹

Sets the base recoil of this Weapon

my_weapon:SetRecoil(recoil)
Parameters
NameTypeDescription
recoilfloat0 means no Recoil, default is 1

See also GetRecoil.

SetRightHandOffsetOptimalโ€‹

Set the offset of Right Hand

Set the Offset of Right Hand. To position relative to the camera

my_weapon:SetRightHandOffset(right_hand_offset)
Parameters
NameTypeDescription
right_hand_offsetVectorThe new offset of Right Hand

See also GetRightHandOffset.

SetSightFOVMultiplierOptimalโ€‹

Sets the Field of View multiplier applied when aiming down sights

my_weapon:SetSightFOVMultiplier(sight_fov_multiplier)
Parameters
NameTypeDescription
sight_fov_multiplierfloatValues below 1 zoom in, for example 0.5 for a scope

See also GetSightFOVMultiplier.

SetSightTransformOptimalโ€‹

Sets the offset that aligns the Player's view with the Weapon's sight when aiming down sights

my_weapon:SetSightTransform(sight_location, sight_rotation)
Parameters
NameTypeDescription
sight_locationVectorOffset between the camera and the sight
sight_rotationRotatorRotation applied to the Weapon while aiming

๐Ÿš€ Eventsโ€‹

AmmoBagChangeWhen the Ammo Bag is changed, by reloading or manually setting through scripting
AmmoClipChangeWhen the Ammo Clip is changed, by reloading or manually setting through scripting
BulletHitTriggered when bullets hit (this will be triggered for each bullet shot)
FireTriggered when Weapon fires (this will be triggered for each shot)
ReloadWhen a Weapon is reloaded, optionally by a Character

AmmoBagChangeโ€‹

When the Ammo Bag is changed, by reloading or manually setting through scripting

Weapon.Subscribe("AmmoBagChange", function(self, old_ammo_bag, new_ammo_bag)
-- AmmoBagChange was called
end)
Arguments
NameTypeDescription
selfWeaponThe Weapon that triggered the event
old_ammo_bagintegerThe previous bag ammo
new_ammo_bagintegerThe new bag ammo

AmmoClipChangeโ€‹

When the Ammo Clip is changed, by reloading or manually setting through scripting

Weapon.Subscribe("AmmoClipChange", function(self, old_ammo_clip, new_ammo_clip)
-- AmmoClipChange was called
end)
Arguments
NameTypeDescription
selfWeaponThe Weapon that triggered the event
old_ammo_clipintegerThe previous clip ammo
new_ammo_clipintegerThe new clip ammo

BulletHitโ€‹

Triggered when bullets hit (this will be triggered for each bullet shot)

Weapon.Subscribe("BulletHit", function(self, impact_point, impact_normal, damage, actor_hit)
-- BulletHit was called
end)
Arguments
NameTypeDescription
selfWeaponThe Weapon that triggered the event
impact_pointVectorLocation in world space of the bullet hit
impact_normalVectorNormal of the bullet hit in world space
damageintegerDamage that was applied
actor_hitBase Actor or nilActor entity that was hit, if any

Fireโ€‹

Triggered when Weapon fires (this will be triggered for each shot)

Weapon.Subscribe("Fire", function(self, shooter)
-- Fire was called
end)
Arguments
NameTypeDescription
selfWeaponThe Weapon that triggered the event
shooterCharacterThe Character holding the Weapon, if any

Reloadโ€‹

When a Weapon is reloaded, optionally by a Character

Weapon.Subscribe("Reload", function(self, character, ammo_to_reload)
-- Reload was called
end)
Arguments
NameTypeDescription
selfWeaponThe Weapon that triggered the event
characterCharacterThe Character
ammo_to_reloadintegerHow many bullets were reloaded