Skip to main content
Version: latest - a1.156.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

TypeNameDefaultDescription
Vectorlocation Required parameter World location to spawn at
Rotatorrotation Required parameter World rotation to spawn with
SkeletalMesh Referenceasset Required parameter The asset to use
CollisionTypecollision_typeCollisionType.AutoCollision profile of this Actor
booleangravity_enabledtrueWhether gravity affects this Actor
SpawnModespawn_modeSpawnMode.ImmediatePass 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

๐Ÿ—ฟย Static Functionsโ€‹

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 EntityGetAllReturns a table containing all Entities of the class this is called on
Base EntityGetByIndexReturns a specific Entity of this class at an index
integerGetCountReturns how many Entities of this class exist
table of tableGetInheritedClassesGets a list of all directly inherited classes from this Class created with the Inheriting System
iteratorGetPairsReturns an iterator with all Entities of this class to be used with pairs()
table or nilGetParentClassGets the parent class if this Class was created with the Inheriting System
tableInheritInherits this class with the Inheriting System
booleanIsChildOfGets if this Class is child of another class if this Class was created with the Inheriting System
functionSubscribeSubscribes to an Event for all entities of this Class
functionSubscribeRemoteSubscribes to a custom event called from server
UnsubscribeUnsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed

This class doesn't have own static functions.

๐Ÿฆ ย Functionsโ€‹

Inherited Entity Functions
Weapon inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
BroadcastRemoteEventCalls a custom remote event directly on this entity to all Players
BroadcastRemoteInRadiusEventCalls a custom remote event directly on this entity to all Players in a radius
CallRemoteEventCalls a custom remote event directly on this entity to a specific Player
CallRemoteEventCalls a custom remote event directly on this entity
CallRemotePlayersEventCalls a custom remote event directly on this entity to a list of Players
DestroyDestroys this Entity
FinishSpawnFinish the spawning process and send the entity to clients if it was spawned with a deferred spawn_mode
table of stringGetAllValuesKeysGets a list of all values keys
tableGetClassGets the class of this entity
integerGetIDGets the universal network ID of this Entity (same on both client and server)
anyGetValueGets a Value stored on this Entity at the given key
booleanHasAuthorityGets if the local context has authority over this Entity (true if spawned by the client, false if spawned by the server)
booleanIsARecursively checks if this entity is inherited from a Class
booleanIsBeingDestroyedReturns true if this Entity is being destroyed
booleanIsSpawnedGets if this Entity finished spawning
booleanIsValidReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
SetSpawnModeOverrides when this Entity finishes spawning, from the Constructor of an Inherited Class
SetValueSets a Value in this Entity
functionSubscribeSubscribes to an Event on this specific entity
functionSubscribeRemoteSubscribes to a custom event called from server on this specific entity
UnsubscribeUnsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed
Inherited Actor Functions
Weapon inherits from Base Actor Class, sharing it's methods and functions:
Base Actorscripting-reference/classes/base-classes/actor
ReturnsNameDescription
AddActorTagAdds an Unreal Actor Tag to this Actor
AddAngularImpulseAdd an angular impulse to this Actor. Good for one time instant burst
AddImpulseAdd an impulse to this Actor. Good for one time instant burst
booleanAttachToAttaches this Actor to any other Actor, optionally at a specific bone
DetachDetaches this Actor from AttachedTo Actor
table of stringGetActorTagsGets all Unreal Actor Tags on this Actor
VectorGetAngularForceGets this Actor's angular force (set by SetAngularForce())
floatGetAngularVelocityReturns the angular velocity of this Actor
table of Base ActorGetAttachedEntitiesGets all Actors attached to this Actor
Base Actor or nilGetAttachedToGets the Actor this Actor is attached to
stringGetAttachedToSocketGets the bone or socket name this Actor is attached to
tableGetBoundsGets this Actor's bounds, useful to know its size in the world
CollisionTypeGetCollisionGets this Actor's collision type
integerGetDimensionGets this Actor's dimension
floatGetDistanceFromCameraGets the distance of this Actor from the Camera
VectorGetForceGets this Actor's force (set by SetForce())
floatGetLifeSpanGets the time (in seconds) left before this Actor is destroyed
VectorGetLocationGets this Actor's location in the game world
floatGetMassReturns the mass of this Actor
Player or nilGetNetworkAuthorityGets this Actor's Network Authority Player
VectorGetRelativeLocationGets this Actor's Relative Location if it's attached
RotatorGetRelativeRotationGets this Actor's Relative Rotation if it's attached
RotatorGetRotationGets this Actor's angle in the game world
VectorGetScaleGets this Actor's scale
floatGetScreenPercentageGets the percentage of this Actor size in the screen
tableGetSocketTransformGets a Socket Transform in world space given a bone or socket name
VectorGetVelocityGets this Actor's current velocity
booleanHasNetworkAuthorityReturns true if the local Player is currently the Network Authority of this Actor
booleanIsGravityEnabledReturns true if gravity is enabled on this Actor
booleanIsInWaterReturns true if this Actor is in water
booleanIsNetworkDistributedReturns true if this Actor is currently network distributed
booleanIsVisibleReturns true if this Actor is visible
RemoveActorTagRemoves an Unreal Actor Tag from this Actor
RotateToSmoothly rotates this actor to an angle over a certain time
SetAngularForceAdds a permanent angular force to this Actor, set to Vector(0, 0, 0) to cancel
SetCastShadowSets this Actor's to cast shadows or not
SetCollisionSets this Actor's collision type
SetDimensionSets this Actor's Dimension. Actors only see and interact with entities in the same Dimension
SetDistanceOptimizationMultiplierSets this Actor's distance optimization multiplier
SetForceAdds a permanent force to this Actor, set to Vector(0, 0, 0) to cancel
SetGravityEnabledSets whether gravity is enabled on this Actor
SetHighlightEnabledSets whether the highlight is enabled on this Actor, and which highlight index to use
SetLifeSpanSets the time (in seconds) before this Actor is destroyed. After this time has passed, the actor will be automatically destroyed.
SetLocationSets this Actor's location in the game world
SetNetworkAuthoritySets the Player to have network authority over this Actor
SetNetworkAuthorityAutoDistributedSets if this Actor will auto distribute the network authority between players
SetOutlineEnabledSets whether the outline is enabled on this Actor, and which outline index to use
SetRelativeLocationSets this Actor's relative location in local space (only if this actor is attached)
SetRelativeRotationSets this Actor's relative rotation in local space (only if this actor is attached)
SetRenderCullDistanceSets this Actor's render cull distance
SetRotationSets this Actor's rotation in the game world
SetScaleSets this Actor's scale
SetVisibilitySets whether the actor is visible or not
TranslateToSmoothly moves this actor to a location over a certain time
booleanWasRecentlyRenderedGets if this Actor was recently rendered on screen
Inherited Paintable Functions
Weapon inherits from Base Paintable Class, sharing it's methods and functions:
Base Paintablescripting-reference/classes/base-classes/paintable
ReturnsNameDescription
ColorGetMaterialColorParameterGets a Color parameter from this Actor's material
floatGetMaterialScalarParameterGets a Scalar parameter from this Actor's material
stringGetMaterialTextureParameterGets a Texture parameter from this Actor's material
VectorGetMaterialVectorParameterGets a Vector parameter from this Actor's material
ResetMaterialResets the material from the specified index to the original one
SetMaterialSets the material at the specified index of this Actor
SetMaterialColorParameterSets a Color parameter in this Actor's material
SetMaterialFromCanvasSets the material at the specified index of this Actor to a Canvas object
SetMaterialFromSceneCaptureSets the material at the specified index of this Actor to a SceneCapture object
SetMaterialFromWebUISets the material at the specified index of this Actor to a WebUI object
SetMaterialScalarParameterSets a Scalar parameter in this Actor's material
SetMaterialTextureParameterSets a texture parameter in this Actor's material to an image
SetMaterialVectorParameterSets a Vector parameter in this Actor's material
SetPhysicalMaterialOverrides this Actor's Physical Material with a new one
Inherited Pickable Functions
Weapon inherits from Base Pickable Class, sharing it's methods and functions:
Base Pickablescripting-reference/classes/base-classes/pickable
ReturnsNameDescription
AddSkeletalMeshAttachedAttaches a Skeletal Mesh as master pose to this entity
AddStaticMeshAttachedAttaches a Static Mesh to this entity
table of stringGetAllSkeletalMeshAttachedGets all Skeletal Meshes attached to this entity
table of stringGetAllStaticMeshAttachedGets all Static Meshes attached to this entity
Character or nilGetHandlerGets the Character, if it exists, that's holding this Pickable
HandlingModeGetHandlingModeGets the Handling Mode of this Pickable
SkeletalMesh ReferenceGetMeshGets the name of the asset this Pickable uses
PullUsePulls the usage of this Pickable (will start firing if this is a weapon)
ReleaseUseReleases the usage of this Pickable (will stop firing if this is a weapon)
RemoveAllSkeletalMeshesAttachedRemoves all SkeletalMeshes attached
RemoveAllStaticMeshesAttachedRemoves all StaticMeshes attached
RemoveSkeletalMeshAttachedRemoves, if it exists, a SkeletalMesh from this Pickable given its custom ID
RemoveStaticMeshAttachedRemoves, if it exists, a StaticMesh from this Pickable given its custom ID
SetAttachmentSettingsSets the Attachment Settings for this Pickable (how it attaches to the Character when Picking up)
SetBuoyancyPontoonsSets the Buoyancy Pontoons used by the Water simulation
SetBuoyancySettingsSets how this entity behaves on Water
SetCanUseSets if this Pickable can be used by the player when held
SetCrosshairMaterialSets the crosshair material for this Pickable
SetPickableSets if this Pickable can be picked up from ground by the player
SetStaticMeshAttachedTransformSets a Static Mesh Attached location and rotation
ReturnsNameDescription
integerGetAmmoBagGets this Weapon's Ammo Bag
integerGetAmmoClipGets this Weapon's Ammo Clip
integerGetAmmoToReloadGets the amount of ammo needed to fully reload
Animation ReferenceGetAnimationCharacterFireGets the Animation played by the Character when firing
Animation ReferenceGetAnimationFireGets the Animation played by the Weapon when firing
Animation ReferenceGetAnimationReloadGets the reload animation
ColorGetBulletColorGets the color of the bullet trail
integerGetBulletCountGets how many bullets are fired per shot
floatGetCadenceGets the time between shots
booleanGetCanHoldUseGets if the weapon can be used continuously by holding the use button
integerGetClipCapacityGets the max number of bullets the clip can hold
integerGetDamageGets the base damage of this Weapon
booleanGetHoldReleaseUseGets if the weapon is triggered/fired when releasing the use button
VectorGetLeftHandLocationGets the location offset of the left hand
RotatorGetLeftHandRotationGets the rotation offset of the left hand
StaticMesh ReferenceGetMagazineMeshGets the magazine Static Mesh used when reloading
Particle ReferenceGetParticlesBarrelGets the Particle of the Fire Blast in the muzzle
Particle ReferenceGetParticlesBulletTrailGets the Particle of the bullet trail
Particle ReferenceGetParticlesShellsGets the Particle of the ejected shells
floatGetRecoilGets the base recoil of this Weapon
VectorGetRightHandOffsetGets the offset of the right hand, relative to the camera
floatGetSightFOVMultiplierGets the Field of View multiplier applied when aiming down sights
VectorGetSightLocationGets the sight location offset used when aiming down sights
RotatorGetSightRotationGets the sight rotation used when aiming down sights
Sound ReferenceGetSoundAimGets the Sound played when aiming
Sound ReferenceGetSoundDryGets the Sound played when firing with an empty clip
Sound ReferenceGetSoundFireGets the Sound played when firing
Sound ReferenceGetSoundLoadGets the Sound played when loading a magazine
Sound ReferenceGetSoundUnloadGets the Sound played when unloading a magazine
Sound ReferenceGetSoundZoomingGets the Sound played when zooming
floatGetSpreadGets the base spread of this Weapon
floatGetWallbangDamageMultiplierGets the damage multiplier applied when a bullet passes through a wall
floatGetWallbangMaxDistanceGets the max distance a bullet can pass through walls
PlayAnimationPlays an Animation on this Weapon
ReloadForces 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
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
SetAutoReloadSets if the Character will reload automatically when the clip is empty
SetBulletColorSet the Bullet Color
SetBulletSettingsSets how many bullets are fired per shot and how they look and travel
SetCadenceSets the time between shots
SetClipCapacitySets the max number of bullets the Weapon's clip can hold
SetDamageSet the Base Weapon's Damage
SetHandlingModeSets how the Character grabs this Weapon
SetLeftHandTransformSets where the Character's left hand holds this Weapon, relative to the Weapon
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
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
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
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
StopAnimationStops an Animation Montage on this Weapon

Optimal

GetAmmoBagโ€‹

Gets this Weapon's Ammo Bag
local ammo_bag = my_weapon:GetAmmoBag()

Returns

TypeDescription
integerThis Weapon's Ammo Bag

See also SetAmmoBag.


Optimal

GetAmmoClipโ€‹

Gets this Weapon's Ammo Clip
local ammo_clip = my_weapon:GetAmmoClip()

Returns

TypeDescription
integerThis Weapon's Ammo Clip

See also SetAmmoClip.


Slow

GetAmmoToReloadโ€‹

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

Optimal

GetAnimationCharacterFireโ€‹

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.


Optimal

GetAnimationFireโ€‹

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.


Optimal

GetAnimationReloadโ€‹

Gets the reload animation
local reload_animation_path = my_weapon:GetAnimationReload()

Returns

TypeDescription
Animation ReferenceReload animation

See also SetAnimationReload.


Optimal

GetBulletColorโ€‹

Gets the color of the bullet trail
local bullet_color = my_weapon:GetBulletColor()

Returns

TypeDescription
ColorThe bullet trail color

See also SetBulletColor.


Optimal

GetBulletCountโ€‹

Gets how many bullets are fired per shot
local bullet_count = my_weapon:GetBulletCount()

Returns

TypeDescription
integerBullets per shot

Optimal

GetCadenceโ€‹

Gets the time between shots
local cadence = my_weapon:GetCadence()

Returns

TypeDescription
floatSeconds between shots

See also SetCadence.


Optimal

GetCanHoldUseโ€‹

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

Optimal

GetClipCapacityโ€‹

Gets the max number of bullets the clip can hold
local clip = my_weapon:GetClipCapacity()

Returns

TypeDescription
integerThe clip capacity

See also SetClipCapacity.


Optimal

GetDamageโ€‹

Gets the base damage of this Weapon
local damage = my_weapon:GetDamage()

Returns

TypeDescription
integerThe base damage

See also SetDamage.


Optimal

GetHoldReleaseUseโ€‹

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

Optimal

GetLeftHandLocationโ€‹

Gets the location offset of the left hand
local left_hand_location = my_weapon:GetLeftHandLocation()

Returns

TypeDescription
VectorThe left hand location offset

Optimal

GetLeftHandRotationโ€‹

Gets the rotation offset of the left hand
local left_hand_rotation = my_weapon:GetLeftHandRotation()

Returns

TypeDescription
RotatorThe left hand rotation offset

Optimal

GetMagazineMeshโ€‹

Gets the magazine Static Mesh used when reloading
local magazine_mesh = my_weapon:GetMagazineMesh()

Returns

TypeDescription
StaticMesh ReferenceThe Static Mesh asset

See also SetMagazineMesh.


Optimal

GetParticlesBarrelโ€‹

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.


Optimal

GetParticlesBulletTrailโ€‹

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.


Optimal

GetParticlesShellsโ€‹

Gets the Particle of the ejected shells
local particle_shells_asset_path = my_weapon:GetParticlesShells()

Returns

TypeDescription
Particle ReferenceThe Particle asset

See also SetParticlesShells.


Optimal

GetRecoilโ€‹

Gets the base recoil of this Weapon
local recoil = my_weapon:GetRecoil()

Returns

TypeDescription
floatThe base recoil, 0 means no recoil

See also SetRecoil.


Optimal

GetRightHandOffsetโ€‹

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.


Optimal

GetSightFOVMultiplierโ€‹

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.


Optimal

GetSightLocationโ€‹

Gets the sight location offset used when aiming down sights
local sight_location = my_weapon:GetSightLocation()

Returns

TypeDescription
VectorThe sight location offset

Optimal

GetSightRotationโ€‹

Gets the sight rotation used when aiming down sights
local sight_rotation = my_weapon:GetSightRotation()

Returns

TypeDescription
RotatorThe sight rotation

Optimal

GetSoundAimโ€‹

Gets the Sound played when aiming
local sound_aim_asset_path = my_weapon:GetSoundAim()

Returns

TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundAim.


Optimal

GetSoundDryโ€‹

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.


Optimal

GetSoundFireโ€‹

Gets the Sound played when firing
local sound_fire_asset_path = my_weapon:GetSoundFire()

Returns

TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundFire.


Slow

GetSoundLoadโ€‹

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.


Slow

GetSoundUnloadโ€‹

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.


Optimal

GetSoundZoomingโ€‹

Gets the Sound played when zooming
local sound_zooming_asset_path = my_weapon:GetSoundZooming()

Returns

TypeDescription
Sound ReferenceThe Sound asset

See also SetSoundZooming.


Optimal

GetSpreadโ€‹

Gets the base spread of this Weapon
local spread = my_weapon:GetSpread()

Returns

TypeDescription
floatThe base spread, higher means less precision

See also SetSpread.


Optimal

GetWallbangDamageMultiplierโ€‹

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

Optimal

GetWallbangMaxDistanceโ€‹

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

Slow

PlayAnimationโ€‹

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

TypeParameterDefaultDescription
Animation Referenceanimation_path Required parameter The Animation asset to play
stringslot_name?DefaultSlot
The Animation Slot to play it on
booleanloop_indefinitely?false
This parameter is only used if the Weapon has an Animation Blueprint
floatblend_in_time?0.25
This parameter is only used if the Weapon has an Animation Blueprint
floatblend_out_time?0.25
This parameter is only used if the Weapon has an Animation Blueprint
floatplay_rate?1.0
This parameter is only used if the Weapon has an Animation Blueprint
booleanstop_all_montages?false
Stops all running Montages from the same Group. This parameter is only used if the Weapon has an Animation Blueprint

Moderate

Reloadโ€‹

Forces this Weapon to reload (only if being handled by a Character)
my_weapon:Reload()

Optimal

SetAmmoBagโ€‹

Sets this Weapon's Ammo in the Bag
my_weapon:SetAmmoBag(new_ammo_bag)

Parameters

TypeParameterDefaultDescription
integernew_ammo_bag Required parameter The new Ammo in the Bag

See also GetAmmoBag.


Optimal

SetAmmoClipโ€‹

Sets this Weapon's Ammo in the Clip
my_weapon:SetAmmoClip(new_ammo_clip)

Parameters

TypeParameterDefaultDescription
integernew_ammo_clip Required parameter The new Ammo in the Clip

See also GetAmmoClip.


Optimal

SetAmmoSettingsโ€‹

Sets the ammo counts and the clip capacity at once
my_weapon:SetAmmoSettings(ammo_clip, ammo_bag, ammo_to_reload?, clip_capacity?)

Parameters

TypeParameterDefaultDescription
integerammo_clip Required parameter Bullets currently loaded in the clip
integerammo_bag Required parameter Spare bullets carried, used when reloading
integerammo_to_reload?ammo_clip
Bullets loaded on each reload, useful for shotguns that load one shell at a time. Defaults to the clip capacity
integerclip_capacity?ammo_clip
Max bullets the clip can hold

Slow

SetAnimationCharacterFireโ€‹

Sets the Animation played by the Character when firing this Weapon
my_weapon:SetAnimationCharacterFire(animation_character_fire_path, play_rate?)

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_character_fire_path Required parameter The Animation asset to play on the Character
floatplay_rate?1
Speed multiplier of the animation

See also GetAnimationCharacterFire.


Slow

SetAnimationFireโ€‹

Sets the Animation played by the Weapon itself when firing
my_weapon:SetAnimationFire(animation_fire_path, play_rate?)

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_fire_path Required parameter The Animation asset to play on the Weapon mesh
floatplay_rate?1
Speed multiplier of the animation

See also GetAnimationFire.


Slow

SetAnimationReloadโ€‹

Sets the Animation played by the Character when reloading this Weapon
my_weapon:SetAnimationReload(reload_animation_path, play_rate?)

Parameters

TypeParameterDefaultDescription
Animation Referencereload_animation_path Required parameter The Animation asset to play on the Character
floatplay_rate?1
Speed multiplier of the animation

See also GetAnimationReload.


Optimal

SetAutoReloadโ€‹

If the Character will reload automatically when ammo empties. Default is true
my_weapon:SetAutoReload(auto_reload)

Parameters

TypeParameterDefaultDescription
booleanauto_reload Required parameter Whether to reload automatically

Optimal

SetBulletColorโ€‹

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

TypeParameterDefaultDescription
Colorbullet_color Required parameter The new Bullet Color

See also GetBulletColor.


Optimal

SetBulletSettingsโ€‹

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

TypeParameterDefaultDescription
integerbullet_count Required parameter 1 for common weapons
> 1 for shotguns
integerbullet_max_distance Required parameter Max distance the bullet travels (in units, 1 unit = 1 cm)
integerbullet_velocity Required parameter Visuals only
Colorbullet_color Required parameter Color of the bullet trail

Optimal

SetCadenceโ€‹

Sets the time between shots
my_weapon:SetCadence(cadence)

Parameters

TypeParameterDefaultDescription
floatcadence Required parameter 1 shot at each cadence second

See also GetCadence.


Optimal

SetClipCapacityโ€‹

Sets the max number of bullets the Weapon's clip can hold
my_weapon:SetClipCapacity(clip)

Parameters

TypeParameterDefaultDescription
integerclip Required parameter The new clip capacity

See also GetClipCapacity.


Optimal

SetDamageโ€‹

Base Weapon's Damage

This will be multiplied by multiplier factors when hitting specific bones
my_weapon:SetDamage(damage)

Parameters

TypeParameterDefaultDescription
integerdamage Required parameter The new Base Weapon's Damage

See also GetDamage.


Optimal

SetHandlingModeโ€‹

Sets how the Character grabs this Weapon
my_weapon:SetHandlingMode(handling_mode)

Parameters

TypeParameterDefaultDescription
HandlingModehandling_mode Required parameter The new how the Character grabs this Weapon

Optimal

SetLeftHandTransformโ€‹

Sets where the Character's left hand holds this Weapon, relative to the Weapon
my_weapon:SetLeftHandTransform(left_hand_location, left_hand_rotation)

Parameters

TypeParameterDefaultDescription
Vectorleft_hand_location Required parameter Location offset of the left hand
Rotatorleft_hand_rotation Required parameter Rotation offset of the left hand

Slow

SetMagazineMeshโ€‹

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

TypeParameterDefaultDescription
StaticMesh Referencemagazine_mesh Required parameter The Static Mesh of the magazine, spawned in the Character's hand during the reload
stringmagazine_mesh_hide_bone?b_gun_mag
Weapon bone to hide when reloading it

See also GetMagazineMesh.


Slow

SetParticlesBarrelโ€‹

Sets the Particle of the fire blast at the muzzle
my_weapon:SetParticlesBarrel(particle_asset_path)

Parameters

TypeParameterDefaultDescription
Particle Referenceparticle_asset_path Required parameter The Particle asset to spawn at the muzzle when firing

See also GetParticlesBarrel.


Slow

SetParticlesBulletTrailโ€‹

Sets the Particle of the bullet trail
my_weapon:SetParticlesBulletTrail(particle_bullet_trail_asset_path)

Parameters

TypeParameterDefaultDescription
Particle Referenceparticle_bullet_trail_asset_path Required parameter The Particle asset to spawn for each bullet

See also GetParticlesBulletTrail.


Slow

SetParticlesShellsโ€‹

Sets the Particle of the empty shells ejected when firing
my_weapon:SetParticlesShells(particle_shells_asset_path)

Parameters

TypeParameterDefaultDescription
Particle Referenceparticle_shells_asset_path Required parameter The Particle asset to spawn when ejecting a shell

See also GetParticlesShells.


Optimal

SetRecoilโ€‹

Sets the base recoil of this Weapon
my_weapon:SetRecoil(recoil)

Parameters

TypeParameterDefaultDescription
floatrecoil Required parameter 0 means no Recoil, default is 1

See also GetRecoil.


Optimal

SetRightHandOffsetโ€‹

Set the Offset of Right Hand. To position relative to the camera.
my_weapon:SetRightHandOffset(right_hand_offset)

Parameters

TypeParameterDefaultDescription
Vectorright_hand_offset Required parameter The new offset of Right Hand

See also GetRightHandOffset.


Optimal

SetSightFOVMultiplierโ€‹

Sets the Field of View multiplier applied when aiming down sights
my_weapon:SetSightFOVMultiplier(sight_fov_multiplier)

Parameters

TypeParameterDefaultDescription
floatsight_fov_multiplier Required parameter Values below 1 zoom in, for example 0.5 for a scope

See also GetSightFOVMultiplier.


Optimal

SetSightTransformโ€‹

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

TypeParameterDefaultDescription
Vectorsight_location Required parameter Offset between the camera and the sight
Rotatorsight_rotation Required parameter Rotation applied to the Weapon while aiming

Slow

SetSoundAimโ€‹

Sets the Sound played when starting to aim
my_weapon:SetSoundAim(sound_aim_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_aim_asset_path Required parameter The Sound asset to play
floatvolume?1
Volume multiplier
floatpitch?1
Pitch multiplier

See also GetSoundAim.


Slow

SetSoundDryโ€‹

Sets the Sound played when trying to fire with an empty clip
my_weapon:SetSoundDry(sound_dry_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_dry_asset_path Required parameter The Sound asset to play
floatvolume?1
Volume multiplier
floatpitch?1
Pitch multiplier

See also GetSoundDry.


Slow

SetSoundFireโ€‹

Sets the Sound played when firing
my_weapon:SetSoundFire(sound_fire_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_fire_asset_path Required parameter The Sound asset to play
floatvolume?1
Volume multiplier
floatpitch?1
Pitch multiplier

See also GetSoundFire.


Slow

SetSoundFireLastBulletsโ€‹

Sound when firing with only having X remaining bullets in the magazine, useful for last shot 'ping' or sound when low on bullets
my_weapon:SetSoundFireLastBullets(sound_asset_path, remaining_bullets_count?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_asset_path Required parameter The Sound asset to play
integerremaining_bullets_count?1
The amount of remaining bullet to start playing this sound

Slow

SetSoundLoadโ€‹

Sets the Sound played when loading a magazine
my_weapon:SetSoundLoad(sound_load_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_load_asset_path Required parameter The Sound asset to play
floatvolume?1
Volume multiplier
floatpitch?1
Pitch multiplier

See also GetSoundLoad.


Slow

SetSoundUnloadโ€‹

Sets the Sound played when unloading a magazine
my_weapon:SetSoundUnload(sound_unload_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_unload_asset_path Required parameter The Sound asset to play
floatvolume?1
Volume multiplier
floatpitch?1
Pitch multiplier

See also GetSoundUnload.


Slow

SetSoundZoomingโ€‹

Sets the Sound played when zooming
my_weapon:SetSoundZooming(sound_zooming_asset_path, volume?, pitch?)

Parameters

TypeParameterDefaultDescription
Sound Referencesound_zooming_asset_path Required parameter The Sound asset to play
floatvolume?1
Volume multiplier
floatpitch?1
Pitch multiplier

See also GetSoundZooming.


Optimal

SetSpreadโ€‹

Sets the base spread of this Weapon
my_weapon:SetSpread(spread)

Parameters

TypeParameterDefaultDescription
floatspread Required parameter the higher the less precision - recommended value: 20

See also GetSpread.


Optimal

SetUsageSettingsโ€‹

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

TypeParameterDefaultDescription
booleancan_hold_use Required parameter Whether holding the fire button keeps firing (automatic weapons)
booleanhold_release_use Required parameter Whether it only fires when the fire button is released (e.g. bows)

Optimal

SetWallbangSettingsโ€‹

Sets how the bullet will pass through walls
my_weapon:SetWallbangSettings(max_distance, damage_multiplier)

Parameters

TypeParameterDefaultDescription
integermax_distance Required parameter Max distance to pass through another wall
floatdamage_multiplier Required parameter Damage given if wallbangged

Optimal

StopAnimationโ€‹

Stops an Animation Montage on this Weapon
my_weapon:StopAnimation(animation_asset?)

Parameters

TypeParameterDefaultDescription
Animation Referenceanimation_asset?
Leave empty to stop all Montages

๐Ÿš€ย Eventsโ€‹

Inherited Entity Events
Weapon inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/entity
NameDescription
ClassRegisterTriggered when a new Class is registered with the Inheriting System
DestroyTriggered when an Entity is destroyed
SpawnTriggered when an Entity is spawned/created
ValueChangeTriggered when an Entity has a value changed with :SetValue()
Inherited Actor Events
Weapon inherits from Base Actor Class, sharing it's events:
Base Actorscripting-reference/classes/base-classes/actor
NameDescription
DimensionChangeTriggered when an Actor changes its dimension
EnterWaterTriggered when an Actor enters a water body
LeaveWaterTriggered when an Actor leaves a water body
NetworkAuthorityChangeTriggered when an Actor changes its network authority Player
NetworkAuthorityChangeTriggered when the local Player gets/loses network authority over this actor
Inherited Pickable Events
Weapon inherits from Base Pickable Class, sharing it's events:
Base Pickablescripting-reference/classes/base-classes/pickable
NameDescription
DropWhen a Character drops this Pickable
HitWhen this Pickable hits something
InteractTriggered when a Character interacts with this Pickable (i.e. tries to pick it up)
PickUpTriggered When a Character picks this up
PullUseTriggered when a Character presses the use button for this Pickable (i.e. clicks left mouse button with this equipped)
ReleaseUseTriggered when a Character releases the use button for this Pickable (i.e. releases left mouse button with this equipped)
NameDescription
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

TypeArgumentDescription
WeaponselfThe Weapon that triggered the event
integerold_ammo_bagThe previous bag ammo
integernew_ammo_bagThe 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

TypeArgumentDescription
WeaponselfThe Weapon that triggered the event
integerold_ammo_clipThe previous clip ammo
integernew_ammo_clipThe 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

TypeArgumentDescription
WeaponselfThe Weapon that triggered the event
Vectorimpact_pointLocation in world space of the bullet hit
Vectorimpact_normalNormal of the bullet hit in world space
integerdamageDamage that was applied
Base Actor or nilactor_hitActor 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

TypeArgumentDescription
WeaponselfThe Weapon that triggered the event
CharactershooterThe 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

TypeArgumentDescription
WeaponselfThe Weapon that triggered the event
CharactercharacterThe Character
integerammo_to_reloadHow many bullets were reloaded