Module ORGM.ReloadableWeapon

This module serves as a lower level API to the ISORGMWeapon class.

It allows for the data its operating on be either a ISReloadableWeapon class object, or a HandWeapon/InventoryItem’s modData.

Info:

  • Copyright: 2018 File: shared/2LoadOrder/ORGMReloadableWeapon.lua
  • Release: v3.09
  • Author: Fenris_Wolf

Firing Functions

Fire.valid (this) Called when checking if a shot will attempt to fire when the trigger is pulled.
Fire.pre (this, playerObj, weaponItem) Called as just as the trigger is pulled.
Fire.post (this, playerObj, weaponItem) Called after the trigger is pulled.
Fire.dry (this, playerObj, weaponItem) Called when the trigger is pulled on a empty chamber.

Reloading Functions

Reload.valid (this, playerObj) Checks if a reload action can be performed.
Reload.start (this, playerObj, weaponItem) Called at the start of a reload action.
Reload.perform (this, playerObj, weaponItem) Called at successful completion of the reload action.

Unloading Functions

Unload.valid (this, playerObj) Checks if a unload action can be performed.
Unload.start (this, playerObj, weaponItem) Called at the start of a unload action.
Unload.perform (this, playerObj, weaponItem) Called at successful completion of the unload action.

Magazine Functions

Magazine.eject (this, playerObj[, playSound]) Ejects the current magazine and adds it to the players inventory.
Magazine.insert (this, playerObj[, playSound]) Inserts the best magazine from the players inventory into the firearm.
Magazine.create (this, playerObj) Creates a new magazine InventoryItem with modData.
Magazine.setup (this, magItem, playerObj) Sets up the ISReloadableMagazine on the InventoryItem
Magazine.findBest (this, playerObj, ammoType) Finds and returns the best magazine available in the players inventory.

Ammo Functions

Ammo.load (this, ammoType, weaponItem[, position]) Loads a round into the firearm (internal magazine or cylinder).
Ammo.convert (this, ammoType) Converts a AmmoGroup round to a real round if required.
Ammo.findBest (this, playerObj) Finds and returns the best ammo available in the players inventory.
Ammo.get (this, position) Gets the ammo at specified position.
Ammo.peek (this[, wrap]) Gets the ammo at the next position.
Ammo.ejectAll (this, playerObj[, playSound]) Ejects all shells (live and spent) onto the ground.
Ammo.hasCases (this) Gets the number of empty cases in the magazine/cylinder.
Ammo.next (this, playerObj, weaponItem) Loads the next round into the chamber
Ammo.setCurrent (this, ammoType, weaponItem) Triggers a recalcuation of firearm stats on ammo changes.

Racking Functions

Rack.valid (this, playerObj) Checks if the weapon can be racked.
Rack.start (this, playerObj, weaponItem) Called at the start of a rack action.
Rack.perform (this, playerObj, weaponItem) Called at successful completion of a rack action.

Hammer Functions

Hammer.cock (this, playerObj, playSound, weaponItem) Cocks the hammer and rotates the cylinder for Rotary actionType.
Hammer.release (this, playerObj, playSound) Releases a cocked hammer.

Bolt Functions

Bolt.open (this, playerObj, playSound, weaponItem) Opens the bolt, ejecting whatever is currently in the chamber onto the ground.
Bolt.close (this, playerObj, playSound, weaponItem) Closes the bolt and chambers the next round.

Cylinder Functions

Cylinder.rotate (this, count, playerObj, playSound, weaponItem) Rotates the cylinder by the specified amount.
Cylinder.open (this, playerObj, playSound, weaponItem) Opens the cylinder.
Cylinder.close (this, playerObj, playSound, weaponItem) Closes the cylinder and sets the current round.

Break Barrel Functions

Break.open (this, playerObj, playSound, weaponItem) Opens the breech and ejects any shells.
Break.close (this, playerObj, playSound, weaponItem) Closes the breech and sets the current round.


Firing Functions

Fire.valid (this)
Called when checking if a shot will attempt to fire when the trigger is pulled.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()

Returns:

    bool true if pulling the trigger ‘should’ fire the gun.

Usage:

    ORGM.Reloadable.Fire.valid(weaponItem:getModData())
Fire.pre (this, playerObj, weaponItem)
Called as just as the trigger is pulled.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Fire.pre(weaponItem:getModData(), playerObj, weaponItem)
Fire.post (this, playerObj, weaponItem)
Called after the trigger is pulled.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Fire.post(weaponItem:getModData(), playerObj, weaponItem)
Fire.dry (this, playerObj, weaponItem)
Called when the trigger is pulled on a empty chamber.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Fire.dry(weaponItem:getModData(), playerObj, weaponItem)

Reloading Functions

Reload.valid (this, playerObj)
Checks if a reload action can be performed.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer

Returns:

    boolean, true if a reload action can be performed, otherwise false.

Usage:

    ORGM.Reloadable.Reload.valid(weaponItem:getModData(), playerObj)
Reload.start (this, playerObj, weaponItem)
Called at the start of a reload action.

This mostly just plays sounds, and opens the break barrel (for shotguns) or revolver cylinder.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Reload.start(weaponItem:getModData(), playerObj, weaponItem)
Reload.perform (this, playerObj, weaponItem)
Called at successful completion of the reload action.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Returns:

    bool false if the reloading should stop

Usage:

    ORGM.Reloadable.Reload.perform(weaponItem:getModData(), playerObj, weaponItem)

Unloading Functions

Unload.valid (this, playerObj)
Checks if a unload action can be performed.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer

Returns:

    bool true if a unload action can be performed

Usage:

    ORGM.Reloadable.Unload.valid(weaponItem:getModData(), playerObj)
Unload.start (this, playerObj, weaponItem)
Called at the start of a unload action.

This mostly just plays sounds, and opens the break barrel (for shotguns) or revolver cylinder.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Unload.start(weaponItem:getModData(), playerObj, weaponItem)
Unload.perform (this, playerObj, weaponItem)
Called at successful completion of the unload action.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Returns:

    bool false if the unloading should stop

Usage:

    ORGM.Reloadable.Unload.perform(weaponItem:getModData(), playerObj, weaponItem)

Magazine Functions

Magazine.eject (this, playerObj[, playSound])
Ejects the current magazine and adds it to the players inventory.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound bool if true plays the ejectSound (optional)

Usage:

    ORGM.Reloadable.Magazine.eject(weaponItem:getModData(), playerObj, true)
Magazine.insert (this, playerObj[, playSound])
Inserts the best magazine from the players inventory into the firearm.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound bool if true plays the insertSound (optional)

Usage:

    ORGM.Reloadable.Magazine.insert(weaponItem:getModData(), playerObj, true)
Magazine.create (this, playerObj)
Creates a new magazine InventoryItem with modData.

This is called on Reloadable.Magazine.eject() Copies some data from the firearm into the magazines modData, setting up the ammo count.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer

Returns:

    InventoryItem the magazine with setup modData.

Usage:

    local magItem = ORGM.Reloadable.Magazine.create(weaponItem:getModData(), playerObj)
Magazine.setup (this, magItem, playerObj)
Sets up the ISReloadableMagazine on the InventoryItem

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • magItem InventoryItem the magazine to setup
  • playerObj IsoPlayer

Usage:

    ORGM.Reloadable.Magazine.setup(weaponItem:getModData(), magItem, playerObj)
Magazine.findBest (this, playerObj, ammoType)
Finds and returns the best magazine available in the players inventory.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • ammoType nil or string name of a registered ORGM magazine, auto detected if nil

Returns:

    nil or InventoryItem the best suited magazine

See also:

Usage:

    local magItem = ORGM.Reloadable.Magazine.findBest(weaponItem:getModData(), playerObj, nil)

Ammo Functions

Ammo.load (this, ammoType, weaponItem[, position])
Loads a round into the firearm (internal magazine or cylinder).

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • ammoType string name of a registered ORGM ammo
  • weaponItem HandWeapon
  • position int to insert the round at. If nil it is appended to the list. (optional)

Usage:

    ORGM.Reloadable.Ammo.load(weaponItem:getModData(), "Ammo_9x19mm_FMJ", weaponItem, nil)
Ammo.convert (this, ammoType)
Converts a AmmoGroup round to a real round if required.

This is a safety check performed to ensure we can properly get the ammo stats.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • ammoType string name of a AmmoGroup or a registered ammo.

Returns:

    string name of the first ammo in the group or ammoType if a real ammo was already passed in.

Usage:

    local ammoType = ORGM.Reloadable.Ammo.convert(weaponItem:getModData(), "Ammo_9x19mm",)
Ammo.findBest (this, playerObj)
Finds and returns the best ammo available in the players inventory.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer

Returns:

    nil or InventoryItem the best suited ammo

See also:

Usage:

    ORGM.Reloadable.Ammo.findBest(weaponItem:getModData(), playerObj)
Ammo.get (this, position)
Gets the ammo at specified position.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • position int the index position to get

Returns:

    nil or string the ammo (or case) name at the position

Usage:

    local ammoType = ORGM.Reloadable.Ammo.get(weaponItem:getModData(), position)
Ammo.peek (this[, wrap])
Gets the ammo at the next position.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • wrap bool if true wraps around the end of the list to the begining past maxCapacity. true for rotary actions. (optional)

Returns:

    nil or string ammo (or case) name at the next position

Usage:

    local ammoType = ORGM.Reloadable.Ammo.peek(weaponItem:getModData(), true)
Ammo.ejectAll (this, playerObj[, playSound])
Ejects all shells (live and spent) onto the ground.

Used primarly with revolvers and break barrels on opening.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound bool if true plays the ejectSound (optional)

Usage:

    ORGM.Reloadable.Ammo.ejectAll(weaponItem:getModData(), playerObj, true)
Ammo.hasCases (this)
Gets the number of empty cases in the magazine/cylinder.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()

Returns:

    int number of spent cases

Usage:

    local count = ORGM.Reloadable.Ammo.hasCases(weaponItem:getModData())
Ammo.next (this, playerObj, weaponItem)
Loads the next round into the chamber

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Ammo.next(weaponItem:getModData(), playerObj, weaponItem)
Ammo.setCurrent (this, ammoType, weaponItem)
Triggers a recalcuation of firearm stats on ammo changes.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • ammoType string name of the ammo in use
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Ammo.setCurrent(weaponItem:getModData(), ammoType, weaponItem)

Racking Functions

Rack.valid (this, playerObj)
Checks if the weapon can be racked.

On Easy/Normal reloading, this returns false if there is already a round chambered.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer

Returns:

    bool true if the gun can be racked.

Usage:

    local result = ORGM.Reloadable.rack.setCurrent(weaponItem:getModData(), playerObj)
Rack.start (this, playerObj, weaponItem)
Called at the start of a rack action.

This mostly just plays sounds.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Rack.start(weaponItem:getModData(), playerObj, weaponItem)
Rack.perform (this, playerObj, weaponItem)
Called at successful completion of a rack action.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Rack.perform(weaponItem:getModData(), playerObj, weaponItem)

Hammer Functions

Hammer.cock (this, playerObj, playSound, weaponItem)
Cocks the hammer and rotates the cylinder for Rotary actionType.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound nil or bool if true plays the cockSound
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Hammer.cock(weaponItem:getModData(), playerObj, true, weaponItem)
Hammer.release (this, playerObj, playSound)
Releases a cocked hammer.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound nil or bool not used atm

Usage:

    ORGM.Reloadable.Hammer.release(weaponItem:getModData(), playerObj, true)

Bolt Functions

Bolt.open (this, playerObj, playSound, weaponItem)
Opens the bolt, ejecting whatever is currently in the chamber onto the ground.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound nil or bool if true plays the openSound
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Bolt.open(weaponItem:getModData(), playerObj, true, weaponItem)
Bolt.close (this, playerObj, playSound, weaponItem)
Closes the bolt and chambers the next round.

Single and Double actions this also cocks the hammer.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound nil or bool if true plays the closeSound
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Bolt.close(weaponItem:getModData(), playerObj, true, weaponItem)

Cylinder Functions

Cylinder.rotate (this, count, playerObj, playSound, weaponItem)
Rotates the cylinder by the specified amount.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • count int Number of positions to rotate. If nil or 0, randomly selects (chamber spin)
  • playerObj IsoPlayer
  • playSound nil or bool not used atm
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Cylinder.rotate(weaponItem:getModData(), 1, playerObj, true, weaponItem)
Cylinder.open (this, playerObj, playSound, weaponItem)
Opens the cylinder.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound nil or bool if true plays the openSound
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Cylinder.open(weaponItem:getModData(), playerObj, true, weaponItem)
Cylinder.close (this, playerObj, playSound, weaponItem)
Closes the cylinder and sets the current round.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound nil or bool if true plays the closeSound
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Cylinder.close(weaponItem:getModData(), playerObj, true, weaponItem)

Break Barrel Functions

Break.open (this, playerObj, playSound, weaponItem)
Opens the breech and ejects any shells.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound nil or bool if true plays the openSound
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Break.open(weaponItem:getModData(), playerObj, true, weaponItem)
Break.close (this, playerObj, playSound, weaponItem)
Closes the breech and sets the current round.

Parameters:

  • this ISReloadableWeapon or HandWeapon:getModData()
  • playerObj IsoPlayer
  • playSound nil or bool if true plays the closeSound
  • weaponItem HandWeapon

Usage:

    ORGM.Reloadable.Break.close(weaponItem:getModData(), playerObj, true, weaponItem)
generated by LDoc 1.4.3 Last updated 2019-04-11 18:37:45