Page 1 of 1

Whats wrong with my onlineTimer? :)

Posted: Mon Apr 27, 2009 11:15 am
by Damien.
Hello once again.. I was trying to create an onlinetimer that would count how many seconds (then convert to minutes) that you have been online but it seems like I can't get it working no matter what. The #logontime property wont be reseted everytime I logoff, which is odd, and the onlineTime/#logontime sums are way higher than it should be. This is how the script looks like:

Logon.src

Code: Select all

SetObjProperty(mobile, "#logontime", ReadGameClock());
Start_Script(":onlineTime:onlineTimer", mobile);
onlineTimer.src

Code: Select all

use uo;
use os;

program online_timer()

while(1)
	foreach character in EnumerateOnlineCharacters()
	var startTime := GetObjProperty(character, "#logontime");
		if(!startTime)
			SetObjProperty(character, "#logontime", ReadGameClock());
		endif
	var onlineTimer := GetObjProperty(character, "onlineTimer");
		if(!onlineTimer)
		onlineTimer := 0;
	endif
			SetObjProperty(character, "onlineTimer", startTime+onlineTimer);
	endforeach
Sleep(300);
endwhile
endprogram
Logoff.src

Code: Select all

EraseObjProperty(mobile, "#logontime");
Thanks :angel:

Re: Whats wrong with my onlineTimer? :)

Posted: Mon Apr 27, 2009 11:26 am
by *Edwards
Here is an exemple:

pkg/other/statistics

from my set:

http://forums.polserver.com/viewtopic.php?f=8&t=2607

You might get enough informations for your own business. Also note that the Profile journal has been if you look in the packet folder.

Re: Whats wrong with my onlineTimer? :)

Posted: Tue Apr 28, 2009 3:24 am
by OWHorus
[quote="Damien."]Hello once again.. I was trying to create an onlinetimer that would count how many seconds (then convert to minutes) that you have been online but it seems like I can't get it working no matter what. The #logontime property wont be reseted everytime I logoff, which is odd, and the onlineTime/#logontime sums are way higher than it should be. This is how the script looks like:

Logon.src

Code: Select all

SetObjProperty(mobile, "#logontime", ReadGameClock());
Start_Script(":onlineTime:onlineTimer", mobile);
Hello,

actually the variable '#logontime' should be enough. If you set #logontime every time somebody logs on, then the onlinetime is always
var onlinetime := ReadGameClock() - CInt(GetObjProperty(mobile, "#logontime"));

since the game clock ticks always up and is never reset. You should only change the property '#logontime' during logon, and the onlinetime is only valid, if the mobile is currently online. If the mobile is offline, this method does not work, and delivers wrong values (actually it counts the time since last logon).

The line above is not optimal, since there is no check for a missing property, this would lead to massively wrong values. The following code snippet will work better:

Code: Select all

...
var onlinetime := GetObjProperty(mobile, "#logontime");
if (onlinetime == error)
  // Property not found - error handling
  syslog("Mobile "+mobile.name+", "+mobile.serial+" had no logontime set");
  // best correction possible at this time
  onlinetime := ReadGameClock();
  SetObjProperty(mobile), "#logontime", onlinetime);
endif
onlinetime := ReadGameClock() - CInt(onlinetime);
...
Hope this helps :-)

Horus