• Networking (Server -> client)
    1 replies, posted
I'm trying to recover the value of a Slidebar in order to activate a function with in parameters the value of this slidebar. If you have an idea. Thank you ! init.lua util.AddNetworkString("utilisationRadio") util.AddNetworkString("receptionRadio") function ENT:Use(activator, caller) net.Start("utilisationRadio") net.WriteEntity(self) net.Send(activator) end net.Receive("receptionRadio", function() print("test message") local ent = net.ReadEntity() ent:SetChannel(value) end) cl_init.lua net.Receive("utilisationRadio", function() local radioFrame = vgui.Create( "DFrame" ) radioFrame:SetTitle( "Choix du canal radio" ) radioFrame:SetSize( 300, 100 ) radioFrame:Center() radioFrame:MakePopup() radioFrame.Paint = function( self, w, h ) surface.SetDrawColor(0,0,0) surface.DrawOutlinedRect(1, 1, w - 2, h - 2) surface.SetDrawColor(60,60,60, 220) surface.DrawRect(2, 2, w - 4, h - 4) end local radioSlider = vgui.Create( "Slider", radioFrame ) radioSlider:SetPos( 5, 23.5 ) radioSlider:SetWide( 300 ) radioSlider:SetMin( 1 ) radioSlider:SetMax( 100 ) radioSlider:SetValue( 1 ) radioSlider:SetDecimals( 0 ) local radioButton = vgui.Create( "DButton", radioFrame ) radioButton:SetText( "Se calibrer sur le bon canal radio" ) radioButton:SetSize( 260, 30 ) radioButton:SetPos( 20, 60 ) radioButton.Paint = function( self, w, h ) surface.SetDrawColor(0,0,0) surface.DrawOutlinedRect(1, 1, w - 2, h - 2) surface.SetDrawColor(200,200,200, 200) surface.DrawRect(2, 2, w - 4, h - 4) end radioButton.DoClick = function() local value = radioSlider:GetValue() net.Start("receptionRadio") net.SendToServer() radioFrame:Close() end end)
So you need to write the value with one of the net.Write functions. Supposing this is an integer value it would be net.WriteInt(value, 32) as seen net.WriteInt or a float (decimal) value net.WriteFloat(value). Reading the value would be the same but the net.Read functions and remember to read in the same order you write in. Do not send the Player entity over a net.WriteEntity() instead use the built in argument of net.Receive on server (Refer to wiki) so it would be something like this on the receive net.Receive("receptionRadio", function(len, ply) --blah blah end)
Sorry, you need to Log In to post a reply to this thread.