fakelib/API.md
2025-05-22 18:37:47 +10:00

3.9 KiB

API Documentation

This documentation covers the API specific to fakelib. For documentation of the functionality provided by the fake player, metatdata and inventory, refer to the Lua API, as they function the same as the real thing.

Type checks

fakelib.is_player(x)

Checks if a value is a player. Only returns true for real players and fakelib's fake players.

Arguments

  • x - Any value. The value to be checked.

fakelib.is_inventory(x)

Checks if a value is an inventory. Only returns true for real inventories and fakelib's fake inventories.

Arguments

  • x - Any value. The value to be checked.

fakelib.is_metadata(x)

Checks if a value is metadata. Only returns true for real metadata and fakelib's fake metadata.

Arguments

  • x - Any value. The value to be checked.

fakelib.is_vector(x, [add_metatable])

Checks if a value is a vector. Returns true for any table with x, y, and z values that are numbers.

Arguments

  • x - Any value. The value to be checked.
  • add_metatable - Boolean, optional. Add the vector metatable to basic vectors.

Creation

fakelib.create_player([options])

Creates a new fake player.

Arguments

  • options - Definition table, optional. Specifies player data. See options below. Can also be a string as shorthand to set the player name only.

fakelib.create_inventory([sizes])

Creates a new fake inventory.

Arguments

  • sizes - Definition table, optional. Specifies list names and sizes. See sizes below.

fakelib.create_metadata([data])

Creates a new fake metadata object.

Arguments

  • data - Definition table, optional. Specifies metadata keys and values. See data below.

Definition tables.

options

Specifies player data. Used by fakelib.create_player([options]).

All values are optional.

  • name - String. Player name. Unlike real player names, this can contain any characters.
  • position - Vector. Player position.
  • direction - Vector. Player look direction.
  • controls - Table. Player controls. Uses the same format returned by player:get_player_controls().
  • metadata - Metadata. Player metadata. Can be fake metadata or a reference to real metadata.
  • inventory - Inventory. Player inventory. Can be a fake inventory or a reference to a real inventory.
  • wield_list - String. Selected inventory list. Must be a list that exists in the player's inventory.
  • wield_index - Number. Selected list index. Must be an index that exists in the selected list.

Example:

local options = {
	name = "sam",
	position = vector.new(1, 5, 3),
	direction = vector(1, 0, 0),
	controls = {sneak = true},
}
local player = fakelib.create_player(options)

sizes

Specifies list names and sizes. Used by fakelib.create_inventory([sizes]).

List names must be strings, and list sizes must be numbers greater than zero.

Example:

local sizes = {
	main = 32,
	craft = 9,
	craftpreview = 1,
	craftresult = 1,
}
local inv = fakelib.create_inventory(sizes)

data

Specifies metadata keys and values. Used by fakelib.create_metadata([data]).

Keys must be strings, and values must be strings or numbers.

Example:

local data = {
	enabled = "true",
	energy = 300,
}
local meta = fakelib.create_metadata(data)