View Single Post
  #17  
Old 08-26-2011, 04:59 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
Quote:
Originally Posted by callimuc View Post
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"3232);
}

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 View Post
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).
__________________
Reply With Quote