Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MAKE SURE TO SAVE YOUR CURRENCY BY OVERWRITING THE CURRENCY VARIABLE BELOW THIS LINE BEFORE YOU EXIT MINECRAFT
- let currency = 0
- let selloff = 0.5 // selling an item is worth this value times the buy value of the item
- let boom = 100 // price boom, all prices and value of currency will be mutiplied by this number
- let gamble = true // set to true to enable to ability to gamble your earnings (INCREDIBLY UNBALANCED)
- player.onChat(";bal", function() {
- chat("§aYou have: §l$"+currency.toString(),false)
- })
- let marketplace_items = [
- [IRON_INGOT,"iron",1,"iron_ingot"],
- [DIAMOND,"diamond",13,"diamond"],
- [GOLD_INGOT,"gold",2,"gold_ingot"],
- [LOG_OAK,"log",0.05,"log"],
- [STICK,"stick",0.0065,"stick"],
- [PLANKS_OAK,"planks",0.015,"planks"],
- [LAPIS_LAZULI_BLOCK,"lapisblock",0.5*9,"lapis_block"],
- [DIRT,"dirt",0.01,"dirt"],
- [GRASS,"grass",0.025,"grass"],
- [COBBLESTONE,"cobblestone",0.015,"cobblestone"],
- [STONE,"stone",0.03,"stone"],
- [STONE_BRICKS,"stonebricks",0.035,"stone_bricks"],
- [STRING,"string",0.35,"string"],
- [GUNPOWDER,"gunpowder",0.45,"gunpowder"],
- [LEATHER,"leather",0.15,"leather"],
- [LEAD,"lead",0.9,"lead"],
- [BONE,"bone",0.25,"bone"],
- [ROTTEN_FLESH,"rottenflesh",0.015,"rotten_flesh"],
- [INK_SAC,"inksac",0.06,"ink_sac"],
- [BONE,"bone",0.25,"bone"],
- [GOLDEN_APPLE,"goldenapple",17,"golden_apple"],
- [SPIDER_EYE,"spidereye",0.03,"spider_eye"],
- [GRAVEL,"gravel",0.02,"gravel"],
- [FLINT,"flint",0.05,"flint"],
- [IRON_NUGGET,"ironnugget",0.11,"iron_nugget"],
- [GOLD_NUGGET,"goldnugget",0.22,"gold_nugget"],
- [EMERALD,"emerald",6,"emerald"],
- [SHULKER_SHELL,"shulkershell",7,"shulker_shell"],
- [ICE,"ice",0.05,"ice"],
- [PACKED_ICE,"packedice",0.50,"packed_ice"],
- [BLUE_ICE,"blueice",5,"BLUE_ICE"], // may need to rebalance this
- [OAK_SAPLING,"sapling",0.07,"sapling"],
- [OBSIDIAN,"obsidian",1.5,"obsidian"],
- [COAL,"coal",0.25,"coal"],
- [SAND,"sand",0.025,"sand"],
- [SLIMEBALL,"slimeball",0.4,"slimeball"],
- [REDSTONE,"restone",0.25,"redstone"],
- [REDSTONE_BLOCK,"restoneblock",0.27*9,"redstone_block"],
- [WOOL,"wool",0.16,"wool"],
- [FEATHER,"feather",0.15,"feather"],
- [ARROW,"arrow",0.21,"arrow"],
- ]
- let marketplace_mobs = [
- [CHICKEN,0.05,"chicken"],
- [PIG,0.08,"pig"],
- [COW,0.08,"cow"],
- [ZOMBIE,0.15,"zombie"],
- [SKELETON,0.2,"skeleton"],
- [CREEPER,0.15,"creeper"],
- [DONKEY,0.1,"donkey"],
- [HORSE,0.11,"horse"],
- [SHEEP,0.08,"sheep"],
- [DROWNED,0.15,"drowned"],
- [BAT,0.15,"bat"],
- [RABBIT,0.05,"rabbit"],
- [SPIDER,0.1,"spider"],
- [ZOMBIE_VILLAGER,0.2,"zombie villager"],
- [ENDERMAN,0.3,"enderman"],
- [SILVERFISH,0.2,"silverfish"],
- [COD,0.02,"cod fish"],
- [SALMON,0.02,"salmon"],
- [TROPICAL_FISH,0.02,"tropical fish"],
- [PUFFERFISH,0.1,"puffer fish"],
- [SQUID,0.05,"squid"],
- [STRAY,0.25,"stray"],
- [HUSK,0.15,"husk"],
- [BEE,-0.3,"bee"],
- [LLAMA,0.11,"llama"],
- [WANDERING_TRADER,-1,"wandering trader"],
- [PANDA,-0.5,"panda"],
- [PARROT,-0.5,"parrot"],
- [WITHER_SKELETON,0.5,"wither skeleton"],
- [GHAST,0.5,"ghast"],
- [BLAZE,0.6,"blaze"],
- [SLIME,0.3,"slime"],
- [LAVA_SLIME,0.5,"magma cube"],
- [WITHER,-2.5,"iron golem"],
- [WOLF,-0.25,"wolf"],
- [CAT,-0.5,"cat"],
- [OCELOT,-0.5,"ocelot"],
- [FOX,-0.5,"fox"],
- [] // extra space needed for resolving weirdness
- ]
- function chat(str:string,self:boolean) {
- if (self) {
- player.execute('tellraw @s {"rawtext":[{"text":"'+str+'"}]}')
- } else {
- player.execute('tellraw @a {"rawtext":[{"text":"'+str+'"}]}')
- }
- }
- function doDing() {
- loops.runInBackground(function() {
- player.execute("playsound note.pling @s ~ ~ ~ 1 2")
- player.execute("playsound note.pling @s ~ ~ ~ 1 2.5")
- })
- }
- for (let i = 0; i < marketplace_mobs.length; i++) {
- if (i != marketplace_mobs.length-1) {
- let li = i
- loops.runInBackground(function() {
- loops.forever(function() { // because we're only allowed to use let and const, and not var, we have to reset variables using while loops (var would of been really nice to use here )
- let tig = false // we also could just reuse a mob event, but for some reason they fire twice, once upon mob death, and another after the code inside the event has finished running.
- let an:any = marketplace_mobs[li][0]
- let an1:any = marketplace_mobs[li][1]
- let an2:any = marketplace_mobs[li][2]
- mobs.onMobKilled(mobs.monster(an), function() {
- if (tig == false) {
- tig = true
- let worth = an1*boom
- if (worth > 0) {
- chat("§a§l+$"+worth.toString()+" §r§afor killing a §g§l"+an2,true)
- currency+=worth
- } else {
- worth = worth *-1
- chat("§4You were fined §l$"+worth.toString()+"§r§4 for killing a §g§l"+an2,true)
- currency-=worth
- }
- }
- })
- while (tig == false) {
- loops.pause(100)
- }
- })
- })
- } else {
- break
- }
- }
- function isItem(num:number) {
- for (let i = 0; i < marketplace_items.length; i++) {
- if (num == marketplace_items[i][0]) {
- let re:number = i
- return i
- }
- }
- return null
- }
- function findItem(str:string) {
- for (let i = 0; i < marketplace_items.length; i++) {
- if (str.toLowerCase() == marketplace_items[i][1]) {
- return i
- }
- }
- return null
- }
- player.onChat(";tp", function() {
- chat("§gAgent has been teleported to your position",false)
- agent.teleportToPlayer()
- })
- if (gamble) {
- player.onChat(";gamble", function(num:number) {
- let arg = player.getChatArg(0)
- let pars = parseFloat(arg)
- if (isNaN(pars) == true || pars < 0) {
- chat("§4Value must be a valid number.",false)
- } else {
- if (pars > currency) {
- chat("§4You do not have §l$"+pars.toString()+"§r§4. You have: §l$"+currency.toString(),false)
- } else {
- let r = randint(0,1)
- if (r == 0) {
- let botroll = randint(1, 12)
- let yourroll = randint(1, 12)
- if (botroll == yourroll || botroll > yourroll) {
- currency -= pars
- chat("§4§l------------------------\n§r§cYou lost: §l$"+pars.toString()+"\n§r§cYour roll: §l"+yourroll.toString()+"§r§c | Bot roll: §l"+botroll.toString()+"§r§4§l\n------------------------",false)
- } else {
- let winpercentage = randint(50, 150)
- let w = winpercentage/100
- pars = pars*w
- currency += pars
- chat("§2§l------------------------\n§r§aYou won: §l$"+pars.toString()+"\n§r§aYour roll: §l"+yourroll.toString()+"§r§a | Bot roll: §l"+botroll.toString()+"\n§r§aYou won §l"+winpercentage.toString()+"%§r§a of your bet"+"§r§2§l\n------------------------",false)
- }
- } else if(r == 1) {
- let pos1 = positions.groundPosition(pos(1, 100, 2).toWorld())
- let pos2 = positions.groundPosition(pos(1, 100, 0).toWorld())
- let pos3 = positions.groundPosition(pos(1, 100, -2).toWorld())
- let bet = randint(1, 3)
- let tochoose:number = 0
- let mult = randint(2, 4)
- chat("§gIn front of you are 3 dirt piles. Within one of them contains your bet. If you choose correctly you will earn §l"+mult.toString()+"x§r§g your bet.", false)
- blocks.place(COARSE_DIRT, pos1.add(pos(0,-1,0)))
- player.execute("summon splash_potion "+pos1.add(pos(0,1,0)))
- blocks.place(COARSE_DIRT, pos2.add(pos(0,-1,0)))
- player.execute("summon splash_potion "+pos2.add(pos(0,1,0)))
- blocks.place(COARSE_DIRT, pos3.add(pos(0,-1,0)))
- player.execute("summon splash_potion "+pos3.add(pos(0,1,0)))
- loops.runInBackground(function() {
- while (blocks.testForBlock(COARSE_DIRT, pos1.add(pos(0,-1,0))) && tochoose == 0) {
- loops.pause(100)
- }
- if (tochoose == 0) {
- tochoose = 1
- }
- })
- loops.runInBackground(function() {
- while (blocks.testForBlock(COARSE_DIRT, pos2.add(pos(0,-1,0))) && tochoose == 0) {
- loops.pause(100)
- }
- if (tochoose == 0) {
- tochoose = 2
- }
- })
- loops.runInBackground(function() {
- while (blocks.testForBlock(COARSE_DIRT, pos3.add(pos(0,-1,0))) && tochoose == 0) {
- loops.pause(100)
- }
- if (tochoose == 0) {
- tochoose = 3
- }
- })
- while (tochoose == 0) {
- loops.pause(500)
- }
- blocks.place(GRASS, pos1.add(pos(0,-1,0)))
- blocks.place(GRASS, pos2.add(pos(0,-1,0)))
- blocks.place(GRASS, pos3.add(pos(0,-1,0)))
- if (tochoose == bet) {
- doDing()
- let earnings = pars*mult
- currency += earnings
- chat("§a§lYou got it! §r§aYou have won: §l$"+earnings.toString(), false)
- } else {
- player.execute("playsound ambient.weather.lightning.impact @s ~ ~ ~ 5 0.4")
- player.execute("playsound block.bell.hit @s ~ ~ ~ 5 0.2")
- currency -= pars
- chat("§4§lOops!§r §4Wrong one, you have lost: §l$"+pars.toString(),false)
- }
- }
- }
- }
- })
- }
- player.onChat(";sell", function() {
- if (agent.getItemCount(1) > 0) {
- let tab = []
- let i = 1
- let ongo = true
- while (ongo) {
- if (i != 27) {
- let itemcount = agent.getItemCount(i)
- if (itemcount == 0) {
- ongo = false
- break
- } else {
- let itemtype = agent.getItemDetail(i)
- tab.push([itemtype,itemcount,i])
- i += 1
- }
- } else {
- let itemcount = agent.getItemCount(i)
- if (itemcount != 0) {
- let itemtype = agent.getItemDetail(i)
- tab.push([itemtype,itemcount,i])
- i += 1
- ongo = false
- break
- } else {
- ongo = false
- break
- }
- }
- }
- let selltab = []
- let amount = 0
- for (let i = 0; i < tab.length; i++) {
- let h:number = isItem(tab[i][0])
- let hh:(string | number)[] = marketplace_items[h]
- if (h != null) {
- let d:any = (marketplace_items[h][2])
- d = parseFloat(d)
- let num = d
- currency += ((num*boom)*tab[i][1])*selloff
- amount += ((num*boom)*tab[i][1])*selloff
- selltab.push([hh[1],tab[i][1].toString()])
- agent.setItem(AIR, 0, tab[i][2])
- }
- }
- if (amount == 0) {
- chat("§4§lNothing was sold.",false)
- } else {
- let str = "§aYou've sold: "
- for (let i = 0; i < selltab.length; i++) {
- str = "§l"+str+selltab[i][0]+"§r§lx"+selltab[i][1]+"§a, "
- }
- str = str.substr(0,str.length-2)
- chat(str,false)
- chat("§a§l+$"+amount.toString(),false)
- }
- } else {
- chat("§4Please put in items into the agent starting from the first slot. Say ;tp to bring your agent to you.",false)
- }
- })
- player.onChat(";buy", function(n:number,n2:number) {
- let item = player.getChatArg(0)
- let num = findItem(item)
- if (num != null) {
- let it = marketplace_items[num]
- let price:any = it[2]
- let itemid = it[3]
- let amount = parseFloat(player.getChatArg(1))
- price = parseFloat(price) * boom
- let setprice:number = price*amount
- if (item != null && amount != null) {
- if (setprice > currency) {
- chat("§4Insufficient funds; Funds needed: §l$"+setprice.toString()+"§r§4, You have: §l"+currency.toString()+"",false)
- } else {
- if (amount > 0) {
- currency -= setprice
- player.execute("give @s "+itemid+" "+amount)
- chat("§aYou have bought: §l§g"+item+"§fx"+amount.toString()+"§r§a for §l$"+setprice.toString(),false)
- } else {
- chat("§4You cannot buy a negative amount of an item.",false)
- }
- }
- } else {
- chat("§4Arguments are incorrect; Correct usage: ;buy string integer. For example: ;buy iron 5",false)
- }
- } else {
- chat("§4No item named '"+item+"'. Please check your spelling.",false)
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement