Hi,
I try to reconnect the player to a server when the player died (client side)
But when I execute the command "connect". I have an error:
Bad server address ("MyIP")
But the server ip is good.
I think the command send this error when called in a Hook because otherwise the command work in main menu. Any solution ?
[code]
gameevent.Listen( "entity_killed" )
hook.Add( "entity_killed", "entity_killed_example", function( data )
RunConsoleCommand("connect", "MyIP")
end )
[/code]
[url=http://wiki.garrysmod.com/page/Global/RunConsoleCommand]RunConsoleCommand[/url] inserts quotations (") around each given argument, which in the case of the [I]connect[/I] ConCommand, the Engine doesn't like it. Use [url=http://wiki.garrysmod.com/page/Player/ConCommand]Player:ConCommand[/url] instead.
Your original code is going to make the Player connect to the IP as soon as [B]any[/B] Player or Entity is killed however. The below changes should correct that and the IP issue:
[CODE]gameevent.Listen( "entity_killed" )
hook.Add( "entity_killed", "entity_killed_example", function( data )
local ply = LocalPlayer()
if data.entindex_killed == ply:EntIndex() then -- We use this if statement to check the Killed Entity is the Local Player.
ply:ConCommand("connect "..MyIP) -- We use 'Player:ConCommand' here instead of 'RunConsoleCommand'.
end
end )[/CODE]
This is also assuming 'MyIP' is supposed to be a variable holding the actual IP address. If you just removed the actual IP address for the purpose of this post and 'MyIP' is actually a raw IP address, use the following instead:
[CODE]ply:ConCommand("connect 127.0.0.1:27015") -- Replace the IP address with your own desired.[/CODE]
Thanks it's work for the hook entity_killed but not shutdown (I need this hook also). Only RunConsoleCommand works with the shutdown hook I think.
[code]
hook.Add( "ShutDown", "shutdown", function( )
--RunConsoleCommand("connect", "ip") //reconnect but error Bad server address ("ip")
LocalPlayer():ConCommand("connect " .. "ip") //doesn't reconnect, do nothing
end )
[/code]
Is there a solution ? Is it a bug ?
[QUOTE=azerty2016;50673094]Thanks it's work for the hook entity_killed but not shutdown (I need this hook also). Only RunConsoleCommand works with the shutdown hook I think.
[code]
hook.Add( "ShutDown", "shutdown", function( )
--RunConsoleCommand("connect", "ip") //reconnect but error Bad server address ("ip")
LocalPlayer():ConCommand("connect " .. "ip") //doesn't reconnect, do nothing
end )
[/code]
Is there a solution ? Is it a bug ?[/QUOTE]
What is 'ip'? Is it a variable holding the actual IP Address, or is there normally an IP Address in its place, but you're replacing it with that for the purpose of posting here?
I've never tried having a Client (re)connect to an IP in a ShutDown hook before. It's possible that your code is working, but simply inoperational due to the game's design because when a Client disconnects from a server, they don't want to be reconnected or taken to another one without consent. Why do you want to do this, might I ask? Same for having the Client (re)connect to an IP if they die?
Why not use "retry" to reconnect?
Also the error
[QUOTE]Bad server address ("MyIP")[/QUOTE]
Means you tried to execute "connect MyIP" .. you need a valid IP.
Thanks "retry" works.
Sorry, you need to Log In to post a reply to this thread.