Player module

Player global creation.

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

All existing and new players will be added to the global.players 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 Player = require 'stdlib/event/player'
-- The fist time this module is required it will register player creation events

Functions

add_data_all (data) Merge a copy of the passed data to all players in global.players.
get (player) Get game.players[index] & global.players[index], or create global.players[index] if it doesn't exist.
init ([event][, overwrite=false]) Init or re-init a player or players.
remove (event) Remove data for a player when they are deleted.

Functions

# add_data_all (data)

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

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

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

Parameters: Returns: Usage:
local Player = require 'stdlib/event/player'
local player, player_data = Player.get(event.player_index)
# init ([event][, overwrite=false])

Init or re-init a player or players.

Passing a nil event will iterate all existing players.

Parameters:
# remove (event)

Remove data for a player when they are deleted.

Parameters:
  • event : (table) event table containing the player_index