NpcSpawner lib - spawn basic NPCs

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

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

    Luloak2

    With the last Dev-Build, it is not working anymore, change this in the NPCManager.java to get it work:
    Code:
    public NPCManager(JavaPlugin plugin) {
            server = BServer.getInstance();
     
            npcNetworkManager = new NPCNetworkManager();
            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.aA();
                        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);
        }
    The j.az(); in the old NPCManager.java is not working anymore, so it must be replaced with j.aA();


    Top_Cat Maybe you could update it ;)
     
  2. Offline

    kumpelblase2

    I'm using this lib since about two days or so and most of the things do work and do work really well. There are still some things that I have a problem with:
    1) Setting the yaw does only rotate the body, not the head. Though changing the pitch does rotate it (up and down ofc.). See PR.
    2) (This might be spout related) I tried lots of things but nothing worked to set the skin. Neither getting the npc as a spout player nor setting it through a real player. Does somebody might have an idea?
     
  3. Offline

    Trc202

    Pretty sure only spout clients can see the skin changes. The skins for a player are retrieved by the client.
     
  4. Offline

    kumpelblase2

    I think I tested it with both, normal and spoutcraft, clients and neither worked. I'm gonna test the experimental builds for 1.2.5 from spout though.

    However, I have a new issue. NPC_BOUNCED does not get triggered at all. Maybe it isn't c() anymore?
     
  5. Offline

    Sir Savary

    How can I get an NPC to attack an entity?
     
  6. Offline

    kumpelblase2

    You were correct, but it took me some time figuring out which method you need to use to get the skin right. It's not working for me using the code of post #336 because I don't have a player all the time. So using this code should do it:
    Code:
    SpoutPlayer sp = <HumanNPC>.getSpoutPlayer();
    sp.setSkin(url);
    Moreover I've a solution/workaround for the NPC_BOUNCED event, which is not working for me, because it doesn't get called. To make it working again you need to copy the code from the c() method in the a_() method and check if the (square)distance is 1 (you can adjust it to your liking). Basically you can use this:
    Code:
    if ((lastBounceId != entity.id || System.currentTimeMillis() - lastBounceTick > 1000) && entity.getBukkitEntity().getLocation().distanceSquared(getBukkitEntity().getLocation()) <= 1) {
        EntityTargetEvent event = new NpcEntityTargetEvent(getBukkitEntity(), entity.getBukkitEntity(), NpcEntityTargetEvent.NpcTargetReason.NPC_BOUNCED);
        CraftServer server = ((WorldServer) world).getServer();
        server.getPluginManager().callEvent(event);
     
        lastBounceTick = System.currentTimeMillis();
        lastBounceId = entity.id;
    }
    just put it somewhere in the a_() method.


    I don't think there's a method for that but maybe you want to make a scheduler that does the following:
    Code:
    if target is in range
        animate arm swing
        damage target
     
    else
        walk towards target
     
  7. Offline

    Cue

    Has anyone has any luck with the lookAtPoint method?

    When I use it, it only looks at my location when I first spawn it (I'm calling it whenever I move near it), after that the NPC refuses to look anywhere else.

    I tried getting it to move but only changing the pitch and yaw, with a bit more success:
    http://dl.dropbox.com/u/16589629/minecraft/2012-04-14_13.48.18.png

    As you can see, the body looks at me, but not the head. Anyone got any ideas?
     
  8. Offline

    kumpelblase2

    Neodork likes this.
  9. Offline

    Neodork

    How do I get to use the lookAtPoint Method?

    Manager. ?? . ??

    Edit: Found it sorry for being lazy :)

    Code:java
    1. HumanNPC npc = (HumanNPC)plugin.m.getHumanNPCByName(input[0]);
     
  10. Offline

    notrodash

    Where can I download this? I cant seem to find a link anywhere!
     
  11. Offline

    tehbeard

    TopCat has a repo for it, let me look for the git link.

    https://github.com/Top-Cat/NPCLib
     
  12. Offline

    EchoMC

    I bet this sounds weird. Does anyone know how fast npcs walk? I'm trying to use the path functions to make npc walk around and need to set up timers.
     
  13. Offline

    rmb938

    NPCs don't like walking up blocks. The walk down them fine but walking up just makes them teleport.
     
  14. Offline

    Iron_Crystal

    Hey all, I am kinda lost here. I read through the other posts, and this is what I came up with for spawning an npc,

    Code:java
    1. package me.IronCrystal.NPCWorkers;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.PluginDescriptionFile;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. import com.topcat.npclib.NPCManager;
    13.  
    14.  
    15. public class NPCWorkers extends JavaPlugin{
    16.  
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18.  
    19. public static NPCWorkers plugin;
    20.  
    21. NPCManager m = new NPCManager(plugin);
    22.  
    23. @Override
    24. public void onDisable() {
    25. PluginDescriptionFile pdfFile = this.getDescription();
    26. this.logger.info(pdfFile.getName() + " is now disabled!");
    27. }
    28.  
    29. @Override
    30. public void onEnable() {
    31. PluginDescriptionFile pdfFile = this.getDescription();
    32. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
    33. PluginManager pm = getServer().getPluginManager();
    34. }
    35.  
    36. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    37. {
    38. Player player = null;
    39.  
    40. if (sender instanceof Player)
    41. {
    42. player = (Player) sender;
    43. }
    44. else
    45. {
    46. sender.sendMessage("You must be a player to use this command!");
    47. return true;
    48. }
    49.  
    50. if (cmd.getName().equalsIgnoreCase("npc"))
    51. {
    52. m.spawnHumanNPC("name of npc", player.getLocation());
    53. }
    54. return false;
    55. }
    56. }
    57.  


    But it comes up with this error upon onEnable

    Code:java
    1. 03:29:59 [SEVERE] Could not load 'plugins/NPCWorkers.jar' in folder 'plugins'
    2. org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin cannot be null
    3. at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:148)
    4. at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    5. at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    6. at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207)
    7. at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:183)
    8. at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:53)
    9. at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:156)
    10. at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:422)
    11. at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    12. Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    13. at org.bukkit.craftbukkit.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:189)
    14. at com.topcat.npclib.NPCManager.<init>(NPCManager.java:52)
    15. at me.IronCrystal.NPCWorkers.NPCWorkers.<init>(NPCWorkers.java:21)
    16. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    17. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    18. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    19. at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    20. at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:144)
    21. ... 8 more
    22.  


    What is going wrong?
     
  15. Offline

    Kekec852

    You should change NPCManager initialization

    Like:
    Code:
    public class NPCWorkers extends JavaPlugin{
     
        public final Logger logger = Logger.getLogger("Minecraft");
     
        public static NPCWorkers plugin;   
     
        NPCManager m;
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " is now disabled!");
            plugin = this;
            m = new NPCManager(plugin);
        }
    
     
    Iron_Crystal likes this.
  16. Offline

    Neodork

    Add this to your onEnable method and not onDisable like shown above..

    Code:java
    1. m = new NPCManager(this)


    +be sure to call it before you call any npc methods.
     
    Iron_Crystal likes this.
  17. Offline

    Iron_Crystal

  18. Offline

    Kekec852

    Ups and ty
     
  19. Offline

    Neodork

    So if I understand this right, I have to check if the CraftPlayer players contains the NPC's name. and whenever getBukkitEntity() is called I'm supposed to remove it from the CraftPlayer player?

    Anyone cares to enlighten me ?
     
  20. Offline

    fullwall

    Neodork - the cache has been removed as of the latest version of bukkit.
     
    Neodork likes this.
  21. Offline

    Neodork

    Thanks for the information!


    Edit: This makes my day ^^.
     
  22. Offline

    iKeirNez

    Wow this is awesome! Without this my plugin wouldn't be possible!
     
  23. Offline

    nehuskerfan2

    Thank you!!! I'm making a cop plugin and this will work out just fine :D
    Now I want to hide the name and this code doesn't even work when I paste it into Eclipse.
    ( I DON'T WANT SPOUT CODE )
     
  24. Offline

    Iron_Crystal

    Whats wrong with Spout code?
     
  25. Offline

    kumpelblase2

    No other way than spout since it's actually a player which ALWAYS has a nameplate.
     
  26. Offline

    nehuskerfan2

    Sorry I'm just a little bit confused, I'll leave the name in, I just want it to work like Citizens, does Citizens use Spout? I didn't fully skim through the plugin. >.>
     
  27. Offline

    kumpelblase2

    Not necessarily. But to be able to use skins, without using the skin provided by a player with that name, you'll probably need spout since there's no other way.
     
  28. Offline

    Waffletastic

    For some reason I can't cast an NPC to a human npc. Am I suppose to not be able to?

    How did you do it?

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

    Neodork

    Code:
    HumanNPC npc = (HumanNPC)plugin.m.getHumanNPCByName(input).get(0);
    The .get(0); should do the trick for you.
     
  30. Offline

    Taces

    I can't get it work...
    I included the latest craftbukkit RB, Spout and i put the classes from this link into my project (https://github.com/Top-Cat/NPCLib), but i still get errors, when i paste the listeners from the first poste into my code. Eclipse tells me that it can't find "BasicHumanNpc" and "NpcSpawner". Could you give me a link where this classes are included?
     
Thread Status:
Not open for further replies.

Share This Page