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

Solved Specific Item ID

Discussion in 'Development' started by ethaniccc, Feb 28, 2020.

  1. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    So, right now I have this piece of code:
    PHP:
    public function newParticlez(Player $playerItem $item){
            if(
    $item->getId() == 351){
                
    $player->sendMessage("RED");
                return 
    true;
            } elseif(
    $item->getId() == 35){
                
    $player->sendMessage("BLUE");
                return 
    true;
            } elseif(
    $item->getId() == 50){
                
    $player->sendMessage("YELLOW");
                return 
    true;
            } elseif(
    $item->getId() == 351){
                
    $player->sendMessage("GREEN");
                return 
    true;
            }
        }
    You see, the different dyes have a different item id. Red dye has the Item ID of 351,1 while Green dye has the Item ID of 351,2 . However, the plugin does not recognize that, and only outputs "RED", even if you chose the Green dye or any other dye.

    Can someone help me get a fix for this? Thank you all so much in advance! :D

    ~Ethaniccc
     
  2. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    PHP:
    if($item->getId() === ItemIds::DYE && $item->getDamage() === 1){
                
    $player->sendMessage("RED");
                return 
    true;
            } elseif(
    $item->getId() === ItemIds::WOOL){
                
    $player->sendMessage("BLUE");
                return 
    true;
            } elseif(
    $item->getId() === ItemIds::TORCH){
                
    $player->sendMessage("YELLOW");
                return 
    true;
            } elseif(
    $item->getId() === ItemIds::DYE && $item->getDamage() === 2){
                
    $player->sendMessage("GREEN");
                return 
    true;
            }
     
    ethaniccc likes this.
  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.