Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences here.
×
×
Cookie Preferences
We use Cookies to help personalize and improve Roll20. For more information on our use of non-essential Cookies, visit our Privacy Policy here.
I see "ready" as an event for the initialization of a campaign. Is there an appropriate event for leaving a campaign that I can use to do some housekeeping to make sure the campaign is in an appropriate state for the next time it loads up?
Probably the best you could do is monitor the online status of the players and act when the last one turns to false. My MotD script watches that value to trigger the Message of the day.
Thanks, Aaron. So like... change:player:online? Just track that with state and call a function when its empty? Or maybe just do a: if(findObjs({ _type: "player", _online: true }) == undefined){} I forget what the found nothing return is. I tested at some point. What do you think would be better? I'm open to suggestions. For the most part, I just need to toggle a state boolean so some functions don't try to handle all the add: events when the campaign loads.
Jonathan S. said: if(findObjs({ _type: "player", _online: true }) == undefined){} I forget what the found nothing return is. I tested at some point. findObjs always returns an array. If no objects were found, the length of the array will be 0. What I usually do is access element 0 of the array immediately (since most of the time I'm only interested in one object found), and then check it for a falsey value. In other words: var player = findObjs({ type: 'player', name: playerName })[0]; if (player) { // Player exists }
Just to clarify-- a player object will persist so long as a player has at some point joined himself to a campaign-- whether he's currently online or not? And, thus, the relevance of the _online property when trying to detect who's actually logged into the campaign at any given time? The player object isn't removed when the player logs off? Right?
Certainly, the player logging off doesn't remove the object. I've never checked on players actually leaving a game (I've actually never had that happen that I can remember.). Probably I would add an on('change:player:_online', function(){}) handler ( Note : you must have the _ here or it won't work ), then when the event occurs, get all of the player objects and make sure they are all false, then do your logic for shutdown.