• How to convert Datastream to net?
    5 replies, posted
How can I Convert datastream to net... For example, I have this piece of code: [lua]datastream.StreamToClients( ply, "sysreports", string.Explode( "\n", file.Read( "sys_reports.txt" ) ) ) -- on Server Side[/lua] and [lua]datastream.Hook( "sysreports", function( t, b, l, tbl ) -- on Client Side[/lua] What should I do to convert them? (That's an addon called "sysreport" wich uses datastream)
Server: [lua]net.Start("sysreports") net.WriteString(file.Read("sys_reports.txt")) net.Send(ply)[/lua] Client: [lua]net.Receive("sysreports", function(len) local tbl = string.Explode("\n", net.ReadString()) end)[/lua] Note that I moved the string.Explode to the client.
[QUOTE=MakeR;40048690]Server: [lua]net.Start("sysreports") net.WriteString(file.Read("sys_reports.txt")) net.Send(ply)[/lua] Client: [lua]net.Receive("sysreports", function(len) local tbl = string.Explode("\n", net.ReadString()) end)[/lua] Note that I moved the string.Explode to the client.[/QUOTE] I have an error: [CODE]unknown command: receivereports [ERROR] lua/autorun/client/cl_sysreport.lua:96: attempt to index field 'TextEntry' (a nil value) 1. DoClick - lua/autorun/client/cl_sysreport.lua:96 2. unknown - lua/vgui/dlabel.lua:206 [/CODE] I don't think that is a net/datastream problem, what do you think? Client lua file: [lua]//SysReport ClientSide function SysReportMenu() ReasonWhy = "" local SMM = vgui.Create( "DPropertySheet" ) SMM:SetParent( SMM ) SMM:SetPos( ScrW() / 2 - 150, ScrH() / 2 - 150 ) SMM:SetSize( 300, 300 ) SMM:SetVisible( true ) SMM:MakePopup() local ReportTab = vgui.Create( "DFrame", SMM ) ReportTab:SetPos( 0, 0 ) ReportTab:ShowCloseButton( false ) ReportTab:SetTitle("") ReportTab:SetDraggable( false ) local UserListLabel = vgui.Create( "DLabel", ReportTab ) UserListLabel:SetPos( 85, 35 ) UserListLabel:SetText( "Player: " ) local UserList = vgui.Create( "DComboBox", ReportTab ) UserList:SetPos( 85, 55 ) UserList:SetSize( 100, 20 ) for k, v in pairs( player.GetAll() ) do if v ~= LocalPlayer() then UserList:AddChoice( v:Nick() ) end end local ReportThem = vgui.Create( "DButton", ReportTab ) ReportThem:SetPos( 110, 225 ) ReportThem:SetSize( 50, 25 ) ReportThem:SetText( "Report! " ) ReportThem.DoClick = function() ------------------------------------------------------------------------------------------ SMM:SetVisible( false ) local ReasonPanel = vgui.Create( "DFrame" ) ReasonPanel:SetPos( ScrW() / 2 - 150, ScrH() / 2 - 150 ) ReasonPanel:SetSize( 250, 150 ) ReasonPanel:SetTitle( "Custom Reason and Level / Amount" ) ReasonPanel:ShowCloseButton( true ) ReasonPanel:SetBackgroundBlur( true ) ReasonPanel:SetDraggable( false ) ReasonPanel:SetVisible( true ) ReasonPanel:MakePopup() local HowMuchTextLabel = vgui.Create( "DLabel", ReasonPanel ) HowMuchTextLabel:SetPos( 40, 25 ) HowMuchTextLabel:SetText( "Reason:" ) HowMuchTextLabel:SizeToContents() local ReasonText = vgui.Create( "DTextEntry", ReasonPanel ) ReasonText:SetPos( 40, 40 ) ReasonText:SetTall( 20 ) ReasonText:SetWide( 150 ) ReasonText:RequestFocus() ReasonText.OnEnter = function() ReasonPanel:SetVisible( false ) ReasonWhy = ReasonText:GetValue() end local HowMuchTextLabel = vgui.Create( "DLabel", ReasonPanel ) HowMuchTextLabel:SetPos( 40, 65 ) HowMuchTextLabel:SetText( "Level / Amount:" ) HowMuchTextLabel:SizeToContents() local HowMuchText = vgui.Create( "DTextEntry", ReasonPanel ) HowMuchText:SetPos( 40, 80 ) HowMuchText:SetTall( 20 ) HowMuchText:SetWide( 150 ) local OkB = vgui.Create( "DButton", ReasonPanel ) OkB:SetText( "Report!" ) OkB:SetPos( 90, 115 ) OkB:SetSize( 50, 20 ) OkB.DoClick = function() ReasonPanel:SetVisible( false ) if string.len( ReasonText:GetValue() ) <= 3 then ReasonWhy = "" HowMuchWhy = "" LocalPlayer():ChatPrint( "Sorry, your reason must be longer than 3 characters..." ) else ReasonWhy = ReasonText:GetValue() HowMuchWhy = HowMuchText:GetValue() if UserList.TextEntry:GetValue() ~= "" and ReasonWhy ~= "" and HowMuchWhy ~= "" then if UserList.TextEntry:GetValue() and ReasonWhy ~= "" and HowMuchWhy ~= "" then if UserList.TextEntry:GetValue() ~= "" and ReasonWhy and HowMuchWhy ~= "" then if UserList.TextEntry:GetValue() ~= "" and ReasonWhy and HowMuchWhy then RunConsoleCommand( "sys_report", UserList.TextEntry:GetValue(), ReasonWhy, HowMuchWhy ) LocalPlayer():ChatPrint( "You have reported " .. UserList.TextEntry:GetValue() .. ", Reason: " .. ReasonWhy ) end end end end end end end --------------------------------------------------------------------------------------------------------------------- local ReportL = vgui.Create( "DLabel", ReportTab ) ReportL:SetPos( 100, 2 ) ReportL:SetText( "Report Players" ) ReportL:SetColor( Color( 0, 0, 0 ) ) ReportL:SetFont( "Default" ) ReportL:SizeToContents() local ReportClose = vgui.Create( "DButton", ReportTab ) ReportClose:SetPos( 245, 0 ) ReportClose:SetSize( 45, 20 ) ReportClose:SetText("Close") ReportClose.DoClick = function() ReportTab:SetVisible( false ) SMM:SetVisible( false ) ReportTab:Remove() SMM:Remove() end SMM:AddSheet( "Report User", ReportTab, "gui/silkicons/user", false, false, "Report!" ) /////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// sys_reports = {} RunConsoleCommand( "receivereports" ) if LocalPlayer():IsAdmin() then local ReviewTab = vgui.Create( "DFrame", SMM ) ReviewTab:SetPos( 0, 0 ) ReviewTab:ShowCloseButton( false ) ReviewTab:SetTitle("") sys_reports = {} RunConsoleCommand( "receivereports" ) local ReviewText = vgui.Create( "DTextEntry", ReviewTab ) ReviewText:SetPos( 15, 21 ) ReviewText:SetSize( 250, 200 ) ReviewText:SetMultiline( true ) ReviewText:SetText( table.concat( sys_reports, "\n" ) ) ReviewText:RequestFocus() /*datastream.Hook( "sysreports", function( t, b, l, tbl )*/ net.Receive("sysreports", function(len) local tbl = string.Explode("\n", net.ReadString()) sys_reports = tbl ReviewText:SetText( table.concat( sys_reports, "\n" ) ) end ) local ReviewR = vgui.Create( "DButton", ReviewTab ) ReviewR:SetPos( 108, 222 ) ReviewR:SetSize( 55, 20 ) ReviewR:SetText( "Refresh!" ) ReviewR.DoClick = function() sys_reports = {} RunConsoleCommand( "receivereports" ) end if LocalPlayer():IsSuperAdmin() then local ClearB = vgui.Create( "DButton", ReviewTab ) ClearB:SetPos( 0, 0 ) ClearB:SetSize( 45, 20 ) ClearB:SetText( "Clear" ) ClearB.DoClick = function() RunConsoleCommand( "cleanreports" ) sys_reports = {} RunConsoleCommand( "receivereports" ) end end local PrintC = vgui.Create( "DButton", ReviewTab ) PrintC:SetPos( 112, 245 ) PrintC:SetSize( 45, 20 ) PrintC:SetText( "Print" ) PrintC.DoClick = function() LocalPlayer():ChatPrint( "All The Reports Have Been Printed Into Console!" ) print( "Reports:" ) print( "\n" ) print( table.concat( sys_reports, "\n" ) ) ReportTab:SetVisible( false ) ReviewTab:SetVisible( false ) SMM:SetVisible( false ) ReportTab:Remove() ReviewTab:Remove() SMM:Remove() end local ReviewL = vgui.Create( "DLabel", ReviewTab ) ReviewL:SetPos( 100, 2 ) ReviewL:SetText( "Review Reports" ) ReviewL:SetColor( Color( 0, 0, 0 ) ) ReviewL:SetFont( "Default" ) ReviewL:SizeToContents() local ReviewClose = vgui.Create( "DButton", ReviewTab ) ReviewClose:SetPos( 245, 0 ) ReviewClose:SetSize( 45, 20 ) ReviewClose:SetText("Close") ReviewClose.DoClick = function() ReportTab:SetVisible( false ) ReviewTab:SetVisible( false ) SMM:SetVisible( false ) ReportTab:Remove() ReviewTab:Remove() SMM:Remove() end SMM:AddSheet( "Review", ReviewTab, "gui/silkicons/world", false, false, "Review" ) end end concommand.Add( "report", SysReportMenu )[/lua] Thanks
I think UserList.TextEntry:GetValue() should be UserList:GetSelectedItems[1]:GetValue(). This returns the value of the first selected item in the DComboBox.
[QUOTE=MakeR;40048998]I think UserList.TextEntry:GetValue() should be UserList:GetSelectedItems[1]:GetValue(). This returns the value of the first selected item in the DComboBox.[/QUOTE] [CODE] [ERROR] lua/autorun/client/cl_sysreport.lua:96: attempt to index field 'GetSelectedItems' (a nil value) 1. DoClick - lua/autorun/client/cl_sysreport.lua:96 2. unknown - lua/vgui/dlabel.lua:206 [/CODE] Didn't work :\
Anyone?
Sorry, you need to Log In to post a reply to this thread.