Detect if a player closed their browser?

0 favourites
  • 7 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hi,

    Is there a way to detect if a player closed their browser?

    I am working on a multiplayer game and need a way to check if the other player closed the game tab or their entire browser, if that happens and just before they leave I want an action to be sent to the database informing that the other player left.

    I have checked the Browser object but there is nothing there as far as my knowledge goes, and the end of layout command does not do it either.

    I have a leave button in the game but sometimes people will just close their browser instead, and then there is now way for the other player to know what happened.

    Thanks.

    Regards

    Edgar

  • Don't think it's possible. What you can do is send a ping from each player to the host every couple of seconds or so. If there have been no pings from a peer for some time, you can assume it has disconnected or quit the game.

  • Don't think it's possible. What you can do is send a ping from each player to the host every couple of seconds or so. If there have been no pings from a peer for some time, you can assume it has disconnected or quit the game.

    Thanks for the suggestion dop2000.

    I have been trying to set up something like this for a while but not sure how the condition will be.

    Basically what I'm trying now is this:

    Every 2 Seconds

    - Add 1 To Ping Variable

    - Send Ping To database

    But I'm struggling with what the condition would be to check if there has been no ping from the other player for some time. I only have the action for getting the ping from the database.

    Every 2 Seconds

    - Request Ping

    - Set Ping Variable To Ajax.Last.Data

    Thanks for the help.

    Regards,

    Edgar

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Why AJAX? Are you not using the Multiplayer plugin?

    After receiving every successful ping on the host, you can restart a timer, for example "Player1IsAlive" for 10 seconds. When this timer triggers, this means that the host hasn't received a ping from this player for 10 seconds.

  • Why AJAX? Are you not using the Multiplayer plugin?

    After receiving every successful ping on the host, you can restart a timer, for example "Player1IsAlive" for 10 seconds. When this timer triggers, this means that the host hasn't received a ping from this player for 10 seconds.

    I'm not using the Multiplayer plugin, everything is done with Ajax.

    I looked at your example, but not absolutely sure how to implement it.

    You wouldn't know if there is a way to disable the red cross that closes the game with NW.js applications or playable ad? or even a setting to remove the window around the application? That would be an easy solution, so then the player is forced to click on the leave button.

    Thanks.

    Regards,

    Edgar

  • Not sure how to do using Ajax but the native Multiplayer plugin supports this function.

    You can simply use the conditions like:

    On Peer Disconnected ->

    On Kicked ->

  • Not sure how to do using Ajax but the native Multiplayer plugin supports this function.

    You can simply use the conditions like:

    On Peer Disconnected ->

    On Kicked ->

    Thanks for that shepherdgames, the On Peer Disconnected works as I want it.

    So basically I have just implemented that into my existing framework.

    Thanks.

    Regards,

    Edgar

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)