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

Entity Damage Dont Work

Discussion in 'Development' started by Harviy11, Jan 20, 2017.

  1. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    I spawned human by this code
    PHP:
    public function spawnd($p)
    {
        
    $name $p->getName();
        
    $text "ZTT";
        
    $pk = new AddPlayerPacket();
        
    $pk->eid 2234;
        
    $pk->uuid UUID::fromRandom();
        
    $pk->$p->x;
        
    $pk->$p->3;
        
    $pk->$p->z;
        
    $pk->speedX 0;
        
    $pk->speedY 0;
        
    $pk->speedZ 0;
        
    $pk->yaw 20;
        
    $pk->pitch = -30;
        
    $pk->item Item::get(0);
        
    $flags 0;
        
    // $flags |= 1 << Entity::DATA_FLAG_CAN_SHOW_NAMETAG;
        // $flags |= 1 << Entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG;
        
    $flags |= << Entity::DATA_FLAG_IMMOBILE;
        
    $pk->metadata = [
            
    Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG$flags],
            
    //  Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $text],
            
    Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG12],];
        
    $p->dataPacket($pk);
        
    $p->dataPacket($pk);
    }
    Why when i use this
    public function onDamage(EntityDamageEvent $e)
    {
    $en = $e->getEntity();
    $this->getServer()->broadcastMessage("WORKING!!");
    }
    and damage human it doesnt say Working
     
  2. kaliiks

    kaliiks Zombie

    Messages:
    250
    Why u add 2nd code to spoiler and 1 longest code no?:D
     
  3. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Sandertv likes this.
  4. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Yes it dont work only when i add player with addplayer packet
    on other players it normally work
     
  5. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Oh yeah of course, you didn't create the entity how PocketMine would like it. The entity just doesn't exist for the Server since you only sent a packet to the client.

    Try using createEntity().
     
  6. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Used
    public function addNPC(Player $p){
    $block = $p;
    $npc = new Human($p->chunk,
    new CompoundTag("", [
    "Pos" => new ListTag("Pos", [
    new DoubleTag("", $block->getX()),
    new DoubleTag("", $block->getY()),
    new DoubleTag("", $block->getZ())
    ]),
    "Motion" => new ListTag("Motion", [
    new DoubleTag("", 0),
    new DoubleTag("", 0),
    new DoubleTag("", 0)
    ]),
    "Rotation" => new ListTag("Rotation", [
    new FloatTag("", 0),
    new FloatTag("", 90)
    ]),
    "Skin" => new CompoundTag("Skin", [
    "Data" => new StringTag("Data", $p->getSkinData())
    ])
    ]
    ));

    $npc->spawnToAll();
    $npc->setNameTagVisible(true);
    $npc->setNameTagAlwaysVisible(true);
    $npc->setNameTag("TEST");
    $npc->setMaxHealth(99999999);
    $npc->setHealth(99999999);

    }
    But nametag is not always visible when i restart server!
     
  7. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    I guess you have to set the nametagvisible again. That shouldn't be the case though, will check on that.
     
  8. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Can you give me code?: :facepalm:
     
  9. MioTaku

    MioTaku Witch

    Messages:
    69
    GitHub:
    uselesswaifu
    Use PlayerInteractPacket
     
  10. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    Thanks can u help finish it?
    PHP:
    public function onInteract(PlayerInteractEvent $e){
        
    $p $e->getPlayer();
        
    $pk = new PlayerInteractPacket();
        
    $pk->eid 2233;
        
    $pk->action $p->sendMessage("It work");
        
    $pk->target
    }
     
  11. MioTaku

    MioTaku Witch

    Messages:
    69
    GitHub:
    uselesswaifu
  12. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    PHP:
    public function onPacketReceived(DataPacketReceiveEvent $e)
    {
        
    $pk $e->getPacket();
        if (
    $pk instanceof InteractPacket and InteractPacket::ACTION_LEFT_CLICK) {
            
    $pk->eid 2233;
            
    $e->getPlayer()->sendMessage("It is working");
        }
    }
    What is bad :'(
     
  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.