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

Timer problems

Comments in 'Plugin Development' started by Angelo Vidrio, Mar 30, 2015.

  1. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Ok, so I need help making a timer. I looked in other threads but didnt find any answers. Here is what I have:
    PHP:
    foreach($this->plugin->getServer()->getLevelByName($this->level)->getPlayers() as $p) {
                    
    $time $this->plugin->timer[$this->id];
                    if(isset(
    $this->plugin->gamePlayers[$p->getName()])) {
                        
    $p->sendMessage("/> $time..");
                       --
    $this->plugin->timer[$this->id];
                    }
                }
    This code is all in a task.php, I use
    PHP:
    $this->plugin->getServer()->getScheduler()->scheduleTask(new timer($this->plugin$this->id$this->level$this->task));
    in an other task.php to call it. Okay so lets call this 'callTimerTask.php', now in my main file, I call 'callTimerTask.php' with 'scheduleRepeatingTask' with a period of 1 second (or 20 ticks). My problem is that since the '--$this->plugin->timer[$id];' is in a 'foreach', every second it will subtract '2' from '--$this->plugin->timer[$id];' if there are 2 players in the world and then subtract 3 because there are 3 people, and it goes on. So I just want to make a timer that will be shown to the players in a desired world.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Maybe just simply move the `--` assignment out of the foreach loop?
  3. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Then it will not be reduced until the foreach function is done :(
  4. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Move --$this->plugin->timer[$this->id]; out of the foreach bracket, put the it below the end of foreach
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then before it.
  6. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Ill try it.

Share This Page

Advertisement