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

Cooldown to kit UI

Discussion in 'Development' started by Flow, May 5, 2019.

  1. Flow

    Flow Silverfish

    Messages:
    22
    hey , i created a plugin kit UI , i want to set a cooldown but i do not know how to do it, can you help me?
     
  2. Flow

    Flow Silverfish

    Messages:
    22
    PHP:
    case "hkit":
                
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
                
    $ui $api->createSimpleForm(function (Player $p$data){
                    
    $res $data;
                    
                    switch(
    $res){
                        case 
    0:
                        
    $p->getInventory()->addItem(Item::get(30601));
                        
    $p->getInventory()->addItem(Item::get(30701));
                        
    $p->getInventory()->addItem(Item::get(30801));
                        
    $p->getInventory()->addItem(Item::get(30901));
                        break;
                    }
                });
                
    $ui->setTitle("Hyru-Kit");
                
    $ui->setContent("Kit de base");
                
    $ui->addButton("Kit 1"0);
                
    $ui->sendToPlayer($p);
                break;
            }
            return 
    true;
        }
     
  3. Flow

    Flow Silverfish

    Messages:
    22
    I would like to put the cooldown here
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    save time using function time() or microtime(true) and then just check if it's bigger than you want
    PHP:
    public const KIT_DELAY 60*5// 60 sec * 5 -> 5 minutes
    public $time = [];

    function 
    selectKit(Player $p) {
        if(isset(
    $this->time[$p->getName()]) && time()-$this->time[$p->getName()] < self::KIT_DELAY) {
           
    $p->sendMessage("Please, wait");
            return;
        }
        
    $this->time[$p->getName()] = time();
    }
     
    OnTheVerge and HimbeersaftLP like this.
  5. Flow

    Flow Silverfish

    Messages:
    22
    Tu as discord ? You have discord ?
     
  6. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    discord.gg/uwBf2jS
     
  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.