Creating and Spawning Custom NPC's

Discussion in 'Plugin Development' started by Sabersamus, Aug 2, 2012.

  1. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Simple question, How do i do it?

    Im not asking for code, im not asking for you to do anything for me.

    Since february i've been getting 'decent' with java, and the Bukkit API.

    I'm just asking for maybe a walk through, a tutorial, or maybe just a helping hand.

    I know its possible, i just don't know what to do.

    Thanks!

    //Sabersamus
  2. Offline

    Firefly

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Plenty of threads have answered this, just search! :)
  3. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I did search, I haven't found anything. I looked for about half an hour :p
  4. Offline

    Firefly

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    From what I've seen in many threads, the best way is to look through the NPC lib used by a plugin that does this (the name of the plugin slips my mind at the moment)
  5. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  6. Offline

    Firefly

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Probably. I'm not sure.
  7. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Eh, :/ i wanted to challenge myself and not use someone elses code with this
    DealerNextDoor likes this.
  8. Online

    ZeusAllMighty11 BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I think the plugin was outdated, so I stopped replying to people when they asked for it.

    But here's the thread you were talking about: http://forums.bukkit.org/threads/npcspawner-lib-spawn-basic-npcs.3298/
  9. Offline

    Icyene

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    There are quite alot of resources to do this.

    I'd direct you to this tutorial.
    Additionally, if you feel you need to do more advanced things, you might find a simple Advanced Mob API I wrote a while for zombies and wolves. It is here.

    Please note that both the resources I've provided are 1.2.5 DEPENDENT, and probably will NOT WORK with 1.3. I'll update the second resource's classes sometime tomorrow.

    This post has been edited 3 times. It was last edited by Icyene Aug 2, 2012.
  10. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    (bump)

    I have this HUGE error (i replaced all SpawnReason.CUSTOM creepers with my custom 'extends EntityPlayer' NPC's)

    As soon as i spawn one:

    Code:
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:304)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredLi
    stener.java:35)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callCreatureSpawnEvent
    (CraftEventFactory.java:226)
            at net.minecraft.server.World.addEntity(World.java:887)
            at net.minecraft.server.SpawnerCreature.spawnEntities(SpawnerCreature.ja
    va:180)
            at net.minecraft.server.World.doTick(World.java:1735)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:546)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
            at net.minecraft.server.EntityTrackerEntry.updatePlayer(EntityTrackerEnt
    ry.java:240)
            at net.minecraft.server.EntityTracker.track(EntityTracker.java:33)
            at net.minecraft.server.WorldManager.a(WorldManager.java:16)
            at net.minecraft.server.World.c(World.java:921)
            at net.minecraft.server.WorldServer.c(WorldServer.java:164)
            at net.minecraft.server.World.addEntity(World.java:914)
            at info.bytecraft.npcs.NPCPlugin$EntityListener.onSpawn(NPCPlugin.java:5
    8)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302)
            ... 11 more
    00:59:40 [SEVERE] Could not pass event CreatureSpawnEvent to NPCs
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:304)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredLi
    stener.java:35)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callCreatureSpawnEvent
    (CraftEventFactory.java:226)
            at net.minecraft.server.World.addEntity(World.java:887)
            at net.minecraft.server.SpawnerCreature.spawnEntities(SpawnerCreature.ja
    va:180)
            at net.minecraft.server.World.doTick(World.java:1735)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:546)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
            at net.minecraft.server.EntityTrackerEntry.updatePlayer(EntityTrackerEnt
    ry.java:240)
            at net.minecraft.server.EntityTrackerEntry.scanPlayers(EntityTrackerEntr
    y.java:286)
            at net.minecraft.server.EntityTracker.addEntity(EntityTracker.java:99)
            at net.minecraft.server.EntityTracker.addEntity(EntityTracker.java:82)
            at net.minecraft.server.EntityTracker.track(EntityTracker.java:25)
            at net.minecraft.server.WorldManager.a(WorldManager.java:16)
            at net.minecraft.server.World.c(World.java:921)
            at net.minecraft.server.WorldServer.c(WorldServer.java:164)
            at net.minecraft.server.World.addEntity(World.java:914)
            at info.bytecraft.npcs.NPCPlugin$EntityListener.onSpawn(NPCPlugin.java:5
    8)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302)
            ... 11 more
    00:59:40 [SEVERE] java.lang.NullPointerException
    00:59:40 [SEVERE]      at net.minecraft.server.EntityTrackerEntry.updatePlayer(
    EntityTrackerEntry.java:240)
    00:59:40 [SEVERE]      at net.minecraft.server.EntityTrackerEntry.scanPlayers(E
    ntityTrackerEntry.java:286)
    00:59:40 [SEVERE]      at net.minecraft.server.EntityTracker.addEntity(EntityTr
    acker.java:99)
    00:59:40 [SEVERE]      at net.minecraft.server.EntityTracker.track(EntityTracke
    r.java:65)
    00:59:40 [SEVERE]      at net.minecraft.server.WorldManager.a(WorldManager.java
    :16)
    00:59:40 [SEVERE]      at net.minecraft.server.World.c(World.java:921)
    00:59:40 [SEVERE]      at net.minecraft.server.WorldServer.c(WorldServer.java:1
    64)
    00:59:40 [SEVERE]      at net.minecraft.server.World.addEntity(World.java:914)
    00:59:40 [SEVERE]      at net.minecraft.server.SpawnerCreature.spawnEntities(Sp
    awnerCreature.java:180)
    00:59:40 [SEVERE]      at net.minecraft.server.World.doTick(World.java:1735)
    00:59:40 [SEVERE]      at net.minecraft.server.MinecraftServer.w(MinecraftServe
    r.java:546)
    00:59:40 [SEVERE]      at net.minecraft.server.MinecraftServer.run(MinecraftSer
    ver.java:451)
    00:59:40 [SEVERE]      at net.minecraft.server.ThreadServerApplication.run(Sour
    ceFile:492)
    00:59:40 [SEVERE] Unexpected exception
    java.lang.NullPointerException
            at net.minecraft.server.EntityTrackerEntry.updatePlayer(EntityTrackerEnt
    ry.java:240)
            at net.minecraft.server.EntityTrackerEntry.scanPlayers(EntityTrackerEntr
    y.java:286)
            at net.minecraft.server.EntityTracker.addEntity(EntityTracker.java:99)
            at net.minecraft.server.EntityTracker.track(EntityTracker.java:65)
            at net.minecraft.server.WorldManager.a(WorldManager.java:16)
            at net.minecraft.server.World.c(World.java:921)
            at net.minecraft.server.WorldServer.c(WorldServer.java:164)
            at net.minecraft.server.World.addEntity(World.java:914)
            at net.minecraft.server.SpawnerCreature.spawnEntities(SpawnerCreature.ja
    va:180)
            at net.minecraft.server.World.doTick(World.java:1735)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:546)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    >

    This post has been edited 1 time. It was last edited by Sabersamus Aug 4, 2012.
  11. Offline

    Icyene

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    There is no way someone other then Jon Skeet can troubleshoot without the code that caused that =/
  12. Offline

    Firefly

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Nullpointer in your onSpawn handler on line 58. ;) Code for that method please?
  13. Offline

    Clem

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Any guys ported this to python? I've been using the pythonplugin loader (a god-send) for my plugins...

    I can read Java codes, but if it gets quite long I find myself having problems xD
  14. Offline

    devilquak

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Sorry to bring up a 3-day old post, but I'm trying to do this as well, and it's hard to do something without knowing where to start or having anything to start off of. While you can see the source for most of the NPC plugins, pretty much all of them have super-restrictive licenses where you can only see the source code and aren't allowed to distribute a modified version at all under any circumstances. It looks like the ones Icyene linked to would work but I think they're outdated, is there anything like that I can reference off of that is built to work off the current CB?
  15. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code:java
    1. public void onSpawn(CreatureSpawnEvent event){
    2. if (event.isCancelled()) return;
    3.  
    4. Location location = event.getLocation();
    5. Entity entity = event.getEntity();
    6. EntityType creatureType = event.getEntityType();
    7. World world = location.getWorld();
    8.  
    9. net.minecraft.server.World mcWorld = ((CraftWorld) world).getHandle();
    10. net.minecraft.server.Entity mcEntity = (((CraftEntity) entity).getHandle());
    11.  
    12. if (creatureType == EntityType.VILLAGER && mcEntity instanceof HumanNPC == false){
    13. HumanNPC npc = new HumanNPC(((CraftServer)Bukkit.getServer()).getServer(), mcWorld, "Npc", new ItemInWorldManager(mcWorld));
    14.  
    15. npc.setPosition(location.getX(), location.getY(), location.getZ());
    16.  
    17. mcWorld.removeEntity((net.minecraft.server.EntityVillager) mcEntity);
    18. mcWorld.addEntity(npc, SpawnReason.CUSTOM);
    19.  
    20. return;
    21. }
    22. }


    sorry, i meant to put the code but i lost internet
  16. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @devilquak
    AFAIK, the one that @ZeusAllMighty11 mentioned works for RB 1.3 as I'm currently using it. So far, I've managed to spawn an NPC, make it move/look at players, and currently I'm trying to code a combat bot for my plugin. If you need any help, PM me and I'll try to explain the basics.

Share This Page