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

How to spawn an Entity which follows you?

Discussion in 'Development' started by InspectorGadget, Apr 6, 2017.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi! Unfortunately i don't have any codes on my hand now. I'd like to learn on how to spawn any type of pets which follows you?

    Please advice!

    Thanks
     
  2. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    Follow like a pet ?
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Pretty much yes
     
  4. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    There are available pets' plugins on GitHub too, again x)
     
  5. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I prefer learning than copying..
     
    Aviv and NIIP99 like this.
  6. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Then your going to be going up a steep learning curve...

    First you need to know how to create your own custom entity (preferably by extending one of PocketMine's entity classes) then you need to write the AI into this new entities Entity::onUpdate() method. After you've got your AI done the rest should be pretty simple, add way(s) for players to get their pets!

    There is nothing wrong with copying code, so long as you understand it. What's the point of reinventing the wheel just for the sake of learning? Wouldn't it be wiser to simply study it instead?
     
    Last edited: Apr 7, 2017
  7. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    Ok so you prefer learning. A big thumbs up for you

    Here's a basic guide for you.
    1. Create a new class extends Entity (or maybe Living class, depends on what you need) (Let's assume the new class called Pet)
    2. Implement AI to follow owner into Pet class (You can do it by passing Player class into Pet class, and every tick check movements of Player and move the Pet)
    3. Register Pet class with your plugin (Entity::registerEntity())
    4. When Player joined or executed command /pet or whatever (depends on your flavour) spawn Entity as usual using PocketMine API with your Pet class
    5. done :)

    Everyone has thier own way to learn. Someone do it by copying code, someone do it by other way. There's no right or wrong as long as you achieve your aim, to learn.

    P/S: The guide i provided is just my way of spawning Pet. There are still a lot of different ways to do it.
     
    MagicLJ likes this.
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    yes, go learn it by reading it, sometimes you cant just get someone to teach you stuff and it relies on you to learn for yourself
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Here's how:
    PHP:
    $pos Position::class;
    $nbt = new CompoundTag('', [
        
    'Pos' => new ListTag('Pos', [
            new 
    DoubleTag(''$pos->x),
            new 
    DoubleTag(''$pos->y),
            new 
    DoubleTag(''$pos->z)
        ]),
        
    'Motion' => new ListTag('Motion', [
            new 
    DoubleTag(''0),
            new 
    DoubleTag(''0),
            new 
    DoubleTag(''0)
        ]),
        
    'Rotation' => new ListTag('Rotation', [
            new 
    FloatTag(''lcg_value() * 360),
            new 
    FloatTag(''0)
        ]),
    ]);
    $entity Entity::createEntity("Zombie"$pos->getLevel(), $nbt);
    $entity->setNameTag("you");
    $entity->spawnToAll();
    You can use setNameTagVisible to make sure everyone can see it's name.
    If I'm correct, you actually meant:
    "How to spawn an entity and program it to follow a player?". But that would be two questions. One question per thread please.
     
    HyperxXxHound likes this.
  10. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    For following the player, I'll be releasing a work in progress new pet plugin this afternoon. I'm currently in school, (I shouldn't even be typing this...) but I'll notify you when it's public.
     
  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.