Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   timevar2 question (https://forums.graalonline.com/forums/showthread.php?t=134264413)

furry_mougle 08-30-2011 03:58 AM

timevar2 question
 
i'm utilizing timevar2 for a renting system, however i've come into a problem when comparing rentTime to timevar2. essentially if you do something like this

PHP Code:

function onActionRentTime(){

  
rentTime timevar2 6// somewhat stupid comparison

  
if( timevar2 >= rentTime ){
    
player.chat "Rent expired!";
  }
  


timevar2 is always incrementing, so there is no real way to compare the var rentTime to timevar because it'll always be greater than 6. (since it always increments). however, if there was a way to freeze the current timevar and THEN compare it to 6 and wait for the incrementing timevar to get over 6, thus leading the rent to expire that would be a much greater solution.

so, is there a way to freeze the current timevar2/ record it somehow?

Mark Sir Link 08-30-2011 04:01 AM

Quote:

Originally Posted by furry_mougle (Post 1666174)
i'm writing a renting-system script, however i've come into a problem when comparing rentTime to timevar2. essentially if you do something like this

timevar2 is always incrementing, so there is no real way to compare the var rentTime to timevar because it'll always be greater than 6. (since it always increments). however, if there was a way to freeze the current timevar and THEN compare it to 6 and wait for the incrementing timevar to get over 6, thus leading the rent to expire that would be a much greater solution.

so, is there a way to freeze the current timevar2 or record it somehow?

??

you seem to have answered your own question within the script.

PHP Code:

function onActionRentTime(){
  
this.rent_time timevar 26;
  
setTimer(1);
}

function 
onTimeout(){
  if(
this.rent_time <= timevar2){
    
player.chat "Rent expired!";
  }
  
setTimer(1);



fowlplay4 08-30-2011 04:03 AM

When the player rents time in whatever service, store the time when it expires (timevar2+6) in a clientr flag. I.e: clientr.rentexpires

Then all you need to do is check if timevar2 is greater than or equal to clientr.rentexpires and act accordingly.

You don't have to use clientr flags either, if it's a house you can store it in a DB as well.

furry_mougle 08-30-2011 04:10 AM

oh, I thought since the number increments it's always going to be +6, anyway ty! i'm such a silly goose!

fowlplay4 08-30-2011 04:15 AM

Quote:

Originally Posted by furry_mougle (Post 1666177)
oh, I thought since the number increments it's always going to be +6, anyway ty! i'm such a silly goose!

The variable timevar2 always increments but if you store the value of timevar2 in another variable you have (in your terms) froze time in that new variable.


All times are GMT +2. The time now is 06:19 PM.

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