Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In order to craft items, gather the resources for one of the crafting recipes shown
- // below, right click on your agent, and put in the recipe exactly as shown on the top
- // most bar of it's inventory.
- // CRAFTING RECIPES:
- // 5 cod + 4 clay + 4 iron = 130 maxoxygen
- // 5 cod + 10 salmon + 4 clay + 4 iron + 3 Nether Quartz + 1 diamond = 210 maxoxygen
- // 15 cod + 30 salmon + 4 clay + 4 Ender pearls + 6 Blaze Powder + 4 diamonds = 304 maxoxygen
- // 2 Dragon's Breath + 10 Enderpearls + 4 Clay + 4 Diamond + 30 Charcoal + 1 Netherstar = 420 maxoxygen
- // 1 Iron Block + 8 Flint + 5 Redstone + 1 Lever + 4 Nether Wart = iron lungs
- // 1 Iron Pickaxe + 1 obsidian + 5 Gold + 5 Ink Sacks + 1 Feather + 1 Book = aqua affinity
- // 1 Bottle O' Enchanting + 1 Golden Boots + 1 Diamond + 3 Emeralds + 4 Feathers + 1 Book = Depth Stider 3
- // 3 Blaze Rods + 3 Diamonds + 4 Iron + 9 Iron Nugget + 12 Lapis + 1 Heart of the sea = Loyal Trident
- // COMMANDS:
- // Say ;craft to initiate crafting
- // Say ;tp to teleport the agent to you
- // Say ;refresh to fix your oxygen GUI
- // ITEMS:
- // Snow blocks replenish 26 oxygen
- // SETTINGS:
- let oxygen = 65 // current oxygen
- let maxoxygen = 65 // the max oxygen the player may have
- let regen = 1 // how much oxygen is regenerated, values above 1 will allow snow to be more effective (iron lungs)
- let agent_turning = 0 // if the agent is allowed to turn towards the player (causes minor lag)
- let lag_offset = 1 // the amount it takes for oxygen to reach 0 (from 65) divided by 9.21 (ignore this if you're server administrator)
- let inwater = true
- let land = false
- let loop = true // fixing the nil loop bug
- let dying = false // fix poison saturation bug
- let dead = false // fix localplayer oxygen count title command bug
- let playername = player.name()
- let countup = 0
- let lastturn = 0
- loops.pause(100)
- player.execute("title @s actionbar §bOxygen: "+oxygen) // minecraft title bug fix
- loops.pause(100)
- player.execute("scoreboard objectives add Oxygen dummy")
- player.execute("scoreboard objectives setdisplay belowname Oxygen")
- player.execute("scoreboard objectives setdisplay list Oxygen")
- agent.teleportToPlayer()
- player.onTravelled(WALK, function () {
- inwater = false
- dead = false
- land = true
- })
- player.onTravelled(FLY, function () {
- inwater = false
- dead = false
- })
- player.onTravelled(SNEAK, function () {
- inwater = false
- dead = false
- })
- player.onTravelled(FALL, function () {
- inwater = false
- dead = false
- land = false
- })
- player.onTravelled(SWIM_LAVA, function () {
- inwater = false
- dead = false
- land = false
- })
- player.onTravelled(RIDING, function () {
- inwater = false
- dead = false
- })
- player.onTravelled(SPRINT, function () {
- inwater = false
- dead = false
- land = true
- })
- player.onTravelled(SWIM_WATER, function () {
- inwater = true
- land = false
- })
- player.onItemInteracted(SNOW, function () {
- if (oxygen < maxoxygen) {
- player.execute("clear @s snow 0 1")
- if (regen < 2) {
- if (oxygen + 26 <= maxoxygen) {
- oxygen = oxygen + 26
- } else {
- oxygen = maxoxygen
- }
- } else {
- if (oxygen + 32 <= maxoxygen) {
- oxygen = oxygen + 32
- } else {
- oxygen = maxoxygen
- }
- }
- }
- })
- player.onDied(function () {
- maxoxygen = 65
- oxygen = maxoxygen
- inwater = true
- dead = true
- })
- loops.forever(function () {
- if (loop == true && dead == false) {
- if (inwater == true) {
- if (oxygen < maxoxygen) {
- oxygen = oxygen + regen*lag_offset
- loops.pause(45)
- } else if (oxygen >= maxoxygen) {
- oxygen = maxoxygen
- }
- } else {
- if (oxygen > 0) {
- oxygen = oxygen - 1*lag_offset
- } else if (oxygen <= 0) {
- oxygen = 0
- player.execute("effect @s fatal_poison 1 2 true")
- dying = true
- }
- }
- player.execute("title @s actionbar §bOxygen: "+oxygen)
- } else {
- loops.pause(400/lag_offset)
- }
- })
- loops.forever(function () {
- if (inwater == true) {
- player.execute("effect @s water_breathing 1 0 true")
- if (dying == true) {
- dying = false
- player.execute("effect @s clear")
- }
- }
- if (dead == false) {
- player.execute('scoreboard players set "'+playername+'" Oxygen '+oxygen)
- }
- })
- function agentDrop(poss:Position) {
- agent.teleport(poss.add(pos(-50,-70,-50)), NORTH)
- // player.execute("execute @e[rm=0,r=5] "+poss.add(pos(-50,-10,-50))+" kill @s")
- agent.dropAll(DOWN)
- agent.teleport(poss, NORTH)
- }
- player.onChat(";refresh", function () {
- loop = false
- loops.pause(1000/lag_offset)
- loop = true
- })
- player.onChat(";craft", function () {
- player.say("§a§lBegun crafting...")
- player.execute("effect @s slowness 999999 255 true")
- if (oxygen > 0) {
- player.execute("effect @s water_breathing 999999 0 true")
- } else {
- player.execute("effect @s fatal_poison 999999 2 true")
- }
- loop = false
- let de1 = agent.getItemDetail(1) // optimizations
- let de2 = agent.getItemDetail(2)
- let de3 = agent.getItemDetail(3)
- let de4 = agent.getItemDetail(4)
- let de5 = agent.getItemDetail(5)
- let de6 = agent.getItemDetail(6)
- let co1 = agent.getItemCount(1)
- let co2 = agent.getItemCount(2)
- let co3 = agent.getItemCount(3)
- let co4 = agent.getItemCount(4)
- let co5 = agent.getItemCount(5)
- let co6 = agent.getItemCount(6)
- if (de1 == 349 && co1 == 5 && de2 == 337 && co2 == 4 && de3 == 265 && co3 == 4) {
- maxoxygen = 130
- agentDrop(agent.getPosition())
- player.say("§e§lCrafted an oxygen tank.")
- } else if (de1 == 349 && co1 == 5 && de2 == 460 && co2 == 10 && de3 == 337 && co3 == 4 && de4 == 265 && co4 == 4 && de5 == 406 && co5 == 3 && de6 == 264 && co6 == 1) {
- maxoxygen = 210
- agentDrop(agent.getPosition())
- player.say("§e§lCrafted a compressed oxygen tank.")
- } else if (de1 == 349 && co1 == 15 && de2 == 460 && co2 == 30 && de3 == 337 && co3 == 4 && de4 == 368 && co4 == 4 && de5 == 377 && co5 == 6 && de6 == 264 && co6 == 4) {
- maxoxygen = 306
- agentDrop(agent.getPosition())
- player.say("§e§lCrafted an advanced compressed oxygen tank.")
- } else if (de1 == 437 && co1 == 2 && de2 == 368 && co2 == 10 && de3 == 337 && co3 == 4 && de4 == 264 && co4 == 4 && de5 == 263 && co5 == 30 && de6 == 399 && co6 == 1) {
- maxoxygen = 420
- agentDrop(agent.getPosition())
- player.say("§e§lCrafted an overly complicated advanced compressed oxygen tank.")
- } else if (de1 == 42 && co1 == 1 && de2 == 318 && co2 == 8 && de3 == 331 && co3 == 5 && de4 == 69 && co4 == 1 && de5 == 372 && co5 == 4) {
- regen = 2
- agentDrop(agent.getPosition())
- player.say("§e§lCrafted iron lungs.")
- } else if (de1 == 257 && co1 == 1 && de2 == 49 && co2 == 1 && de3 == 266 && co3 == 5 && de4 == 351 && co4 == 5 && de5 == 288 && co5 == 1 && de6 == 340 && co6 == 1) {
- agentDrop(agent.getPosition())
- player.execute("give @s book")
- player.say("§a§lHold the book you were just given, you have 7 seconds.")
- loop = true
- player.execute("effect @s clear")
- loops.pause(7000)
- player.execute("enchant @s aqua_affinity")
- player.say("§e§lCrafted an aqua affinity enchantment.")
- } else if (de1 == 369 && co1 == 3 && de2 == 264 && co2 == 3 && de3 == 265 && co3 == 4 && de4 == 452 && co4 == 9 && de5 == 351 && co5 == 12 && de6 == 467 && co6 == 1) {
- agentDrop(agent.getPosition())
- player.execute("give @s trident")
- player.say("§a§lHold the trident you were just given, you have 7 seconds.")
- loop = true
- player.execute("effect @s clear")
- loops.pause(7000)
- player.execute("enchant @s impaling 4")
- player.execute("enchant @s loyalty 3")
- player.execute("enchant @s channeling")
- player.say("§e§lCrafted a loyal trident.")
- } else if (de1 == 384 && co1 == 1 && de2 == 317 && co2 == 1 && de3 == 264 && co3 == 1 && de4 == 388 && co4 == 3 && de5 == 288 && co5 == 4 && de6 == 340 && co6 == 1) {
- agentDrop(agent.getPosition())
- player.execute("give @s book")
- player.say("§a§lHold the book you were just given, you have 7 seconds.")
- loop = true
- player.execute("effect @s clear")
- loops.pause(7000)
- player.execute("enchant @s depth_strider 3")
- player.say("§e§lCrafted a depth strider enchantment.")
- } else {
- player.say("§c§lNothing was crafted, check your crafting recipe.")
- }
- loop = true
- player.execute("effect @s clear")
- })
- function rotateAgent(rot:string) {
- lastturn = countup + 4
- let curr = agent.getOrientation()
- if (rot == "west") {
- if (curr == -90) {
- agent.turn(TurnDirection.Right)
- agent.turn(TurnDirection.Right)
- } else if (curr == -180) {
- agent.turn(TurnDirection.Left)
- } else if (curr == 0) {
- agent.turn(TurnDirection.Right)
- }
- } else if (rot == "east") {
- if (curr == 90) {
- agent.turn(TurnDirection.Right)
- agent.turn(TurnDirection.Right)
- } else if (curr == 0) {
- agent.turn(TurnDirection.Left)
- } else if (curr == -180) {
- agent.turn(TurnDirection.Right)
- }
- } else if (rot == "north") {
- if (curr == 0) {
- agent.turn(TurnDirection.Right)
- agent.turn(TurnDirection.Right)
- } else if (curr == -90) {
- agent.turn(TurnDirection.Left)
- } else if (curr == 90) {
- agent.turn(TurnDirection.Right)
- }
- } else if (rot == "south") {
- if (curr == -180) {
- agent.turn(TurnDirection.Right)
- agent.turn(TurnDirection.Right)
- } else if (curr == 90) {
- agent.turn(TurnDirection.Left)
- } else if (curr == -90) {
- agent.turn(TurnDirection.Right)
- }
- }
- }
- function boop() {
- loops.runInBackground(function () {
- loops.forever(function () {
- if (lastturn <= countup) {
- let beforehand = agent.getOrientation()
- let pos = player.position()
- let pos2 = agent.getPosition()
- let xval = pos.getValue(Axis.X) - pos2.getValue(Axis.X) // west is negative
- let zval = pos.getValue(Axis.Z) - pos2.getValue(Axis.Z) // north is negative
- let xx = xval
- let zz = zval
- if (xval < 0) {
- xx = xx * -1
- }
- if (zval < 0) {
- zz = zz * -1
- }
- if (xx >= zz) {
- if (xx <= 6) {
- if (xval < 0) {
- if (beforehand != 90) {
- loop = false
- rotateAgent("west")
- loop = true
- }
- } else {
- if (beforehand != -90) {
- loop = false
- rotateAgent("east")
- loop = true
- }
- }
- } else if (xx >= 60) {
- let poss = player.position()
- let lop = positions.groundPosition(poss.add(positions.create(-7,30,-7)))
- agent.teleport(lop, NORTH)
- }
- } else {
- if (zz <= 6) {
- if (zval < 0) {
- if (beforehand != -180) {
- loop = false
- rotateAgent("north")
- loop = true
- }
- } else {
- if (beforehand != 0) {
- loop = false
- rotateAgent("south")
- loop = true
- }
- }
- } else if (zz >= 60) {
- let poss = player.position()
- let lop = positions.groundPosition(poss.add(positions.create(-7,30,-7)))
- agent.teleport(lop, NORTH)
- }
- }
- }
- })
- })
- }
- function boop2() {
- loops.runInBackground(function () {
- loops.forever(function () {
- countup = countup + 1
- loops.pause(1000/lag_offset)
- })
- })
- }
- if (agent_turning == 1) {
- boop()
- }
- boop2()
- player.onChat(";de", function () { // debug command
- player.say(agent.getItemDetail(1))
- })
- player.onChat(";tp", function () {
- agent.teleportToPlayer()
- })
Add Comment
Please, Sign In to add comment