Topic: On Connection Disconnect Declare Other Player Win

Hello everyone, I hope everyone here doing great. I have a question, can we implement win/lose situation on connection disconnection? Like let's say when 2 players game online and one player disconnects. For now what happens that it simply appears disconnect panel but what i want the player which is in room it make that player win. How can we achieve this? which script and where should I make changes in the project?
Thanks

Share

Thumbs up Thumbs down

Re: On Connection Disconnect Declare Other Player Win

You can subscribe to the MultiplayerAPI event "OnPlayerDisconnectedFromMatch" like so:

void Start()
{
    UFE.MultiplayerAPI.OnPlayerDisconnectedFromMatch += this.OnPlayerDisconnectedFromMatch;
}

Then create a function that calls a set of functions to emulate the end of a match:

void OnPlayerDisconnectedFromMatch()
{
    // Declare Local Player as Winner
    ControlsScript winner = UFE.GetControlsScript(UFE.GetLocalPlayer());

    // Fire Game Ends Event
    UFE.FireGameEnds(winner);

    // Play Game Won Outro Animation
    UFE.GetControlsScript(UFE.GetLocalPlayer()).SetMoveToOutro(2);

    // Call for End Game and open menu a few seconds later
    UFE.DelaySynchronizedAction(UFE.MatchManager.EndMatch, UFE.config.roundOptions._endGameDelay);
}

On a side note:
You might need to override how UFE handles disconnections. Under file ConnectionHandler.cs, comment line 19 like so:

//UFE.MultiplayerAPI.OnPlayerDisconnectedFromMatch += this.OnPlayerDisconnectedFromMatch;

This will prevent UFE from also disconnecting the local player from the room.

Like UFE? Please rate and review us on the Asset Store!
Questions about the Forum? Check out our Karma FAQ.