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

How can i cancel a task running for one player when he lefts?

Discussion in 'Development' started by LewBr, Apr 22, 2018.

  1. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    How can i cancel a task running for one player when he lefts? should i get the taskid?
     
    Last edited: Apr 22, 2018
  2. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    PHP:
    // On PluginTask
    $this->getOwner()->getServer()->getScheduler()->cancelTask($this->getTaskId());
     
  3. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Men, i know how to cancel a task, but i want to cancel a task registered for a player when they left the server............
     
  4. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    Do you want to identify whether the player is online in the onRun function, and cancel if it is offline.
    PHP:
    public function onRun($tick) {
      if (!
    $this->player->isOnline()) {
        
    // On offline!
        
    $this->getOwner()->getServer()->getScheduler()->cancelTask($this->getTaskId());
      }else {
        
    // something
      
    }
    }
     
    OnTheVerge 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.