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
local stats = player:get_data("stats")
add_data
Add a new data namespace to the player.
Parameters
namespace:
string
value:
any
replicated?:
boolean
Returns
boolean|nil
player:add_data("stats", { health = 100 }, true)
remove_data
Delete an existing data namespace.
Parameters
namespace:
string
player:remove_data("stats")
set_data
Update values inside an existing namespace (must be a table).
Parameters
namespace:
string
updates:
table
sync?:
boolean
Returns
boolean
player:set_data("stats", { health = 80 }, true)
sync_data
Force replication of a namespace to the client.
Parameters
namespace?:
string
player:sync_data("stats")
update_user_data
Update a value inside the persistent user block and propagate it to storage.
Parameters
key:
string
value:
any
player:update_user_data("rank", "admin")
add_method
Add a new dynamic method to the player.
Parameters
namespace:
string
name:
string
fn:
function(player, ...)
player:add_method("combat", "take_damage", function(self, amount)
local stats = self:get_data("stats")
stats.health = stats.health - amount
end)
remove_method
Remove a method from the player.
Parameters
namespace:
string
name:
string
player:remove_method("combat", "take_damage")
has_method
Check if a player has a method defined.
Parameters
namespace:
string
name:
string
Returns
boolean
if player:has_method("combat", "take_damage") then
...
end
run_method
Execute a method that was added to the player.
Parameters
namespace:
string
name:
string
...: any
Returns
any
player:run_method("combat", "take_damage", 25)
save
Call on_save()
method for all namespaces if defined.
player:save()
destroy
Triggers on_destroy()
for all namespaces if defined, saves the player, and unregisters it.
player:destroy()
Last updated