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

getting Item with custom name wont work

Discussion in 'Development' started by Karanpatel567, Oct 24, 2017.

  1. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Any idea why this code won't work, i have checked through everything and doesn't work.
    PHP:
    public function onInteract(PlayerInteractEvent $event){
        
    $player $event->getPlayer();
        
    $iteminhand $player->getInventory()->getItemInHand();
        if(
    $iteminhand->getId() === 399){
            if(
    $iteminhand->getCustomName() === c::GREEN"BankNote : $10000"){
                if(
    $ev->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK){
                
    $player->sendMessage(c::GREEN"Redeemed BankNote worth $10000");
                
    $player->removeItem($iteminhand);
                    }
                }
            }
        }
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Use getName()
     
  3. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    What difference would that make?
     
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Difference is getName() works
     
  5. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Well then let's see if your right.
     
  6. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Doesn't work
     
  7. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Lol for me working
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    public function onInteract(PlayerInteractEvent $event){
        
    $player $event->getPlayer();
        
    $iteminhand $player->getInventory()->getItemInHand();
        if(
    $iteminhand->getId() === 399){
            if(
    $iteminhand->getCustomName() === c::GREEN"BankNote : $10000"){
                if(
    $ev->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK){
                    
    $player->sendMessage(c::GREEN"Redeemed BankNote worth $10000");
                    
    $player->removeItem($iteminhand);
                }
            }else{
                
    $player->getServer()->getLogger()->notice("Skipped note redeeming due to unmatched item name.");
                
    var_dump($iteminhand->getCustomName(), c::GREEN"BankNote : $10000");
            }
        }
    }
    That should help you debug your problem.
     
    jasonwynn10 likes this.
  9. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    nope doesn't work at all. Check your dm.
     
  10. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    make sure your item has that custom name
     
  11. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    c::GREEN. "BankNote : $10000"
     
  12. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
  13. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    What is the console output on muqsit's code?
     
  14. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    ?
     
  15. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    The code he displayed gives console output. Is there anything in the console from the plugin? you said you tested it.
     
    Muqsit likes this.
  16. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    EdwardHamHam and jasonwynn10 like this.
  17. SleepSpace9

    SleepSpace9 Slime

    Messages:
    78
    GitHub:
    sleepspace9
    Maybe try using single quotes
    PHP:
    c::GREEN'BankNote : $10000'
    instead of
    PHP:
    c::GREEN"BankNote : $10000"
    if the dollar sign will interpret it as a variable (although this wouldn't be a valid variable name).
     
    Last edited: Oct 25, 2017
    jasonwynn10 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.