Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-11-2010, 12:17 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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);
  }

Reply With Quote
  #2  
Old 03-11-2010, 12:20 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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
__________________
Reply With Quote
  #3  
Old 03-11-2010, 12:21 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:40 PM.


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