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

Cooldown?

Discussion in 'Development' started by xSmoothy, Mar 26, 2017.

  1. xSmoothy

    xSmoothy Creeper

    Messages:
    2
    How to make cooldown in plugin using time() ? Some ideas?
     
  2. xSmoothy

    xSmoothy Creeper

    Messages:
    2
    I made something like that from code in other plugins like from antispam. It's working in 50% because when i throw this snowball at first time it's send's me "You can throw pearls every 5 seconds" but 2rd time it's doing nothing. Any ideas how to repair this?

    PHP:
          $player $shooter;
          
    $player_name $shooter->getName();
          
    $cooldown 5;
          if(isset(
    $this->cooldown[$player_name]))
          {
            
    $last_chat_time $this->cooldown[$player_name];
            if((
    time() - $last_chat_time) <= $cooldown)
            {
              
    $timeDifference = (time() - $last_chat_time);
              
    $player->sendMessage("ยง7You can throw pearl every 5 seconds!");
              
    $event->setCancelled();
            }
          }
          else
          {
            
    $this->cooldown[$player_name] = time();
                            
    $shooter->teleport($posTo);
                            if(!
    $shooter->isCreative()){
                                
    $ev = new EntityDamageEvent$shooterEntityDamageEvent::CAUSE_MAGIC$this->config->get("damage") );
                                
    $shooter->attack($ev->getFinalDamage(), $ev);
                            }
                    }
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    //$time = last throw $player = Player $cooldown = cooldown
    if (!isset($time) OR time() - $time > $cooldown){
    tell($player,"thrown");
    $time = time();
    //throw it
    } else {
    tell($player,"cooldown wait ".$cooldown- time() - $time);
    }
    something like this SHOULD do
    if you dont copy directly from it
     
  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.