Advertisement
antonsavov

Untitled

Dec 15th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.68 KB | None | 0 0
  1. local VERSION = '0.8.3 - Heimkehr harry-fix'
  2. os.loadAPI('tracker')
  3. os.loadAPI('json')
  4.  
  5. print("Starting 20,000 Blocks")
  6.  
  7. DEBUG_MODE = true
  8. local monitor = peripheral.wrap("right")
  9. local ox,oy,oz = commands.getBlockPosition()
  10.  
  11. SPAWN_VILLAGER = false
  12. DO_GRID = true
  13. GRID_HOLE_CHANCE = 0
  14. NUMBER_OF_BUILDZONES = 6
  15. NUMBER_OF_VOCAB = 10
  16. GAME_LENGTH = 600
  17. VOCAB_WIDTH = 27
  18. VOCAB_HEIGHT = 19
  19. BUILDZONE_WIDTH = 62
  20. BUILDZONE_FLOOR_HEIGHT = -1
  21. SPAWN = {
  22. x=12110,
  23. y=57,
  24. z=-1777,
  25. a1=90,
  26. a2=0
  27. }
  28. FIRSTZONE= {
  29. x=11685,
  30. y=57,
  31. z=-1869
  32. }
  33. WAITZONE = {
  34. x=12092,
  35. y=57,
  36. z=-1773,
  37. w=7,
  38. l=7
  39. }
  40. VICTORY_HEIGHT = 30
  41. VICTORY_TOTAL = 50
  42. VICTORY_SPECIFIC = {name='garden',count=101}
  43.  
  44. DEFAULT_REWARD = 'minecraft:emerald 2 0 {display:{Name:"Emerald",Lore:[Trade this to the villager for wool]}}'
  45. WOOL_PER_EMERALD = 64
  46. PICKAXE_USES = 10
  47.  
  48. BLOCKS = {
  49. CAMP_FLOOR = {block='minecraft:sandstone',data=0},
  50. CONSTRUCTION = {block='minecraft:diamond_ore',data=0},
  51. RING = {block='minecraft:diamond_ore',data=0},
  52. DETECT = {block='minecraft:red_sandstone',data=0},
  53. DETECT_DEAD = {block='minecraft:obsidian',data=0},
  54. VOCAB_DETECT = {block="minecraft:quartz_block",data=0},
  55. VOCAB_REPLACE = {block="minecraft:coal_block",data=0},
  56. VICTORY_MARKER = {block="minecraft:emerald_block",data=0},
  57. PLUG = {block="minecraft:lapis_ore",data=0},
  58. PHVFLOOR = {block="minecraft:stone_slab",data=3},
  59. BUILDING_HOUSE = {block="minecraft:wool",data=0},
  60. BUILDING_GARDEN = {block="minecraft:wool",data=13},
  61. BUILDING_WATER = {block="minecraft:wool",data=1},
  62. }
  63.  
  64. --contains a list of all posible Buildzones (build a bit later)
  65. LOCS = {}
  66.  
  67. if DEBUG_MODE then
  68. GAME_LENGTH = 12000
  69. NUMBER_OF_BUILDZONES = 1
  70. end
  71.  
  72. --creates a grid of absoulte references (0,0) (1,0)
  73. function buildGrid(w,h)
  74. local grid = {}
  75. for x=0,w-1 do
  76. for z=0,h-1 do
  77. table.insert(grid,{x=x,z=z})
  78. end
  79. end
  80. return grid
  81. end
  82.  
  83. --sets where and how big the PHV area is
  84. --second number is along the long edge of PHV starting at the spawn side
  85. --first number is along the short edge of PHV starting from the park side
  86. if DEBUG_MODE then
  87. FIRSTZONE= {
  88. x=5,
  89. y=57,
  90. z=-7
  91. }
  92.  
  93. LOCS = buildGrid(1,3)
  94. else
  95. LOCS = buildGrid(11,5)
  96. end
  97.  
  98. --call these to return a proper minecraft item string including adventure mode properties
  99. function houseBlock(quant)
  100. text = BLOCKS.BUILDING_HOUSE.block..' '..quant..' '..BLOCKS.BUILDING_HOUSE.data..' {display:{Name:"House Construction Block",Lore:[Place this against a Diamond to build a house]},CanPlaceOn:["'..BLOCKS.BUILDING_HOUSE.block..'","'..BLOCKS.PLUG.block..'","'..BLOCKS.DETECT.block..'"]}'
  101. return text
  102. end
  103.  
  104. function waterBlock(quant)
  105. text = BLOCKS.BUILDING_WATER.block..' '..quant..' '..BLOCKS.BUILDING_WATER.data..' {display:{Name:"Water Construction Block",Lore:[Place this against a Diamond to build a pond or pool]},CanPlaceOn:["'..BLOCKS.BUILDING_HOUSE.block..'","'..BLOCKS.PLUG.block..'","'..BLOCKS.DETECT.block..'"]}'
  106. return text
  107. end
  108.  
  109. function gardenBlock(quant)
  110. text = BLOCKS.BUILDING_GARDEN.block..' '..quant..' '..BLOCKS.BUILDING_GARDEN.data..' {display:{Name:"Garden Construction Block",Lore:[Place this against a Diamond to build a pond or pool]},CanPlaceOn:["'..BLOCKS.BUILDING_HOUSE.block..'","'..BLOCKS.PLUG.block..'","'..BLOCKS.DETECT.block..'"]}'
  111. return text
  112. end
  113.  
  114. STARTING_ITEMS = {
  115. houseBlock(30), gardenBlock(30),
  116. 'stone_pickaxe 1 '..131-PICKAXE_USES..' {CanDestroy:["'..BLOCKS.BUILDING_HOUSE.block..'"],display:{Name:"Construction Remover",Lore:[Use this to remove up to '..PICKAXE_USES..' pieces of construction material]}}'
  117.  
  118. }
  119.  
  120. REWARDS = {}
  121. --plain singlehouse rewards (costs 4 house, -2+1 activators)
  122. REWARDS[1] = gardenBlock(4)
  123. REWARDS[2] = gardenBlock(4)
  124. REWARDS[3] = gardenBlock(4)
  125. REWARDS[4] = gardenBlock(4)
  126. --extension rise rewards (costs 6 house, -2+1 activators)
  127. REWARDS[5] = gardenBlock(7)
  128. REWARDS[6] = gardenBlock(7)
  129. REWARDS[7] = gardenBlock(7)
  130. REWARDS[8] = gardenBlock(7)
  131. --house bridge rewards (costs 6 house, -3+2 activators)
  132. REWARDS[9] = gardenBlock(10)
  133. REWARDS[10] = gardenBlock(10)
  134. --garden bridge (unused)
  135. REWARDS[11] = gardenBlock(7)
  136. REWARDS[12] = gardenBlock(7)
  137. --extention row house rewards (costs 4 house, 1 activators)
  138. REWARDS[13] = houseBlock(6)
  139. REWARDS[14] = houseBlock(6)
  140. REWARDS[15] = houseBlock(6)
  141. REWARDS[16] = houseBlock(6)
  142. --riser 1
  143. REWARDS[17] = houseBlock(1)
  144. --riser 2
  145. REWARDS[18] = houseBlock(1)
  146. --filler garden
  147. REWARDS[19] = houseBlock(1)
  148. --filler house plaza
  149. REWARDS[20] = gardenBlock(3)
  150. --extention-farm (like extension rise) (costs 6 garden, -2 activators)
  151. REWARDS[21] = houseBlock(3)
  152. REWARDS[22] = houseBlock(3)
  153. REWARDS[23] = houseBlock(3)
  154. REWARDS[24] = houseBlock(3)
  155. --extension-garden (like extension row house)rewards (costs 3 garden, 1 activators)
  156. REWARDS[25] = "minecraft:emerald"
  157. REWARDS[26] = "minecraft:emerald"
  158. REWARDS[27] = "minecraft:emerald"
  159. REWARDS[28] = "minecraft:emerald"
  160. --L-shaped small business agriculture (costs 6 garden, -3+2 activators)
  161. REWARDS[29] = "minecraft:emerald 2"
  162. REWARDS[30] = "minecraft:emerald 2"
  163. REWARDS[31] = "minecraft:emerald 2"
  164. REWARDS[32] = "minecraft:emerald 2"
  165. --L-shaped small business urban (costs 6 housing, -3+2 activators)
  166. REWARDS[33] = gardenBlock(6)
  167. REWARDS[34] = gardenBlock(6)
  168. REWARDS[35] = gardenBlock(6)
  169. REWARDS[36] = gardenBlock(6)
  170. --allotments (costs 4 garden, -2 activators)
  171. REWARDS[37] = houseBlock(2)
  172. REWARDS[38] = houseBlock(2)
  173. REWARDS[39] = houseBlock(2)
  174. REWARDS[40] = houseBlock(2)
  175.  
  176. DEFAULT_NAME = 'default-vocab'
  177. VOCAB_NAMES = {
  178. 'freestand-house',
  179. 'freestand-house',
  180. 'freestand-house',
  181. 'freestand-house',
  182. 'dbl-ext-house',
  183. 'dbl-ext-house',
  184. 'dbl-ext-house',
  185. 'dbl-ext-house',
  186. 'bridge-house',
  187. 'bridge-house',
  188. 'bridge-garden',
  189. 'bridge-garden',
  190. 'ext-house',
  191. 'ext-house',
  192. 'ext-house',
  193. 'ext-house',
  194. 'riser-1',
  195. 'riser-2',
  196. 'city-garden',
  197. 'city-plaza',
  198. 'dbl-ext-garden',
  199. 'dbl-ext-garden',
  200. 'dbl-ext-garden',
  201. 'dbl-ext-garden',
  202. 'ext-garden',
  203. 'ext-garden',
  204. 'ext-garden',
  205. 'ext-garden',
  206. 'corner-garden',
  207. 'corner-garden',
  208. 'corner-garden',
  209. 'corner-garden',
  210. 'corner-house',
  211. 'corner-house',
  212. 'corner-house',
  213. 'corner-house',
  214. 'freestand-garden',
  215. 'freestand-garden',
  216. 'freestand-garden',
  217. 'freestand-garden',
  218. 'zoo',
  219. 'bookstore',
  220. 'greenhouse',
  221. 'fablab'
  222. }
  223.  
  224. --constructor for player object so that data structure is consistant
  225. function newPlayerData(name,x,y,z)
  226. local p = {
  227. name = name,
  228. x=x,
  229. y=y,
  230. z=z
  231. }
  232. return p
  233. end
  234.  
  235. --return a list of all players in the game world as player objects
  236. local function getAllPos(selector)
  237. local result, message = commands.tp("@a["..selector.."]","~ ~ ~")
  238. local names = {}
  239. if result == true then
  240. for i,result in ipairs(message) do
  241. local wordpattern = "[^, ]+"
  242. local numberpattern = "[%-% ]%d+[%.]%d+"
  243. local words,numbers = {},{}
  244.  
  245. for word in string.gmatch(result, wordpattern) do
  246. table.insert(words,word)
  247. end
  248.  
  249. for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
  250.  
  251. local coords = {
  252. x = math.floor(numbers[1]),
  253. y = math.floor(numbers[2]),
  254. z = math.floor(numbers[3])
  255. }
  256. local name = words[2]
  257. table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
  258. --print("Player Found - getAllPos")
  259. end
  260. end
  261. return names
  262. end
  263.  
  264. --sort table by random
  265. local function shuffleTable( t )
  266. local rand = math.random
  267. assert( t, "shuffleTable() expected a table, got nil" )
  268. local iterations = #t
  269. local j
  270.  
  271. for i = iterations, 2, -1 do
  272. j = rand(i)
  273. t[i], t[j] = t[j], t[i]
  274. end
  275. end
  276.  
  277. --returns a list of player objects containing all players who are standing on the given block, and who also are in the given selection
  278. local function getAllOnBlockType(block,selector)
  279. local result, message = commands.exec("execute @a["..selector.."] ~ ~ ~ detect ~ ~-1 ~ "..block.." -1 tp @p[r=1] ~ ~ ~")
  280. local names = {}
  281. if result == true then
  282. for i,result in ipairs(message) do
  283. local wordpattern = "[^, ]+"
  284. local numberpattern = "[%-% ]%d+[%.]%d+"
  285. local words,numbers = {},{}
  286.  
  287. for word in string.gmatch(result, wordpattern) do table.insert(words,word) end
  288. for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
  289.  
  290. if numbers[1] and numbers[2] and numbers[3] then
  291. local coords = {
  292. x = math.floor(numbers[1]),
  293. y = math.floor(numbers[2]),
  294. z = math.floor(numbers[3])
  295. }
  296. local name = words[2]
  297. table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
  298. print("Found a player - getOnBlock")
  299. else
  300. print("Error: Coordinate Numbers were missing")
  301. end
  302. end
  303. end
  304. return names
  305. end
  306.  
  307. --gives a player a squid egg with their name on it. Removes all spawn eggs first
  308. local function giveSquid(name)
  309. commands.clear(name,'spawn_egg')
  310. commands.give(name,'spawn_egg 1 94 {CanPlaceOn:["'..BLOCKS.PHVFLOOR.block..'","'..BLOCKS.CAMP_FLOOR.block..'"],display:{Name:"Heimkehrer - '..name..'",Lore:[Use this on the floor to return to spawn]}}')
  311. end
  312.  
  313. --returns a list of squid objects and their names
  314. local function getSquids()
  315. local result, message = commands.exec("execute @e[type=Squid] ~ ~ ~ tp @e[r=1] ~ ~ ~")
  316. local names = {}
  317. if result == true then
  318. for i,result in ipairs(message) do
  319. local wordpattern = "[^, ]+"
  320. local numberpattern = "[%-% ]%d+[%.]%d+"
  321. local words,numbers = {},{}
  322.  
  323. for word in string.gmatch(result, wordpattern) do table.insert(words,word) print(word) end
  324. for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
  325.  
  326. if numbers[1] and numbers[2] and numbers[3] then
  327. local coords = {
  328. x = math.floor(numbers[1]),
  329. y = math.floor(numbers[2]),
  330. z = math.floor(numbers[3])
  331. }
  332. local name = words[4]
  333. table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
  334. print("Found a player - getOnBlock "..name)
  335. else
  336. print("Error: Coordinate Numbers were missing")
  337. end
  338. end
  339. end
  340. return names
  341. end
  342.  
  343. local function removePlayerFromKew(game,playername)
  344. for _,kew in pairs(game.queues) do
  345. for index, player in ipairs(kew.playerlist) do
  346. if player.name == playername then
  347. table.remove(kew.playerlist,index)
  348. end
  349. end
  350. if #kew.playerlist == 0 and kew.phase == 2 then
  351. --game can be ended as no players are left
  352. kew.timer = 0
  353. end
  354. end
  355. end
  356.  
  357. local function movePlayerToSpawn(playername)
  358. respawnPlayer(playername)
  359. commands.async.tp(playername,SPAWN.x,SPAWN.y,SPAWN.z,SPAWN.a1,SPAWN.a2)
  360. commands.async.tellraw(playername,'["",{"text":"TELEPORTED: You used your Heimkehrer","color":"blue"}]')
  361. end
  362.  
  363. --takes a list of squids and deals with all those players, moving them back to spawn and removing them from game
  364. --also gives them a new squid
  365. local function dealWithSquidders(game,squids)
  366. for _,squid in pairs(squids) do
  367. --remove player from current game if in game
  368. removePlayerFromKew(game,squid.name)
  369. --teleport them back to spawn
  370. movePlayerToSpawn(squid.name)
  371. --give a new squid
  372. giveSquid(squid.name)
  373. --particle effects
  374. --teleport message
  375. end
  376. --kill all squids
  377. if #squids>0 then
  378. commands.tp("@e[type=Squid]",100000,200,100000)
  379. commands.kill("@e[type=Squid]")
  380. os.sleep(#squids*0.2)
  381. end
  382. end
  383.  
  384.  
  385.  
  386.  
  387. --creates a village with special items
  388. local function spawnVillager(x,y,z)
  389. commands.summon("Villager",x,y,z,'{Invulnerable:1,CustomName:Wool_Seller,Profession:2,Career:1,CareerLevel:6,Offers:{Recipes:[ {buy:{id:emerald,Count:1},sell:{id:wool,Count:'..WOOL_PER_EMERALD..',tag:{CanPlaceOn:["minecraft:diamond_block","minecraft:clay","minecraft:wool","minecraft:stained_hardened_clay"]}}}, {buy:{id:emerald,Count:1},sell:{id:stone_pickaxe,Count:1,Damage:'..131-PICKAXE_USES..',tag:{CanDestroy:["minecraft:wool"]}}} ]}}')
  390. end
  391.  
  392. --displays a subtitle of time to a selection of players
  393. local function displayTime(selector,minutes,seconds)
  394. --commands.title("@a["..selector.."]","subtitle",'{text:"Time left: '..minutes..":"..seconds..'",color:red,bold:false,underlined:false,italic:false,strikethrough:false,obfuscated:false}')
  395. commands.async.xp("-1000000L","@a["..selector.."]")
  396. local secondstot = (minutes * 60) + seconds
  397. commands.async.xp(tostring(secondstot).."L","@a["..selector.."]")
  398. end
  399.  
  400. --displays a title to a selection of players
  401. local function displayTitle(selector,text)
  402. commands.async.title("@a["..selector.."]","title",'{text:"'..text..'"}')
  403. end
  404.  
  405. --simply runs displayTitle on a list of players
  406. local function displayTitleToGroup(playerlist,text)
  407. for i,player in ipairs(playerlist) do
  408. displayTitle("name="..player.name,text)
  409. end
  410. end
  411.  
  412. --simply runs displayTime on a list of players
  413. local function displayTimeToGroup(playerlist,minutes,seconds)
  414. for i,player in ipairs(playerlist) do
  415. displayTime("name="..player.name,minutes,seconds)
  416. end
  417. end
  418.  
  419. --teleports a list of players to an exact place and sends them a message about it
  420. local function teleportToPoint(x,y,z,playerlist,clear,text)
  421. for i,player in ipairs(playerlist) do
  422. player.x = x
  423. player.y = y
  424. player.z = z
  425. commands.async.gamemode(2,player.name)
  426. if clear then
  427. commands.async.clear(player.name,"wool")
  428. commands.async.clear(player.name,"stone_pickaxe")
  429. end
  430. commands.tp("@a[name="..player.name.."]",x,y,z)
  431. commands.async.tellraw(player.name,'["",{"text":"'..text..'","color":"blue"}]')
  432. end
  433. end
  434.  
  435. --teleports a list of players to a given buildzone
  436. local function teleportToZone(buildzone,playerlist,text)
  437. teleportToPoint(buildzone.x+2+(buildzone.w/2),buildzone.y+5,buildzone.z+2+(buildzone.w/2),playerlist,true,text)
  438.  
  439. end
  440.  
  441. --gives the same list of items to a list of players
  442. local function giveItems(playerlist,itemlist)
  443. local given = 0
  444. for i,player in ipairs(playerlist) do
  445. --commands.async.clear(player.name)
  446. for j,item in ipairs(itemlist) do
  447. commands.async.give("@a[name="..player.name.."]",item)
  448. given = given +1
  449. end
  450. giveSquid(player.name)
  451. end
  452. return given
  453. end
  454.  
  455. --a multi builder which uses the vocab constructor to create sets of vocab
  456. local function makeVocabZones(quant,w)
  457. local x,y,z = ox,oy,oz+6
  458. local result = {}
  459. local namecount = 1
  460. for i=0,quant-1 do
  461. for k=0,3 do
  462. local zpos = i-4
  463. local ypos = k
  464. local nextVocab = newVocabZone(x-(2*w)-6,y+(ypos*(VOCAB_HEIGHT+3)),z+((w+1)*zpos),w,REWARDS[namecount] or DEFAULT_REWARD,VOCAB_NAMES[namecount] or DEFAULT_NAME)
  465. table.insert(result,nextVocab)
  466. namecount = namecount +1
  467. end
  468. end
  469. return result
  470. end
  471.  
  472. --finds the next free location in a given area.
  473. --giving force as True will mean it overrides the first location no matter what
  474. local function findNextLoc(width,zones,force)
  475. local x,y,z = 0,0,0
  476. for i,loc in ipairs(LOCS) do
  477. x,y,z = FIRSTZONE.x+(loc.x*(width+1)),FIRSTZONE.y,FIRSTZONE.z+(-loc.z*(width+1))
  478. local result,message = commands.testforblock(x,y+BUILDZONE_FLOOR_HEIGHT,z,"minecraft:air")
  479. if force then result = true end
  480. local zonefree = true
  481. for i,zone in ipairs(zones) do
  482. if zone.x == x and zone.z == z then
  483. zonefree = false
  484. end
  485. end
  486. --print("next position free is ",loc.x*width,oy,loc.z*width)
  487. --if result then print("true") else print("false") end
  488. if result and zonefree then
  489. --print("using loc: ",loc.x,loc.z)
  490. return x,y,z
  491. end
  492. end
  493. return nil,nil,nil
  494.  
  495. end
  496.  
  497. --relocates a buildzone to a new coordinate safely
  498. --avoids overlapping with other buildzones
  499. function moveBuildzone(buildzone,zones)
  500. local x,y,z = findNextLoc(buildzone.w,zones)
  501. if x and y and z then
  502. print("moved buildzone from "..buildzone.x..","..buildzone.z.." to "..x..","..y)
  503. local w = buildzone.w
  504. buildzone.x,buildzone.y,buildzone.z = x,y+BUILDZONE_FLOOR_HEIGHT,z
  505. buildzone.selector = "x="..x..",y="..tostring(y-1)..",z="..z..",dx="..w..",dy=256,dz="..w
  506. buildzone.structures = {} --a list of all vocabularies which have been contructed
  507. else
  508. print("buildzone at "..buildzone.x..","..buildzone.z.." stayed where it is")
  509. end
  510. end
  511.  
  512. --multi builder to create sets of buildzones using the buildzone constructor
  513. local function makeBuildzones(quant,vocab,width,height)
  514. local result = {}
  515. for i=1,quant do
  516. local x,y,z = findNextLoc(width,result)
  517. if x and y and z then
  518. --print("made new buildzone at",x,y,z)
  519. table.insert(result,newBuildZone(x,y+height,z,width,vocab))
  520. else
  521. --print("failed to make new buildzone")
  522. end
  523. end
  524.  
  525. local remaining = NUMBER_OF_BUILDZONES - #result
  526.  
  527. for i=1, remaining do
  528. local x,y,z = findNextLoc(width,result,true)
  529. if x and y and z then
  530. --print("forced new buildzone at",x,y,z)
  531. table.insert(result,newBuildZone(x,y+height,z,width,vocab))
  532. else
  533. print("failed to force new buildzone")
  534. end
  535. end
  536.  
  537.  
  538. return result
  539. end
  540.  
  541. --vocab constructor. Enforces some data structure
  542. function newVocabZone(x,y,z,w,reward,name)
  543. local nvz = {}
  544. nvz.x ,nvz.y ,nvz.z ,nvz.w = x,y,z,w
  545.  
  546. nvz.cx = nvz.x - nvz.w - 2
  547. nvz.cy = nvz.y
  548. nvz.cz = nvz.z
  549. nvz.name = name
  550. nvz.reward = reward
  551.  
  552. return nvz
  553.  
  554. end
  555.  
  556. --buildzone constructor. Enforces some data structure
  557. function newBuildZone(x,y,z,w,vocabZones)
  558. local nbz = {}
  559. nbz.x ,nbz.y ,nbz.z ,nbz.w = x,y,z,w
  560. nbz.selector = "x="..x..",y="..(y-5)..",z="..z..",dx="..w..",dy=256,dz="..w
  561. nbz.structures = {} --a list of all vocabularies which have been contructed
  562. nbz.waitingForCheck = {}
  563. nbz.highest = 0
  564. nbz.vocab = vocabZones
  565.  
  566. return nbz
  567. end
  568.  
  569. --kew constructor. Enforces some data structure
  570. function newQueue(buildzone,maxplayers)
  571. local q = {}
  572. q.timer = 1
  573. q.phase = 1
  574.  
  575. q.victory = false
  576. q.phases = {
  577. {
  578. name = "Selecting Players",
  579. length = 25,
  580. displaylength = 15
  581. },
  582. {
  583. name = "Game In Progress",
  584. length = GAME_LENGTH,
  585. displaylength = 70
  586. },
  587. {
  588. name = "Round Complete",
  589. length = 35,
  590. displaylength = 5
  591. }
  592. }
  593. q.playerlist = {}
  594. q.maxplayers = maxplayers
  595. q.buildzone = buildzone
  596.  
  597. return q
  598. end
  599.  
  600.  
  601. --creates a ring of blocks using coordinates
  602. function fillRing(x,y,z,w,block)
  603. commands.fill(x,y,z,x+w,y,z,block)
  604. commands.fill(x+w,y,z,x+w,y,z+w,block)
  605. commands.fill(x,y,z+w,x+w,y,z+w,block)
  606. commands.fill(x,y,z+w,x,y,z,block)
  607. end
  608.  
  609. function setup()
  610. local game = {}
  611. game.vocab = {}
  612. game.builds = {}
  613. game.queues = {}
  614. game.waitlist = {}
  615. game.spawn = SPAWN
  616. game.lastClock = os.clock()
  617. game.nowTime = os.clock()
  618.  
  619. --kill all villagers
  620. commands.exec("kill @e[type=Villager]")
  621.  
  622. --buildzone and vocabzone creation
  623. game.vocab = makeVocabZones(NUMBER_OF_VOCAB,VOCAB_WIDTH)
  624.  
  625. game.builds = makeBuildzones(NUMBER_OF_BUILDZONES,game.vocab,BUILDZONE_WIDTH,BUILDZONE_FLOOR_HEIGHT)
  626.  
  627. for i,build in ipairs(game.builds) do
  628. table.insert(game.queues,newQueue(build,4))
  629. end
  630.  
  631. for i,vz in ipairs(game.vocab) do
  632. local x,y,z,w = vz.x,vz.y,vz.z,vz.w
  633. local cx,cy,cz = vz.cx,vz.cy,vz.cz
  634.  
  635. local detector, message1 = commands.testforblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT.block)
  636. local blocker, message2 = commands.testforblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD.block)
  637. if not (detector or blocker) then
  638. for nx=0,2 do
  639. for nz=0,2 do
  640. commands.setblock(x+(nx*9)+4,y-1,z+(nz*9)+4,BLOCKS.VOCAB_REPLACE.block)
  641. commands.setblock(cx+(nx*9)+4,cy-1,cz+(nz*9)+4,BLOCKS.VOCAB_DETECT.block)
  642. end
  643. end
  644. commands.setblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD.block)
  645.  
  646. end
  647.  
  648. end
  649.  
  650. for i, name in ipairs(VOCAB_NAMES) do
  651. commands.scoreboard("objectives","add",name,"dummy")
  652. end
  653.  
  654. commands.gamerule("doDaylightCycle",false)
  655. commands.gamerule("keepInventory",true)
  656. commands.gamerule("doTileDrops",false)
  657. commands.gamerule("logAdminCommands",false)
  658. commands.gamerule("commandBlockOutput",false)
  659. commands.time("set",6000)
  660. commands.scoreboard("objectives","add","highscores","dummy","Server-wide Best")
  661. commands.scoreboard("objectives","add","VillagerLife","dummy")
  662. commands.scoreboard("objectives","add","built","dummy", "Structures Built")
  663. commands.scoreboard("objectives","add","highest","dummy", "Personal Highest")
  664. commands.scoreboard("objectives","add","played","dummy","Games Played")
  665.  
  666. commands.title("@a","times",0,30,30)
  667. math.randomseed( os.time() )
  668. commands.scoreboard("objectives","setdisplay","sidebar","highscores")
  669. commands.scoreboard("objectives","setdisplay","list","played")
  670.  
  671. if DEBUG_MODE then
  672. for i,build in ipairs(game.builds) do
  673. build.phase = 2
  674. build.timer = 500
  675. end
  676. end
  677.  
  678. print("Computer Co-ordinates ",ox,oy,oz)
  679. print("20,000 Blocks Active!")
  680.  
  681. return game
  682. end
  683.  
  684. function checkForSquids(game)
  685. --execute on all squids
  686. local squidders = getSquids()
  687. dealWithSquidders(game,squidders)
  688. end
  689.  
  690. --main game loop
  691. --runs the game object through each of these update steps in order
  692. function update(game)
  693. local elapsed = updateClock(game)
  694. --update players
  695. checkPlayers(game)
  696. doTimerUpdates(game,elapsed)
  697. doPhaseUpdates(game)
  698. doPhaseEnds(game)
  699. checkBoundaries(game)
  700. checkForSquids(game)
  701. if #game.waitlist > 0 then allocateWaiters(game) end
  702. end
  703.  
  704. --calculates elapsed time during a game tick
  705. function updateClock(game)
  706. game.nowTime = os.clock()
  707. local elapsed = game.nowTime - game.lastClock
  708. game.lastClock = game.nowTime
  709. return elapsed
  710. end
  711.  
  712. --updates all kews in the game object based on elapsed time
  713. function doTimerUpdates(game,elapsed)
  714. for i,kew in ipairs(game.queues) do
  715. kew.timer = kew.timer - elapsed
  716. end
  717. end
  718.  
  719. --check players are inside their buildzone and move them back if not
  720. function checkBoundaries(game)
  721. for i,kew in ipairs(game.queues) do
  722. if kew.phase ==2 then
  723. --boundaries
  724. local x_min = kew.buildzone.x
  725. local x_max = kew.buildzone.x+kew.buildzone.w
  726. local z_min = kew.buildzone.z
  727. local z_max = kew.buildzone.z+kew.buildzone.w
  728.  
  729. local toBeCorrected = {}
  730.  
  731. for j,player in ipairs(kew.playerlist) do
  732. local listOfOne = getAllPos('m=2,name='..player.name)
  733. if listOfOne and listOfOne[1] then
  734. player.x = listOfOne[1].x
  735. player.y = listOfOne[1].y
  736. player.z = listOfOne[1].z
  737. local changed = false
  738. if player.x > x_max then
  739. changed = true
  740. player.x = x_max-2
  741. end
  742. if player.x < x_min then
  743. changed = true
  744. player.x = x_min+2
  745. end
  746. if player.z > z_max then
  747. changed = true
  748. player.z = z_max-2
  749. end
  750. if player.z < z_min then
  751. changed = true
  752. player.z = z_min+2
  753. end
  754. if changed then teleportToPoint(player.x,kew.buildzone.y,player.z,{player},false,"TELEPORTED: Please stay inside the building zone until your game has ended") end
  755. end
  756. end
  757. end
  758. end
  759. end
  760.  
  761.  
  762. --here you can set the logic which determines if a buildzone was valuable.
  763. --Return true if it is crap and should be replaced
  764. function checkIfBuildzoneIsCrap(buildzone)
  765. if #buildzone.structures < 5 then
  766. print("Buildzone was crap")
  767. return true
  768. end
  769. print("Buildzone was ok")
  770. return false
  771. end
  772.  
  773.  
  774. --Everything that happens after a buildzone was completed
  775. --due to time limit.
  776. function cleanAfterVictory(buildzone)
  777. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,BLOCKS.VICTORY_MARKER.block)
  778. fillRing(buildzone.x,buildzone.y,buildzone.z,buildzone.w,"minecraft:air",0,"replace",BLOCKS.CONSTRUCTION.block,BLOCKS.CONSTRUCTION.data)
  779. for h=0,VICTORY_HEIGHT do
  780. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air 0","replace",BLOCKS.DETECT.block,BLOCKS.DETECT.data)
  781. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air 0","replace",BLOCKS.PLUG.block,BLOCKS.PLUG.data)
  782. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air 0","replace",BLOCKS.BUILDING_GARDEN.block,BLOCKS.BUILDING_GARDEN.data)
  783. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air 0","replace",BLOCKS.BUILDING_HOUSE.block,BLOCKS.BUILDING_HOUSE.data)
  784. end
  785. commands.async.fill(buildzone.x,buildzone.y-1,buildzone.z,buildzone.x+buildzone.w,buildzone.y-1,buildzone.z+buildzone.w,BLOCKS.CAMP_FLOOR.block,BLOCKS.CAMP_FLOOR.data,"replace",BLOCKS.PLUG.block,BLOCKS.PLUG.data)
  786. commands.async.fill(buildzone.x,buildzone.y,buildzone.z,buildzone.x+buildzone.w,buildzone.y,buildzone.z+buildzone.w,BLOCKS.PHVFLOOR.block,BLOCKS.PHVFLOOR.data,"replace","minecraft:air","0")
  787.  
  788. local wasCrap = checkIfBuildzoneIsCrap(buildzone)
  789. if wasCrap then
  790. --mark this buildzone for replacement
  791. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,"minecraft:air")
  792. end
  793. end
  794.  
  795. --these happen every tick and require the game object
  796. --updates are performed on each Queue (kew) and within each
  797. --of those on each buildzone.
  798. function doPhaseUpdates(game)
  799. for i,kew in ipairs(game.queues) do
  800.  
  801. local minutes = string.format("%02d",math.floor(kew.timer/60))
  802. local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
  803. if kew.timer <= 0 then
  804. minutes = "00"
  805. seconds = "00"
  806. end
  807.  
  808. if kew.phase == 1 then
  809. --waiting phase
  810. if #kew.playerlist == kew.maxplayers and kew.timer > 5 then kew.timer = 5 end
  811. if not DEBUG_MODE and #kew.playerlist == 0 then kew.timer = kew.phases[1].length end
  812.  
  813. displayTitleToGroup(kew.playerlist,"Game starting!")
  814. displayTimeToGroup(kew.playerlist,minutes,seconds)
  815. --show countdown
  816. elseif kew.phase == 2 then
  817. --playing phase
  818. if #kew.playerlist == 0 then timer = 0 end -- finish if all players quit
  819. local victory = updatePlayedZone(kew.buildzone) -- do vocab logic
  820. displayTimeToGroup(kew.playerlist,minutes,seconds)
  821.  
  822. elseif kew.phase == 3 then
  823. --end phase
  824. displayTitleToGroup(kew.playerlist,"Returning to Spawn")
  825. displayTimeToGroup(kew.playerlist,minutes,seconds)
  826.  
  827.  
  828. end
  829. end
  830. end
  831.  
  832. --this runs after a buildzone is completed
  833. --it should tally structure types and set scoreboard highscores
  834. --it also rewards all participants with more played score
  835. function processHighscores(kew)
  836. local buildzone = kew.buildzone
  837. --calculate total structures
  838. local structures = tracker.tallyTable(buildzone.structures)
  839. local most = tracker.getScore("Most-Structures","highscores")
  840. if #buildzone.structures > most.count then
  841. commands.async.scoreboard("players","set","Most-Structures","highscores",#buildzone.structures)
  842. commands.async.say("@a","The record for Most Structures in a single game has been topped!")
  843. end
  844. --calculate total residential structures
  845. --calculate total commerical structures
  846. --calculate total industrial structures
  847. --calculate highest placement
  848. local highest = tracker.getScore("Highest-Structure","highscores")
  849. if buildzone.highest - buildzone.y >= highest.count then
  850. commands.async.scoreboard("players","set","Highest-Structure","highscores",buildzone.highest - buildzone.y)
  851. commands.async.say("@a","The record for the Highest Structure in a single game as been topped!")
  852. end
  853.  
  854. --add score to players who finished this game
  855. for _,player in ipairs(kew.playerlist) do
  856. commands.async.scoreboard("players","add",player.name,"played",1)
  857. end
  858. end
  859.  
  860. --function to export a buildzone detail once it is complete
  861. --requires a kew so it can access the playerlist
  862. local function exportKewData(kew)
  863. local buildzone = kew.buildzone
  864. local saved = {}
  865. saved.position =
  866. {
  867. x=buildzone.x,
  868. y=buildzone.y,
  869. z=buildzone.z
  870. }
  871. saved.completed = os.time()
  872. saved.players = {}
  873. for _, player in ipairs(kew.playerlist) do
  874. table.insert(saved.players,player.name)
  875. end
  876. saved.structures = buildzone.structures
  877. saved.totals = tracker.tallyTable(buildzone.structures)
  878. saved.highest = buildzone.highest - buildzone.y
  879.  
  880. fs.makeDir("/records")
  881. local file = fs.open("/records/"..buildzone.x.."_"..buildzone.z,"w")
  882. file.write(json.encodePretty(saved))
  883. file.close()
  884. end
  885.  
  886. --this code runs ONCE at the end of each phase
  887. --what actually happens is specific to which phase the
  888. --particular kew is in.
  889. function doPhaseEnds(game)
  890. for i,kew in ipairs(game.queues) do
  891. if kew.timer <= 0 then
  892. if kew.phase == 1 then
  893. --waiting phase ends goto play phase
  894.  
  895. moveBuildzone(kew.buildzone,game.builds)
  896. teleportToZone(kew.buildzone,kew.playerlist,"TELEPORTED: Your game has started.")--teleport selected players
  897. cleanBuildzone(kew.buildzone)
  898. prepareBuildzone(kew.buildzone)--prepare build zone
  899. giveItems(kew.playerlist,STARTING_ITEMS) --give starting items
  900. displayTitle(kew.buildzone.selector,"Build!")
  901. kew.victory = false
  902. displayTime(kew.buildzone.selector,0,0)
  903. kew.phase = 2
  904. kew.timer = kew.phases[2].length
  905. elseif kew.phase == 2 then
  906. --playing phase ends goto end phase
  907. processHighscores(kew)
  908. exportKewData(kew)
  909. cleanAfterVictory(kew.buildzone)
  910. kew.phase = 3
  911. displayTime(kew.buildzone.selector,0,0)
  912. kew.timer = kew.phases[3].length
  913. elseif kew.phase == 3 then
  914. --end phase ends goto waiting phase
  915. removePlayersFromKew(game,kew)
  916. kew.phase = 1
  917. displayTime(kew.buildzone.selector,0,0)
  918. kew.timer = kew.phases[1].length
  919. end
  920. end
  921. end
  922. end
  923.  
  924.  
  925. --Replaces everything that is needed to start the game. Does not rebuild the floor, or clear anything away.
  926. --based on the settings it creates a full grid, or a partial grid, or no grid
  927. --it also places the ring, although this is disabled for now
  928. function prepareBuildzone(buildzone)
  929. local bz = buildzone
  930. local x,y,z,w = bz.x,bz.y,bz.z,bz.w
  931. --commands.fill(x,y-1,z,x+w,y-1,z+w,BLOCKS.CAMP_FLOOR)
  932. fillRing(buildzone.x,buildzone.y,buildzone.z,buildzone.w,BLOCKS.CONSTRUCTION.block)
  933. if DO_GRID then
  934. for x=0,6 do
  935. for z=0,6 do
  936. local rand = math.random()*100
  937. local result, text = commands.testforblock(bz.x+(x*9)+4,bz.y-1,bz.z+(z*9)+4,BLOCKS.CAMP_FLOOR.block)
  938. if rand > GRID_HOLE_CHANCE and result then
  939. commands.async.setblock(bz.x+(x*9)+4,bz.y,bz.z+(z*9)+4,BLOCKS.DETECT.block,BLOCKS.DETECT.data,"replace","minecraft:air")
  940. commands.async.fill(bz.x+(x*9)+1,bz.y-1,bz.z+(z*9)+4,bz.x+(x*9)+7,bz.y-1,bz.z+(z*9)+4,BLOCKS.PLUG.block)
  941. commands.async.fill(bz.x+(x*9)+4,bz.y-1,bz.z+(z*9)+1,bz.x+(x*9)+4,bz.y-1,bz.z+(z*9)+7,BLOCKS.PLUG.block)
  942. commands.async.setblock(bz.x+(x*9)+4,bz.y-1,bz.z+(z*9)+4,BLOCKS.CAMP_FLOOR.block)
  943. end
  944. end
  945. end
  946. end
  947. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,BLOCKS.CONSTRUCTION.block)
  948. end
  949.  
  950. --deletes everything inside the buildzone
  951. function cleanBuildzone(buildzone)
  952. print("Cleaning buildzone")
  953. for h=0,VICTORY_HEIGHT+20 do
  954. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air")
  955. end
  956. end
  957.  
  958. --moves all players assigned to the queue into the waiting area for the provided game.
  959. --It also changes them to Adventure mode and clears their inventory
  960. function respawnPlayers(game,kew)
  961. teleportToPoint(game.spawn.x,game.spawn.y,game.spawn.z,kew.playerlist,true,"TELEPORTED: Your game ended so you have been returned to the Spawn Point") --put players back in spawn area
  962. for i,player in ipairs(kew.playerlist) do
  963. --table.insert(game.waitlist,player)
  964. respawnPlayer(player,"")
  965. end
  966. kew.playerlist = {}
  967. end
  968.  
  969. function removePlayersFromKew(game,kew)
  970. for _, player in ipairs(kew.playerlist) do
  971. commands.tell(player.name,"Your game is over. Use your Heimkehrer to return to spawn")
  972. end
  973. kew.playerlist = {}
  974. end
  975.  
  976. function respawnPlayer(playername,message)
  977. commands.tell(playername,message)
  978. commands.async.gamemode(2,playername)
  979. commands.async.clear(playername,"minecraft:wool")
  980. commands.async.clear(playername,"minecraft:stone_pickaxe")
  981. end
  982.  
  983. function checkForPlayerInBuildzone(player,buildzone)
  984. local result,message = commands.testfor('@a[name='..player.name..','..buildzone.selector..']')
  985. return result
  986. end
  987.  
  988. function checkForPlayerInWaitzone(player)
  989. local selector = "x="..WAITZONE.x..",y="..WAITZONE.y..",z="..WAITZONE.z..",dx="..WAITZONE.w..",dy=256,dz="..WAITZONE.l
  990. local result,message = commands.testfor('@a[name='..player.name..','..selector..']')
  991. return result
  992. end
  993.  
  994. function checkPlayers(game)
  995. local selector = "x="..WAITZONE.x..",y="..WAITZONE.y..",z="..WAITZONE.z..",dx="..WAITZONE.w..",dy=256,dz="..WAITZONE.l
  996. local loggedIn = getAllPos('m=2,'..selector)
  997. --refresh waitlist
  998. game.waitlist = loggedIn
  999. --check currently playing players
  1000. for l,kew in ipairs(game.queues) do
  1001. for i,builder in ipairs(kew.playerlist) do
  1002. local isPlaying = checkForPlayerInBuildzone(builder,kew.buildzone)
  1003. --remove players who are already in kews from the waitlist
  1004. for j, player in ipairs(loggedIn) do
  1005. if player.name == builder.name then
  1006. table.remove(loggedIn,j)
  1007. end
  1008. end
  1009. --if the game is in progress and the player is not found then remove them from the gamekew
  1010. if not isPlaying and kew.phase == 2 then
  1011. --table.remove(kew.playerlist,i)
  1012. --print("Removed "..builder.name.." from game in progress")
  1013. end
  1014. end
  1015. end
  1016. end
  1017.  
  1018. --adds players who wait in the orange room to slots in waiting buildzones
  1019. function allocateWaiters(game)
  1020. --find free slots
  1021. local freeslots = {}
  1022. for i, kew in ipairs(game.queues) do
  1023. if kew.phase == 1 and #kew.playerlist < kew.maxplayers then
  1024. local slots = kew.maxplayers - #kew.playerlist
  1025. for j=1,slots do
  1026. table.insert(freeslots,kew)
  1027. end
  1028. end
  1029. end
  1030.  
  1031. --RE-ENABLE SECOND SHUFFLETABLE IF YOU WANT RANDOM PLAYER MATCHUPS
  1032. shuffleTable(game.waitlist)
  1033. --shuffleTable(freeslots)
  1034.  
  1035. while #freeslots > 0 and #game.waitlist > 0 do
  1036. local player = table.remove(game.waitlist,1)
  1037. local freeslot = table.remove(freeslots,1).playerlist
  1038. table.insert(freeslot,player)
  1039. end
  1040. end
  1041.  
  1042. --PARTICLE FUNCTIONS
  1043. function searchParticle(x,y,z)
  1044. commands.async.particle("fireworksSpark",x,y,z,0.01,3,0.01,0.01,100)
  1045. end
  1046.  
  1047. function successParticle(x,y,z)
  1048. commands.async.particle("happyVillager",x,y,z,2,2,2,1,1000)
  1049. commands.async.playsound("random.levelup","@a",x,y,z,1,1.2)
  1050. end
  1051.  
  1052. function failParticle(x,y,z)
  1053. commands.async.particle("reddust",x,y,z,0.1,0.1,1.5,1,200)
  1054. commands.async.particle("reddust",x,y,z,1.5,0.1,0.1,1,200)
  1055. commands.async.playsound("random.bowhit","@a",x,y,z,1,0.8)
  1056. end
  1057.  
  1058. --makes sure that incoming check requests dont exist already
  1059. function addToChecklist(player,buildzone)
  1060. for _, detector in ipairs(buildzone.waitingForCheck) do
  1061. if detector.x == player.x and detector.y == player.y and detector.z == player.z then
  1062. return false
  1063. end
  1064. end
  1065. table.insert(buildzone.waitingForCheck,player)
  1066. return true
  1067. end
  1068.  
  1069. --removed all barrier blocks from a buildzone which are used to carve space in vocabs
  1070. function cleanBarriers(buildzone)
  1071. for h=0,50 do
  1072. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air",0,"replace","minecraft:barrier")
  1073. end
  1074. end
  1075.  
  1076. --The main chunk of code which deals with stepping on detector blocks and reading the vocab
  1077. function updatePlayedZone(buildzone)
  1078. local victory = false
  1079. local buildzoneSelector = buildzone.selector
  1080. --get all players on diamond, add them to the list of things to check
  1081. local detectLocations = getAllOnBlockType(BLOCKS.DETECT.block,buildzoneSelector)
  1082. for _, player in ipairs(detectLocations) do
  1083. addToChecklist(player,buildzone)
  1084. end
  1085.  
  1086. --DEAL WITH THE DETECTOR AT THE TOP OF THE LIST IF THERE IS ONE
  1087. if #buildzone.waitingForCheck > 0 then
  1088. --DO PARTICLE EFFECTS IF A DETECTING BLOCK THAT IS DETECTING
  1089. for i,loc in ipairs(buildzone.waitingForCheck) do
  1090. searchParticle(loc.x,loc.y+1,loc.z)
  1091. end
  1092. local totalResult = false
  1093. local checked = table.remove(buildzone.waitingForCheck,1)
  1094. local x,y,z,name = checked.x,checked.y,checked.z,checked.name
  1095. for i,vocab in pairs(buildzone.vocab) do
  1096. local result,message = commands.testforblocks(vocab.x,vocab.y,vocab.z,vocab.x+vocab.w,vocab.y+VOCAB_HEIGHT,vocab.z+vocab.w,x-math.floor(vocab.w/2),y-1,z-math.floor(vocab.w/2),"masked")
  1097. if result then
  1098. --clone in the correct vocab
  1099. local cloneres,clonemes = commands.clone(vocab.cx,vocab.cy,vocab.cz,vocab.cx+vocab.w,vocab.cy+VOCAB_HEIGHT,vocab.cz+vocab.w,x-math.floor(vocab.w/2),y-1,z-math.floor(vocab.w/2),"masked")
  1100. if DEBUG_MODE then
  1101. print(clonemes[1])
  1102. end
  1103. commands.async.give(name,vocab.reward)
  1104. commands.async.tellraw(name,'["",{"text":"You built a '..vocab.name.. ' and received more building materials!!","color":"green"}]')
  1105.  
  1106. --clear out barrier blocks
  1107. cleanBarriers(buildzone)
  1108.  
  1109. --add the new structure to the records and check if it is the highest
  1110. table.insert(buildzone.structures,vocab.name)
  1111. if y > buildzone.highest then
  1112. buildzone.highest = y
  1113. local personalbest = tracker.getScore(name,"highest")
  1114. if personalbest.count < y - buildzone.y then
  1115. commands.async.tell(name,"You just topped your personal record for highest structure")
  1116. commands.async.scoreboard("players","add",name,"highest",1)
  1117. end
  1118. end
  1119.  
  1120. --increase score for the building player
  1121. commands.async.scoreboard("players","add",name,"built",1)
  1122. commands.async.scoreboard("players","add",name,vocab.name,1)
  1123.  
  1124. totalResult = true
  1125. break
  1126.  
  1127. end
  1128. end
  1129. if totalResult then
  1130. --yey win, do a happy time
  1131. successParticle(x,y,z)
  1132. else
  1133. --no vocab found so do a fail particle
  1134. commands.async.tellraw(name,'["",{"text":"Your structure is not built correctly, try a different shape.","color":"red"}]')
  1135. failParticle(x,y-1,z)
  1136. end
  1137. end
  1138. return victory
  1139. end
  1140.  
  1141. --Display game information on the monitor
  1142. function debugDisplay(game)
  1143. monitor.clear()
  1144. if blink then
  1145. monitor.setCursorPos(1,1)
  1146. monitor.setTextColor(colors.red)
  1147. monitor.write("Running")
  1148. monitor.setTextColor(colors.white)
  1149. redstone.setOutput("top",true)
  1150. blink = false
  1151. else
  1152. redstone.setOutput("top",false)
  1153. blink = true
  1154. end
  1155. local line = 2
  1156.  
  1157. for i,kew in ipairs(game.queues) do
  1158. monitor.setCursorPos(1,line)
  1159. local minutes = string.format("%02d",math.floor(kew.timer/60))
  1160. local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
  1161. monitor.write("Buildzone "..i.." | Phase: "..kew.phase.." | Time: "..minutes..":"..seconds)
  1162. monitor.setCursorPos(1,line+1)
  1163. for i,player in ipairs(kew.playerlist) do
  1164. monitor.write(player.name.." ")
  1165. end
  1166. line = line +2
  1167. end
  1168.  
  1169. monitor.setCursorPos(1,10)
  1170. for i,player in ipairs(game.waitlist) do
  1171. monitor.write(player.name.." ")
  1172. end
  1173.  
  1174. end
  1175.  
  1176. --BEGIN RUNTIME CODE
  1177. local blink = true
  1178. local game = setup()
  1179. while true do
  1180. update(game)
  1181. if monitor then debugDisplay(game) end
  1182. commands.async.weather("clear",10000)
  1183.  
  1184. local resetbutton = redstone.getInput("left")
  1185. if resetbutton then
  1186. print("reset!")
  1187. for i,kew in ipairs(game.queues) do
  1188. if kew.phase == 2 then
  1189. kew.timer = 5
  1190. end
  1191. end
  1192. end
  1193. sleep(2)
  1194. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement