Infotables - Player based table storage.

[release]
About
Infotables is an old script i wrote for easily creating tables which store info on the player serverside. If you want it clientside, you can network it. It’s easy.

Basically things like a inventory script, or character data for a roleplay gamemode, can easily be made by making a new infotable, setting it’s default info. Then adding operations for doing certain things, like taking items, giving items, or changing a character name.

I figured I should release this because I used it for many many things and it works well, but I will probably end up rewriting it for gmod 13.
[/release]

[release]
Use

I’m not going to waste my time making a huge descriptive thread on this, so here is a list of the functions, what they do and a quick example.
[/release]

[release]
Functions

BRPLib.infotables:new( str id, tbl default) – Creates a new info table with a unique ID and a default data table. returns nothing.
BRPLib.infotables:get( str id ) – gets & returns a info table.
BRPLib.infotables.operations:add( str infotableID, str operationID, func operationFunc ) – creates a new operation for a infotable, returns nothing.
BRPLib.infotables.operations:call( str infotableID, str operationID, … Args) – Calls a operation from a infotable, returns nothing.
BRPLib.infotables.operations:addcommand( str infotableID, str operationID, bool public, func filter) – adds a console command to directly access a infotables operation, the filter function needs to return true or false, it’s to see if the player is allowed to run it.
BRPLib.infotables:saveall(player) – Save all the players infotables, returns nothing.
BRPLib.infotables:save(player, str infotableID) – Save a specific infotable on the player. returns nothing.
BRPLib.infotables:refresh(player) – Refresh the players infotable based on the saved version of their infotables. returns nothing
BRPLib.infotables:getsaved(player, str infotableID) – get a specific saved infotable from the player.
BRPLib.infotables:connect(player) – This is a callback that needs to be ran in PlayerInitialSpawn
*
[/release]

[release]
Example
[lua]
if ( SERVER ) then

BRPLib.infotables:new( “CHARACTER”, { name = “Unknown”, description = “Some description”, age = 40 });

– first 2 arguments passed are infotable id and operation id, after that you can add as many others as you want.
BRPLib.infotables.operations:add( “CHARACTER”, “SETNAME”, function(infotable, operation, player ,name)
if ( player.infotables[infotable] == nil ) then return end;

player.infotables[infotable].name = name;

BRPLib.infotables:save(player,infotable);

end);

BRPLib.infotables.operations:addcommand( “CHARACTER”, “SETNAME”, false, function(player)
return player:IsAdmin();
end);

end
[/lua]

After doing that, you could go ingame and put the following in the console:

CHARACTER_SETNAME “target’s STEAMID” “Bob Jenkins”

then do:

lua_run PrintTable( player.GetByID(1).infotables )

assuming you’re player 1.
[/release]

Source: http://pastebin.com/w6FHdrsH

Note: The entire thing is serverside. It seems i stopped making this before i implemented the networking part

Good job Lau!

Looks nice!

thanks