How do i communicate with a derma panel from a server function?
Example: user presses button1 on frame1 > run server function > frame1 is altered.
you can use commands or the net library
[lua]
//Serverside
concommand.Add("request_random_number", function(ply, c, a)
local num = math.random(1,9)
ply:ConCommand("get_random_number " .. num)
end)
//Clientside
derma_thing = vgui.Create("DButton")
derma_thing:SetText("0")
derma_thiong.OnPressed = function()
LocalPlayer():ConCommand("request_random_number")
end
concommand.Add("get_random_number", function(p, c, a)
local number = a[1]
derma_thing:SetText(number)
end)
[/lua]
For example, im tired & i have no idea if i even wrote it right but atleast i tried to show you.
you can use "if's" like if the panel is open etc..
Learn how to use the net library.
Concommands for that sort of thing are a sort of a bad idea. Concommands are supposed to be commands, not a way for the client to communicate with the server - that's the purpose of the Net library.
[QUOTE=typedef state;39977882]Learn how to use the net library.
Concommands for that sort of thing are a sort of a bad idea. Concommands are supposed to be commands, not a way for the client to communicate with the server - that's the purpose of the Net library.[/QUOTE]
i mentioned that you can use the net library too, but concommands is the easiest way for beginners.
[QUOTE=typedef state;39977882]Learn how to use the net library.
Concommands for that sort of thing are a sort of a bad idea. Concommands are supposed to be commands, not a way for the client to communicate with the server - that's the purpose of the Net library.[/QUOTE]
Actually the console commands are the perfect way to do this. That's how spawning props in GMod works. It just runs "gm_spawn modelname"
i like concommands for this sort of thing as it allows users to make binds to do things more efficiently
I'm guessing he meant to say that using a clientside concommand for server->client communication is a bad idea, which it is.
Thanks SweetTea, that helped a heap!
And after seeing typedef's post i worked out how to use net too, killing two birds with one stone.
:v:
Sorry, you need to Log In to post a reply to this thread.