Hi all, I have little problems with client and server side.
1) So, for example, I have Derma menu with checkboxes wich must to change con_vars... but Derma menus can be run on client side but con_vars can be changed only on the server side... and how I can make Derma menu with checkboxes wich can changed con_vars like this: sv_alltak, mp_falldamage, sbox_noclip etc.....
2) How I can use this command? chat.AddText on client as server sending for each player? For example: I have game hook in server side like this:
function PlyConnect(ply, ip)
---- and here I need to send this command : chat.AddText(...) to any player on the server...
end
hook.Add("PlayerConnect", "PlyCon", PlyConnect)
I try to use Player.SendLua("...") but it doesn't work...
Thanks.
Server -> Client
[url]http://wiki.garrysmod.com/?title=User_Messages[/url]
Client -> Server
[url]http://wiki.garrysmod.com/?title=Datastream[/url]
You can also use datastream to stream in both directions, but I use umsg when possible as it is simpler. You may want someone to hold your hand through this, but these two links are more than enough to let you figure it out yourself( I had to xD ). If you have to figure it out yourself, you will remember it better and can say that you truly wrote the code on your own. Try to get it working, if you cant, just ask about what you are stuck on.
@Rayjingstorm
concommands.
Ok, thanks, I will try it..
[QUOTE=Dron-elektron;24785183]Ok, thanks, I will try it..[/QUOTE]
just to make it clearer, ignore what he said about the datastream. You want to be using concommands for client->server
Because it's the easiest.
But, the worst.
[QUOTE=cpf;24786899]Because it's the easiest.[/QUOTE]
If anything it's more complicated.
datastream.StreamToServer("some_handler" , {"derp" 1 , 3})
RunConsoleCommand("some_handler" , "derp" , 1 , 3)
[editline]10:32PM[/editline]
20 minute ninja
:ninja:
I know, umsg. functions good for Server -> Client
But, I asked, how to make Checkboxes with server con_vars?
MyCheckBox:SetConVar("sv_alltak") -> client can't to do this, but can I do SetConVar as ("rcon sv_alltak") ? or something function...
You could make a console command for it:
[lua]concommand.Add( "changeconvar", function( ply, com, args )
if ( ply:IsAdmin() and #args > 2 and tonumber( args[2] ) ) then
RunConsoleCommand( args[1], args[2] )
end
end )[/lua]
D:< I asked about CHECKBOX which change server convar, I KNOW WHAT I CAN DO MY CONCOMMAND, I NEED CHECKBOX in MY PANEL: when I checked so convar set to 1, else convar set to 0! =/
argghh.... -_-
[QUOTE=Dron-elektron;24799905]D:< I asked about CHECKBOX which change server convar, I KNOW WHAT I CAN DO MY CONCOMMAND, I NEED CHECKBOX in MY PANEL: when I checked so convar set to 1, else convar set to 0! =/
argghh.... -_-[/QUOTE]
D:< You should BE ABLE TO figure out HOW TO DO IT by looking at THE DERMA EXAMPLES ON THE WIKI: as you can see, you can run the console command when the state of the checkbox changes! =/
[lua]checkbox.OnChange = function( self )
RunConsoleCommand( "setconvar", "sv_alltalk", self:GetChecked() and 1 or 0 )
end )[/lua]
-_-
[QUOTE=Dron-elektron;24799905]D:< I asked about CHECKBOX which change server convar, I KNOW WHAT I CAN DO MY CONCOMMAND, I NEED CHECKBOX in MY PANEL: when I checked so convar set to 1, else convar set to 0! =/
argghh.... -_-[/QUOTE]
I'm going to assume capitals is you raising your voice, do not expect any help around here if you are going to be like that you ungrateful bastard.
I don't know who is bastard, and I not...
Just want to see normal answer on current question.
Thx Overv, this is what I wanted to know...
[editline]06:53PM[/editline]
And THIS = not cry, remember, in normal chats etc it equal to Accent on words.... ^_-
I can... =/ but don't know where it must be placed...
So with change convars I will work after...
Now I try to use umsg and I take this error.... (Warning: unhandled usermessage '...') or something... when I do this:
SERVER:
--------------
function TestUmsg(ply, cmd, args)
umsg.Start("TestUm")
umsg.End()
end
concommand.Add("testum", TestUmsg)
CLIENT:
--------------
function PrintUmsg()
chat.AddText(Color(255,0,0), "Umsg is work :)")
chat.PlaySound()
end
usermessage.Hook("TestUm", PrintUmsg)
What's wrong?
This two files work on own sides... but Umsg doesn't work...
On the server, the usermessage is called TestUm, but on the client it's called testum. It's case sensitive.
Hm? So, please, write short code like this but which will be work curectly ;)
[editline]07:16PM[/editline]
Stop, Sorry, it's wrong, I know, TestUm on client and server equal to TestUm... And don't work..
All you need to do is make sure they're the same, down to the capitalisation.
SERVER:
--------------
function TestUmsg(ply, cmd, args)
umsg.Start("TestUm")
umsg.End()
end
concommand.Add("testum", TestUmsg)
CLIENT:
--------------
function PrintUmsg()
chat.AddText(Color(255,0,0), "Umsg is work :)")
chat.PlaySound()
end
usermessage.Hook("TestUm", PrintUmsg) --edited line
[QUOTE=Dron-elektron;24801907]Hm? So, please, write short code like this but which will be work curectly ;)
[editline]07:16PM[/editline]
Stop, Sorry, it's wrong, I know, TestUm on client and server equal to TestUm... And don't work..[/QUOTE]
[QUOTE=MegaJohnny;24801887]On the server, the usermessage is called TestUm, but on the client it's called testum. It's case sensitive.[/QUOTE]
:ninja:
Yea, I saw this mistake and after fixing it Umsg doesn't work =(
[editline]07:19PM[/editline]
Now, I quicly make to files and write it again and test it... wait pls :)
Do you get any errors? I can't see anything else wrong with the code.
Warning: Unhandled usermessage 'TestUm'
Again...
Yep...
Check the whole of the console for any errors relating to clientside code (yellow).
No any errors.. I see only Warning: unhandled usermessage when call my func... =/
[editline]07:54PM[/editline]
Hm, it start work :D but when I ran script with console... hm... thanks for answers.. =)
[editline]08:01PM[/editline]
I think, I have found this small error in unicode of file... and when I join the game my client file don't download and usermessages were broken..
Thanks guys ;) for helping.
Yes, of course, my mistake was in unicode of file... and so it couldn't to download ;) Now, umsg is working perfectly :D
Why is datastream so horrible, is it just less efficient? And, if so, how can I use concommands without allowing players to use the command. Does the handler or the command need a check to see if the player is trying to execute it? Or is there a special concommand type that can only be executed through code. ( I use datastream to give players a gun, with a certain amount of ammo through their client script through a derma menu. I don't want the player to be able to use a concommand to bypass my points system, and I don't know how to stop them with concommands!!!)
Thanks, I want to use the best method, but I spent much too long trying to do this with concommands, and I finnaly gave up about a week ago, then discovered datastream.
[QUOTE=Rayjingstorm;24812507]Why is datastream so horrible, is it just less efficient? And, if so, how can I use concommands without allowing players to use the command. Does the handler or the command need a check to see if the player is trying to execute it? Or is there a special concommand type that can only be executed through code. ( I use datastream to give players a gun, with a certain amount of ammo through their client script through a derma menu. I don't want the player to be able to use a concommand to bypass my points system, and I don't know how to stop them with concommands!!!)
Thanks, I want to use the best method, but I spent much too long trying to do this with concommands, and I finnaly gave up about a week ago, then discovered datastream.[/QUOTE]
If you're using datastream, there is nothing stopping a client from sending data by itself (this is analogous to just manually running a concommand).
If you expect some sort of security with datastream, you're misunderstanding the concept.
You need to validate the actions taken by the client on the server.
For example, say you have a store NPC which runs the concommand "open_store" when you press use on it.
On the server side of things, you must check if the client is close enough to this NPC, has privileges to access it, is alive, etc.
This is no different than having datastream handle this. You still need to perform the same validation.
[QUOTE=Rayjingstorm;24812507]
I don't want the player to be able to use a concommand to bypass my points system, and I don't know how to stop them with concommands!!!)
[/QUOTE]
This is a fatal mistake. There is no security by simply using datastream. I could create my own client side script to perform the same actions yours does, and give myself more ammo than normally possible. (Assuming that you're really not doing any checks. Shame on you.)
The server must [i]always[/i] validate the client action for both systems.
[QUOTE=VoiDeD;24813626]If you're using datastream, there is nothing stopping a client from sending data by itself (this is analogous to just manually running a concommand).[/QUOTE]
That, and for server to client stuff it sends the data in three separate usermessages. That makes it much slower. The average usermessage takes about 0.1 to 0.3 seconds to make it to the client depending on the data being sent. Multiply by three and try to send a table via datastream, transfers could take up to a whole second or more. Taking that long for things such as network synchronization is generally a bad thing.
[QUOTE=grea$emonkey;24813947]Multiply by three and try to send a table via datastream, transfers could take up to a whole second or more. Taking that long for things such as network synchronization is generally a bad thing.[/QUOTE]
It doesn't work like that. It's easily possible to send more than 200 user messages per second.
Sorry, you need to Log In to post a reply to this thread.