Quote:
Originally Posted by callimuc
PHP Code:
//#CLIENTSIDE function onCreated() { client.two = 3600; //one hour onTimeOut(); } function onTimeOut() { client.one = timevar2; client.two--; client.three = client.one + client.two; player.chat = client.three; settimer(1); }
Didnīt test it yet, something looks strange for me (couldnīt find something) but I still think this should work.
|
Why are you adding the time the player has remaining to
timevar2...?
PHP Code:
function onTimeOut() {
player.timeRemaining --;
if (player.timeRemaining <= 0) {
// free player
} else {
this.setTimer(1);
}
}
This is all you need if you're using a timer.
Also, things like this should never be done clientside. If you absolutely must use a timeout for each player, it should probably be done in a serverside class joined to the player.
To use timevar2, you'll want to do something like this (in a player class for this example):
PHP Code:
function onCreated() {
// player logs in
if (this.isInJail()) {
// player is still jailed, warp to jail
this.warpToJail();
} else if (this.level.name == "jail.nw") {
// player is in jail.nw, but time has expired
this.unstick();
}
}
public function jailPlayer(temp.seconds) {
this.jailedUntil = timevar2 + temp.seconds;
this.warpToJail();
// schedule an event in case the player is still online when the time
// expires
this.cancelEvents("onJailTimeExpired"); // in case there was already an event
this.scheduleEvent(temp.seconds, "onJailTimeExpired");
}
public function warpToJail() {
this.setLevel2("jail.nw", 32, 32);
}
function onJailTimeExpired() {
this.freeFromJail();
}
public function isInJail() {
return this.jailedUntil > timevar2;
}
public function freeFromJail() {
this.jailedUntil = 0;
this.cancelEvents("onJailTimeExpired"); // in case there was still an event pending
this.unstick();
}
Quote:
Originally Posted by DustyPorViva
If you want a timer to keep track of how long even while the player is offline you'll simply need to compare timevar2's.
When you jail the player, save a clientr of the current timevar2(on serverside) and time to stay jailed. For example: clientr.jailtime = {timevar2,days*24+hours*60+minutes*60}; Days, hours and minutes are simply representing real time you want them to be jailed.
|
Why bother with storing the length at all? Why not just store the time they get out?
Also, that length calculation is totally wrong (days*24+hours*60+minutes*60).