Jump to content

Removing character selection on disconnecting from a server


Recommended Posts

So I'm trying to create a scenario where anyone who joins the server, even if they have played on the server previously, is forced to pick a new character and respawn as if it was their first time joining. 

I imagine the cleanest way to do this would be to run   TheWorld:PushEvent("ms_playerdespawnanddelete", player)   as the player disconnects, but haven't been able to get this to work because  TheWorld:PushEvent("ms_playerdespawn", player)  is already pushed as soon as the player disconnects, and so I'm pretty sure it's trying to delete the player twice. It doesn't crash, but the main menu becomes frozen in time and breaks the game until you restart.

If I can't get the character to be removed on disconnecting, another lazy alternative would be to just despawnanddelete a player whenever they connect to the server with an existing character. Unfortunately, "ms_playerjoined" happens any time a player spawns, regardless of if it's their first time picking a character, reconnecting to an existing one, or respawning as a new character within the same session.

So I'm kind of unsure where to go from here. Maybe there are some other events that I'm not familiar with, but I don't do a whole lot with server events so I'm hoping someone will know more than I do.

  • Like 1
Link to comment
Share on other sites

Oh, yea that would be a pretty simple way to do it. Thanks!

I'm sure your method would have worked, but I realized recently that despawning the player after joining would cause other issues with other parts of the mod, so I had to find an alternative.

I did finally figure out how to despawn them as they leave though. Attaching  "DeleteUserSession(inst)"  to a the playercommon's OnDespawn function does the trick for everyone except a local host. Luckily, this doesn't need to apply to the host, so it works out well for me.

  • Wavey 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...