[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