Math.random() gives a random number between 0 and 1. You can easily turn this in a random number of your choice:
var num;
num = (int) Math.random()*100+1; //This line saves a random number from 0 until 100 in the variable num. (I don´t know if you Need (int) at ModPE-Scripts)
For your own random numbers Change the "*100", NOT THE "+1"!
You wrote Level.dropItem, but you can only drop one item (one Id) whenever you want to use this, so just write Level.dropItem
At if you have to write (rnd==0)
You shouldn`t make Level.getTile() in a destroy-hook, because then the block you want to check doesn´t exist anymore
I dont know anything about the function random
will someone explain it to me plz!
function destroyBlock(x, y, z, side){
if (Level.getTile(x, y, z)==2){
var rnd = random(0,2);
if (rnd=0){
setTile(Player.getX(), Player.getY()-2, Player.getZ(), 10);
}
else if (rnd=1){
setTile(x, y+1, z, 7);
clientMessage("Well there's your problem");
}
else if (rnd=2){
Level.dropItems(x, y, z, 0, 263, 3, 0);
}
Level.destroyBlock(x, y, z, false);
}
}
function random(min, max) { //inclusive
return Math.floor(Math.random()*(max+1)+min);
}
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumMath.random() gives a random number between 0 and 1. You can easily turn this in a random number of your choice:
var num;
num = (int) Math.random()*100+1; //This line saves a random number from 0 until 100 in the variable num. (I don´t know if you Need (int) at ModPE-Scripts)
For your own random numbers Change the "*100", NOT THE "+1"!
You wrote Level.dropItem, but you can only drop one item (one Id) whenever you want to use this, so just write Level.dropItem
At if you have to write (rnd==0)
You shouldn`t make Level.getTile() in a destroy-hook, because then the block you want to check doesn´t exist anymore
var check=0;
function useItem(x,y,z,itemId,blockId,side){
if(blockId==2){
check==1;
}
}
function destroyBlock(x, y, z, side) {
if(check==1){
check=0;
var rnd = Math.random()*2+1;
if (rnd==0){
setTile(Player.getX(), Player.getY()-2, Player.getZ(), 10);
}
if (rnd==1){
Level.setTile(x, y+1, z, 7);
clientMessage("Well there's your problem");
}
if (rnd==2){
Level.dropItem(x, y, z, 0, 263, 3, 0);
}
Level.destroyBlock(x, y, z, false);
}
}
}
}