Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- the table from the main thing, this infotables is only one library of BRP, a old library of a ton of roleplay useful features.
- BRPLb = {};
- BRPLib.infotables = {};
- -- storage
- BRPLib.infotables.tables = {};
- BRPLib.infotables.operations = {};
- BRPLib.infotables.operations.commands = {};
- BRPLib.infotables.players = {};
- -- add a new infotable.
- function BRPLib.infotables:new( id, defaultinfo )
- if ( self.tables[id] != nil ) then return end;
- self.tables[id] = {
- default = defaultinfo,
- operations = {}
- };
- end
- -- get a specific info table.
- function BRPLib.infotables:get( id )
- if ( self.tables[id] == nil ) then return nil; end;
- return self.tables[id];
- end
- -- add a new infotable operation
- function BRPLib.infotables.operations:add( infotableid, operationid, operationFunc )
- if ( BRPLib.infotables.tables[infotableid] == nil ) then return end;
- if ( BRPLib.infotables.tables[infotableid].operations == nil ) then return end;
- if ( BRPLib.infotables.tables[infotableid].operations[operationid] != nil ) then return end;
- BRPLib.infotables.tables[infotableid].operations[operationid] = operationFunc;
- end
- -- call a infotable operation
- function BRPLib.infotables.operations:call( infotable, operation, ...)
- if ( BRPLib.infotables.tables[infotable] == nil ) then return end;
- if ( BRPLib.infotables.tables[infotable].operations[operation] == nil ) then return end;
- BRPLib.infotables.tables[infotable].operations[operation]( infotable, operation, ... );
- end
- function BRPLib.infotables.operations:addcommand( infotable, operation, public, filter)
- if ( public == false ) then
- concommand.Add( infotable .. "_" .. operation, function( p, c, a )
- if ( filter(p) != true ) then return end;
- -- Convert all steam id's to players.
- local na = a;
- for k,v in pairs(na) do
- for _,p in pairs( player.GetAll() ) do
- if ( p:SteamID() == v ) then
- na[k] = p;
- end
- end
- end
- BRPLib.infotables.operations:call( infotable, operation, unpack(na) );
- end);
- else
- concommand.Add( infotable .. "_" .. operation, function( p, c, a )
- local na = a;
- for k,v in pairs(na) do
- for _,p in pairs( player.GetAll() ) do
- if ( p:SteamID() == v ) then
- na[k] = p;
- end
- end
- end
- BRPLib.infotables.operations:call( infotable, operation, unpack(na) );
- end);
- end
- end
- -- save all infotables.
- function BRPLib.infotables:saveall(player)
- if ( player.infotables == nil ) then return end;
- for id,info in pairs( player.infotables ) do
- player:SetPData( id, glon.encode(info) );
- end
- end
- -- save a specific infotable
- function BRPLib.infotables:save(player,id)
- if ( player.infotables == nil ) then return end;
- if ( player.infotables[id] == nil ) then return end;
- player:SetPData( id, glon.encode(player.infotables[id]) );
- end
- -- Reload the entire player's infotable.
- function BRPLib.infotables:refresh(player)
- if ( player.infotables == nil ) then
- player.infotables = {};
- end
- for id,data in pairs( self.tables ) do
- if ( self:getsaved(player,id) != nil ) then
- player.infotables[id] = self:getsaved(player,id);
- else
- print("Could not refresh infotable '" .. id .. "' on player '" .. player:Nick() .. "->" .. player:SteamID() .. "'.");
- end
- end
- end
- -- This gets a saved info table by id.
- function BRPLib.infotables:getsaved(player,infotable)
- if ( self.tables[infotable] == nil ) then return end;
- return glon.decode( player:GetPData(infotable) ) or nil;
- end
- -- This should be called when the player connects.
- function BRPLib.infotables:connect(player)
- player.infotables = {};
- for id,data in pairs( self.tables ) do
- if ( self:getsaved(player,id) != nil ) then
- player.infotables[id] = self:getsaved(player,id);
- else
- player.infotables[id] = data.default;
- end
- end
- end
- function BRPLib.infotables:network(player,infotable)
- if ( player.infotables[infotable] == nil ) then return end;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement