What is going wrong with this code?

Discussion in 'Development' started by charada, Aug 29, 2020.

  1. charada

    charada Spider

    Messages:
    8
    GitHub:
    Ntem
    I was trying to make a plugin that I use the item if the player moved but I was trying to put it so that when using the EX item: I have 32 stone blocks and I use one with 31 blocks, but this is giving an error what is happening?
    PHP:
    public function onLeapPluginInteract(PlayerInteractEvent $event) {
            
    $player $event->getPlayer();
            
    $config = new Config($this->getDataFolder() . "Config.yml"Config::YAML);
            if(
    $event->getItem()->getID() === 401) {
                if(!isset(
    $this->cd[$player->getName()
                
    $inventory->removeItem(Item::get(Item::FIREEORKS01));
     
    Mehrbod likes this.
  2. Taco

    Taco Spider Jockey

    Messages:
    28
    GitHub:
    twrrr
    ok, so i see you are using the code i gave you before.

    Remove the if !isset($this->cd
    remove the $config
    use the code below to remove an 1 of the item from the players inventory
    $player->getInventory()->setItemInHand($item->setCount($item->getCount() - 1));

    and please specify what you mean by "i use the item if the player moved"

    then i can help you with the moving part
     
  3. charada

    charada Spider

    Messages:
    8
    GitHub:
    Ntem
    well i'm making a launcher plugin for factions it is working but i wanted to put it for the items to end and for now it's getting like this, right?

    PHP:
     public function onLeapPluginInteract (PlayerInteractEvent event) {
            $ 
    player = $ event-> getPlayer ();
            $ 
    config = new Config ($ this-> getDataFolder (). "Config.yml"Config :: YAML);
            if ($ 
    event-> getItem () -> getID () === 401) {
                $ 
    player-> getInventory () -> setItemInHand ($ item-> setCount ($ item-> getCount () - 1)); [$ player-> getName ()])) {
                    $ 
    this-> cd [$ player-> getName ()] = time () + $ config-> get ("cooldown"); [/ PHP] [/ PHP] [/ PHP]
     
    Last edited: Aug 30, 2020
  4. Taco

    Taco Spider Jockey

    Messages:
    28
    GitHub:
    twrrr
    use this code to add a item to the players inventory $player->getInventory()->addItem(Item::get(351, 3, 1)); // = 1 Cocoa Bean
     
  5. Levi

    Levi Skeleton

    Messages:
    943
    GitHub:
    captainleviftw
    don’t use hardcoded item IDs
     

Share This Page

  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.