Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

double tap on block or a mob

Comments in 'Plugin Development' started by Flabe, Mar 22, 2016.

  1. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    i wanna make something like this: when player hit once - something happens , but when player hit twice something else happens . Is it possible , i need it for my new public shop plugin=)
  2. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    PHP:
    if(!isset($this->test[$player->getName()])){
    $name $player->getName();
    $this->test[$name] = true;

    //1st time

    }else{
    $name $player->getName();
    unset(
    $this->test[$name]);

    //2nd time

    }
    Nawaf_Craft1b, Primus and PEMapModder like this.
  3. CookieSteve
    Offline

    CookieSteve Active Member

    Joined:
    Apr 22, 2014
    Posts:
    132
    Minecraft User:
    iStrqfeChris
    What if they tap it once and decide not to tap it again until later
    Primus and PocketKiller like this.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    public function onTap(PlayerInteractEvent $event){ // Or EntityDamageEvent
       
    $first false
       
    if(isset($this->test[$event->getPlayer()->getName()])){
          if(
    microtime() - $this->test[$event->getPlayer()->getName()] < 3$first true// I think this should make 3 seconds
       
    } else {
          
    $first true;
       }
       if(
    $first)
         
    // First time
         
    $this->test[$player->getName()] = microtime();
       } else {
         
    // Second time
       
    }
    }
    korado531m7 and Nawaf_Craft1b like this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For such precise time comparison, try using microtime(true) instead. time() will round the time to an integer.
    Nawaf_Craft1b likes this.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Something new to me, thanks.

Share This Page

Advertisement