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

How to edit the ai of a mob?

Discussion in 'Development' started by Indexfire, Dec 12, 2016.

  1. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    I just came up with an idea of a minigame... But I need to to edit the ai of a Wither as shown:

    The Wither stays in the same place and takes no knock back. Players on the same team as the Wither cannot damage it. The Wither attacks enemies and grants potion buffs to players on the same team when they are close to it. I also want to trigger an action from the plugin when the Wither dies.

    Any idea how to do that?
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    If you just started developing plugins I DEFINITELY do not recommend doing this. Nobody even has a functional wither AI. I recommend starting with easy plugins.
     
    Magicode likes this.
  3. Magicode

    Magicode Baby Zombie

    Messages:
    183
    GitHub:
    magicode1
    I don't even know if Pocketmine has Bosses even in it yet.
     
    Sandertv likes this.
  4. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Tbh, since you dont want it to move it all, just spawn a wither at the beginning of each game. But, I dont think pocketmine even has withers yet.
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    Is it correct to say that? PocketMine doesn't have wither implementation, but you surely can spawn it.
     
    archie426 and SOFe like this.
  6. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I should reword that, if you can spawn the entity at the beginning of each game with code, it shouldnt move since PM hasn't implemented the ai code yet. But, I don't think it's possible to spawn it with code yet, don't quote me though.
     
  7. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    You can implement fully working mobs even in plugin. You dont need to implement it to pocketmine directly
     
  8. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    But what is the code
     
  9. Skullex

    Skullex Spider

    Messages:
    13
    GitHub:
    skull3x
    Primus likes this.
  10. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    foreach($this->teamblue as $player){ //$this->teamblue is team blue players
      
    if($teambluewither->distance($player) <= $distance){ //$distance will be the amount of blocks the players need to be in to get the buffs
        //your code
      
    }
    }
     
  11. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Uhm? I don't think this has anything to do with the topic. :p Look closely at the topic.
     
    Magicode likes this.
  12. Aviv

    Aviv Baby Zombie

    Messages:
    156
     
  13. Magicode

    Magicode Baby Zombie

    Messages:
    183
    GitHub:
    magicode1
    But that doesn't answer his question. He is asking about the Wither AI, not that part of the code.
     
    Sandertv likes this.
  14. KnownUnown

    KnownUnown Spider Jockey Poggit Reviewer

    Messages:
    47
    GitHub:
    knownunown
    Let's start off here. To use the Wither, you've to create a new class for it, as it doesn't seem that there is currently one. This class has to extend Monster, as it is hostile and default behavior and other things for hostile mobs may be added in the future. Now that you have a Wither class, how do we define custom behavior on attack? We can see how PrimedTNT does it, as it is another entity that is invulnerable. It simply overrides Living::attack(), and doesn't call the parent function (unless it's being damaged by the void). We then override this in Wither and get the player from EntityDamageEvent. The rest for this part is up to you. Now, how do we define custom behavior for our Wither when players are close? We probably want to do this on every tick (or so), so we can override Entity::eek:nUpdate(). To get nearby entities in a Level, you can use Level::getNearbyEntities(). The rest is left as an exercise to the reader.
     
    Last edited: Dec 13, 2016
    SOFe, Skullex, Indexfire and 3 others like this.
  15. Aviv

    Aviv Baby Zombie

    Messages:
    156
    youre right. shouldve look closely ;)
    this is plugin development section, here you ask for code and we will give you code, you can clearly see he said he wants to know how to get nearby players and buff them/attack them. that doesnt answears on his full question, but that gives him a little idea of how to make it
     
    Sandertv likes this.
  16. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Uhhh my head exploded i have no idea what that gigantic chunk of code means
     
  17. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Start small, learn how to just spawn entitys.
     
  18. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I haven't seen anyone learning how to spawn entities for a long time. For so many months I just see people copying the code for spawning arrows everywhere.
     
    Last edited: Dec 14, 2016
    Jack Noordhuis and HimbeersaftLP like this.
  19. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    If you are here just for the code sorry, we dont have it [yet...]
     
  20. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    If you are just looking for code, request a plugin. Code isn't the armor you mix in a crafting table put on your Steve to make it stronger. Code is part of the plugin, something that cannot be alienated from the rest of the plugin. If you want code, you are asking for the whole plugin.
     
    Indexfire and HimbeersaftLP like 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.