I'm using the following to send information to clients about their owned models, trails, masks and money, etc. I used to use a single usermessage to send all this, but with adding more items, this then exceeded the umsg limit.
How could I convert the following to user usermessages? I read the wiki entires on datastream, but I couldn't really get to grips with how to use them.
[lua]function Store.SQLInitialize( arg, result, _, error )
if error and error != 0 then print( "SQL STORE INIT ERROR: " .. error ) return end
if !arg[1].InitCounter then
arg[1].InitCounter = 1
else
arg[1].InitCounter = arg[1].InitCounter + 1
end
if arg[2] == 1 then
if !result or #result == 0 then
tmysql.query( "INSERT INTO dollars VALUES( '" .. arg[1]:SteamID() .. "', '500' )" )
arg[1].Dollars = STARTINGCASH
else
arg[1].Dollars = tonumber( result[1][1] )
end
elseif arg[2] == 2 then
if !result or #result == 0 then
tmysql.query( "INSERT INTO trails VALUES( '" .. arg[1]:SteamID() .. "', '' )" )
arg[1].PersonalTrails = {}
else
trails = result[1][1]
arg[1].PersonalTrails = string.Explode( " ", result[1][1] ) or {}
end
elseif arg[2] == 3 then
if !result or #result == 0 then
tmysql.query( "INSERT INTO masks VALUES( '" .. arg[1]:SteamID() .. "', '' )" )
arg[1].PersonalMasks = {}
else
masks = result[1][1]
arg[1].PersonalMasks = string.Explode( " ", result[1][1] ) or {}
end
elseif arg[2] == 4 then
if !result or #result == 0 then
tmysql.query( "INSERT INTO models VALUES( '" .. arg[1]:SteamID() .. "', '' )" )
arg[1].PersonalModels = {}
else
models = result[1][1]
arg[1].PersonalModels = string.Explode( " ", result[1][1] ) or {}
end
end
-- Send the info to the client.
if arg[1].InitCounter == 4 then
SendUserMessage( "StoreInfo1", arg[1], arg[1].Dollars)
SendUserMessage( "StoreInfo2", arg[1], trails)
SendUserMessage( "StoreInfo3", arg[1], masks)
SendUserMessage( "StoreInfo4", arg[1], models)
arg[1].InitCounter = 0 -- This is here just in case someone decides to reinitialize a client's store.
end
end
[/lua]
[lua]
datastream.StreamToClients({arg[1]},"StoreInfo",{arg[1].Dollars,trails,masks,models})
[/lua]
And on the client
[lua]
datastream.Hook("StoreInfo",function(_,_,_,info)
local dollars = info[1]
local trails = info[2]
--etc etc
end)
[/lua]
Thanks a bunch.
Sorry, you need to Log In to post a reply to this thread.