Force module

Force global creation.

Requiring this module will register init and force creation events using the stdlib Event module.

All existing and new players will be added to the global.forces table.

This module should be first required after any other Init functions but before any scripts needing global.players.

This module registers the following events: on_init, on_configuration_changed, on_player_created, and on_player_removed.

Usage

local Force = require 'stdlib/event/force'
-- The fist time this is required it will register force creation events

Functions

add_data_all (data) Merge a copy of the passed data to all forces in global.forces.
get (force) Get game.forces[name] & global.forces[name], or create global.forces[name] if it doesn't exist.
init ([event][, overwrite=false]) Init or re-init a force or forces.

Functions

# add_data_all (data)

Merge a copy of the passed data to all forces in global.forces.

Parameters:
  • data : (table) a table containing variables to merge
Usage:
local data = {a = "abc", b = "def"}
Force.add_data_all(data)
# get (force)

Get game.forces[name] & global.forces[name], or create global.forces[name] if it doesn't exist.

Parameters: Returns: Usage:
local Force = require 'stdlib/event/force'
local force_name, force_data = Force.get("player")
local force_name, force_data = Force.get(game.forces["player"])
-- Returns data for the force named "player" from either a string or LuaForce object
# init ([event][, overwrite=false])

Init or re-init a force or forces.

Passing a nil event will iterate all existing forces.

Parameters:
  • event : (string or table) table or a string containing force name (optional)
  • overwrite : (boolean) the force data (default: false)