Weapon

https://i.imgur.com/GqB7p3Z.png

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

Attention

This page is under construction.

Tip

Since update 0.16 it is possible to create any kind of weapon with any kind of mesh

Tip

Please take a look at our Default’s Weapon package with all of them already properly configured and ready to use: https://github.com/nanos-world/nanos-world-weapons.

Usage

-- spawning a AK47
local NewWeapon = Weapon(
    Vector(-900, 185, 215), -- Spawn Location
    Rotator(0, 90, 90),     -- Spawn Rotation
    "NanosWorld::SK_AK47", -- Model
    0,                    -- Collision (Normal)
    true,                 -- Gravity Enabled
    30,                   -- Default Ammo in the Clip
    1000,                 -- Default Ammo in the Bag
    30,                   -- Clip Capacity
    30,                   -- Base Damage
    20,                   -- Spread
    1,                    -- Bullet Count (1 for common weapons, > 1 for shotguns)
    30,                   -- Ammo to Reload (Ammo Clip for common weapons, 1 for shotguns)
    20000,                -- Max Bullet Distance
    7500,                 -- Bullet Speed (visual only)
    Color(20, 10000, 0),  -- Bullet Color
    0.5,                  -- Sight's FOV multiplier
    Vector(0, 0, -14.85), -- Sight Location
    Rotator(-1, 0, 0),    -- Sight Rotation
    Vector(26, 0, 8.5),   -- Left Hand Location
    Rotator(0, 60, 90),   -- Left Hand Rotation
    Vector(-10, 0, 0),    -- Right Hand Offset
    1,                    -- Handling Mode (0. SingleHandedWeapon, 1. DoubleHandedWeapon, 2. SingleHandedMelee, 3. DoubleHandedMelee, 4. Throwable, 5. Torch)
    0.15,                 -- Cadence (1 shot at each 0.15seconds)
    true,                 -- Can Hold Use (keep pressing to keep firing, common to automatic weapons)
    false,                -- Need to release to Fire (common to Bows)
    "NanosWorld::P_Bullet_Trail_System",                       -- Bullet Trail Particle
    "NanosWorld::P_Weapon_BarrelSmoke",                        -- Barrel Particle
    "NanosWorld::P_Weapon_Shells_762x39",                      -- Shells Particle
    "NanosWorld::A_Rifle_Dry",                                 -- Weapon's Dry Sound
    "NanosWorld::A_Rifle_Load",                                -- Weapon's Load Sound
    "NanosWorld::A_Rifle_Unload",                              -- Weapon's Unload Sound
    "NanosWorld::A_AimZoom",                                   -- Weapon's Zooming Sound
    "NanosWorld::A_Rattle",                                    -- Weapon's Aiming Sound
    "NanosWorld::A_AK47_Shot",                                 -- Weapon's Shot Sound
    "NanosWorld::AM_Mannequin_Reload_Rifle",                   -- Character's Reloading Animation
    "NanosWorld::AM_Mannequin_Sight_Fire",                     -- Character's Aiming Animation
    "NanosWorld::SM_AK47_Mag_Empty"                            -- Magazine Mesh
)

Using our Default Weapons Package https://github.com/nanos-world/nanos-world-weapons (already built-in included) for spawning and attaching a Red Dot:

-- Includes this Package in your Package
Package:RequirePackage("NanosWorldWeapons")

-- Spawning the AK47
local my_ak47 = NanosWorldWeapons.AK47(Vector(1035, 154, 300), Rotator())

-- Spawning a Red Dot Sight Prop anywhere
local my_reddot = Prop(
    Vector(),
    Rotator(),
    "NanosWorld::SM_T4_Sight", -- Red Dot Static Mesh Path
    2, -- No Collision
    false, -- No Gravity
    false -- No Grabbing
)

-- Attaches the RedDot Prop into AK47 on sight_socket bone from AK47 model. As our AK47 model already
-- have a bone named sight_socket at the right location, we can just attach to it, otherwise we would
-- need to set it's Attach Location to where the RedDot fits and using bone name empty ""
my_reddot:AttachTo(my_ak47, "sight_socket", Vector(), Rotator())

-- Makes the FOV multiplier reduces by 0.35x when ADS (aiming)
my_ak47.SightFOVMultiplier = 0.35

-- Sets the ADS transform offset to fit the RedDot center position,
-- each weapon will need a different offset to fit it's sight. AK47 + RedDot best fit is -15.9
Weapon:SetSightTransform(Vector(0, 0, -15.9), Rotator(0, 0, 0))

Constructor Parameters

Type

Name

Default

Vector

Location

Vector(0, 0, 0)

Rotator

Rotation

Rotation(0, 0, 0)

string

ModelName

Skeletal Mesh Path

number

CollisionType

0 (Normal)

boolean

GravityEnabled

true

number

AmmoClip

32

number

AmmoBag

1024

number

ClipCapacity

32

number

BaseDamage

30

number

Spread (the higher the less precision)

20

number

BulletCount (how many bullets are fired at once - 1 for common weapons and >1 for shotguns)

1

number

AmmoToReload (AmmoClip for common weapons, 1 for shotguns)

32

number

BulletMaxDistance

20000

number

BulletVelocity (visuals only)

7500

Color

BulletColor

Color(10000, 20, 0)

number

SightFOVMultiplier (amount of FOV reduced when Aiming Down Sights (ADS))

0.5

Vector

SightLocation (offset applied to align player’s head to weapon’s sight when ADS)

Rotator

SightRotation (rotation applied on the weapon when ADS)

Vector

LeftHandLocation (location relative to weapon’s root to put the left hand)

Rotator

LeftHandRotation (rotation relative to weapon’s root to put the left hand)

Vector

RightHandOffset (offset of right hand - to offset the weapon as well)

number

HandlingMode (0. SingleHandedWeapon, 1. DoubleHandedWeapon, 2. SingleHandedMelee, 3. DoubleHandedMelee, 4. Throwable, 5. Torch)

0

number

Cadence (frequency of shots in seconds)

0.15

boolean

CanHoldUse (enables keep holding to keep firing)

true

boolean

ReleaseToShot (needs to release the fire button to shot)

false

string

BulletTrailParticle (particle of bullet trail)

string

BarrelParticle (particle of muzzle fire effect)

string

ShellsParticle (particle of shells being spit out)

string

DrySound (sound when weapon is dry)

string

LoadSound

string

UnloadSound

string

ZoomingSound (sound when switching aimings (wheel mouse))

string

AimingSound (sound when going from no aim to aiming)

string

ShotSound

string

CharacterReloadingAnimation

string

CharacterAimingAnimation

string

MagazineMesh (mesh used when reloading)

Static Mesh Path

Properties

Type

Name

Description

client-ready-only-label

number

BaseDamage

Weapon’s Base Damage

client-ready-only-label

number

ClipCapacity

Weapon’s Clip Capacity

client-ready-only-label

number

SightFOVMultiplier

Amount of FOV reduced when Aiming Down Sights (ADS)

client-ready-only-label

number

Cadence

Speed of shots (1 shot at each Cadence seconds)

client-ready-only-label

number

Spread

The higher the less precision

Functions

Returns

Name

Description

server-only-label

SetAmmoClip(number NewAmmo)

Sets this Weapon’s Ammo Clip

server-only-label

SetAmmoBag(number NewAmmo)

Sets this Weapon’s Ammo Bag

server-only-label

SetSightTransform(Vector Location, Rotator Rotation)

Offset applied to align player’s head to weapon’s sight and rotation applied on the weapon when ADS

server-only-label

SetLeftHandTransform(Vector Location, Rotator Rotation)

Left Hand Offset

server-only-label

SetRightHandOffset(Vector Offset)

Offset of Right Hand

server-only-label

SetBulletColor(Color Color)

Bullet Color

number

GetAmmoClip()

Gets this Weapon’s Ammo Clip

number

GetAmmoBag()

Gets this Weapon’s Ammo Bag

Vector

GetRightHandOffset()

Color

GetBulletColor()

Functions (Inherited from Pickable)

Returns

Name

Description

string

GetAssetName()

Gets the Asset name

Character

GetHandler()

Gets the Character (if existing) which is holding this

server-only-label

PullUse()

Force this Pickable to be used (e.g. if this is a Weapon, will fire)

server-only-label

ReleaseUse()

Force this Pickable to be released the usage

Functions (Inherited from Actor)

Returns

Name

Description

Vector

GetLocation()

Get the actor’s position in the game world

Rotator

GetRotation()

Gets the actor’s rotation in the game world

number

GetCollision()

Gets the current actor’s collision

boolean

IsGravityEnabled()

Gets the actor’s gravity enabled

server-only-label

SetRotation(Rotator NewRotation)

Sets the actor’s rotation in the game world

server-only-label

SetLocation(Vector NewLocation)

Sets the actor’s location in the game world

server-only-label

SetScale(Vector Scale)

Sets the actor’s scale

server-only-label

SetCollision(number CollisionType)

Sets the actor’s collision (0 - Normal, 1 - Static Only, 2 - No Collision)

server-only-label

SetGravityEnabled(boolean NewGravity)

Sets the actor’s gravity enabled

server-only-label

SetInitialLocation(Vector NewInitialLocation)

Sets the initial location

server-only-label

Vector

GetInitialLocation()

Gets the initial location

server-only-label

SetTintColor(Color NewTintColor)

Sets the tint color, for completely paint an object, multiply the color by 10 or 100

Color

GetTintColor()

Gets the Tint Color

server-only-label

Destroy()

Destroys this Actor

boolean

IsValid()

Returns if this is Valid

string

GetType()

Returns the type of this Actor

server-only-label

AttachTo(Actor Other, string BoneName, Vector RelativeLocation)

Attaches this Actor to any other Actor with a Relative Offset

server-only-label

AddImpulse(Vector Force)

Applies a Force in world coordinate on this Actor (the force is applied on Client side, by the (in most of cases) the closest player of this object)

SetValue(string Key, any Value)

Sets a value in this entity, which can be accessed by any package (local only)

any

GetValue(string Key)

Gets a value given a key

Events

Name

Arguments

Description

Fire

Weapon self, Character shooter

When this weapon is fired

Reload

Weapon self, Character character, number AmmoToReload

When this weapon is reloaded, optionally by a Character

Events (Inherited from Pickable)

Name

Arguments

Description

PickUp

Entity pickable, Character character

When a Character picks up this

Drop

Entity pickable, Character character

When a Character drops this

Events (Inherited from Actor)

Name

Arguments

Description

Spawn

Entity actor

Triggered when an Entity is Spawned/Created

Destroy

Entity actor

Triggered when an Entity is Destroyed