I'm sending a message from the client to the server as you can see here:
[CODE]DButton.DoClick = function()
net.Start("IPAddressGiver")
--net.WriteType(k)
net.WriteString("Testing, 123 net received")
net.SendToServer()
LocalPlayer():ConCommand("connect " .. k.. ";password "..table.concat(ppoppassword,"",v, v ))
end[/CODE]
This is the serverside of the stuff:
[CODE]if SERVER then
util.AddNetworkString("IPAddressGiver")
net.Receive("IPAddressGiver", function()
--MsgN( net.ReadType() )
MsgN( net.ReadString() )
end)[/CODE]
Whatever I do, it won't reach the server :/
What server are you trying to send it to? Because you can only send it to the current one.
Make sure that net.Receive code is actually ran.
[QUOTE=Robotboy655;50186295]What server are you trying to send it to? Because you can only send it to the current one.
Make sure that net.Receive code is actually ran.[/QUOTE]
I'm trying to run it on the current server, just from client to server, not to another server.
Those lines of code are in the autorun so I assume they're loaded :P
No errors? Is [I][B]LocalPlayer():ConCommand(...)[/B][/I] working? I mean, are you sure, that its the button you want to press?
[QUOTE=Shadow2hel;50186298]Those lines of code are in the autorun so I assume they're loaded :P[/QUOTE]
Well they should be... Could you post a bit more code maybe? I have no clue why this wouldn't be working
That's because you have DButton.DoClick.
Try naming your button something else, like 'myButton' and see if it works then.
[QUOTE=iJohnny;50186315]No errors? Is [I][B]LocalPlayer():ConCommand(...)[/B][/I] working? I mean, are you sure, that its the button you want to press?[/QUOTE]
No errors at all, and yes this is the button that I want to press.
I'm not sure if you could've derived it from the ConCommand, but this is actually the serverhopper addon and I'm trying to find a way to actually post a message of which server the player's going to join.
[QUOTE=MPan1;50186316]Well they should be... Could you post a bit more code maybe? I have no clue why this wouldn't be working[/QUOTE]
I cannot due to the fact that it's an addon from scriptfodder called Server Hopper
[QUOTE=Netheous;50186318]That's because you have DButton.DoClick.
Try naming your button something else, like 'myButton' and see if it works then.[/QUOTE]
Trying it with JBUTTON right now..
Edit: Nope, still the same.
Did you do a map change? - Sometimes fixes my issue with net strings.
Also, is your file even executing, do you see the button? - do you load the file via console command such as openscript or does it load automatically?
Also is it located in autorun or autorun/server, autorun/client?
[QUOTE=Netheous;50186318]That's because you have DButton.DoClick.
Try naming your button something else, like 'myButton' and see if it works then.[/QUOTE]
:snip:
Wow, gmod is really odd
[QUOTE=Netheous;50186344]Did you do a map change? - Sometimes fixes my issue with net strings.
Also, is your file even executing, do you see the button? - do you load the file via console command such as openscript or does it load automatically?
Also is it located in autorun or autorun/server, autorun/client?[/QUOTE]
I restarted the server for every change.
The file is located in autorun, not /autorun/server or /autorun/client.
[QUOTE=MPan1;50186346]How would that make the slightest bit of difference? It's not like you can change the actual core metatable of the DButton just by doing that[/QUOTE]
It would if he had an addon that uses globals for elements and isn't as creative with naming either.
I've seen that happen - someone had a HUD with buttons and whenever he hit button that was supposed to open inventory, it voted for mayor instead.
print("Iwork")
net.Start()
and
print("serverworkstoo!")
net.Receive( ...
Check if your net functions are being ran.
[QUOTE=Robotboy655;50186366]print("Iwork")
net.Start()
and
print("serverworkstoo!")
net.Receive( ...
Check if your net functions are being ran.[/QUOTE]
Adding print on top of 'DoClick' would also help.
[QUOTE=MPan1;50186346]How would that make the slightest bit of difference? It's not like you can change the actual core metatable of the DButton just by doing that[/QUOTE]
You actually can:
[img]http://i.imgur.com/TVyhuSo.png[/img]
[img]http://i.imgur.com/bBeVmRC.png[/img]
[QUOTE=MPan1;50186346]How would that make the slightest bit of difference? It's not like you can change the actual core metatable of the DButton just by doing that[/QUOTE]
You're going to override the default functionality of DButton and not the actual instance unless that variable is just a local.
[QUOTE=Robotboy655;50186366]print("Iwork")
net.Start()
and
print("serverworkstoo!")
net.Receive( ...
Check if your net functions are being ran.[/QUOTE]
This just prints serverworkstoo upon startup twice.
iworktoo doesn't seem to wanna print even if I press the button, but I can tell that the button works because I still join a server if I click the corresponding button.
Well then clearly your problem is sending the net message, so look into problems in that code.
[QUOTE=Shadow2hel;50186463]This just prints serverworkstoo upon startup twice.
iworktoo doesn't seem to wanna print even if I press the button, but I can tell that the button works because I still join a server if I click the corresponding button.[/QUOTE]
It should print clientside.
Add a timer to your connection, so it connects after 5 seconds - maybe it connects before message is sent.
Is it at all possible that you put "if SERVER then" inside the client-side part of the code?
In order for it to work you need to specifiy the network channel on startup serverside.
[URL]https://wiki.garrysmod.com/page/util/AddNetworkString[/URL]
[CODE]util.AddNetworkString( "The string I want to use net.Start with " ) [/CODE]
[B]Edit:[/B][B] Just noticed you do have this.. , Although to add..you shoulnt have the network stuff in a shared file, just purely a server file. I usually just use my own "data.lua" that i include in init.lua[/B]
You should also just use net.WriteTable, and make sure youve stuffed all your arguments into a table. if your packing a string and a table together you can stuff that into one table and then upon receiving it do [CODE]unpack(sendTable)[/CODE]
Also for example,
[CODE]local tableToSend = {
"Test string", testStringVariable, {tableVariable1,"someStringInTable"}, thisTableName = {someVariable,"the tableName is used to access like such, TableToSend['thisTableName']"}
}
//net stuff
net.WriteTable(tableToSend)
//net stuff
//receive part
local args = net.ReadTable
//Just use the table, or you can unpack if you really want..useful for chat.AddText stuff
args = unpack(args)
[/CODE]
I don't know how, but I finally managed to do it!
The message is finally reaching the server and I've reached my goal :)
[img]http://i.imgur.com/iIMIxBF.jpg[/img]
you know, if you needed help with my addon, you could probably add me on steam and ask?
seeing as that is code directly from my server hopper on scriptfodder anyways.
And my god do i need to fix the padding on the server list XD, DERP
The problem is, scriptfodder was down so I had no way to contact you, I'll add you right now :P
-snip-
Out of curiosity did it have anything to do with the fact that the player disconnects to go to the new IP before the net message has had time to completely send?
I do not remember, there was a MUCH easier way to do this as the table of servers is sent to the client already and the server was already named, so all he had to do was send the netmessage with a single integer and he could get the name automatically instead of sending an entire string for no reason
Sorry, you need to Log In to post a reply to this thread.