Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Time to final dual?

Comments in 'Plugin Development' started by Legoboy0215, Jul 7, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Now, my brain is messed up. How do I count the time to dual?
    My timers code:
    PHP:
                $timetod $this->totalminutes $this->minutespast $this->prefs->get('dual_time');
    This is a scheduleRepeatingTask with 1200 ticks(1 minute).
    This code will count the numbers up. How do I make it count down the correct way?
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    What do you mean..
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I recommend you to use time() or microtime(true), because they give you the real time instead of the server ticks which may be affected by TPS.
    Don't count the minutes yourself. Compare time() and saved timestamps directly. time() gives the number of seconds (in integer) passed since 1/1/1970 UTC 0:00:00.
    PHP:
    initialize:
    $this->startTime time(); // saves the time for timer start

    seconds_after_initialize:
    $secondsElapsed time() - $this->startTime// gets the number of seconds pased since timer start

    // if the timer should end 5 minutes after initialize
    timestamp_for_end:
    $endTime $this->startTime 60 5// adds 300 seconds (5 minutes) to the timer start time, which is the timer end time
    seconds_left:
    $secondsLeft $endTime time(); // difference between timer end time and current time is the number of seconds left.
    Last edited: Jul 7, 2015
    iiDeathStrokeii and Legoboy0215 like this.

Share This Page

Advertisement