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

Removing a custom name or not item from a stack

Discussion in 'Development' started by Saxavlax001, Apr 26, 2019.

  1. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    Hello,I'm trying to edit a cosmetics plugin to add some things I want, like a lightning stick which when you tap it(with interact event),it will remove one "lightning stick",but theres a problem.The first time it was removing all the sticks not the 1 only,and the other times when I searched my problem here, it wasn't do anything,or it was removing any item on hand,or it was giving errors.
     
  2. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    PHP:
     public function onInteract(PlayerInteractEvent $ev)
      {
            
    $index $ev->getPlayer()->getInventory()->getItemInHand()->getCustomName() == "Lightning stick";
            if(
    $index){
            
    $item Item::get(280);
            
    $item->pop();
            
    $level $ev->getPlayer()->getLevel();
            
    $lightning = new AddEntityPacket();
            
    $lightning->type 93;
            
    $lightning->entityRuntimeId Entity::$entityCount++;
            
    $lightning->metadata = [];
            
    $lightning->position $ev->getPlayer()->asVector3()->add(0$height 0);
            
    $lightning->yaw $ev->getPlayer()->getYaw();
            
    $lightning->pitch $ev->getPlayer()->getPitch();
            
    $ev->getPlayer()->getServer()->broadcastPacket($level->getPlayers(), $lightning);
        }
       }
      }
     
  3. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    I tried copy pasting all the possibly working codes to my plugin,but I had problems on every change I had done.
     
  4. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    try this
    PHP:
    public function onPlayerInteract(PlayerInteractEvent $ev): void{
        
    $player $ev->getPlayer();
        if((
    $item $player->getInventory()->getItemInHand())->getCustomName() == "Lightning stick"){
            
    $player->getInventory()->setItemInHand($item->pop());
            
    $lightning = new AddEntityPacket();
            
    $lightning->type Entity::LIGHTNING_BOLT;
            
    $lightning->entityRuntimeId Entity::$entityCount++;
            
    $lightning->metadata = [];
            
    $lightning->position $player;
            
    $lightning->yaw $player->getYaw();
            
    $lightning->pitch $player->getPitch();
            
    $player->getServer()->broadcastPacket($player->getLevel()->getPlayers(), $lightning);
        }
    }
     
  5. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    I tried now,but it still doesn't work.It just spawns the lightning.
     
  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.