Player Object
The player object provides a clean public interface for interacting with a specific player in BDSC.
Each player is represented by a dynamically extendable object that supports:
Accessing and modifying custom data
Syncing values to the client
Adding and running namespaced methods
Lifecycle functions like
save()anddestroy()
All logic attached to a player should go through this API — not directly via internal tables.
Use bdsc.get_player(source) to retrieve the player object, then call methods like player:get_data() or player:run_method(...) to interact with it.
has_data
Check if the player has a data namespace assigned.
Parameters
namespace:
string
Returns
boolean– True if it exists.
player:has_data("stats")get_data
Retrieve data from a specific namespace.
Parameters
namespace:
string
Returns
table|any
add_data
Add a new data namespace to the player.
Parameters
namespace:
stringvalue:
anyreplicated?:
boolean
Returns
boolean|nil
remove_data
Delete an existing data namespace.
Parameters
namespace:
string
set_data
Update values inside an existing namespace (must be a table).
Parameters
namespace:
stringupdates:
tablesync?:
boolean
Returns
boolean
sync_data
Force replication of a namespace to the client.
Parameters
namespace?:
string
update_user_data
Update a value inside the persistent user block and propagate it to storage.
Parameters
key:
stringvalue:
any
add_method
Add a new dynamic method to the player.
Parameters
namespace:
stringname:
stringfn:
function(player, ...)
remove_method
Remove a method from the player.
Parameters
namespace:
stringname:
string
has_method
Check if a player has a method defined.
Parameters
namespace:
stringname:
string
Returns
boolean
run_method
Execute a method that was added to the player.
Parameters
namespace:
stringname:
string...: any
Returns
any
save
Call on_save() method for all namespaces if defined.
destroy
Triggers on_destroy() for all namespaces if defined, saves the player, and unregisters it.
Last updated