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

CHecking Item Name

Discussion in 'Development' started by Junkdude, Jan 3, 2017.

  1. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    applqpak likes this.
  2. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    yeah i guess, ill have to give a look into it soon
     
    VentroxStudio and applqpak like this.
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    anyways, looks like it's working now, so thank you guys!
     
    applqpak likes this.
  4. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    No problem :)

    Pls take a look at the link I've sent you.
     
    applqpak likes this.
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    kk i need ur help, im checking if it has an enchant again, and it isnt working again. Basically, on sign tap it checks if it has the enchant, if it does, it just sends the enchant name, if it doesnt, it adds it. Well it always adds it even if it has the enchant. Here's the new code.
    PHP:
    public function onTap(PlayerInteractEvent $event){
        
    $player $event->getPlayer();
        
    $item $player->getinventory()->getItemInHand();
        
    $tile $event->getPlayer()->getLevel()->getTile($event->getBlock());
        
    $blindness "\nBlindness";
        
    $event->setCancelled(true);
        if(
    $tile instanceof \pocketmine\tile\Sign){
          
    ##CUE TIER 1 ENCHANTS##
            
    if($tile->getText()[0] === "[Tier 1]"){
            if(
    $tile->getText()[1] === "25 XP"){
            if(
    $tile->getText()[2] === "Blindness Enchant"){
              
    $words $item->getName(); //The item name
              
    $name strtolower($item->getName());
               if(
    strpos($name$blindness) == true){ ##CHECKS IF IT CONTAINS THE ENCHANT
                  
    $player->sendMessage($blindness);
                  return 
    false;
              }else{ 
    ##IF IT DOESNT, IT ADDS IT HERE
              
    $nbt = new CompoundTag();
              
    $nbt->display = new CompoundTag("display");
              
    $nbt->display->Name = new StringTag("Name",$item->getName().$blindness);       
              
    $item->setNamedTag($nbt);
              
    $player->getInventory()->setItemInHand($item);
              
    $player->sendPopup(TF::GREEN "Blindess Enchant Recieved!");
              return 
    true;
              
            }
          }
        }
      }
    }
    }
     
  6. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  7. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Error?
     
    applqpak likes this.
  8. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    None
     
  9. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Lel. You cancelled the event
     
    applqpak likes this.
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    1 issue per thread please.
     
    applqpak likes this.
  11. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    If you want cancel the event, put it on last line of that function.
     
  12. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I didnt want to make a new thread, since this fell into the same type of issue
     
  13. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I removed that and it still adds the next line even if it already has that line
     
  14. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  15. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    With the strpos if statement, you've converted the item name to lowercase, but you're checking if it contains 'Blindness'(with a capital 'B'), this will return false, so the else statement always executes.
     
    Last edited: Jan 5, 2017
    Muqsit and HimbeersaftLP like this.
  16. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Wow, did not know that, but I didnt know it was case sensitive, so im using stripos() instead
     
    applqpak likes this.
  17. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    try str to lowe before doing anything
     
    applqpak likes this.
  18. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    did
     
  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.