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

How to do action all 10 seconds

Comments in 'Plugin Development' started by jjmc, Feb 3, 2016.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    It's your code, I just expended with mine to test it.
    Omar2s2 likes this.
  2. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Aha Okey Nice Mines
    I Just urgent
    The wheel of the devil
    Omar2s2 likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Are you russian?
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    He isn't.
    Omar2s2 and Primus like this.
  5. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    What makes you think if he is Russian :p
    PocketKiller, Omar2s2 and Primus like this.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    His name sounds like russian.
  7. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    I found a good solution to do it like Primus with a second class and AsyncTask. I think it's no different if I use seconds or ticks.
  8. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    PHP:
    public $time 0;
    public 
    $pla 0;

    public function 
    onRun($tkck){//$this->time--;
    if($this->pla == 1){
    $this->time--;
    if(
    $this->time == 0){//-----------------------
    // code
    $this->pla 0;
    }}
    }
    // How Can Start Time !
    $this->time 10;
    $this->pla 1;
    //
    Omar2s2 likes this.
  9. Omar2s2
    Offline

    Omar2s2 New Member

    Joined:
    Dec 23, 2015
    Posts:
    12
    Minecraft User:
    Pop
    Thankeyou
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Don't use AsyncTask for such use.

    There is a significant diffrence between seconds and ticks.
    For example: 3 seconds in ticks will be 60.
    PHP:
    function ticksToSeconds($ticks){
       return 
    round( ($ticks 20), 0);
    }

    function 
    secondsToTick($seconds){
       return 
    round( ($seconds 20), 0);
    }
    Won't work.
    Last edited: Feb 4, 2016
  11. Omar2s2
    Offline

    Omar2s2 New Member

    Joined:
    Dec 23, 2015
    Posts:
    12
    Minecraft User:
    Pop
    Why Use Round
    he Can Use
    Function ticks($s){
    return $s * 20;
    }
    And Code Nawaf Work
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    What if
    PHP:
    $s 0.7821;
    Nawaf's code is not effective.
  13. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    Is there a special reason why don't use AsyncTask?
    For my case, it's enough to check it all 10 seconds (about 200 ticks).
    Nawaf_Craft1b likes this.
  14. Omar2s2
    Offline

    Omar2s2 New Member

    Joined:
    Dec 23, 2015
    Posts:
    12
    Minecraft User:
    Pop
    What IF Nawaf Code IS Work
    Nawaf_Craft1b likes this.
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Do you even know what AsyncTask is meant for?
    Yes it work but it's not effective!
    PocketKiller and Nawaf_Craft1b like this.
  16. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why are you discussing about it, this is so simple..
    PHP:
    class tenSecTask extends PluginTask
    {

        public 
    $count 10;

        public function 
    __construct($plugin)
        {
            
    $this->plugin $plugin;
            
    parent::__construct($plugin);
        }

        public function 
    onRun($tick)
        {
            if (
    $this->count 1) {
                
    $this->count--;
            } else {
                
    $this->count 10;
                
    $this->plugin->getServer()->broadcastMessage("10 Seconds passed");
            }
        }

    }
  17. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    I Think i dont understand What he Want @jjmc IN This Thread
  18. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Same as Nawaf's old code - after ten seconds the message "10 Seconds passed" will be sent every second.
    Just add self::cancel() or something to stop executing once the class has done his mission.
  19. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    PHP:
    public $time 0;
    public 
    $pla 0;
    //
    public function onRun($tkck){//$this->time--;
    if($this->pla == 1){$this->time--;
    if(
    $this->time == 0){
    // code
    $this->pla 0;
    }}
    }
    // How Can Start Time !
    $this->time 10;
    $this->pla 1;
  20. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    We have seen your infinity loop before, calm down.
    PocketKiller likes this.

Share This Page

Advertisement