Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 08-26-2011, 04:51 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
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.
__________________
MEEP!
Reply With Quote
  #17  
Old 08-26-2011, 04:55 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to 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.

Then every time they log in(or in the jail level, in a loop) do something like:

PHP Code:
if (timevar2 clientr.jailtime[0] + clientr.jailtime[1]) {
  
// JAIL TIME OVER!

Alternatively you can have a DBNPC that handles all jailings.

Not only would doing this clientside yield undesired results, it would also be extremely insecure. I wouldn't trust the clientside to handle any of it, if it's meant for a jailing system.
Reply With Quote
  #18  
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
  #19  
Old 08-26-2011, 08:51 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by cbk1994 View Post
Why are you adding the time the player has remaining to timevar2...?
Thought after relogging the this.bla get "resetted". Or did I missunderstood something?
__________________
MEEP!

Last edited by callimuc; 08-26-2011 at 09:18 PM..
Reply With Quote
  #20  
Old 08-26-2011, 08:56 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by cbk1994 View Post
Why bother with storing the length at all? Why not just store the time they get out?
*shrug* could be useful to tell when they were jailed, no?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.