Use Usermessages: User Messages - GMod Wiki
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:
client 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 )
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.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")
Just to say, this works perfectly, but its very unefficent.
Hurr
Use Usermessages: User Messages - GMod Wiki
PewPew (New GCombat) | SVN Tutorial | EGP v3
MY SVN LINK:Code:http://divranspack.googlecode.com/svn/trunk/%20divranspack/
Thanks for clicking, everyone!
http://www.minerwars.com/?aid=927
But if I get even more clicks, I get the full game, so keep at it!
Tutorials: Wire GPU | 3D Projections
Black Phoenix: drun KIE
Black Phoenix: PLEASE CONFIRM THIS MESSAGE DRUN KIE
Drunkie: confirmed
Black Phoenix: THE INTERGALACTIC CONTINIUM WANTS DRUN KIE TO GO ON A SPECIAL MISSION
Black Phoenix: this will be AN EASY mission TO THE UNKNOWN AND beyonD<HP> ... I can't believe I'm talking to a fucking script at 4 am
Usermessages aren't perfect, but they're a lot better than networked vars and far more suited to this kinda thing.
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
Server -> Client use usermessages. Client -> Server use concommands.
Filipe - you never know what ends up in your love hole
Poonage - It's not a disorder, it can be solved
Drunkie - vista was on the trail of complete beauty and perfection
Omicron - cable management is for losers, and people who know what they're doing
Drunkie - me and solece have tickets to go see justin bieber, i'm looking forward to it
JatGoodwin - I don't normally suck dick, but when I do they call me immibis
Drunkie - THERE IS SIMPLY NOT ENOUGH DICKS
JatGoodwin - stand back, im going to do science
Problem.
I got this code in my serverside:
(The function gets run at a init hook)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
I know it gets run couse it prints and all that.
And this code in my clientside:
This dont work for some reason and gives me:Code:function Usermessages_names(um) Globalvars = um.ReadString() end usermessage.Hook("Globalvars", Usermessages_names)
autorun/client/telelist.lua:21: bad argument #1 to 'ReadString' (bf_read expected, got no value)
Line 21 is Globalvars = um.ReadString()
Hurr


It has to beas the "ReadString" function needs "self" set with the bf_read object from which you called the function. only using "." will not set "self".Code:Globalvars = um:ReadString()
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
Bookmarks