NpcSpawner lib - spawn basic NPCs

Discussion in 'Resources' started by Redecouverte, Feb 3, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    black_ixx

    Well but it is possible. Ok. Thanks. I'll try it out!
     
  2. Offline

    black_ixx

    Same problem...
    the EntityDamageByEntityEvent is not triggered when a HumanNPC gets attacked by a player. Nothing happens to the NPC...
     
  3. Offline

    Adamki11s

    It works for me. You have to monitor the EntityDamageByEntityEvent event and then make the npc act hurt.

    Code:java
    1.  
    2. getHumanNPC().actAsHurt();
    3.  
     
  4. Offline

    black_ixx

    With my code the EntityTargetEvent or EntityDamageByEntityEvent is not even fired when I am hitting/rightclicking a NPC... I am using the main part of this code.

    Edit:
    Finally fixed it!
     
  5. Offline

    jeremytrains

    Could you tell me how you fixed it? My EntityDamageByEntityEvents are not fired either.
     
  6. Offline

    black_ixx

    Well the event was called all the time. You could just check at the top of your listener if the entity is instance of a HumanEntity. Then you could continue with your code. Just check with something like "bukkit.broadcastMessage("1"); etc. if the part of the line was even triggered.
     
  7. Offline

    jeremytrains

    black_ixx
    Thanks

    Neodork and all others
    So should I make a BukkitDev page? Do I have permission?
     
  8. Offline

    Neodork

    The library was not released by me, so I cannot make decisions for it. If you want to create a BukkitDev page for it you should talk to Top_Cat. I prefer to keep this hard-coded into my plugin to prevent adding any unnecessary dependencies.
     
  9. Offline

    Throk

    Anyone have this lib for 1.4.7?
     
  10. Offline

    jeremytrains

    I tried that, but my events are not even triggered. I had a line at the top of my method and it said
    Code:
    Logger.getLogger("Minecraft").info("EntityDamageByEntityEvent - wasNPC:" + plugin.manager.isNPC(event.getEntity()));
    The line was never shown when I hit the NPC, but it did pop up when a pig died and it said "EntityDamageByEntityEvent - wasNPC:false" I can't figure this out!
     
  11. Offline

    Neodork

  12. Offline

    jeremytrains

    Neodork
    Yes. This is the constructor:

    Code:
    public NPCManager(JavaPlugin plugin) {
            server = BServer.getInstance();
     
            try {
                npcNetworkManager = new NPCNetworkManager();
            } catch (IOException e) {
                e.printStackTrace();
            }
           
            NPCManager.plugin = plugin;
            taskid = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                @Override
                public void run() {
                    HashSet<String> toRemove = new HashSet<String>();
                    for (String i : npcs.keySet()) {
                        Entity j = npcs.get(i).getEntity();
                        j.y(); //jeremytrains: z -> y
                        if (j.dead) {
                            toRemove.add(i);
                        }
                    }
                    for (String n : toRemove) {
                        npcs.remove(n);
                    }
                }
            }, 1L, 1L);
            Bukkit.getServer().getPluginManager().registerEvents(new SL(), plugin);
            Bukkit.getServer().getPluginManager().registerEvents(new WL(), plugin);
        }
     
  13. Offline

    jeremytrains

    Neodork Any other suggestions?
     
  14. Offline

    Neodork


    I'll be looking into it once I have some time.
     
  15. Offline

    jeremytrains

    Neodork
    If it helps, I am making guards. When a wolf is in range of the NPC, I call the damageEntity() method, and then send an arm movement packet to nearby players. If the wolf is hurt by the damageEntity() method, then the wolf will attack the NPC, the NPC will blink red (like it is hurt), and then once it is attacked enough the NPC will die and an EntityDeathEvent will be fired. So, the problem is - what is the difference between a player damaging an NPC and a wolf? Is there any way for me to listen for PlayerLeftClickEntity or something? If so, I will manually call the Player.damageEntity(HumanNPC.getBukkitEntity()) method. Thanks!
     
  16. Offline

    Adamki11s

    jeremytrains
    Yes, for the NPC you will have to implement your own health tracking system, it's what I have had to do for my plugin.
     
  17. Offline

    jeremytrains

    Adamki11s Neodork
    Sorry for the trouble. It is actually fine. I made a stupid mistake - I had pvp set to false in my server.properties. *facepalm*
     
  18. Offline

    Jozeth

    Where can I download this?
     
  19. Offline

    black_ixx

    Does somebody know how to compare the locations two objects are looking at? Well what I want to do is to check if a npc sees the player/faces him/looks close to his direction. I've tried to figure that out at my own but didn't succeed yet.

    Help is welcome!
     
  20. Offline

    Neodork

    Get the locations from the objects and compare them? Did you try to use entity.getNearbyEntities?
     
  21. Offline

    Crawford

    Hi everyone
    I need some help:
    So, I want to hit an NPC (EntityDamageByEntityEvent)
    Code:
    @EventHandler
        public void onEntityDamageByEntity(EntityDamageByEntityEvent evt) {
         
            Player damager = (Player) evt.getDamager();
            NPCManager NPCMan = new NPCManager(plugin);
         
            plugin.getLogger().info("Called!");
            if(NPCMan.isNPC(evt.getEntity())) {
             
                String npcID = NPCMan.getNPCIdFromEntity(evt.getEntity());
                plugin.getLogger().info("Is NPC!");
                plugin.getLogger().info("NPC: " + npcID);
             
                NPC npc = NPCMan.getNPC(npcID);
                HumanNPC hNPC = new HumanNPC(((NPCEntity) npc.getEntity()));
     
                if ((npc != null) && (damager instanceof Player)) {
                 
                    hNPC.actAsHurt();
                    damager.sendMessage("<" + hNPC.getName() + "> Don't hit me so much!");
     
                    evt.setCancelled(true);
     
                }
     
            }
         
        }
    But, the String "npcID" is always null.

    Console says:
    ]Called!
    ]Is NPC!
    ]NPC: null

    Ideas?
     
  22. Offline

    Der_Udo

    Does somebody has updated the lib to 1.5?

    How to get the IConsoleLogManager? I need it for the NPCNetworkManager...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 8, 2016
  23. Offline

    Cybermaxke

    I have already found it. ;)
    Code:
    MinecraftServer.getServer().getLogger()
     
    Der_Udo likes this.
  24. Offline

    Der_Udo

    Thanks!
     
  25. Offline

    Der_Udo

    I just found out that my npcs look to the wrong location when they walk. This is my recent code:
    Code:
        private void pathStep() {
            if (pathIterator.hasNext()) {
                final Node n = pathIterator.next();
                if (n.b.getWorld() != getBukkitEntity().getWorld()) {
                    getBukkitEntity().teleport(n.b.getLocation());
                } else {
                    float angle = getEntity().yaw;
                    float look = getEntity().pitch;
                    if (last == null || runningPath.checkPath(n, last, true)) {
                        if (last != null) {
                            angle = (float) Math.toDegrees(Math.atan2(last.b.getX() - n.b.getX(), n.b.getZ() - last.b.getZ()));
                            look = (float) (Math.toDegrees(Math.asin(last.b.getY() - n.b.getY())) / 2);
                        }
                        getEntity().setPositionRotation(n.b.getX() + 0.5, n.b.getY(), n.b.getZ() + 0.5, angle, look);
                        ((EntityPlayer) getEntity()).az = angle;
                    } else {
                        onFail.run();
                    }
                }
                last = n;
            } else {
                getEntity().setPositionRotation(runningPath.getEnd().getX(), runningPath.getEnd().getY(), runningPath.getEnd().getZ(), runningPath.getEnd().getYaw(), runningPath.getEnd().getPitch());
                ((EntityPlayer) getEntity()).az = runningPath.getEnd().getYaw();
                Bukkit.getServer().getScheduler().cancelTask(taskid);
                taskid = 0;
            }
        }

    And to be honest I can't figure out how to prevent them from teleporting when the amount of iterations is not enough to get them to the "goal" location. I want them to just stop then...

    Help is much welcome!
     
  26. Offline

    zta192

    Where you have
    Code:
     ((EntityPlayer) getEntity()).az = angle; 
    Try changing it to...
    Code:
     ((EntityPlayer) getEntity()).aA = angle; 
     
    Der_Udo likes this.
  27. Offline

    Der_Udo

    Thanks :D

    Just one thing left: My npcs dissappear when they get attacked by an explosion. Does this happen to you too? And did you fix it?

    Edit:
    Well the npc is still there and is able to walk and attack etc. just like normal but it becomes invisible...
     
  28. Offline

    caliog

    Is there an updated version of the full npc lib ?
    Does someone know a internet page or something where you can see how the new names of the old methods is ?
    And who is the creator or developer of this lib ? I would like to help to update it and to fix bugs etc.
     
  29. Offline

    jeremytrains

    To get new method names, try searching around on https://github.com/agaricusb/MinecraftRemapping. The only method that I can't fix (compiler error wise) is the following line:
    Code:
    AxisAlignedBB box = net.minecraft.server.v1_5_R2.Block.byId[b.getTypeId()].e(((CraftWorld) b.getWorld()).getHandle(), b.getX(), b.getY(), b.getZ());
    in
    Code:
    com/topcat/npclib/pathing/Node.java
    Does anybody else have a fix? I am updating from 1.4.7 to 1.5.1. The problem is that the method "e" no longer exists. The website above suggests it was renamed to "g", but the method "g" is void and does not return an AxisAlignedBB
     
  30. Offline

    caliog

    But its really hard to search around there..
    Can you tell me the new name of the c_(EntityHuman entity) function in NPCEntity.java
    And how did you manage the new super constructor in NPCNetworkManager.java where you need a IConsoleLogManager object for the constructor of the NetworkManager ?
     
Thread Status:
Not open for further replies.

Share This Page