Author Topic: Need help checking time  (Read 831 times)

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Need help checking time
« on: December 02, 2016, 08:01:06 pm »
Using onTimeChange, how can I tell if five minutes have passed? I don't mind whether it's a multiple of five (5, 10, 15, etc.) or just each five (2, 7, 12, 17, etc.).

</noob> :-[

JamesConway

  • Newbie
  • *
  • Posts: 38
  • Karma: +9/-3
    • View Profile
Re: Need help checking time
« Reply #1 on: December 02, 2016, 08:08:25 pm »
Save a time, then check every onTimeChange if 5 mins has passed with the saved time and then save the new time when 5 mins passed?

Motley

  • Full Member
  • ***
  • Posts: 240
  • Karma: +32/-33
    • View Profile
Re: Need help checking time
« Reply #2 on: December 03, 2016, 02:15:10 am »
This is my very first time using that function. I have other methods.


But Theremin, Did someone do the wiki wrong for that page?? I did a shit load of testing on that function until I grew lazy and bored.

Hear is the real output of that function.
unless I some how fucked up

Code: [Select]
Minute <- 0;
Hour <- 0;
Second <- 0;

function onTimeChange( Min, Sec )
{

    Minute = Min;
    Second = Sec;

    // Now lets create the Hour check
    if ( Minute == 60 )
    {
        // Increase the hour
        Hour++;
    }

     print("Hour: " + Hour + " Minute: " + Minute + " Second: " + Second);

     return true;
}
« Last Edit: December 03, 2016, 02:17:14 am by Mötley »

Vortrex

  • Full Member
  • ***
  • Posts: 265
  • Karma: +54/-70
    • View Profile
Re: Need help checking time
« Reply #3 on: December 03, 2016, 02:39:00 am »
Uhhhhh ...

I don't think onTimeChange measures seconds. It's only hours and minutes.

By default, the game clock increments a minute of in-game time for every second of real time. Every 60 seconds is one hour in-game, which means that 24 minutes is 24 hours in-game.


Motley

  • Full Member
  • ***
  • Posts: 240
  • Karma: +32/-33
    • View Profile
Re: Need help checking time
« Reply #4 on: December 03, 2016, 02:41:36 am »
I could never return hours and minutes by default, This function ran this print by default as well , Do you mind running this code and watching the console  :), I would love to be proven wrong.

Vortrex

  • Full Member
  • ***
  • Posts: 265
  • Karma: +54/-70
    • View Profile
Re: Need help checking time
« Reply #5 on: December 03, 2016, 02:49:50 am »
That does t make any sense. Did you read my post? What we know as seconds in life are actually minutes in game

Sent from my Nexus 4 using Tapatalk


Motley

  • Full Member
  • ***
  • Posts: 240
  • Karma: +32/-33
    • View Profile
Re: Need help checking time
« Reply #6 on: December 03, 2016, 03:02:39 am »
Do you think that it's because I am not using any-type of time-lock? I went in-game and did some checking out and my minutes are moving in seconds, and hours by minutes

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: Need help checking time
« Reply #7 on: December 04, 2016, 04:18:18 pm »
Motley your code doesn't work, even if you change it you'll never be able to calculate real time that way, because one hour is 2.5 days in game.

Save a time, then check every onTimeChange if 5 mins has passed with the saved time and then save the new time when 5 mins passed?
Yeah, that's a way to do it, and it's exactly where i'm stuck, I'd be really grateful if anyone could provide an example, and possibly keeping it simple.

Motley

  • Full Member
  • ***
  • Posts: 240
  • Karma: +32/-33
    • View Profile
Re: Need help checking time
« Reply #8 on: December 04, 2016, 06:45:32 pm »
Could you possibly provide what you're working with so far? And or private message me the code? I'll take a look at it after work  :)

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: Need help checking time
« Reply #9 on: December 05, 2016, 01:28:41 am »
Here goes nothing :P
Code: [Select]
function onTimeChange( hour, min )
{
if ( min *= 5 ) Message("I know this code is wrong, but it was my last attempt");
}

Vortrex

  • Full Member
  • ***
  • Posts: 265
  • Karma: +54/-70
    • View Profile
Re: Need help checking time
« Reply #10 on: December 05, 2016, 08:16:22 am »
Even for all this, I would prefer a timer. 5 minutes doesn't really have a significantly heavy resource usage. I think a 300,000 millisecond interval is 5 minutes.

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: Need help checking time
« Reply #11 on: December 05, 2016, 02:38:25 pm »
Five minutes in game which corresponds to five real seconds. I need a check each five seconds, what would you use? Do you think a timer is viable for that purpose? I'm currently sticking to a timer, unless I find a way to use onTimeChange.

Motley

  • Full Member
  • ***
  • Posts: 240
  • Karma: +32/-33
    • View Profile
Re: Need help checking time
« Reply #12 on: December 05, 2016, 08:12:40 pm »
I'm sorry as I have been really lazy  :-[.
I want to also say this is a lazy example

First thing first Theremin, If you were to check if

min5 = 5 etc during the time of Five, If you use print("It's Five B)");

You will have a constant repeat of that print until five has ended, I noticed this with that function.

So you would have to run a simple check
Code: [Select]
tick_5 <- 0;
function onTimeChange( hour, min )
{
if ( min == 5 )
        {
           if (tick_5 == 1) print("Min 5 already completed its print");
           // Do not enter if the tick of Five has already completed
           if (tick_5 == 0)
           {
               print("It's Five);
               tick_5 = 1;
           }
        }     
if ( min != 5 )
        {
           if (tick_5 == 1)
           {
               tick_5 = 0;
               print("Tick of 5 has been reset")
           }
        }
}

There is a lot of data usage issues and a lot you would need to work with to prevent this...

I hope this was of some help?

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: Need help checking time
« Reply #13 on: December 07, 2016, 02:26:50 am »
Thanks for your script Motley, anyway, It works only partly, because the check tells me only when five seconds pass, but in this case, I'd need to add it also for 10, 15, etc. which isn't really great imho :-\. Anyway fine it gave me some ideas, as for this script I decided to stick to a timer, so pretty much the problem has been solved in someway.

Motley

  • Full Member
  • ***
  • Posts: 240
  • Karma: +32/-33
    • View Profile
Re: Need help checking time
« Reply #14 on: December 07, 2016, 05:42:06 am »
Well just try not to have many timers, Hear is a easy way of altering the time  :)
Code: [Select]
Minutes <- 0;
Seconds <- 0;
Hours <- 0;

function onScriptLoad()
{
    NewTimer("Loop_Seconds", 1000, 0);
}

// Our server loop
function Loop_Seconds()
{
   //time durrations
   if ( Seconds == 60 )
   {
           Seconds = 0;
           Minutes++;
 
           Loop_Minutes();
   }
 
   if ( Minutes == 60 )
   {

           Minutes = 0;
           Hours++;
 
           Loop_Hours();
   }
 
   Seconds++;
   print("Seconds " +  Seconds);
   //time durrations
}

// Our minutes loop
function Loop_Minutes()
{
     print("Minutes " +  Minutes);
}

// Our hour loop
function Loop_Hours()
{
     print("Hours " +  Hours);
}

 

© Liberty Unleashed Team.