So I have this gamemode I’m working on, and it has serverside MySQL database integration. Problem is, I want clients to be able to read the results of a SQL query, but I have no idea how to make a serverside Lua table available to clients. Anyone have an idea on how to do this?
The best way of sending it depends entirely on the data per row. For example, if you need inventory items, you’d use user messages for each row (or multiple if possible) like this:
[lua]umsg.Start( “test”, ply )
umsg.Short( slot )
umsg.Short( itemid )
umsg.Short( count )
I did a bit research on the wiki, wouldn’t it be a better idea to just GLON encode the whole table, send the GLON string with an usermessage, and GLON decode it on the client?
It might be too long for GLON - in which case you could use Overv’s usermessages which are lying around somewhere :buttertroll:
Meh, turns out that usermessages can’t send a string with more than 255 characters, so I’ll have to use datastream.
I know datastream is a very unefficient way of sending stuff, it is for the lazys
It would be handy if I could have the link to Overv’ usermessages…
I’m guessing you use it like this?
umsg.Start( “StoreItemList” )
umsg.String( glon.encode( DB.Main.StoreItems ) )
usermessage.Hook( “StoreItemList”, function( um )
local table = glon.decode( um:ReadString() )
PrintTable( table )
Yes, but that’s pretty much the same as using datastream, which is a very lazy and bad idea.
If delays aren’t an issue I’d say this is the perfect time to use datastream.
Give us the schema and the query and we’ll tell you how to send the data, and if you should be sending it at all.