I've added an optional third parameter "autoClose" to the SecretDoor Constructor. Used as follows:
//Door with a stone brick trigger block, 2 wooden planks as the door blocks, that does not auto close
var thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"], false);
//Door with a stone brick trigger block, 2 wooden planks as the door blocks, that auto closes after 2 seconds(40 Ticks); all of the following are equivelant
var thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"]);
var thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"], true);
var thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"], 40);
//Door with a stone brick trigger block, 2 wooden planks as the door blocks, that auto closes after 4 seconds(80 Ticks)
var thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"], 80);
SecretDoor 1.1
// Secret Door Script for CustomNPCs
// Tags: customnpcscript, Secret Door
// usage:
// var thisSecretDoor;
// function init(event){
// /*
// Door with a stone brick trigger block, 2 wooden planks as the door blocks, that does not auto close
// */
// //thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"], false);
// /*
// Door with a stone brick trigger block, 2 wooden planks as the door blocks, that auto closes after 2 seconds(40 Ticks); all of the following are equivelant
// */
// //thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"]);
// //thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"], true);
// //thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"], 40);
// /*
// Door with a stone brick trigger block, 2 wooden planks as the door blocks, that auto closes after 4 seconds(80 Ticks)
// */
// thisSecretDoor = new SecretDoor(event, ["minecraft:stonebrick", "minecraft:planks", "minecraft:planks"], 80);
// }
// function interact(event){
// thisSecretDoor.interact(event);
// }
// function timer(event){
// thisSecretDoor.timer(event);
// }
function SecretDoor(initEvent, blockList, autoClose){
switch((typeof autoClose)){
case 'boolean':
if(autoClose===true){
autoClose = 40; //2 seconds
}else{
autoClose=0;
}
break;
case 'number':
if(autoClose<0){
autoClose = 0;
}
break;
default:
autoClose = 40; //~2 seconds
break;
}
var block = this.block = initEvent.block;
this.blockList = blockList;
this.autoClose = autoClose;
this.block.setModel(this.block.getWorld().createItem(blockList[0], 0, 1));
this.x = Math.floor(block.getX());
this.y = Math.floor(block.getY());
this.z = Math.floor(block.getZ());
this.isOpen = false;
this.close();
}
SecretDoor.prototype.open = function(){
var world = this.block.getWorld();
this.block.executeCommand("/playsound tile.piston.in @a[r=10] "+this.x+" "+this.y+" "+this.z);
for(var i=1;i<this.blockList.length;i++){
var blockY = this.y - i;
world.setBlock(this.x, blockY, this.z, "minecraft:air", 0);
}
this.isOpen = true;
if(this.autoClose)
//start(or create if it doesn't exist) the "auto-close" timer (id 0, 40 ticks, don't repeat)
this.block.getTimers().start(0, this.autoClose, false);
};
SecretDoor.prototype.close = function() {
var world = this.block.getWorld();
this.block.executeCommand("/playsound tile.piston.out @a[r=10] "+this.x+" "+this.y+" "+this.z);
for(var i=1;i<this.blockList.length;i++){
var blockY = this.y - i;
world.setBlock(this.x, blockY, this.z, this.blockList[i], 0);
}
this.isOpen = false;
};
SecretDoor.prototype.interact = function(event) {
if(this.isOpen===true){
this.close();
}else{
this.open();
}
};
SecretDoor.prototype.timer = function(event) {
switch(event.id){
case 0:// "auto close"
this.close();
break;
}
};