Coder Social home page Coder Social logo

npcfactory's Introduction

NPCFactory

NPC Library for CraftBukkit mod. Inspired by NPCLib Scroll down for useful examples, and a change log.

IMPORTANT

this is massively, massively outdated. Please consider using a modern NPC plugin like Citizens instead of this library.

Examples

Here is a quick example on spawning an npc named lenis0012 without a skin:

final NPCFactory factory = new NPCFactory(plugin);
final Location location = new Location(Bukkit.getWorld("world"), 0, 100, 0);
NPC npc = factory.spawnHumanNPC(location, new NPCProfile("lenis0012"));
npc.setYaw(location.getYaw());

But if you want the npc to have a skin, you need to construct NPCProfile in an async task. Example to spawn lenis0012 with Notch skin:

final NPCFactory factory = new NPCFactory(plugin);
final Location location = new Location(Bukkit.getWorld("world"), 0, 100, 0);
new Thread() {

	@Override
	public void run() {
	    final NPCProfile profile = new NPCProfile("lenis0012", "Notch"); //version 1.3 and lower
		final NPCProfile profile = NPCProfile.loadProfile("lenis0012" , "Notch"); //version 1.4+ (Recommended)
		Bukkit.getScheduler().runTask(plugin, new Runnable() {

			@Override
			public void run() {
				NPC npc = factory.spawnHumanNPC(location, profile);
				npc.setYaw(location.getYaw());
			}
		});
	}
	
}.start();

You can also play animations on status, they are shown in NPCAnimation.java:

npc.playAnimation(NPCAnimation.SWING_ARM); //Swings npc's arm
npc.playAnimation(NPCAnimation.DAMAGE); //Displays red color on skin to mark player as hit.

You can also make npc's walk to certain points. In this case, we have a player called 'player' who is 40 blocks waway from an npc.

npc.pathfindTo(player.getLocation(), 0.2, 50); //Move to @player who is max 50 blocks away with a speed of 0.2 blocks per tick (4 per second)

And you can also make an npc look at a certain player. I this case we have a zombie called 'zombie' and we want our npc to look at him.

Note: The npc's pitch will not change form this method!

npc.lookAt(zombie); //Yup, thats all, use NULL here to stop looking at the zombie.

Changelog:

v1.4:

  • Updated to 1.7.10
  • Fixed issues with loading skins
  • Recoded NPCProfile, allowing to cache the profile

v1.3:

  • Fixed NPCInteractEvent, sort off....
  • Added gravity
  • Added setEquipment to change npc armor and held item
  • target Entity instead of LivingEntity

v1.2:

  • Added smexy path finding, such coding skills =)
  • Fixed NPE on target logout
  • Fixed non-entity damage not being applied

v1.1:

  • Added look at function for looking at locations
  • Added setTarget function for constantly looking at entities

v1.0:

  • Release

npcfactory's People

Contributors

ceramictitan avatar danielbenv avatar darkshimy00 avatar doctordark avatar farisr99 avatar plazmaz avatar supaham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

npcfactory's Issues

NPC Metadata interefes with actual Player Metadata

When an NPC is spawned its CraftPlayer is given the "NPC" Metadata. When a real CraftPlayer instance (actual player) is checked for the 'NPC' metadata, and an NPC has the name of the player, then it returns true. This is due to the way Player metadata is stored, it's stored 'name:key', this is a rather big issue and can easily be prevented.

  1. Override the NPCEntity's CraftPlayer PlayerMetadataStore to store by entity id or something.

  2. when checking for isNPC, return entity instanceof NPCEntity

I'd recommend the former.

Add potion effect to npc

Hi lenis! thanks for your library to create npcs!!!

I have a problem :S im using ur NPCFactory version for spigot 1.7.9 and works great, but i have a problem. I need add invisibility potion effect to a npc, but it doesnt work...

PotionEffect potion = new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1);

npc.getBukkitEntity().addPotionEffect(potion);

what can i do? :s:
Thanks

Update to 1.10

the current version is for Spigot 1.8.x and i need for 1.10.x so please update it, i really love it !

NpcInteractEvent not being called correctly.

If an NPC is right clicked, using this event will not do anything, instead you have to get the entity by the PlayerInteractEntityEvent and checking the entity that is right-clicked has the 'NPC' metadata.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.