1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to count the time

Discussion in 'Development' started by Palente, Dec 22, 2016.

  1. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Hey, I Want to count the time not with a schedulerrepeating Task
    What I want to do.
    A player do /prime to set money to the head of a player and I just want to count the time like
    if the time between the command and The Player dead is >120
    The Killer have 0$
    Else Killer have 300$


    Just I want to count the time I do the rest.
    Thanks For Read.
    Sorry If I do an error in my English :)
     
  2. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    PHP:
    if(/*saved time*/ /*plus your time*/ == time())
    {
    //Your code
    }
     
    Last edited: Dec 22, 2016
    #A6543 likes this.
  3. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    I want to count between Two things
    Between The command and The Player Death
    So
    I can't use that but thanks for reply
     
  4. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    PHP:
    if($savedtime 60*== time())
    {
    //Your code
    }
    This checks if the current time is your saved time plus 5 minutes. Is that what you mean?
     
    [deleted], #A6543 and Palente like this.
  5. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Pls like if that helped :)
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Declare a global variable:
    PHP:
    public $timestamp = [];
    When the player runs the command, execute this.
    PHP:
    //onCommand...
    //$player = CommandSender
    $this->timestamp[$player->getId()] = time();
    When player dies...
    PHP:
    //$event is PlayerDeathEvent
    //$player = $event->getPlayer();
    if (isset($this->timestamp[$player->getId()])) {
        
    $initial $this->timestamp[$player->getId()];
        
    $difference time() - $initial;
    }
    $difference is the number of seconds between player executing the command and player's death.
     
    Palente likes this.
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    it is good to use >= in state of == as what if the server skipped a beat? due to all sort of things common reason would be lag
     
  8. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Yes. I wrote it to fast and on my mobile xD

    But that should work
     
    #A6543 likes this.
  9. Palente

    Palente Slime

    Messages:
    75
    GitHub:
    palente
    Thanks For all replies I will be test the suggestion of
    Because is it much detailed
    Thanks for all ☺
     
    Muqsit likes this.
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    So suppose the server somehow has a 1-second lag at that exact second, they will never be run.
     
    Muqsit likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.