Page 1 of 1

Extra Player Info

PostPosted: Sat Mar 02, 2013 06:38
by BrandonReese
Is there a way to store extra information on the player object and retrieve it later. For instance I want to divide players up into teams and store the team name/id on on the player object for easy reference.

PostPosted: Sat Mar 02, 2013 07:15
by kaeza
you can create a table and store the player team using the name as key:

Example code:

At top of init.lua:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local team = { };


When player joins:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
team[player:get_player_name()] = "red";

PostPosted: Sat Mar 02, 2013 09:19
by prestidigitator
It might also work to create a new list in the player's inventory and store things in the metadata of the inventory's stacks. Player inventory is persisted automatically by the engine, so this MIGHT give you essentially a small persistent database....

PostPosted: Sat Mar 02, 2013 09:46
by rubenwardy
prestidigitator wrote:It might also work to create a new list in the player's inventory and store things in the metadata of the inventory's stacks. Player inventory is persisted automatically by the engine, so this MIGHT give you essentially a small persistent database....


See this mod: https://github.com/rubenwardy/awards
the player_data table holds stuff for each player, and the function in minetest.register_onnewplayer() or whatever in trigger.lua

PostPosted: Sat Mar 02, 2013 16:21
by BrandonReese
kaeza wrote:you can create a table and store the player team using the name as key:

Example code:

At top of init.lua:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local team = { };


When player joins:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
team[player:get_player_name()] = "red";


I'm going to use this method. Thanks.