Event.Player module

Player global creation.

This module adds player helper functions, it does not automatically register events unless Player.register_events() is called

Usage

local Player = require('__stdlib__/stdlib/event/player').register_events()
-- The fist time this is required it will register player creation events

Functions

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

Functions

# 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__/stdlib/event/player')
local player, player_data = Player.get(event.player_index)
# pdata(index)

Get the players saved data table.

Creates it if it doesn’t exsist.

Parameters:
  • index : (number) The player index to get data for
Returns:
  • (table) the player’s global data
# 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)
# remove(event)

Remove data for a player when they are deleted.

Parameters:
  • event : (table) event table containing the player_index
# init([event][, overwrite=false])

Init or re-init a player or players.

Passing a nil event will iterate all existing players.

Parameters: