Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Way to detect when a player logs off? (https://forums.graalonline.com/forums/showthread.php?t=134265856)

Gunderak 02-28-2012 12:19 PM

Way to detect when a player logs off?
 
I have detection for when players log in but not off.
Basically I have coded my own playercount using PHP.
It uses a static image and adds text to it dynamically when players log on.
If no one logs on it updates every 5 minutes by requesturl.
Anyway here is the image for anyone that's interested.
I might release the source if people want it.
Also is there a way to detect when RC players log on?
http://wr3ckless.net/text/playercount.png
http://wr3ckless.net/text/playercount.png

jamitsu89 02-28-2012 01:29 PM

Considering you already have the framework for the update every 5 minutes, you can just do something similar to:

NPC Code:

function checkPlayers() {
for (temp.pl : allplayers) {
if (temp.pl.level.size <= 0) {
//This is an RC
temp.rccount ++;
} else {
//This is a player
temp.pcount++;
}
}
//Then store temp.rccount and temp.pcount here
}



Also possibly onPlayerLogout()

Gunderak 02-28-2012 02:19 PM

I already have something very similar to that to check for players
it's just how to check when they log on to RC or off of RC or log off of the server.
I would prefer to update it when players leave or enter rather than every 5 minutes.
This way it's more accurate.
Thanks for the help and I'll look into onPlayerLogout() Possibly onPlayerlogout()

xXziroXx 02-28-2012 03:19 PM

Quote:

Originally Posted by Gunderak (Post 1686272)
Also is there a way to detect when RC players log on?

PHP Code:

function onPlayerLogin(temp.object)
{
  
// Let's check if it's a player object to begin with. I could be mistaken, but I vaguely remember IRC channels or something triggering this.
  
if (temp.object.account == "")
    return;
  
  
// Ok, it's a player. Let's check if it's an RC or not by reading the level name.
  
if (temp.object.level.name == "") {
    
// Not in a level, must be an RC!
  
}
  else {
    
// The player is in a level, so it's not an RC.
  
}


Substitute onPlayerLogin with onPlayerLogout for the other way around.

cbk1994 02-28-2012 03:51 PM

No reason to read the level name string, just check the level object.

PHP Code:

if (temp.pl.level == null) { // it's an RC! 


BlueMelon 02-28-2012 03:52 PM

Updating every 5 minutes is a good standard in my opinion. You don't want someone logging in, logging out and sending a request every 1 second either... You should have a delay.

If you cant do it any other way, last resort would be to check the size of 'allplayers' and compare to the previous size on a loop. If its changed, obviously someone has logged out/in.

Gunderak 02-28-2012 11:47 PM

Considering it would use about 1kb bandwidth to communicate with the PHP script, it's not a big deal if someone logs off then on.
As I said, I want it to be as accurate as possible.
Thanks for all the help.


All times are GMT +2. The time now is 05:59 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.