Guest User

[1.10+] Ways to use executeCommand() from a player event

a guest
Nov 29th, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*1.10 dummy ScriptBlock*/
  2. var timerID = 128 /*must be unique*/
  3. /*fill in the coordinated for the dummy block*/
  4. /*WARNING: all NBT data of that block will be lost*/
  5. var prev = {x:0,y:250,z:0};
  6. /*you will have to store any "special" event properties in a global variable to access them from the timer*/
  7. var proxy = {};
  8. function toss(event) {
  9.     proxy.item = event.item; /*storing Item in a global var*/
  10.     /*saving the block at given coords*/
  11.     prev.block = event.player.world.getBlock(prev.x,prev.y,prev.z);
  12.     if(prev.block) {
  13.         prev.id = prev.block.name;
  14.         prev.meta = prev.block.getMetadata();
  15.     }
  16.     /*creating a ScriptBlock*/
  17.     event.player.world.setBlock(prev.x,prev.y,prev.z,"customnpcs:npcScripted", 0);
  18.     event.player.timers.stop(timerID);
  19.     event.player.timers.start(timerID,1,false);
  20. }
  21. function timer(event) {
  22.     if(event.id == timerID) {
  23.         var dummy = event.player.world.getBlock(prev.x,prev.y,prev.z)
  24.         /*commands go here*/
  25.         dummy.executeCommand('/say '+proxy.item.displayName) /*using Item from toss event*/
  26.         /*restoring the original block*/
  27.         event.player.world.setBlock(prev.x,prev.y,prev.z,prev.id,prev.meta);
  28.     }
  29. }
  30. /*-------------------------------*/
  31. /*1.10+ using an NPC clone stored server-side*/
  32. function toss(event) {
  33.     /*fill in the tab and name of the saved clone*/
  34.     var clone = {tab:0,name:"CommandDummy"}
  35.     /*note that this doesnt spawn the npc into the world*/
  36.     var dummy = event.player.world.getClone(clone.tab, clone.name);
  37.     /*the command will be executed from NPC's position, defaults to 0,0,0*/
  38.     dummy.setPosition(event.player.x,event.player.y,event.player.z);
  39.     /*commands go here*/
  40.     dummy.executeCommand('/say '+event.item.displayName);
  41. }
  42. /*-------------------------------*/
  43. /*1.11+ with no clone setup required*/
  44. /*functionally identical to the above*/
  45. function toss(event) {
  46.     var dummy = event.player.world.createEntity('customnpcs:customnpc');
  47.     dummy.setPosition(event.player.x,event.player.y,event.player.z);
  48.     dummy.executeCommand('/say '+event.item.displayName);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment