NpcSpawner lib - spawn basic NPCs

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

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

    jeffadkins51

    There is a like button, learn to use it.
     
  2. Offline

    Pencil

    Just wondering, is it possible to spawn an npc that looks like hes in a bed? :3
     
  3. Offline

    Kekec852

    i don't know. If I'll have some time i'll look in to.
     
  4. Offline

    Pencil

    if it is that would be awesome :D
     
  5. Offline

    fullwall

    @Pencil - I have partially looked into this already, and I couldn't find any way to do it from what I saw (the lying down is handled in RenderLiving/Player, and you actually have to be in a bed to trigger it, IIRC).
     
  6. Offline

    Pencil

    DAMN! That sucks :/
     
  7. Offline

    linio

    Good work!
    But i have an error in spawn:
    java.lang.NoSuchFieldException: j
    And it's my code where i spawn a NPC:
    Code:
        public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
            // TODO Auto-generated method stub
            String[] args = event.getMessage().split(" ");
            Player p = event.getPlayer();
            String cmd = new String("['");
            for(int i = 0;i<args.length;i++){
                cmd = cmd.concat(args[i]+"',");
            }
            cmd+=cmd.concat("]");
            p.sendMessage("args:"+cmd);
     
            if(args[0].equalsIgnoreCase("/npc")){
                NPCManager NPCman = new NPCManager(this.plugin);
                Location pos = p.getLocation();
                NPCEntity spawned = null;
                if(args.length > 1){
                    spawned = NPCman.spawnNPC(args[1], pos);
                }else{
                    spawned = NPCman.spawnNPC("Unnamed", pos);
                }
                if(spawned!=null){
                    p.sendMessage(String.valueOf(spawned.health));
                    spawned.health = 20;
                    p.sendMessage(
                            "NPC added("+spawned.getName()+":"+String.valueOf(spawned.id)+")"
                    );
                }else{
                    p.sendMessage(
                            "Npc error on spawn"
                    );
                }
    
            }
        }
     
  8. Offline

    Kekec852

    Could you get me ful stack trace and Craftbukkit build number on pm.
     
  9. Offline

    Top_Cat

    I think I've fixed this and one other bug to work from #882 onwards

    Also, @Pencil use new putNPCinbed(String npcId, Location bedLocation) function in the manager :)
     
  10. Offline

    linio

    Yes, it's done.
    But i can't kill the npc yet and only the first hit is good i think.
     
  11. Offline

    Kekec852

    No you can't do that yet ...
     
  12. Offline

    fullwall

    @Kekec852 - that's because you need to call entityliving.Q() every tick (or decrement noDamageTicks).
     
    jordandmc likes this.
  13. Offline

    linio

    I do what you say.
    So i could damge it but it don't "unspawn" when it should be dead.
    I have thie message when it should die:
    "23:37:04 [INFO] [email protected](linio at 121.34375,85.0,113.15625)"

    And i have a little bug with damage:
    When i strike it as fast as i can, it take some damage between a few pause like i am mining.
     
  14. Offline

    fullwall

    @linio - you need to remove the entity yourself when it dies.
     
    mbsuperstar1 and jordandmc like this.
  15. Offline

    Lolmewn Retired Staff

    You deserve more then 2 likes.
     
  16. Offline

    IceReaper

    hm.. when i try to add this, i simply put this line in my plugin class:
    public final NPCManager npcManager = new NPCManager(this);

    when i now compile the whole plugin crashes. (using latest RB) anyone has an idea?
     
  17. Offline

    Pencil

    Daimn I never got this notification >.>

    Thats awesome, but does it require a bed? :3
     
  18. Offline

    Top_Cat

    Are you sure you have the latest version?
    Also post the log, I'll be able to work out what it is then ;)

    It does not actually require a bed, no :p
     
  19. Offline

    Pencil

    Zomg! Thanks :D *Time for epic plugin*
     
  20. Offline

    IceReaper

    oaky. goint to github, getting master as .zip, unpacking, adding to my src folder..
    it already gives me 3 errors:
    The method die() in the type EntityHuman is not applicable for the arguments (Entity) NPCEntity.java /NoveriaServer/src/org/martin/bukkit/npclib line 141 Java Problem
    The method die(Entity) of type NPCEntity must override or implement a supertype method NPCEntity.java /NoveriaServer/src/org/martin/bukkit/npclib line 139 Java Problem
    The method queue(Packet) of type NPCNetworkManager must override or implement a supertype method NPCNetworkManager.java /NoveriaServer/src/org/martin/bukkit/npclib line 31 Java Problem

    so i start:
    NPCEntity:
    comment out line 138 and 141
    NPCNetworkManager:
    comment out line 30

    all errors gone!

    now i add this line at top of my plugin:
    public final NPCManager npcManager = new NPCManager(this);
    and of course include:
    import org.martin.bukkit.npclib.NPCManager;

    no error, so i export the .jar...
    i run the server and get an plugin crash. exact message is:
    Code:
    [SEVERE] null
    java.lang.NullPointerException
        at org.martin.bukkit.npclib.BServer.<init>(BServer.java:35)
        at org.martin.bukkit.npclib.BServer.getInstance(BServer.java:119)
        at org.martin.bukkit.npclib.NPCManager.<init>(NPCManager.java:28)
        at de.icereaper.NoveriaServer.NoveriaServer.<init>(NoveriaServer.java:45)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:199)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:122)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:118)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:89)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:132)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:335)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    2011-06-28 19:55:57 [SEVERE] Could not load 'plugins\NoveriaServer.jar' in folder 'plugins':
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:199)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:122)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:118)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:89)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:132)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:335)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    Caused by: java.lang.NullPointerException
        at org.martin.bukkit.npclib.NPCManager.<init>(NPCManager.java:29)
        at de.icereaper.NoveriaServer.NoveriaServer.<init>(NoveriaServer.java:45)
        ... 13 more
     
  21. Offline

    Top_Cat

    The die and queue methods exist only in the latest craftbukkit update when a load of stuff was renamed, before both of these methods were named "a" that is the correct solution... or update craftbukkit.
     
  22. Offline

    IceReaper

    so
    Code:
        public void a(Packet packet) {
        }
    and
    Code:
        public void a(EntityLiving entityliving) {
            System.out.println(entityliving);
            super.a(entityliving);
        }
    is all i need to do? i tried but still crashes. is there a revision which works with latest RB ?
    after renaing that 3 methods i get:
    Code:
    [SEVERE] null
    java.lang.NullPointerException
        at org.martin.bukkit.npclib.BServer.<init>(BServer.java:35)
        at org.martin.bukkit.npclib.BServer.getInstance(BServer.java:119)
        at org.martin.bukkit.npclib.NPCManager.<init>(NPCManager.java:28)
        at de.icereaper.NoveriaServer.NoveriaServer.<init>(NoveriaServer.java:45)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:199)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:122)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:118)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:89)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:132)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:335)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    2011-06-28 20:29:36 [SEVERE] Could not load 'plugins\NoveriaServer.jar' in folder 'plugins':
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:199)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:122)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:118)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:89)
        at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:132)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:335)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    Caused by: java.lang.NullPointerException
        at org.martin.bukkit.npclib.NPCManager.<init>(NPCManager.java:29)
        at de.icereaper.NoveriaServer.NoveriaServer.<init>(NoveriaServer.java:45)
        ... 13 more
     
  23. Offline

    Top_Cat

    You need to initialise the variable in the onEnable sub not at the top.
     
  24. Offline

    IceReaper

    thank you very much. after renaming all 3 methods, and putting the line in onEnable it works :)

    when using .setName() and .setItemInHand() i need to relog to see the changes. so i think respawning the npc after this would work also. is this planned to be implemented? or how should i handle this?

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

    killgoblen

    Ah. Just read the last page. So this is not updated for 1.6?
     
  26. Offline

    IceReaper

    sure, load actual version from github, look at my post 146 and change the 2 functions, then it works :D
     
  27. Offline

    desmin88

  28. Offline

    Kekec852

    Yes, but you need build #938 or newer.
     
  29. Offline

    IceReaper

    hm.. spawning npcs basicaly works... when i teleport away and back, they are gone, but their id is still registered! is there any way to resolve this problem?
     
  30. Offline

    desmin88

    @Kekec852
    Why can't you do instanceof NPCEntity to check if something is an NPC?
    Also, why is there no attack living entity function?
     
Thread Status:
Not open for further replies.

Share This Page