• Net Library Help - Updating an Old Gamemode to Gmod13.
    3 replies, posted
Hi. So I'm updating an old game mode to work with Gmod13, and I'm having a bit of a problem with converting a datastream.Hook to the new net library system. Here's the error I get in console: [ERROR] gamemodes/rpdm/gamemode/client/cl_helpvgui.lua:149: attempt to index global 'datastream' (a nil value) 1. unknown - gamemodes/rpdm/gamemode/client/cl_helpvgui.lua:149 2. include - [C]:-1 3. unknown - gamemodes/rpdm/gamemode/cl_init.lua:6 This is the section of the code from "cl_helpvgui.lua" it's referring to. function StatsIncoming(handler, id, encoded, decoded) statsTable = decoded DermaHelp() end datastream.Hook("ShowTeamStatsStream", StatsIncoming) So I know datastream isn't used anymore, but I don't understand Net Library. [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url] That link helped a bit, but I'm gonna need it dumbed down a bit more.
Well, what part exactly you don't understand? It is described quite well in that article.
Instead of datastream.Hook, use net.Receive. Instead of the arguments handler, id, encoded, decoded, it's now just len on the client or len and ply on the server. Server-side instead of sending a table through datastream, use net.WriteTable. Client-side, instead of setting the table to decoded, use net.ReadTable. Shitty example: [lua] if SERVER then util.AddNetworkString( "GetMessage" ) --Add this wherever the message should be sent: local tbl = {} net.Start( "GetMessage" ) net.WriteTable( tbl ) net.Send( ply ) else net.Receive( "GetMessage", function( len ) tbl = net.ReadTable() --This will set the variable "tbl" on the client to the value of the table sent through the net message. end ) end [/lua]
[QUOTE=Greetings;40893704]Instead of datastream.Hook, use net.Receive. Instead of the arguments handler, id, encoded, decoded, it's now just len on the client or len and ply on the server. Server-side instead of sending a table through datastream, use net.WriteTable. Client-side, instead of setting the table to decoded, use net.ReadTable. Shitty example: [lua] if SERVER then util.AddNetworkString( "GetMessage" ) --Add this wherever the message should be sent: local tbl = {} net.Start( "GetMessage" ) net.WriteTable( tbl ) net.Send( ply ) else net.Receive( "GetMessage", function( len ) tbl = net.ReadTable() --This will set the variable "tbl" on the client to the value of the table sent through the net message. end ) end [/lua][/QUOTE] Thank you sir. No more errors regarding this particular file. Hope I did it correctly!
Sorry, you need to Log In to post a reply to this thread.