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
.
local Player = require 'stdlib/event/player'
-- The fist time this module is required it will register player creation events
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. |
Merge a copy of the passed data to all players in global.players
.
Parameters:
local data = {a = 'abc', b= 'def'}
Player.add_data_all(data)
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 or re-init a player or players.
Passing a nil
event will iterate all existing players.
Remove data for a player when they are deleted.
Parameters:
player_index