Whats wrong with my onlineTimer? :)

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Damien.
Journeyman Poster
Posts: 63
Joined: Thu Feb 08, 2007 11:14 am

Whats wrong with my onlineTimer? :)

Post 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:
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm

Re: Whats wrong with my onlineTimer? :)

Post 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.
OWHorus
Grandmaster Poster
Posts: 106
Joined: Sat Feb 04, 2006 1:24 pm

Re: Whats wrong with my onlineTimer? :)

Post 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
Post Reply