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

Solved How to add coolDown?

Discussion in 'Plugin Help' started by AsponPL, Jul 16, 2019.

  1. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    Hello, I have a problem with my plugin i'm try to create a plugin with coolDown but i don't know how i need to do it please help.

    PHP:
        if($cmd->getName() == "test"){
            
    $sender->sendMessage("HOW TO ADD COOLDOWN?");
     
  2. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    Need just a little more detail
     
  3. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    PHP:
    <?php

    namespace test;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;

    class 
    Main extends PluginBase {
        
        public function 
    onCommand(CommandSender $senderCommand $cmdString $label, array $args): bool {
            
            if(
    $cmd->getName() === "test"){
                
    $sender->sendMessage("HOW TO ADD TO IT A COOLDOWN?");
                return 
    true;
            }
        }
    }
     
  4. Provsnoobgaming

    Provsnoobgaming Baby Zombie

    Messages:
    134
    GitHub:
    provsalt
    php time check php.net
     
  5. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    But please show me example To know more or less how to do it
     
  6. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    PHP:
    private $time = [];
    if (
    $sender instanceof Player){
                    if (isset(
    $this->time[$sender->getName()])){
                        if (
    $this->time[$sender->getName()] <= time()){
                            
    $this->time[$sender->getName()] = time() + 120;
                        }else{
                            
    $time $this->time[$sender->getName()] - time();
                            
    $time gmdate("i:s",$time);
                            
    $sender->sendMessage("Please wait {$time} before using this command again!");
                            return;
                        }
                    }
                    
    //INSERT THE CODE HERE
                    
    $this->time[$sender->getName()] = time() + 120;
                }
            }
     
    OnTheVerge and AsponPL like this.
  7. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    It work THANK YOU!! :3
     
  8. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    NP!!!
     
  9. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    I'm sorry for that but i have a question van i change it to maybe - from time to the For instance Times oraz timer or somthing like that i know I already have but for example. How do I want to do more such a coolDown that it is difficult because everything comes at the same time you know how to do it?

    EDIT: never mind i know how to do this
     
    Last edited: Jul 22, 2019
  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.