Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*1.10 dummy ScriptBlock*/
- var timerID = 128 /*must be unique*/
- /*fill in the coordinated for the dummy block*/
- /*WARNING: all NBT data of that block will be lost*/
- var prev = {x:0,y:250,z:0};
- /*you will have to store any "special" event properties in a global variable to access them from the timer*/
- var proxy = {};
- function toss(event) {
- proxy.item = event.item; /*storing Item in a global var*/
- /*saving the block at given coords*/
- prev.block = event.player.world.getBlock(prev.x,prev.y,prev.z);
- if(prev.block) {
- prev.id = prev.block.name;
- prev.meta = prev.block.getMetadata();
- }
- /*creating a ScriptBlock*/
- event.player.world.setBlock(prev.x,prev.y,prev.z,"customnpcs:npcScripted", 0);
- event.player.timers.stop(timerID);
- event.player.timers.start(timerID,1,false);
- }
- function timer(event) {
- if(event.id == timerID) {
- var dummy = event.player.world.getBlock(prev.x,prev.y,prev.z)
- /*commands go here*/
- dummy.executeCommand('/say '+proxy.item.displayName) /*using Item from toss event*/
- /*restoring the original block*/
- event.player.world.setBlock(prev.x,prev.y,prev.z,prev.id,prev.meta);
- }
- }
- /*-------------------------------*/
- /*1.10+ using an NPC clone stored server-side*/
- function toss(event) {
- /*fill in the tab and name of the saved clone*/
- var clone = {tab:0,name:"CommandDummy"}
- /*note that this doesnt spawn the npc into the world*/
- var dummy = event.player.world.getClone(clone.tab, clone.name);
- /*the command will be executed from NPC's position, defaults to 0,0,0*/
- dummy.setPosition(event.player.x,event.player.y,event.player.z);
- /*commands go here*/
- dummy.executeCommand('/say '+event.item.displayName);
- }
- /*-------------------------------*/
- /*1.11+ with no clone setup required*/
- /*functionally identical to the above*/
- function toss(event) {
- var dummy = event.player.world.createEntity('customnpcs:customnpc');
- dummy.setPosition(event.player.x,event.player.y,event.player.z);
- dummy.executeCommand('/say '+event.item.displayName);
- }
Advertisement
Add Comment
Please, Sign In to add comment