• Personal NWvars replacement
    47 replies, posted
  • Avatar of KatNotDinner
  • Hey guys. I coded a plugin for my gamemode. It replaces NWVars. It is for GMod 13 only though. nwvars.lua ( server side): [URL]http://pastebin.com/6bXDm0HA[/URL] cl_nwvars.lua (client - side): [URL]http://pastebin.com/HDsiYdni[/URL] Feel free to use it in any script but give me credits. Credits to people who helped me: Divran - pointing out mistakes and suggesting solutions, not being an ass MadDog - a good suggestion which I'm working on Note: Both files have to be loaded first (right after the init/cl_init) or there must be no nwvars set before the files have loaded. Else the set nwvars will break. [U][B]If you are seeing no point in this, get out instead of rating me boxes and being[/B][U][B] a pure idiot.[/B][/U][/U]
  • Avatar of Chessnut
  • At the bottom, it should be _R.Entity.SetNetworkedBlah = _R.Entity.SetNWBlah. This wouldn't even work as players who join after you don't get your info.
  • Avatar of KatNotDinner
  • Don't get my info? What are you talking about? There's a hook that sends the stuff to them. Also it would be really nice if you said something like "Nice" or "I like it" instead of pointing out unexisting error ( "Players won't get your info" ).
  • Why so defensive? If anyone levels criticism towards your work it's usually because they want to help. You won't find "trolls" who take the time to read through your script. IIRC the new net library exists because it's more efficient than networked variables. I haven't tackled networking in GLua though, can someone confirm/deny? It's a hole in my knowledge I'd like to mend.
  • Avatar of Divran
  • You're using table.Add to try to add the player or entity to a table called "nwents", which won't work. So Chessnut was correct. [lua]/*--------------------------------------------------------- Name: table.Add( dest, source ) Desc: Unlike merge this adds the two tables together and discards keys. ---------------------------------------------------------*/ function table.Add( dest, source ) // At least one of them needs to be a table or this whole thing will fall on its ass if (type(source)!='table') then return dest end if (type(dest)!='table') then dest = {} end for k,v in pairs(source) do table.insert( dest, v ) end return dest end[/lua] Line 8 will trigger and nothing will happen.
  • Avatar of KatNotDinner
  • [QUOTE=Splambob;35711454]Why so defensive? If anyone levels criticism towards your work it's usually because they want to help. You won't find "trolls" who take the time to read through your script. IIRC the new net library exists because it's more efficient than networked variables. I haven't tackled networking in GLua though, can someone confirm/deny? It's a hole in my knowledge I'd like to mend.[/QUOTE] I made this replacemnt using the net library cause it (should) improve performance in scripts that rely on NW vars and it is aslo easier to write one simple function instead a few lines of code and then calling net.Receive on the other side. @ Divran: Ok, looking into the issue. [editline][/editline] Ok, I think I fixed it. I also made it so that if there are nwvars stored in a player and the player disconnects, the script won't attempt to send these nwvars to the next player joined. I will make actual NWInt functions but it might not be possible to post them today. [editline]25th April 2012[/editline] Updated the code. Here's a small changelog: 1. Removed lots of useless code on the client which would prevent this from working; 2. Added all NWInt functions; 3. Made it so that if a player disconnects he goes away from the nwents table in order to prevent errors; 4. Removed table.Add. Wrote a small function to do what I needed.
  • Avatar of Divran
  • It's still wrong. What you're doing now is copying all the values stored on the player/entity into "nwents". You need to copy the player/entity itself, not all their values. Example [lua]function _R.Entity:SetNWString( str, val ) if not nwents[self] then nwents[self] = true end if !self.NWvars then self.NWvars = {} end if !self.NWvars.String[ str ] then self.NWvars.String[ str ] = {} end self.NWvars[ str ] = val net.Start( "String" ) net.WriteEntity( self ) net.WriteString( str ) net.WriteString( val ) net.Broadcast() end[/lua] EDIT: There's a lot of other things that could be improved with this, but I'm going to play Starcraft 2 with some friends now :)
  • Avatar of KatNotDinner
  • [QUOTE=Divran;35713578]It's still wrong. What you're doing now is copying all the values stored on the player/entity into "nwents". You need to copy the player/entity itself, not all their values. Example [lua]function _R.Entity:SetNWString( str, val ) if not nwents[self] then nwents[self] = true end if !self.NWvars then self.NWvars = {} end if !self.NWvars.String[ str ] then self.NWvars.String[ str ] = {} end self.NWvars[ str ] = val net.Start( "String" ) net.WriteEntity( self ) net.WriteString( str ) net.WriteString( val ) net.Broadcast() end[/lua] EDIT: There's a lot of other things that could be improved with this, but I'm going to play Starcraft 2 with some friends now :)[/QUOTE] Thanks, that was useful. But Somehting is bothering me. Are you allowed to insert "self" into the brackets ([])? And yes Hentie, another one. [editline]26th April 2012[/editline] Updated the code. Also Divran, I want this to work, I will improve it myself. My point is that I would love to hear anything positive rather than just pointing out errors. I mean, I appriciate it but please say something good. I have put time and effort into this.
  • Avatar of Divran
  • [QUOTE=KatNotDinner;35717101]But Somehting is bothering me. Are you allowed to insert "self" into the brackets ([])?[/QUOTE] Yes. It's more efficient than looping through the entire table just to see if this player/entity is in nwents or not. But you will most likely have to change the PlayerInitialSpawn loop to reflect this change. EDIT: Nevermind, you already did.
  • Avatar of KatNotDinner
  • Updated the code. made a huge optimization. I had used net.Broadcast in the InitialSpawn hook by a mistake. I want to ask garry to PLEASE get back the simple editor for OP. The current one fucks up everything (see OP). I will fix it later cause I'm lazy and I don't have time right now.
  • Avatar of KatNotDinner
  • [QUOTE=Banana Lord.;35733069]it seems useless to use the net library where usermessages can still be used[/QUOTE] I was actually thinking about that. I mean if you are sending 64 fucking KBs of data then you are doing something wrong. I will fix it. Does anyone see any use of this? I use it in my script but I want to see someone else using this code.
  • Avatar of Falcqn
  • [QUOTE=Banana Lord.;35733069]it seems useless to use the net library where usermessages can still be used[/QUOTE] You can send much more data with the net library iirc
  • [QUOTE=Azur;35745259]You can send much more data with the net library iirc[/QUOTE] You shouldn't be sending more than 256 bytes of data for a single networked variable in either case.
  • Avatar of wizardsbane
  • [QUOTE=DarKSunrise;35745881]You shouldn't be sending more than 256 bytes of data for a single networked variable in either case.[/QUOTE] Why not, exactly? How many dial-up Garry's Mod players are there?
  • Avatar of Ruzza
  • [QUOTE=wizardsbane;35746405]Why not, exactly? How many dial-up Garry's Mod players are there?[/QUOTE] Because it is stupid?
  • Avatar of KatNotDinner
  • [QUOTE=Ruzza;35746911]Because it is stupid?[/QUOTE] You do realise that you are kinda requesting limitation? Fuck logic!
  • Avatar of lorde banana
  • if you are using NWVars with more than 256 bytes of data you're really doing something wrong/shouldn't be using NWVars
  • [QUOTE=wizardsbane;35746405]Why not, exactly? How many dial-up Garry's Mod players are there?[/QUOTE] In most situations it's a lot more effective to just use plain user messages instead. Large networked variables are usually slow and might contain a lot of data that the client could already have. There's no point sending that over and over again.
  • Avatar of kp3
  • [QUOTE=DarKSunrise;35748555]In most situations it's a lot more effective to just use plain user messages instead.[/QUOTE] Why didn't the 3 posters above you didn't want to answer his question? Why is it more effective by the way? If it's more effective for long strings shouldn't it be more effective on short ones too?
  • Avatar of wizardsbane
  • [QUOTE=Banana Lord.;35747542]if you are using NWVars with more than 256 bytes of data you're really doing something wrong/shouldn't be using NWVars[/QUOTE] [QUOTE=DarKSunrise;35748555]In most situations it's a lot more effective to just use plain user messages instead. Large networked variables are usually slow and might contain a lot of data that the client could already have. There's no point sending that over and over again.[/QUOTE] I'm having trouble seeing how sending 32 bytes of data is crippling/bad practise if you're not using a computer and network connection from 1998.
  • Avatar of KatNotDinner
  • Ok guys, added pastebin links. Please say your opinion if I should use usermessages or net.* messages.
  • Avatar of lorde banana
  • [QUOTE=wizardsbane;35751965]I'm having trouble seeing how sending 32 bytes of data is crippling/bad practise if you're not using a computer and network connection from 1998.[/QUOTE] it's wasteful and inefficient to send more than you need to
  • Avatar of fnox
  • From what I can tell the code that I am seeing isn't any more efficient than NWVars mainly because it is using the exact same scheme than NWVars regardless of if it's using the Net library as opposed to the Usermessage library. The difference in efficiency between both of them is negligible. If you change how and when the variables are sent or updated then you would most likely see a performance increase. Also [lua] local table, net, nwents = table, net, {} [/lua] [B]Stop it.[/B]
  • Avatar of wizardsbane
  • [QUOTE=Banana Lord.;35755004]it's wasteful and inefficient to send more than you need to[/QUOTE] Oh, alright, so this is more of a pragmatic programming thing than an actual harm.
  • Avatar of lorde banana
  • [QUOTE=wizardsbane;35757871]Oh, alright, so this is more of a pragmatic programming thing than an actual harm.[/QUOTE] the actual harm is that you think it's okay to use bad practices and you're wasting bandwidth.
  • Avatar of wizardsbane
  • [QUOTE=Banana Lord.;35758524]the actual harm is that you think it's okay to use bad practices and you're wasting bandwidth.[/QUOTE] It's not [I]me[/I]. Oh! Heavens no. I'm just putting forth that if such a practise doesn't cripple or harm the systems and clients it interacts with, it shouldn't be demonised or decried so quickly. This is not to say that I'm going to look at someone's code sending a 32 byte object every tick and think "a deity must have coded this amazing block of text." I can see where you and DarkSunrise are coming from, and I agree: no one should ever need to send 32 bytes of data every tick, but actually doing so is somewhat valid as it has no real negative impact on the systems or clients that it functions on.
  • Avatar of KatNotDinner
  • [QUOTE=Big Bang;35756198]From what I can tell the code that I am seeing isn't any more efficient than NWVars mainly because it is using the exact same scheme than NWVars regardless of if it's using the Net library as opposed to the Usermessage library. The difference in efficiency between both of them is negligible. If you change how and when the variables are sent or updated then you would most likely see a performance increase. Also [lua] local table, net, nwents = table, net, {} [/lua] [B]Stop it.[/B][/QUOTE] Ok. Can you give me an example how would I send stuff in a different way?