Guns4d | The ultimate 3d gun mod.

Class Gun

Gun class

Defining a gun:

method documentation coming soon (or never...)

guns are defined by two table fields: their consts and their properties. properties define nearly everything, from how a gun handles to how it looks, what model it uses, while consts define attributes that should never change, like bones within the gun, framerates, wether the gun is allowed to have certain attributes at all. The rest is mainly for internal workings of the mod.

Guns4d uses a class system for most moving parts- including the gun. New guns therefor are created with the :inherit(def) method, where def is the definition of your new gun- or rather the changed parts of it. So to make a new gun you can run Guns4d.gun:inherit() or you can do the same thing with a seperate class of weapons. Set name to "__template" for template classes of guns.

gun fields

properties

properties which define the vast majority of gun attributes and may change accross instances

consts

constancts which define gun attributes and should not be changed in an instance of the gun

offsets

offsets. runtime storage of offsets generated by recoil sway wag or any other element.

name

string the name of the gun. Set to __template for guns which have no instances.

itemstack

ItemStack itemstack held by the player

gun_entity

ObjRef the gun entity

itemstring

string the itemstring of the gun- i.e. "guns4d_pack_1:m4". Set to "" for __template guns.

_registered

list of registered guns, DO NOT MODIFY I really need a metatable for this class...

bolt_charged

bool is the bolt charged

particle_spawners

table list of particle spawner handles (generated by firing)

current_firemode

int the active index of the firemode from lvl1_fields.properties.firemodes

walking_tick

float walking time used to generate the figure 8 for wag

time_since_last_fire

float

time_since_creation

float

rechamber_time

float time left for the chamber to cycle (for firerates)

burst_queue

int number of rounds left that need to be fired after a burst fire

muzzle_flash

function

animation_rotation

vector containing the offset from animations, this will be generated if {@consts.ANIMATIONS_OFFSET_AIM}=true

total_offset_rotation

total offsets of the gun in the same format as a an offset

properties

the table containing every attribute of the gun.

hip

table hipfire properties

ads

table aiming ("aiming down sights") properties

firemodes

table list of firemodes

firemode_inventory_overlays

table list of corresponding images for firemodes

recoil

table defines the guns recoil

sway

table defines the guns idle sway

wag

table defines the movement of the gun while walking

charging

table defines how rounds are chambered into the gun

ammo

defines what ammo the gun uses

visuals

defines visual attributes of the gun

breathing_scale

float=.5 max angular deviation (vertical) from breathing

flash_offset

vector the offset from the center of the muzzle flash. Used by fire()

firerateRPM

int=600 The number of rounds (cartidges) this gun can throw per minute. Used by update(), fire() and default controls

item

the item entity's attributes. This will later include held item definition...

burst

int=3 how many rounds in burst using when firemode is at "burst"

infinite_inventory_overlay

string overlay on the item to use when infinite ammo is on

pc_control_actions

table containing a list of actions for PC users passed to Control_handler

touch_control_actions

table containing a list of actions for touch screen users passed to Control_handler

reload

and ordered list of reloading states used by default_controls.

the default reload states for a magazine operated weapon, copied from the m4.

Example
{action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}},
{action="unload_mag", time=.25, anim="unload", sounds = {sound="ar_mag_unload"}},
{action="store", time=.5, anim="store", sounds = {sound="ar_mag_store"}},
{action="load", time=.5, anim="load", sounds = {sound="ar_mag_load", delay = .25}},
{action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}}
sounds

a table of soundspecs to be referenced by other functions

properties.hip

offset

vector the offset of the gun (relative to the right arm's default position) at hip.

axis_rotation_ratio

the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity).

sway_vel_mul

sway speed multiplier while at hip

sway_angle_mul

sway angle multiplier while at hip+

properties.ads

offset

vector the offset of the gun relative to the eye's position at hip.

horizontal_offset

float the horizontal offset of the eye when aiming

aim_time

the time it takes to go into full aim

properties.firemodes

list containing the firemodes of the gun. Default only contains "single". Strings allowed by default:

"single"
"burst"
"auto"

properties.firemode_inventory_overlays

defines the overlay on the gun item for each firemode. These are selected automatically by firemode string. Defaults are as follows:

single

"inventory_overlay_single.png"

auto

"inventory_overlay_auto.png"

burst

"inventory_overlay_burst.png"

safe

"inventory_overlay_safe.png" (unimplemented firemode)

properties.recoil

IMPORTANT: expects fields to be tables containing a "gun_axial" and "player_axial" field.

Example
property = {
    gun_axial = type
    player_axial = type
}
--using a vector...
property = {
    gun_axial={x=float, y=float},
    player_axial={x=float, y=float}
}`
velocity_correction_factor

float TL:DR higher decreases recoil at expense of smoothness. 1/value is the deviation of a normalized bell curve, where x is the time since firing. this means that increasing it decreases the time it takes for the angular velocity to fully "decay".

target_correction_factor

float Correction of recoil offset per second is calculated as such: target_correction_factor[axis]*time_since_fire*recoil[axis]

target_correction_max_rate

float The maximum rate per second of recoil offset as determined with gun.properties.recoil.target_correction_factor

angular_velocity_max

float caps the recoil velocity that can stack up from shots.

angular_velocity

vector {x=float, y=float}, defines the initial angular velocity produced by firing the gun

bias

vector {x=float, y=float}, ranges -1 to 1. Defines the probability of the recoil being positive or negative for any given axis.

hipfire_multiplier

float angular velocity multiplier when firing from the hip

properties.sway

IMPORTANT: expects fields to be tables containing a "gun_axial" and "player_axial" field. In the same format as gun.properties.recoil

max_angle

float maximum angle of the sway

angular_velocity

float angular velocity the sway

hipfire_angle_multiplier

float maximum angle multiplier while the gun is at the hip

hipfire_velocity_multiplier

float velocity multiplier while the gun is at the hip

properties.wag

cycle_speed

float=1.6 the cycle speed multiplier

decay_speed

float=1 decay factor when walking has stopped and offset remains.

offset

table containing angular deviation while walking in the same format as an offset vector. Acts as a multiplier on the figure-8 generated while walking.

properties.charging

require_draw_on_swap

bool defines wether the draw animation is played on swap (when loaded). Used in the instance construction method

bolt_charge_mode

string "none" bolt will never need to be charged after reload, "catch" when fired to empty bolt will not need to be charged after reload, "no_catch" bolt will always need to be charged after reload.

draw_time

float the time it takes to swap to the gun

draw_animation

string name of the animation to play from visuals.animations

draw_sound

string name of the sound to play from sounds

properties.ammo

accepted_bullets

table a list of accepted bullet itemstrings

accepted_magazines

table a list of accepted magazine itemstrings

initial_mag

string the mag the gun starts with. Set to "empty" for no mag, otherwise it defaults to accepted_magazines[1] (if present)

properties.visuals

backface_culling

toggles backface culling

animations

a table of animations in the format {x=int, y=float}. Indexes define the name of the animation to be refrenced by other functions of the gun.

offsets

a list of tables each containing two vectors, a gun_axial offset and a player_axial offset. These are required for automatic initialization of offsets.

Example
recoil = {
    gun_axial = {x=0, y=0}
    player_axial = {x=0, y=0}
}
recoil
sway
walking
breathing
look_snap

consts

These are variables that are constant across the class and should usually not ever be changed by instnaces

AIM_OUT_AIM_IN_SPEED_RATIO
KEYFRAME_SAMPLE_PRECISION

frequency of keyframe samples for animation offsets and

DEFAULT_MAX_HEAR_DISTANCE

default max hear distance when not specified

DEFAULT_FPS

fps=60 animation fps i.e. during firing when no length is specified

HAS_RECOIL

bool

HAS_BREATHING

bool

HAS_SWAY

bool

HAS_WAG

bool

HAS_GUN_AXIAL_OFFSETS

bool wether the gun rotates on it's own axis instead of the player's view (i.e. ironsight misalignments)

ANIMATIONS_OFFSET_AIM

wether animations create an offset

LOOP_IDLE_ANIM

whether the idle animation changes or not

THIRD_PERSON_GAIN_MULTIPLIER

general gain multiplier for third persons when hearing sounds

ROOT_BONE

the root bone of the gun (for animation offsets)

MAG_BONE

string="magazine",the bone of the magazine in the gun (for dropping mags)

ARM_RIGHT_BONE

string="right_aimpoint", the bone which the right arm aims at to

ARM_LEFT_BONE

string="left_aimpoint", the bone which the left arm aims at to