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

Solved How to do a countdown on config like older plugins?

Discussion in 'Development' started by LewBr, Mar 15, 2018.

  1. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Hello, I'm trying to fix a counter type in a minigame but I do not know why it does not work, I'm using the '--' operator to decrease counting number but always continues with 20 or 19 and never goes down and also do not know how that work:
    https://github.com/kaitododoyt/SkyW...rc/KaitoDoDo/SkyWarsTeam/SkyWarsTeam.php#L770
    works and mine not, first of all, yes I am using Tasks.

    I have that code:
    PHP:
    //in config is like this: countdown: 20
        
    $counterArena $config->get($levelArena "countdown");
    //and then after all they send a message to the player with variable $counterArena
                            
    $counterArena--;
    $player->sendPopup("Game starts in ".$counterArena.".");
     
    Last edited: Mar 15, 2018
    MasterPE likes this.
  2. Flavius12

    Flavius12 Spider Jockey

    Messages:
    32
    GitHub:
    flavius12
    The problem is that you update $counterArena variable from config every time you decrease it. You should load $counterArena once and then decrement it.
     
  3. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Yeah, but how can i do that? Because it needs to be in the task file to get that $counterArena, and i can't get whitout update because it's in a task file, mine is similar that, and that works:
    https://github.com/kaitododoyt/SkyW...rc/KaitoDoDo/SkyWarsTeam/SkyWarsTeam.php#L754
     
    MasterPE likes this.
  4. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    create a task and construct the time i guess
     
    xXNiceAssassinlo YT likes this.
  5. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    What you mean?
     
    MasterPE likes this.
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    in the constructor of the task have $this->counterArena = $config->get($levelArena . "countdown"); and then access it with $this->counterArena--; in your onRun
     
    LewBr 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.