Weapon

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

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

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 an AK47:

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

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

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-read-only-label

number

BaseDamage

Weapon’s Base Damage

client-read-only-label

number

Cadence

Speed of shots (1 shot at each Cadence seconds)

client-read-only-label

number

ClipCapacity

Weapon’s Clip Capacity

client-read-only-label

number

SightFOVMultiplier

Amount of FOV reduced when Aiming Down Sights (ADS)

client-read-only-label

number

Spread

The higher the less precision

Functions

Returns

Name

Description

server-only-label

SetAmmoBag(number NewAmmo)

Sets this Weapon’s Ammo Bag

server-only-label

SetAmmoClip(number NewAmmo)

Sets this Weapon’s Ammo Clip

server-only-label

SetBulletColor(Color Color)

Bullet Color

server-only-label

SetLeftHandTransform(Vector Location, Rotator Rotation)

Left Hand Offset

server-only-label

SetRightHandOffset(Vector Offset)

Offset of Right Hand

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

number

GetAmmoBag()

Gets this Weapon’s Ammo Bag

number

GetAmmoClip()

Gets this Weapon’s Ammo Clip

Color

GetBulletColor()

Vector

GetRightHandOffset()

Functions (Inherited from Pickable)

Returns

Name

Description

server-only-label

AddSkeletalMeshAttached(string ID, string StaticMeshPath)

Spawns and Attaches a SkeletalMesh into this Actor, the SkeletalMesh must have the same Skeletal used by this Actor Mesh, and will follow all animations from it. Uses a custom ID to be used for removing it further

server-only-label

AddStaticMeshAttached(string ID, string StaticMeshPath, string Socket = “”, Vector RelativeLocation = Vector(), Rotator RelativeRotation = Rotator())

Spawns and Attaches a StaticMesh into this Actor in a Socket with relative Location and Rotation. Uses a custom ID to be used for removing it further

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

server-only-label

RemoveSkeletalMeshAttached(string ID)

Removes, if existing, a SkeletalMesh from this Actor given it’s custom ID

server-only-label

RemoveStaticMeshAttached(string ID)

Removes, if existing, a StaticMesh from this Actor given it’s custom ID

string

GetAssetName()

Gets the Asset name

Character

GetHandler()

Gets the Character (if existing) which is holding this

Functions (Inherited from Actor)

Returns

Name

Description

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)

server-only-label

AttachTo(Actor Other, string BoneName, Vector RelativeLocation, Rotator RelativeRotation)

Attaches this Actor to any other Actor with a Relative Offset/Rotation

server-only-label

Destroy()

Destroys this Actor

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

client-only-label

SetHighlightEnabled(boolean Enabled)

Sets if this Actors is Highlighting

server-only-label

SetInitialLocation(Vector NewInitialLocation)

Sets the initial location

server-only-label

SetLocation(Vector NewLocation)

Sets the actor’s location in the game world

server-only-label

SetRotation(Rotator NewRotation)

Sets the actor’s rotation in the game world

server-only-label

SetScale(Vector Scale)

Sets the actor’s scale

server-only-label

SetTintColor(Color NewTintColor)

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

SetValue(string Key, any Value)

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

boolean

IsGravityEnabled()

Gets the actor’s gravity enabled

boolean

IsValid()

Returns if this is Valid

number

GetCollision()

Gets the current actor’s collision

number

GetID()

Gets the network ID of this entity (same in both client and server)

Vector

GetLocation()

Get the actor’s position in the game world

server-only-label

Vector

GetInitialLocation()

Gets the initial location

Rotator

GetRotation()

Gets the actor’s rotation in the game world

Vector

GetScale()

Gets the actor’s scale

Color

GetTintColor()

Gets the Tint Color

string

GetType()

Returns the type of this Actor

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

Drop

Entity pickable, Character character, boolean WasTriggeredByPlayer

When a Character drops this

PickUp

Entity pickable, Character character

When a Character picks up this

Events (Inherited from Actor)

Name

Arguments

Description

Destroy

Entity actor

Triggered when an Entity is Destroyed

Spawn

Entity actor

Triggered when an Entity is Spawned/Created