BobMe

Minecraft Subnautica Script MakeCode Code Builder

Apr 30th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.16 KB | None | 0 0
  1. // In order to craft items, gather the resources for one of the crafting recipes shown
  2. // below, right click on your agent, and put in the recipe exactly as shown on the top
  3. // most bar of it's inventory.
  4.  
  5. // CRAFTING RECIPES:
  6. // 5 cod + 4 clay + 4 iron = 130 maxoxygen
  7. // 5 cod + 10 salmon + 4 clay + 4 iron + 3 Nether Quartz + 1 diamond = 210 maxoxygen
  8. // 15 cod + 30 salmon + 4 clay + 4 Ender pearls + 6 Blaze Powder + 4 diamonds = 304 maxoxygen
  9. // 2 Dragon's Breath + 10 Enderpearls + 4 Clay + 4 Diamond + 30 Charcoal + 1 Netherstar = 420 maxoxygen
  10. // 1 Iron Block + 8 Flint + 5 Redstone + 1 Lever + 4 Nether Wart = iron lungs
  11. // 1 Iron Pickaxe + 1 obsidian + 5 Gold + 5 Ink Sacks + 1 Feather + 1 Book = aqua affinity
  12. // 1 Bottle O' Enchanting + 1 Golden Boots + 1 Diamond + 3 Emeralds + 4 Feathers + 1 Book = Depth Stider 3
  13. // 3 Blaze Rods + 3 Diamonds + 4 Iron + 9 Iron Nugget + 12 Lapis + 1 Heart of the sea = Loyal Trident
  14.  
  15. // COMMANDS:
  16. // Say ;craft to initiate crafting
  17. // Say ;tp to teleport the agent to you
  18. // Say ;refresh to fix your oxygen GUI
  19.  
  20. // ITEMS:
  21. // Snow blocks replenish 26 oxygen
  22.  
  23. // SETTINGS:
  24. let oxygen = 65 // current oxygen
  25. let maxoxygen = 65 // the max oxygen the player may have
  26. let regen = 1 // how much oxygen is regenerated, values above 1 will allow snow to be more effective (iron lungs)
  27. let agent_turning = 0 // if the agent is allowed to turn towards the player (causes minor lag)
  28. 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)
  29.  
  30. let inwater = true
  31. let land = false
  32. let loop = true // fixing the nil loop bug
  33. let dying = false // fix poison saturation bug
  34. let dead = false // fix localplayer oxygen count title command bug
  35. let playername = player.name()
  36. let countup = 0
  37. let lastturn = 0
  38.  
  39. loops.pause(100)
  40. player.execute("title @s actionbar §bOxygen: "+oxygen) // minecraft title bug fix
  41. loops.pause(100)
  42. player.execute("scoreboard objectives add Oxygen dummy")
  43. player.execute("scoreboard objectives setdisplay belowname Oxygen")
  44. player.execute("scoreboard objectives setdisplay list Oxygen")
  45.  
  46. agent.teleportToPlayer()
  47. player.onTravelled(WALK, function () {
  48. inwater = false
  49. dead = false
  50. land = true
  51. })
  52. player.onTravelled(FLY, function () {
  53. inwater = false
  54. dead = false
  55. })
  56. player.onTravelled(SNEAK, function () {
  57. inwater = false
  58. dead = false
  59. })
  60. player.onTravelled(FALL, function () {
  61. inwater = false
  62. dead = false
  63. land = false
  64. })
  65. player.onTravelled(SWIM_LAVA, function () {
  66. inwater = false
  67. dead = false
  68. land = false
  69. })
  70. player.onTravelled(RIDING, function () {
  71. inwater = false
  72. dead = false
  73. })
  74. player.onTravelled(SPRINT, function () {
  75. inwater = false
  76. dead = false
  77. land = true
  78. })
  79. player.onTravelled(SWIM_WATER, function () {
  80. inwater = true
  81. land = false
  82. })
  83.  
  84. player.onItemInteracted(SNOW, function () {
  85. if (oxygen < maxoxygen) {
  86. player.execute("clear @s snow 0 1")
  87. if (regen < 2) {
  88. if (oxygen + 26 <= maxoxygen) {
  89. oxygen = oxygen + 26
  90. } else {
  91. oxygen = maxoxygen
  92. }
  93. } else {
  94. if (oxygen + 32 <= maxoxygen) {
  95. oxygen = oxygen + 32
  96. } else {
  97. oxygen = maxoxygen
  98. }
  99. }
  100. }
  101. })
  102.  
  103. player.onDied(function () {
  104. maxoxygen = 65
  105. oxygen = maxoxygen
  106. inwater = true
  107. dead = true
  108. })
  109.  
  110. loops.forever(function () {
  111. if (loop == true && dead == false) {
  112. if (inwater == true) {
  113. if (oxygen < maxoxygen) {
  114. oxygen = oxygen + regen*lag_offset
  115. loops.pause(45)
  116. } else if (oxygen >= maxoxygen) {
  117. oxygen = maxoxygen
  118. }
  119. } else {
  120. if (oxygen > 0) {
  121. oxygen = oxygen - 1*lag_offset
  122. } else if (oxygen <= 0) {
  123. oxygen = 0
  124. player.execute("effect @s fatal_poison 1 2 true")
  125. dying = true
  126. }
  127. }
  128. player.execute("title @s actionbar §bOxygen: "+oxygen)
  129. } else {
  130. loops.pause(400/lag_offset)
  131. }
  132. })
  133.  
  134. loops.forever(function () {
  135. if (inwater == true) {
  136. player.execute("effect @s water_breathing 1 0 true")
  137. if (dying == true) {
  138. dying = false
  139. player.execute("effect @s clear")
  140. }
  141. }
  142. if (dead == false) {
  143. player.execute('scoreboard players set "'+playername+'" Oxygen '+oxygen)
  144. }
  145. })
  146.  
  147. function agentDrop(poss:Position) {
  148. agent.teleport(poss.add(pos(-50,-70,-50)), NORTH)
  149. // player.execute("execute @e[rm=0,r=5] "+poss.add(pos(-50,-10,-50))+" kill @s")
  150. agent.dropAll(DOWN)
  151. agent.teleport(poss, NORTH)
  152. }
  153.  
  154. player.onChat(";refresh", function () {
  155. loop = false
  156. loops.pause(1000/lag_offset)
  157. loop = true
  158. })
  159.  
  160. player.onChat(";craft", function () {
  161. player.say("§a§lBegun crafting...")
  162. player.execute("effect @s slowness 999999 255 true")
  163. if (oxygen > 0) {
  164. player.execute("effect @s water_breathing 999999 0 true")
  165. } else {
  166. player.execute("effect @s fatal_poison 999999 2 true")
  167. }
  168. loop = false
  169. let de1 = agent.getItemDetail(1) // optimizations
  170. let de2 = agent.getItemDetail(2)
  171. let de3 = agent.getItemDetail(3)
  172. let de4 = agent.getItemDetail(4)
  173. let de5 = agent.getItemDetail(5)
  174. let de6 = agent.getItemDetail(6)
  175. let co1 = agent.getItemCount(1)
  176. let co2 = agent.getItemCount(2)
  177. let co3 = agent.getItemCount(3)
  178. let co4 = agent.getItemCount(4)
  179. let co5 = agent.getItemCount(5)
  180. let co6 = agent.getItemCount(6)
  181. if (de1 == 349 && co1 == 5 && de2 == 337 && co2 == 4 && de3 == 265 && co3 == 4) {
  182. maxoxygen = 130
  183. agentDrop(agent.getPosition())
  184. player.say("§e§lCrafted an oxygen tank.")
  185. } 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) {
  186. maxoxygen = 210
  187. agentDrop(agent.getPosition())
  188. player.say("§e§lCrafted a compressed oxygen tank.")
  189. } 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) {
  190. maxoxygen = 306
  191. agentDrop(agent.getPosition())
  192. player.say("§e§lCrafted an advanced compressed oxygen tank.")
  193. } 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) {
  194. maxoxygen = 420
  195. agentDrop(agent.getPosition())
  196. player.say("§e§lCrafted an overly complicated advanced compressed oxygen tank.")
  197. } else if (de1 == 42 && co1 == 1 && de2 == 318 && co2 == 8 && de3 == 331 && co3 == 5 && de4 == 69 && co4 == 1 && de5 == 372 && co5 == 4) {
  198. regen = 2
  199. agentDrop(agent.getPosition())
  200. player.say("§e§lCrafted iron lungs.")
  201. } 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) {
  202. agentDrop(agent.getPosition())
  203. player.execute("give @s book")
  204. player.say("§a§lHold the book you were just given, you have 7 seconds.")
  205. loop = true
  206. player.execute("effect @s clear")
  207. loops.pause(7000)
  208. player.execute("enchant @s aqua_affinity")
  209. player.say("§e§lCrafted an aqua affinity enchantment.")
  210. } 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) {
  211. agentDrop(agent.getPosition())
  212. player.execute("give @s trident")
  213. player.say("§a§lHold the trident you were just given, you have 7 seconds.")
  214. loop = true
  215. player.execute("effect @s clear")
  216. loops.pause(7000)
  217. player.execute("enchant @s impaling 4")
  218. player.execute("enchant @s loyalty 3")
  219. player.execute("enchant @s channeling")
  220. player.say("§e§lCrafted a loyal trident.")
  221. } 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) {
  222. agentDrop(agent.getPosition())
  223. player.execute("give @s book")
  224. player.say("§a§lHold the book you were just given, you have 7 seconds.")
  225. loop = true
  226. player.execute("effect @s clear")
  227. loops.pause(7000)
  228. player.execute("enchant @s depth_strider 3")
  229. player.say("§e§lCrafted a depth strider enchantment.")
  230. } else {
  231. player.say("§c§lNothing was crafted, check your crafting recipe.")
  232. }
  233. loop = true
  234. player.execute("effect @s clear")
  235. })
  236. function rotateAgent(rot:string) {
  237. lastturn = countup + 4
  238. let curr = agent.getOrientation()
  239. if (rot == "west") {
  240. if (curr == -90) {
  241. agent.turn(TurnDirection.Right)
  242. agent.turn(TurnDirection.Right)
  243. } else if (curr == -180) {
  244. agent.turn(TurnDirection.Left)
  245. } else if (curr == 0) {
  246. agent.turn(TurnDirection.Right)
  247. }
  248. } else if (rot == "east") {
  249. if (curr == 90) {
  250. agent.turn(TurnDirection.Right)
  251. agent.turn(TurnDirection.Right)
  252. } else if (curr == 0) {
  253. agent.turn(TurnDirection.Left)
  254. } else if (curr == -180) {
  255. agent.turn(TurnDirection.Right)
  256. }
  257. } else if (rot == "north") {
  258. if (curr == 0) {
  259. agent.turn(TurnDirection.Right)
  260. agent.turn(TurnDirection.Right)
  261. } else if (curr == -90) {
  262. agent.turn(TurnDirection.Left)
  263. } else if (curr == 90) {
  264. agent.turn(TurnDirection.Right)
  265. }
  266. } else if (rot == "south") {
  267. if (curr == -180) {
  268. agent.turn(TurnDirection.Right)
  269. agent.turn(TurnDirection.Right)
  270. } else if (curr == 90) {
  271. agent.turn(TurnDirection.Left)
  272. } else if (curr == -90) {
  273. agent.turn(TurnDirection.Right)
  274. }
  275. }
  276. }
  277.  
  278. function boop() {
  279. loops.runInBackground(function () {
  280. loops.forever(function () {
  281. if (lastturn <= countup) {
  282. let beforehand = agent.getOrientation()
  283. let pos = player.position()
  284. let pos2 = agent.getPosition()
  285. let xval = pos.getValue(Axis.X) - pos2.getValue(Axis.X) // west is negative
  286. let zval = pos.getValue(Axis.Z) - pos2.getValue(Axis.Z) // north is negative
  287. let xx = xval
  288. let zz = zval
  289. if (xval < 0) {
  290. xx = xx * -1
  291. }
  292. if (zval < 0) {
  293. zz = zz * -1
  294. }
  295. if (xx >= zz) {
  296. if (xx <= 6) {
  297. if (xval < 0) {
  298. if (beforehand != 90) {
  299. loop = false
  300. rotateAgent("west")
  301. loop = true
  302. }
  303. } else {
  304. if (beforehand != -90) {
  305. loop = false
  306. rotateAgent("east")
  307. loop = true
  308. }
  309. }
  310. } else if (xx >= 60) {
  311. let poss = player.position()
  312. let lop = positions.groundPosition(poss.add(positions.create(-7,30,-7)))
  313. agent.teleport(lop, NORTH)
  314. }
  315. } else {
  316. if (zz <= 6) {
  317. if (zval < 0) {
  318. if (beforehand != -180) {
  319. loop = false
  320. rotateAgent("north")
  321. loop = true
  322. }
  323. } else {
  324. if (beforehand != 0) {
  325. loop = false
  326. rotateAgent("south")
  327. loop = true
  328. }
  329. }
  330. } else if (zz >= 60) {
  331. let poss = player.position()
  332. let lop = positions.groundPosition(poss.add(positions.create(-7,30,-7)))
  333. agent.teleport(lop, NORTH)
  334. }
  335. }
  336. }
  337. })
  338. })
  339. }
  340.  
  341. function boop2() {
  342. loops.runInBackground(function () {
  343. loops.forever(function () {
  344. countup = countup + 1
  345. loops.pause(1000/lag_offset)
  346. })
  347. })
  348. }
  349.  
  350. if (agent_turning == 1) {
  351. boop()
  352. }
  353. boop2()
  354.  
  355. player.onChat(";de", function () { // debug command
  356. player.say(agent.getItemDetail(1))
  357. })
  358.  
  359. player.onChat(";tp", function () {
  360. agent.teleportToPlayer()
  361. })
Add Comment
Please, Sign In to add comment