PlayerDisconnected doesn't get called at last player?

So I am hosting a local server and for some reason it is not getting called when I reconnect as the only player on the server. But it does work when other players join me.


mayorapplicants = {}

local function disconnectedapplicant(ply)
	local applicantentity = ply
	local applicantname = applicantentity:Nick()
	local applicantid = applicantentity:SteamID()
	if table.HasValue(mayorapplicants, applicantentity) then
		for k, v in pairs(mayorapplicants) do
			if v == applicantentity then
				table.remove(mayorapplicants, k)
				for k, v in pairs(player.GetAll()) do
					GAMEMODE:Notify(v, 3, 4, applicantname.." has disconnected and was automatically signed out of mayor.")
				end
			end
		end
		net.Start("sendnewmayortable")
		net.WriteTable(mayorapplicants)
		net.Broadcast()
	end
end
hook.Add("PlayerDisconnected", "disconnectedapplicant", disconnectedapplicant)

That’s because the server shuts down when you disconnect.

No, I am using the retry command which only makes the client reconnect.

retry = server restart, you did not leave

How about you try it yourself?

Why don’t you stop using a single player server, and click the “2 player” option instead?

Please re-read my thread. I clearly said, it works fine when a player joins; which states it’s not on singleplayer.

When you run the command “retry” the first thing happens is that the process for the server is killed, thus the hook will not be killed. If you leave the server it will probably end up being the same. I hardly doubt Garry will fix this.

Why not use the ShutDown hook instead?

… I am not sure how can I even explain this to you anymore. Retry only affects the CLIENT. Not the SERVER.

Garry’s Mod development isn’t made for local servers, the only thing I suggested was ShutDown hook, which you completely disregarded. Download srcds, and make a proper server and stop complaining about issues you’re experiencing due to your actions.

Try this http://wiki.garrysmod.com/page/gameevent/Listen

Just to make it clear, Deathtitan77, are you using a local SRCDS server or a multiplayer ingame option?

He said in the OP that it’s a ‘local’ server, which usually means a listen server (without SRCDS, that is).

[editline]14th September 2013[/editline]

OP, are you using SRCDS or not?

Nope, I am not using SRCDS.

Well then your server is shutting down when you disconnect, whether you like it or not. Even when using ‘retry’.

It is not. Please try it yourself before you post wrong information. I have always used this command and I know it works.

Here is a basic tutorial on how to try it:

  1. Start your server with like 2+ players.
  2. Spawn a prop.
  3. Type retry in console.
  4. Prop WILL still be there.

Welp, you’re actually right, my apologies.

It’s okay, just try to get your facts right before you post. Think of what you type before you press the submit button.

[editline]14th September 2013[/editline]

Thanks for this.

Maybe the Lua state is recreated? Try making a variable and see if it persists.

Lua state is recreated. It isn’t called because you aren’t disconnecting. You’re just reloading clientside Lua in a Listen server.

Try making an EntityRemoved hook. That’s much more reliable for DC because it includes timeouts and all the whole spectrum.

[lua]
hook.Add(“EntityRemoved”, “Blah”, function(ent)
if ent:IsPlayer() then
–your code.
end
end)
[/lua]