NpcSpawner lib - spawn basic NPCs

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

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

    fullwall

    Respawn the NPC yourself.
     
  2. Offline

    Ygreg

    I would do it, but I still don't know how to check if the NPC is still there. Even after the NPC dissapears, I still get a valid HumanEntity from getBukkitEntity(), and even if I check the location of this entity, it's still the same. How can I check if the NPC should be respawned?
     
  3. Offline

    fullwall

    Hook onChunkUnloaded and onChunkLoaded. Check my github/citizens/worldlisten.java for an example.
     
  4. Offline

    Ygreg

    I didn't think of that, thanks!

    Last time I checked, the source code for citizens was not available. Maybe I'll just add some functionality to your plugin instead of writing my own [​IMG]
     
  5. Offline

    fullwall

    What kind of functionality? You could always submit a pull request for me to add ;). I just added the source, it's in a much better position than it was earlier.
     
  6. Offline

    Ygreg

    I'll be porting a custom NPC I had on my server while running hmod. It was buying materials for the construction of a city, and dispensing them to city builders. We are playing with just a few friends, so it didn't have any permissions. Anyone could sell materials, then take them back, sell again, so it was generaly useless for a larger server. I'll let you know if I make anything useful this time.
     
  7. Offline

    tips48

    im gonna look into it... :confused:
     
  8. Offline

    Kekec852

    On CraftBukkit builds past 1.5._02 update brake this lib. I'am trying to fix it but no luck.

    I successfully upgrade it ... but no events are passed to it ... Tomorow i'll post the code.

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

    MatCat

    Yeah I need to know how you fixed, trying to update my NPCTrader plugin
     
  10. Offline

    jmonk

    Any chance I can get a look at this code? I have been fighting with this but unable to get it going so far. Got an null exception thrown by the NetworkReaderThread that I can't seem to get rid of.
     
  11. Offline

    Kekec852

    Here is Fixed NPCLib: https://github.com/Kekec852/NPCLib
    It's litle diferent than the original but events are same. I change how you spawn new NPC.

    In main plugin class you need this:
    Code:
    NPCManager m = new NPCManager(this);
    
    When you like to spawn one:
    Code:
    NPCEntity npc = m.spawnNPC("NPCName", location);
    
     
  12. Offline

    Top_Cat

    This is great, however I'm having an issue. Any NPC with a name longer than 16 charecters causes the client to disconnect with the error "Received string length longer than maximum allowed ( X > 16 )" Where X is the length of the name.

    They worked fine before, is this something in the 1.5 update from mojang or an issue we can solve?

    P.S. I added a pull request to pass rotation in the spawn command :)
     
  13. Offline

    MatCat

    I believe this limit was put in by the bukkit team themselves.
     
  14. Offline

    Kekec852

    I'll look into it.

    I think that error is caused by client. Because NPC get spawnd but all players in area get disconnected ...

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

    Ggnore_

    um where do i put the file >.>
     
  16. Offline

    Kekec852

    Use this lib as befor ... copy files into your project
     
  17. Offline

    kingzeus91

    ...uhm... yea.. still not getting where u put files...
     
  18. Offline

    aPunch

    This isn't a plugin. It is a library for use by plugin developers.
     
  19. Offline

    kingzeus91

    hmm i know but like isnt it also to help with fixing spawn errors and stuff? cuz im using npc spirits and im getting so lost.... and confused >.> cuz its not working for me sighz.
     
  20. No. This is just code. You shouldn't be trying to fix a plugin yourself unless you're working with the code.
     
  21. Offline

    oleg

    in witch folder lib,plugins,Modim what you mean project

    and craft bukkit is it : craftbukkit-0.0.1-SNAPSHOT ? :/

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

    Kekec852

  23. Mine face hath collided with mine hand in exasperation.

    If you're not a programmer, you shouldn't be touching the files in this thread. End of story.
     
    Kohle, anon and deathhorn like this.
  24. Offline

    Linkupdated

    how do you get the entity when the event is called
    before it was :
    BasicHumanNpc npc = parent.HumanNPCList.getBasicHumanNpc(event.getEntity());
     
  25. Offline

    przerwap

    1. Create your own data structure
    2. Add NPC's to said Data stucture upon creation
    3. Sift through data structure comparing Unique Entity Id's ( net.minecraft.server.Entity.id (int))
    4. If Id of said Entity inside event matches Id of Entity of NPC in data structure return NPC
    5. Perform actions on that NPC
     
  26. Offline

    MatCat

    Has anyone else come across any performance issues with the new lib? I for the life of me cannot figure out where the lag is coming from with my NPCTrader plugin.
     
  27. Offline

    Linkupdated

    THANKS :p works !
     
  28. Offline

    Top_Cat

    I added a function called getNPCIdFromEntity to the manager. Simply pass the event.getEntity(); and it does the above and returns the id of the NPC that was hit, other wise it returns null. You can then use this id to perform actions on the NPC

    :)

    EDIT: MatCat, tbh I've had a lot of lag recently for one reason or another. I've tried having no npcs spawn and i'm not sure it helps a huge deal. Obviously with a lot it's more problematic.
    I was looking at trying to get them to despawn using chunk unload but chunks with them in didn't seem to ever unload :/

    I'd also like to mention my pathfinding code, it's probably shouldn't be used heavily for performance reasons, but for small things it's quite cool to have the NPCs be able to make their way between too locations.
     
  29. Offline

    MatCat

    Yeah for me the focus is on economic function, not exactly NPC function. Toobad we cant just use the monster entity class and have a way to display a name above! Then we would have predefined code or movement.

    You should look at my NPCTrader github, I have spawn/despawn tied to chunk load/unload, but remember spawn never unloads!
     
  30. Offline

    przerwap

    Probably because if you use this guys 'BasicHumanNpcList' or specifically its getBasicHumanNpc(Entity) method it scans through ALL the NPC's in that list linearly to try and match the Entity Id's. As the list grows it takes longer to search, How often you search is also a large factor of the equation.
    If you use a separate Thread incorrectly it would also cause the server to hang.

    EDIT:
    Oh good god, In your case all of the above, but the Thread, apply. Only multiply that by 10. I can bet my money that its 70% your onPlayerMove which sifts through all the NPC's every time a Player moves. And about 30% the onChunkLoaded event. You cannot simply sift through a ton of NPC's like that. Entities are sorted into Chunks not just for fun, its because it eliminates an asston of comparisons. You gotta do the same, create a Chunk data structure thats easily accessible and quick to manage. You only need to Sort ONCE when they are loaded, and simply put them int the right place when you add a new one, but for the love of god dont do linear searches though ALL of them everytime Anyone moves. It wouldn't be as bad it onPlayerMove was called only when someone moves from block to block, but its called when people move their head aswell, not sure how often its called but I sure as hell know that you dont have to sift though them every time it IS called. If your not going to take my advice at the Least add this:
    Code:
    if(System.currentTimeMillis() - lastCheckTick > 5000) {
    Just that you need to separate it for each player.
     
Thread Status:
Not open for further replies.

Share This Page