Crates!

Code Block

Tags:

None

Creator:

TerabyteThunder

Code:

crateName  = "Crate"; // crate name
keyItem    = "Dirt"; // item for the crate
itemCheck  = api.getInventoryItemAmount(myId, keyItem); // check for the items
needAmount = 1; // the amount you need
RNG        = Math.random()*100+1; // rng from 1 to 100
if (itemCheck >= 1){
api.removeItemName(myId, keyItem, needAmount);
api.sendMessage(myId, "Opened a "+crateName+"!");
if (RNG < 20){
api.sendMessage(myId, "You got a Diamond Sword!",{color:"cyan"});
api.giveItem(myId, "Diamond Sword", 1);
} else
if (RNG < 50){
api.sendMessage(myId, "You got a Gold Sword!",{color:"gold"});
api.giveItem(myId, "Gold Sword", 1);
} else
if (RNG < 90){
api.sendMessage(myId, "You got an Iron Sword!",{color:"whitr"});
api.giveItem(myId, "Iron Sword", 1);
} else
if (RNG < 100){
api.sendMessage(myId, "JACKPOT! You got a Knight Sword!",{color:"cyan"});
api.giveItem(myId, "Knight Sword", 1);
}} else
if (itemCheck <= 1){
api.sendMessage(myId, "You need "+(needAmount - itemCheck)+" more "+keyItem+"!",{color:"red"});
}

Instructions:

Look at the code