TheBeastGamer25

NPC

Oct 22nd, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. pluginManager.register("NPCKit", function(lib) {
  2.  
  3. var usage = "/npc <create|say|teleportTo|stop> ...";
  4. var usageCreate = "/npc create <NPC name> <Entity ID> [Command to run on click]";
  5. var usageSay = "/npc say <NPC name> <Text>";
  6. var usageTP = "/npc teleportTo <x> <y> <z>";
  7. var errorColor = "rgb(255,0,0)";
  8.  
  9. var command = lib.getBlock().command + " ";
  10.  
  11. var type = lib.getBlock().type;
  12. var conditional = lib.getBlock().conditional;
  13. var auto = lib.getBlock().auto;
  14.  
  15. if(command.indexOf("/npc ") == 0 || command.indexOf("npc") == 0) {
  16. //Is a /npc command
  17. command = command.substring(0,command.length-1)
  18. var args = command.split(" ");
  19. //Split the string between spaces, and get an array out of it.
  20.  
  21. if(args.length <= 1) {
  22. lib.break();
  23. lib.throw("Error: No arguments found for /npc command. Usage: " + usage + "\n(At line " + lib.getLineNumber() + ")", errorColor);
  24. }
  25.  
  26. if(args.length >= 1 && args[1] == "create") {
  27. if(args[2] != null && args[2].length >= 1) {
  28. if(args[3] != null) {
  29. lib.newBefore("/give @p minecraft:spawn_egg 1 0 {display:{Name:\"" + args[2] + "\"},EntityTag:{id:\"" + args[3] + "\",Tags:[\"" + args[2] + "\"],Offers:{Recipes:[]},NoAI:1b,IsBaby:0b}}");
  30. if(args[4] != null) {
  31. var clickCMD = args.slice(4).join(" ");
  32. lib.newBefore("/scoreboard objectives add npcClick stat.talkedToVillager");
  33. lib.newCommand("/execute @a[score_npcClick_min=1] ~ ~ ~ /execute @e[tag=" + args[2] + "] ~ ~ ~ /execute @a[r=5,score_npcClick_min=1] ~ ~ ~ /execute @e[tag=" + args[2] + ",c=1] ~ ~ ~ " + clickCMD, type, conditional, auto);
  34. }
  35. } else {
  36. lib.break();
  37. lib.throw("Error: No entity ID found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  38. }
  39. } else {
  40. lib.break();
  41. lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  42. }
  43. lib.skip();
  44. }
  45.  
  46. if(args.length >= 1 && args[1] == "say") {
  47. if(args[2] == null) {
  48. lib.break();
  49. lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  50. } else {
  51. var sayString = args.slice(3).join(" ");
  52. lib.setCommand("/execute @e[tag=" + args[2] + "] ~ ~ ~ /say " + sayString);
  53. }
  54. }
  55.  
  56. if(args.length >= 1 && args[1] == "teleportTo") {
  57. if(args[2] == null) {
  58. lib.break();
  59. lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  60. } else if(args[3] == null) {
  61. lib.break();
  62. lib.throw("Error: No X coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  63. } else if(args[4] == null) {
  64. lib.break();
  65. lib.throw("Error: No Y coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  66. } else if(args[5] == null) {
  67. lib.break();
  68. lib.throw("Error: No Z coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  69. } else {
  70. lib.setCommand("/tp @e[tag=" + args[2] + "] " + args[3] + " " + args[4] + " " + args[5]);
  71. }
  72. }
  73.  
  74. if(args.length >= 1 && args[1] == "stop") {
  75. lib.setCommand("/scoreboard players reset @a[score_npcClick_min=1] npcClick");
  76. }
  77. }
  78.  
  79. });
Advertisement
Add Comment
Please, Sign In to add comment