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

"On/Off" Item

Comments in 'Plugin Development' started by JackboyPlay, Apr 17, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How can I make it when I held a item I get the message "HI" if I held it for the second time it sends me the message Ho if I held it for the third time it send me the message Hi and so on
  2. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Do You Mean this
    PHP:
    $i 0;
    # make event
    $i++;
    # evrey body make this event $i + 1;
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Yes
  4. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Okey Nice
  5. _Neisufek_
    Offline

    _Neisufek_ New Member

    Joined:
    Apr 17, 2016
    Posts:
    16
    Minecraft User:
    xNaisu
    You can do that by setting an offset of the player name in an array. If he held it once, set the offset, if he held it twice, check if the name offset is set in the array. Then unset the name and send the message. This explanation might be a little confusing so I will write an example:

    PHP:
    private $used = [];

    public function 
    onItemHeld(PlayerItemHeldEvent $e){
    $p $e -> getPlayer ();
    if( !isset(
    $this->used{$p->getName ()})){
    $p->sendMessage("Hi");
    $this->used{$p-> getName()} = $p;
    }else {
    $p->sendMessage ("Hi 2!");
    unset(
    $this->used {$p-> getName ()});
    }
    }
    Skullex and JackboyPlay like this.
  6. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    False Thats True He Want Like That
    PHP:
    $i = array();
    # To Save His name and number
    $i[$name_player] = 0;
    # Number + 1
    $i{$name_player}++;
    # get Player Number
    $i[$name_player];
    Last edited: Apr 17, 2016
  7. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    PHP:
    private $held = array();

    public function 
    OnHeld(ItemHeldEvent $e){
      if((
    $id $e->getItem()->getID()) == /*ID*/){
        (
    array_key_exists(($pN $e->getPlayer()->getName(),$this->held)) ? $this->held[$pn]++ : $this->held[$pn] = 1;
        switch(
    $this->held[$pN]){
          case 
    1:
          
    /*do anything*/
          
    break;
        }
      }
    }

Share This Page

Advertisement