+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 11

Thread: Sending data from Server to client in a efficent way.

  1. #1
    Wire Sofaking Donkie is on a distinguished road Donkie's Avatar
    Join Date
    May 2008
    Location
    Sweden ofc
    Posts
    639

    Default Sending data from Server to client in a efficent way.

    I need to send some data from the server to the client in a efficent way. The way im having right now is putting global variables on a entity i spawn at server start. I then get those variables at the client code. I have found this is very unefficent and bad but i really dont know any else way.

    To the top of the cake, i need to color code it in a special way otherwise it gives me crappy errors that i cant remember:
    server code:
    Code:
    function Init_TriggerLogic()
    	Failent = ents.Create("prop_physics")
    		Failent:SetModel("models/props_junk/PopCan01a.mdl")
    		Failent:SetColor(143,210,85,123)
    		Failent:SetPos(Vector(0,0,0))
    		Failent:SetName("John")
    		Failent:Spawn()
    		
    	
    	timer.Create("taim bitch",1,1,function()
    		Names = file.Read("Teleportlist/Names/"..game.GetMap()..".txt")
    		Positions = file.Read("Teleportlist/Positions/"..game.GetMap()..".txt")
    		Owners = file.Read("Teleportlist/Owners/"..game.GetMap()..".txt")
    		
    		
    		
    		Failent:SetNWString("Globalnames",Names)
    		Failent:SetNWString("Globalpositions",Positions)
    		Failent:SetNWString("Globalowners",Owners)
    	end)
    end
    hook.Add( "InitPostEntity", "MapStartTrigger", Init_TriggerLogic )
    
    client code:
    Code:
    -- Lots of shit just to find that goddamn can -.-
    	Failenttbl = ents.FindByClass("prop_physics")
    	if Failent == nil then
    		for k, v in pairs( Failenttbl ) do
    			local r,g,b,a = v:GetColor()
    			local str=""..r..g..b..a
    			if str=="14321085123" then
    				Failent = v
    				break
    			end
    		end
    	end
    	-- End
    	
    	FakeGlobalnames = Failent:GetNWString("Globalnames")
    	FakeGlobalpositions = Failent:GetNWString("Globalpositions")
    	FakeGlobalowners = Failent:GetNWString("Globalowners")
    
    If you dident notice, im trying to transfer data from files at the server to every client. Sorry for the bad variable names, i cant really find anything better.

    Just to say, this works perfectly, but its very unefficent.
    Hurr

  2. #2
    Wire Sofaking
    Divran will become famous soon enough Divran will become famous soon enough Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    1,255

    Default Re: Sending data from Server to client in a efficent way.

    Use Usermessages: User Messages - GMod Wiki
    PewPew (New GCombat): http://www.wiremod.com/forum/wiremod...w-gcombat.html
    SVN TUTORIAL: http://www.facepunch.com/showthread.php?t=688324
    E2 THREAD: http://www.wiremod.com/forum/custom-...ns-thread.html
    MY SVN LINK:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    

  3. #3
    Wire Sofaking Drunkie will become famous soon enough Drunkie will become famous soon enough Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    777

    Default Re: Sending data from Server to client in a efficent way.

    Quote Originally Posted by Divran View Post
    Use Usermessages: User Messages - GMod Wiki
    ^ That

  4. #4
    Wire Sofaking Schilcote will become famous soon enough Schilcote's Avatar
    Join Date
    Jan 2009
    Location
    There.
    Posts
    1,196

    Default Re: Sending data from Server to client in a efficent way.

    I thought usermessages were laggy (or maybe it's a relative measure)...


    Well this monster dosen't look to hard to defeOshit

  5. #5
    *

    Azrael is a jewel in the rough Azrael is a jewel in the rough Azrael is a jewel in the rough Azrael's Avatar
    Join Date
    Aug 2007
    Posts
    1,352

    Default Re: Sending data from Server to client in a efficent way.

    Usermessages aren't perfect, but they're a lot better than networked vars and far more suited to this kinda thing.
    <Anticept> i always thought that piss comes out of a womans ass....

  6. #6
    Wire Sofaking Donkie is on a distinguished road Donkie's Avatar
    Join Date
    May 2008
    Location
    Sweden ofc
    Posts
    639

    Default Re: Sending data from Server to client in a efficent way.

    Think i got them working. But AFAIK, should i have 3 of them or could i bake them into one in anyway? The tutorial dont really say anything about that.
    Hurr

  7. #7
    Wire Sofaking
    IamMcLovin will become famous soon enough IamMcLovin's Avatar
    Join Date
    Sep 2008
    Posts
    607

    Default Re: Sending data from Server to client in a efficent way.

    Server -> Client use usermessages. Client -> Server use concommands.
    Projects:
    - E2 Holograms
    - E2 File Loading
    - E2 HUD Rendering
    - YouTube Player

    Working On:
    - My Radio
    - Zero G
    - GMedia

    <Filipe> you never know what ends up in your love hole
    Poonage - "It's not a disorder, it can be solved"

  8. #8
    Wire Sofaking Donkie is on a distinguished road Donkie's Avatar
    Join Date
    May 2008
    Location
    Sweden ofc
    Posts
    639

    Default Re: Sending data from Server to client in a efficent way.

    Problem.
    I got this code in my serverside:
    Code:
    function Update()
    	timer.Create("taim bitch",1,0,function()
    		Names = file.Read("Teleportlist/Names/"..game.GetMap()..".txt")
    		Positions = file.Read("Teleportlist/Positions/"..game.GetMap()..".txt")
    		Owners = file.Read("Teleportlist/Owners/"..game.GetMap()..".txt")
    		
    		local rp = RecipientFilter()     -- Grab a CRecipientFilter object
    		rp:AddAllPlayers()               -- Send to all players!
    
    		umsg.Start("Globalvars", rp)
    			umsg.String(Names.."..D.!.A"..Positions.."..D.!.A"..Owners) -- Some random crap to seperate them so i dont need 3 usermessages
    			print(Names.."..D.!.A"..Positions.."..D.!.A"..Owners)
    		umsg.End()
    	end)
    end
    
    (The function gets run at a init hook)
    I know it gets run couse it prints and all that.

    And this code in my clientside:
    Code:
    function Usermessages_names(um)
    	Globalvars = um.ReadString()
    end
    usermessage.Hook("Globalvars", Usermessages_names)
    
    This dont work for some reason and gives me:
    autorun/client/telelist.lua:21: bad argument #1 to 'ReadString' (bf_read expected, got no value)

    Line 21 is Globalvars = um.ReadString()
    Hurr

  9. #9
    Wire Sofaking Schilcote will become famous soon enough Schilcote's Avatar
    Join Date
    Jan 2009
    Location
    There.
    Posts
    1,196

    Default Re: Sending data from Server to client in a efficent way.

    Quote Originally Posted by IamMcLovin View Post
    Server -> Client use usermessages. Client -> Server use concommands.
    What about Client -> Client?


    Well this monster dosen't look to hard to defeOshit

  10. #10
    General Purpose Madman

    Free Fall is on a distinguished road Free Fall's Avatar
    Join Date
    Dec 2007
    Location
    Got digitalized and now lives in his PC's RAM
    Posts
    292

    Default Re: Sending data from Server to client in a efficent way.

    Quote Originally Posted by Donkie View Post
    *Snip*
    This dont work for some reason and gives me:
    autorun/client/telelist.lua:21: bad argument #1 to 'ReadString' (bf_read expected, got no value)

    Line 21 is Globalvars = um.ReadString()
    It has to be
    Code:
    Globalvars = um:ReadString()
    
    as the "ReadString" function needs "self" set with the bf_read object from which you called the function. only using "." will not set "self".

    Quote Originally Posted by Schilcote View Post
    What about Client -> Client?
    Client -> Client is not supported by default afaik. You would either need to tunnel whatever you want to send over the Server or use some other solution like LuaSocket.
    Needz moar Lua

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts