• umsg client to server?
    19 replies, posted
is there anyway of sending strings of data to the server fom the client like how you can in a umsg server to client?
Console commands. :smile:
datastream maybe?
Console commands work, you can also use datastream. [b][url=http://wiki.garrysmod.com/?title=Datastream]Datastream [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] You could do console commands with args, I'm sure there is examples about. Second option is the easiest, in my opinion.
You can use Datastram of course, but keep in mind it's just a wrapper for console commands and user messages. Which means you could probably get better results by doing it yourself.
I'd be sending kilabytes to megabytes of information though. They are contraption saved files. I don't get how I'd use console commands to do it.
Split the string up into chunks, that's how datastream does it.
[QUOTE=-TB-;21059732]I'd be sending kilabytes to megabytes of information though. They are contraption saved files. I don't get how I'd use console commands to do it.[/QUOTE] datastream will save you a lot of work.
This is what I did by umsg during scripting entity, in which I aim to transport a specific entity number from server to client so the client can do future operation on a certain entity. On the server side, in init.lua: [lua] function ENT:SendTrueMessage() local rp = RecipientFilter()-- Grab a CRecipientFilter object rp:AddAllPlayers()-- Send to all players! umsg.Start("ReceiveTrueMessage", rp) umsg.Entity(self) umsg.End() Msg("\n On server side") Msg(self) end [/lua] On the client side, in cl_init.lua [lua] function ReceiveTrueMessage(um) local MyEntity=um:ReadEntity() Msg("\n The entity is") Msg(MyEntity) end usermessage.Hook("ReceiveTrueMessage",ReceiveTrueMessage) [/lua]
err... yes but I'm talking about sending data to the server from the client.
Only possible way is console commands. Datastream uses console commands, actually.
how many characters can be sent at a time? how fast? and how can i split a string up into lets say 20 characters per send.
Well datastream already does that. Either use it or see how it works. [url]http://luabin.foszor.com/code/lua/includes/modules/datastream.lua[/url]
if I use datastream server side can I use it inside a Stool file or does it have to be in a init.lua file. I can't get it in the stool file I just keep getting this error when I try and add a hook, "attempt to index global 'datastream' (a nil value)" Nevermind found out you have to use require("datastream")
For reference, the longest concommand size is 255 bytes, excluding the size of the command itself.
Was just easier to use datastream.
Well if I have problems with it I will of course use something different but its working fine for what I need so might as well use it since it's already there.
I made this today. It's a semi-replica of umsg/usermessage, but switched. [lua]if SERVER then usermessage = {} usermessage.Hooks = {} function usermessage.Hook( name, func ) usermessage.Hooks[name] = func end concommand.Add("umsg",function(pl,cmd,args) local name,info = args[1], {} if not usermessage.Hooks[name] then error("Unhandled usermessage " .. name .. " from player " .. pl:Name() .. "!") end table.remove(args,1) status, err = pcall( function(str) info = glon.decode(str) end, table.concat( args, " " ) ) if not status then error("Malformed usermessage " .. name .. " from player " .. pl:Name() .. "!") end usermessage.Hooks[name](pl,info) end) end if CLIENT then umsg = {} umsg.CurMessage = "" umsg.CurObjs = {} function umsg.Start( name ) if umsg.CurMessage != "" then ErrorNoHalt("There is already an active usermessage! Overriding...") end if string.Explode(" ",name)[2] then error("Name must not contain a space...") end umsg.CurMessage = name umsg.CurObjs = {} end function umsg.Object( obj ) if not umsg.CurMessage or umsg.CurMessage == "" then return end table.insert( umsg.CurObjs, obj ) end function umsg.End() RunConsoleCommand("umsg", umsg.CurMessage, glon.encode( umsg.CurObjs ) ) umsg.CurMessage = "" umsg.CurObjs = {} end end[/lua] On the client, instead of using umsg.Bool/Ang/etc., you just use umsg.Object( obj ). You can send any glon-encodable object. On the server, usermessage hook functions come with two arguments: the player sending the usermessage, and a table of all the arguments sent.
Sorry, you need to Log In to post a reply to this thread.