Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Check when a player was last seen (https://forums.graalonline.com/forums/showthread.php?t=134258334)

DustyPorViva 03-11-2010 12:17 AM

Check when a player was last seen
 
This little script can show you when a player was last seen on a server. Seems to work from my testing.

A few variables to note:
temp.timeoffset = minutes to offset the time by. This was tested on UN, so I had to offset the time by 23 minutes.

temp.timezone = hours to offset for timezone. I had it set up to 5 to match GMT time.

The above may be wrong, however. It doesn't seem right to ADD the offset of time, as that means the clocks are behind and they're typically ahead... but whatever. Also, account names are case sensitive. This has to do with the way offline player objects are loaded, and really beyond my control unless anyone can come up with a fix.

PHP Code:

function onPlayerLogout(pl) {
  
pl.clientr.seenlast timevar2;

  
// HMM, BACKUP IN CASE ABOVE FAILS?
  
temp.loadedacc = new TServerPlayer((@pl.account));
  
loadedacc.clientr.seenlast timevar2;
  
loadedacc.destroy();
}

function 
onActionServerside(cmd,acc) {
  if (
cmd != "LastSeen") return;

  
temp.pl = new TServerPlayer((@acc)); // LOAD OFFLINE PLAYER OBJECT

  // IF PLAYER HAS NO RECORDS OF LOGIN, GIVE ERROR AND RETURN
  
if (pl.clientr.seenlast == 0) {
    
player.chat acc SPC "has no login records.";
    
pl.destroy();
    return;
  }
  
  
temp.timezone 5;    // TIMEZONE OFFSET, 5 = GMT
  
temp.timeoffset 23// MINUTES OFFSET TO COMPENSATE FOR SHODDY SERVER CLOCKS

  // COMPILE RETURN MESSAGE
  
temp.time = (findplayer(acc) == null pl.clientr.seenlast timevar2)+(timeoffset*60+(timezone*60*60));
  
temp.msg acc " was last seen:" 
             
SPC formatTimeString("%D %I:%M%p",time)
             
SPC "gmt" SPC (findplayer(acc) == null "" "[logged in]");

  
player.chat msg;          // ECHO TO PLAYER'S CHAT
  
player.sendrpgmessage(msg); // ECHO TO PLAYER'S F2 WINDOW

  
pl.destroy(); // DESTROY PLAYER OBJECT WHEN DONE
}
//#CLIENTSIDE
function onPlayerchats() {
  if (
player.chat.starts("/lastseen")) {
    
temp.acc player.chat.substring(10);
    
triggerServer("gui",name,"LastSeen",acc);
  }



cbk1994 03-11-2010 12:20 AM

PHP Code:

function onPlayerLogout(pl) { 
  
pl.clientr.seenlast timevar2

  
// HMM, BACKUP IN CASE ABOVE FAILS? 

This will always fail. The player object given is read-only at this point.

Also, why are you creating the player object even if the player is online? o.o

DustyPorViva 03-11-2010 12:21 AM

Quote:

Originally Posted by cbk1994 (Post 1561701)
PHP Code:

function onPlayerLogout(pl) { 
  
pl.clientr.seenlast timevar2

  
// HMM, BACKUP IN CASE ABOVE FAILS? 

This will always fail. The player object given is read-only at this point.

Also, why are you creating the player object even if the player is online? o.o

I was originally not doing so, as I had a check to return if the player was online but I had removed it and didn't bother to clean up.


All times are GMT +2. The time now is 10:04 PM.

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