It's a pretty inefficient system- anything you come up with yourself would likely be much better.

I've never written up a full guide on how the system works, so, here's a brief guide to get you started in the right direction. Some examples are pulled from the old bans code, which again, spent a lot of resources to ensure the players had ALL of the bans data, which ended up being too cumbersome. I ended up adding #6 to retrieve ban data on demand, but, as it bypasses all of the code that splits the data into chunks, it really just turned into a glorified ULib.clientRPC to send data through XGUI lol.
1) Register a datatype (serverside):https://github.com/TeamUlysses/ulx/blob/6072e9d3ff5dc9ffeb65e9945b3ab6e275335d11/lua/ulx/xgui/server/sv_bans.lua#L8xgui.addDataType( "bans", function() return xgui.ulxbans end, "xgui_managebans", 30, 20 )
Parameters are:
- name of datatype (must be unique)
- function that will return all of the data to be sent to players
- access tag the client must have access to to get this data
- maximum number of items to send in a "chunk" (0 to send all data). Note that this just limits by entries in the top-level table, so it's pretty impossible to limit an exact size in bytes.
- priority level of the data (-20 to 20, higher number means lower priority. Used to determine what order to send the datatypes in). Was useful when XGUI could potentially be downloading a lot of data, which is no longer the case.
With this, XGUI will ensure the player has access to the data they need,
especially after their access level changes. However, this will ensure they always have ALL of the data (bad if you're working with a lot of data).
2) When data is changed on the server and needs to be re-sent to the client, you can manually resend all of the data (serverside). This is the easiest but least efficient option:
https://github.com/TeamUlysses/ulx/blob/master/lua/ulx/xgui/server/sv_settings.lua#L38xgui.sendDataTable( {}, "gimps" )
Parameters:
- List of players who should receive the data. Empty table to send to all. XGUI will always filter out users who don't have access to the data.
- One or more names of dataTypes of the data you want to send. String or table allowed.
3) (Optional) For more efficient data syncing, you have the ability to add, remove, or update a piece of data (serverside).https://github.com/TeamUlysses/ulx/blob/6072e9d3ff5dc9ffeb65e9945b3ab6e275335d11/lua/ulx/xgui/server/sv_bans.lua#L119xgui.addData( {}, "bans", t )
https://github.com/TeamUlysses/ulx/blob/6072e9d3ff5dc9ffeb65e9945b3ab6e275335d11/lua/ulx/xgui/server/sv_bans.lua#L130xgui.removeData( {}, "bans", { steamid } )
https://github.com/TeamUlysses/ulx/blob/master/lua/ulx/xgui/server/sv_groups.lua#L50xgui.updateData( {}, "users", temp )
Parameters are (See #2 for more details):
- List of players
- Name of datatype (string only)
- Data to be inserted, keys to be removed, or data to be replaced.
XGUI will automatically update the client's data tables to match the changes. For more details, see the linked code examples above, or
see how the client actually pieces the data back into the table, and
check these comments for some kind of documentation.4) Prepare XGUI to be aware of your data type: (clientside)https://github.com/TeamUlysses/ulx/blob/6072e9d3ff5dc9ffeb65e9945b3ab6e275335d11/lua/ulx/xgui/bans.lua#L4xgui.prepareDataType( "bans" )
Your data can now be accessed in the 'xgui.data.<datatype>' table.
5) (Optional) Hook into XGUI data events to be notified when your data updates: (clientside)https://github.com/TeamUlysses/ulx/blob/6072e9d3ff5dc9ffeb65e9945b3ab6e275335d11/lua/ulx/xgui/bans.lua#L488-L491xgui.hookEvent( "bans", "process", xbans.populateBans )
xgui.hookEvent( "bans", "clear", xbans.clearbans )
xgui.hookEvent( "bans", "add", xbans.banUpdated )
xgui.hookEvent( "bans", "remove", xbans.banRemoved )
These methods should be passed a single parameter with the same data sent by the data parameter in #3, in case you need to dig into it.
The full list of data events you can hook into can be found here, and you can check
here to see exactly where they are called.6) Advanced: Send your own set of data. This is what I'm currently using for bans that will, when requested by the user, send a page of bans to be displayed in their UI. Unfortunately, this bypasses the splitting data into chunks. I should probably fix that at some point lol.
https://github.com/TeamUlysses/ulx/blob/master/lua/ulx/xgui/server/sv_bans.lua#L237xgui.sendDataEvent( ply, 7, "bans", bansToSend )
Here's where the clientside code listens for and handles this event. XGUI will not automatically do anything with this data:
https://github.com/TeamUlysses/ulx/blob/master/lua/ulx/xgui/bans.lua#L446-L451function xbans.banPageRecieved( data )
xgui.data.bans.cache = data
xbans.clearbans()
xbans.populateBans()
end
xgui.hookEvent( "bans", "data", xbans.banPageRecieved, "bansGotPage" )
.. That ended up being a more thorough rundown than I intended to make. Oh well, it's a good refresher for me since I've forgotten how most of it is pieced together. Hope you find it somewhat useful!
