Advertisement
antonsavov

Untitled

Feb 28th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.21 KB | None | 0 0
  1. local VERSION = '0.8.4 - goals added'
  2. os.loadAPI('tracker')
  3. os.loadAPI('json')
  4.  
  5. print("Starting 20,000 Blocks")
  6.  
  7. DEBUG_MODE = false
  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 -- the actual zone width is 63 blocks, but for some reason due to how minecraft handles relative coordinates this has to be 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=12093,
  35. y=56,
  36. z=-1779,
  37. w=5,
  38. l=5
  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 absolute 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,27)
  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. commands.async.tellraw(playername,'["",{"text":"DE: TELEPORTED: You used your Heimkehrer","color":"orange"}]')
  362. end
  363.  
  364. --takes a list of squids and deals with all those players, moving them back to spawn and removing them from game
  365. --also gives them a new squid
  366. local function dealWithSquidders(game,squids)
  367. for _,squid in pairs(squids) do
  368. --remove player from current game if in game
  369. removePlayerFromKew(game,squid.name)
  370. --teleport them back to spawn
  371. movePlayerToSpawn(squid.name)
  372. --give a new squid
  373. giveSquid(squid.name)
  374. --particle effects
  375. --teleport message
  376. end
  377. --kill all squids
  378. if #squids>0 then
  379. commands.tp("@e[type=Squid]",100000,200,100000)
  380. commands.kill("@e[type=Squid]")
  381. os.sleep(#squids*0.2)
  382. end
  383. end
  384.  
  385.  
  386.  
  387.  
  388. --creates a villager with special items
  389. local function spawnVillager(x,y,z)
  390. 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"]}}} ]}}')
  391. end
  392.  
  393. --displays a subtitle of time to a selection of players
  394. local function displayTime(selector,minutes,seconds)
  395. --commands.title("@a["..selector.."]","subtitle",'{text:"Time left: '..minutes..":"..seconds..'",color:red,bold:false,underlined:false,italic:false,strikethrough:false,obfuscated:false}')
  396. commands.async.xp("-1000000L","@a["..selector.."]")
  397. local secondstot = (minutes * 60) + seconds
  398. commands.async.xp(tostring(secondstot).."L","@a["..selector.."]")
  399. end
  400.  
  401. --displays a title to a selection of players
  402. local function displayTitle(selector,text)
  403. commands.async.title("@a["..selector.."]","title",'{text:"'..text..'"}')
  404. end
  405.  
  406. --simply runs displayTitle on a list of players
  407. local function displayTitleToGroup(playerlist,text)
  408. for i,player in ipairs(playerlist) do
  409. displayTitle("name="..player.name,text)
  410. end
  411. end
  412.  
  413. --simply runs displayTime on a list of players
  414. local function displayTimeToGroup(playerlist,minutes,seconds)
  415. for i,player in ipairs(playerlist) do
  416. displayTime("name="..player.name,minutes,seconds)
  417. end
  418. end
  419.  
  420. --teleports a list of players to an exact place and sends them a message about it
  421. local function teleportToPoint(x,y,z,playerlist,clear,textEN, textDE)
  422. for i,player in ipairs(playerlist) do
  423. player.x = x
  424. player.y = y
  425. player.z = z
  426. commands.async.gamemode(2,player.name)
  427. if clear then
  428. commands.async.clear(player.name,"wool")
  429. commands.async.clear(player.name,"stone_pickaxe")
  430. end
  431. commands.tp("@a[name="..player.name.."]",x,y,z)
  432. commands.async.tellraw(player.name,'["",{"text":"'..textEN..'","color":"blue"}]')
  433. commands.async.tellraw(player.name,'["",{"text":"'..textDE..'","color":"orange"}]')
  434. end
  435. end
  436.  
  437. --teleports a list of players to a given buildzone
  438. local function teleportToZone(buildzone,playerlist,textEN, textDE)
  439. teleportToPoint(buildzone.x+2+(buildzone.w/2),buildzone.y+5,buildzone.z+2+(buildzone.w/2),playerlist,true,textEN, textDE)
  440.  
  441. end
  442.  
  443. --gives the same list of items to a list of players
  444. local function giveItems(playerlist,itemlist)
  445. local given = 0
  446. for i,player in ipairs(playerlist) do
  447. --commands.async.clear(player.name)
  448. for j,item in ipairs(itemlist) do
  449. commands.async.give("@a[name="..player.name.."]",item)
  450. given = given +1
  451. end
  452. giveSquid(player.name)
  453. end
  454. return given
  455. end
  456.  
  457. --a multi builder which uses the vocab constructor to create sets of vocab
  458. local function makeVocabZones(quant,w)
  459. local x,y,z = ox,oy,oz+6
  460. local result = {}
  461. local namecount = 1
  462. for i=0,quant-1 do
  463. for k=0,3 do
  464. local zpos = i-4
  465. local ypos = k
  466. --print("vocab at X")
  467. --print(x-(2*w)-6)
  468. --print("and Z")
  469. --print(z+((w+1)*zpos))
  470. 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)
  471. table.insert(result,nextVocab)
  472. namecount = namecount +1
  473. end
  474. end
  475. return result
  476. end
  477.  
  478. --finds the next free location(or buildzone) for a new game in a given area.
  479. --giving force as True will mean it overrides the first location no matter what
  480. local function findNextLoc(width,zones,force)
  481. local x,y,z = 0,0,0
  482. for i,loc in ipairs(LOCS) do
  483. x,y,z = FIRSTZONE.x+(loc.x*(width+1)),FIRSTZONE.y,FIRSTZONE.z+(-loc.z*(width+1))
  484. local result,message = commands.testforblock(x,y+BUILDZONE_FLOOR_HEIGHT,z,"minecraft:air")
  485. if force then result = true end
  486. local zonefree = true
  487. for i,zone in ipairs(zones) do
  488. if zone.x == x and zone.z == z then
  489. zonefree = false
  490. end
  491. end
  492. --print("next position free is ",loc.x*width,oy,loc.z*width)
  493. --if result then print("true") else print("false") end
  494. if result and zonefree then
  495. --print("using loc: ",loc.x,loc.z)
  496. return x,y,z
  497. end
  498. end
  499. return nil,nil,nil
  500.  
  501. end
  502.  
  503. --relocates a buildzone to a new coordinate safely
  504. --avoids overlapping with other buildzones
  505. function moveBuildzone(buildzone,zones)
  506. local x,y,z = findNextLoc(buildzone.w,zones)
  507. if x and y and z then
  508. print("moved buildzone from "..buildzone.x..","..buildzone.z.." to "..x..","..y)
  509. local w = buildzone.w
  510. buildzone.x,buildzone.y,buildzone.z = x,y+BUILDZONE_FLOOR_HEIGHT,z
  511. buildzone.selector = "x="..x..",y="..tostring(y-1)..",z="..z..",dx="..w..",dy=256,dz="..w
  512. buildzone.structures = {} --a list of all vocabularies which have been contructed
  513. else
  514. print("buildzone at "..buildzone.x..","..buildzone.z.." stayed where it is")
  515. end
  516. end
  517.  
  518. --multi builder to create sets of buildzones using the buildzone constructor
  519. local function makeBuildzones(quant,vocab,width,height)
  520. local result = {}
  521. for i=1,quant do
  522. local x,y,z = findNextLoc(width,result)
  523. if x and y and z then
  524. --print("made new buildzone at",x,y,z)
  525. table.insert(result,newBuildZone(x,y+height,z,width,vocab))
  526. else
  527. --print("failed to make new buildzone")
  528. end
  529. end
  530.  
  531. local remaining = NUMBER_OF_BUILDZONES - #result
  532.  
  533. for i=1, remaining do
  534. local x,y,z = findNextLoc(width,result,true)
  535. if x and y and z then
  536. --print("forced new buildzone at",x,y,z)
  537. table.insert(result,newBuildZone(x,y+height,z,width,vocab))
  538. else
  539. print("failed to force new buildzone")
  540. end
  541. end
  542.  
  543.  
  544. return result
  545. end
  546.  
  547. --vocab constructor. Enforces some data structure
  548. function newVocabZone(x,y,z,w,reward,name)
  549. local nvz = {}
  550. nvz.x ,nvz.y ,nvz.z ,nvz.w = x,y,z,w
  551.  
  552. nvz.cx = nvz.x - nvz.w - 2
  553. nvz.cy = nvz.y
  554. nvz.cz = nvz.z
  555. nvz.name = name
  556. nvz.reward = reward
  557.  
  558. return nvz
  559.  
  560. end
  561.  
  562. --buildzone constructor. Enforces some data structure
  563. function newBuildZone(x,y,z,w,vocabZones)
  564. local nbz = {}
  565. nbz.x ,nbz.y ,nbz.z ,nbz.w = x,y,z,w
  566. nbz.selector = "x="..x..",y="..(y-5)..",z="..z..",dx="..w..",dy=256,dz="..w
  567. nbz.structures = {} --a list of all vocabularies which have been contructed
  568. nbz.waitingForCheck = {}
  569. nbz.highest = 0
  570. nbz.vocab = vocabZones
  571.  
  572. return nbz
  573. end
  574.  
  575. --kew constructor. Enforces some data structure
  576. function newQueue(buildzone,maxplayers)
  577. local q = {}
  578. q.timer = 1
  579. q.phase = 1
  580.  
  581. q.victory = false
  582. q.phases = {
  583. {
  584. name = "Selecting Players",
  585. length = 25,
  586. displaylength = 15
  587. },
  588. {
  589. name = "Game In Progress",
  590. length = GAME_LENGTH,
  591. displaylength = 70
  592. },
  593. {
  594. name = "Round Complete",
  595. length = 35,
  596. displaylength = 5
  597. }
  598. }
  599. q.playerlist = {}
  600. q.maxplayers = maxplayers
  601. q.buildzone = buildzone
  602.  
  603. return q
  604. end
  605.  
  606.  
  607. --creates a ring of blocks using coordinates
  608. function fillRing(x,y,z,w,block)
  609. commands.fill(x,y,z,x+w,y,z,block)
  610. commands.fill(x+w,y,z,x+w,y,z+w,block)
  611. commands.fill(x,y,z+w,x+w,y,z+w,block)
  612. commands.fill(x,y,z+w,x,y,z,block)
  613. end
  614.  
  615. function setup()
  616. local game = {}
  617. game.vocab = {}
  618. game.builds = {}
  619. game.queues = {}
  620. game.waitlist = {}
  621. game.spawn = SPAWN
  622. game.lastClock = os.clock()
  623. game.nowTime = os.clock()
  624.  
  625. --kill all villagers
  626. commands.exec("kill @e[type=Villager]")
  627.  
  628. --buildzone and vocabzone creation
  629. game.vocab = makeVocabZones(NUMBER_OF_VOCAB,VOCAB_WIDTH)
  630.  
  631. game.builds = makeBuildzones(NUMBER_OF_BUILDZONES,game.vocab,BUILDZONE_WIDTH,BUILDZONE_FLOOR_HEIGHT)
  632.  
  633. for i,build in ipairs(game.builds) do
  634. table.insert(game.queues,newQueue(build,4))
  635. end
  636.  
  637. for i,vz in ipairs(game.vocab) do
  638. local x,y,z,w = vz.x,vz.y,vz.z,vz.w
  639. local cx,cy,cz = vz.cx,vz.cy,vz.cz
  640.  
  641. local detector, message1 = commands.testforblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT.block)
  642. local blocker, message2 = commands.testforblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD.block)
  643. if not (detector or blocker) then
  644. for nx=0,2 do
  645. for nz=0,2 do
  646. commands.setblock(x+(nx*9)+4,y-1,z+(nz*9)+4,BLOCKS.VOCAB_REPLACE.block)
  647. commands.setblock(cx+(nx*9)+4,cy-1,cz+(nz*9)+4,BLOCKS.VOCAB_DETECT.block)
  648. end
  649. end
  650. commands.setblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD.block)
  651.  
  652. end
  653.  
  654. end
  655.  
  656. for i, name in ipairs(VOCAB_NAMES) do
  657. commands.scoreboard("objectives","add",name,"dummy")
  658. end
  659.  
  660. commands.gamerule("doDaylightCycle",false)
  661. commands.gamerule("keepInventory",true)
  662. commands.gamerule("doTileDrops",false)
  663. commands.gamerule("logAdminCommands",false)
  664. commands.gamerule("commandBlockOutput",false)
  665. commands.time("set",6000)
  666. commands.scoreboard("objectives","add","highscores","dummy","Best Neighbourhoods")
  667. commands.scoreboard("objectives","add","VillagerLife","dummy")
  668. commands.scoreboard("objectives","add","built","dummy", "Structures Built")
  669. commands.scoreboard("objectives","add","highest","dummy", "Personal Highest")
  670. commands.scoreboard("objectives","add","played","dummy","Games Played")
  671.  
  672. commands.title("@a","times",0,30,30) -- what does this do?
  673. math.randomseed( os.time() )
  674. commands.scoreboard("objectives","setdisplay","sidebar","highscores")
  675. commands.scoreboard("objectives","setdisplay","list","played")
  676.  
  677. if DEBUG_MODE then
  678. for i,build in ipairs(game.builds) do
  679. build.phase = 2
  680. build.timer = 500
  681. end
  682. end
  683.  
  684. print("Computer Co-ordinates ",ox,oy,oz)
  685. print("20,000 Blocks Active!")
  686.  
  687. return game
  688. end
  689.  
  690. function checkForSquids(game)
  691. --execute on all squids
  692. local squidders = getSquids()
  693. dealWithSquidders(game,squidders)
  694. end
  695.  
  696. --main game loop
  697. --runs the game object through each of these update steps in order
  698. function update(game)
  699. local elapsed = updateClock(game)
  700. --update players
  701. checkPlayers(game)
  702. doTimerUpdates(game,elapsed)
  703. doPhaseUpdates(game)
  704. doPhaseEnds(game)
  705. checkBoundaries(game)
  706. checkForSquids(game)
  707. if #game.waitlist > 0 then allocateWaiters(game) end
  708. end
  709.  
  710. --calculates elapsed time during a game tick
  711. function updateClock(game)
  712. game.nowTime = os.clock()
  713. local elapsed = game.nowTime - game.lastClock
  714. game.lastClock = game.nowTime
  715. return elapsed
  716. end
  717.  
  718. --updates all kews in the game object based on elapsed time
  719. function doTimerUpdates(game,elapsed)
  720. for i,kew in ipairs(game.queues) do
  721. kew.timer = kew.timer - elapsed
  722. end
  723. end
  724.  
  725. --check players are inside their buildzone and move them back if not
  726. function checkBoundaries(game)
  727. for i,kew in ipairs(game.queues) do
  728. if kew.phase ==2 then
  729. --boundaries
  730. local x_min = kew.buildzone.x
  731. local x_max = kew.buildzone.x+kew.buildzone.w
  732. local z_min = kew.buildzone.z
  733. local z_max = kew.buildzone.z+kew.buildzone.w
  734.  
  735. local toBeCorrected = {}
  736.  
  737. for j,player in ipairs(kew.playerlist) do
  738. local listOfOne = getAllPos('m=2,name='..player.name)
  739. if listOfOne and listOfOne[1] then
  740. player.x = listOfOne[1].x
  741. player.y = listOfOne[1].y
  742. player.z = listOfOne[1].z
  743. local changed = false
  744. if player.x > x_max then
  745. changed = true
  746. player.x = x_max-2
  747. end
  748. if player.x < x_min then
  749. changed = true
  750. player.x = x_min+2
  751. end
  752. if player.z > z_max then
  753. changed = true
  754. player.z = z_max-2
  755. end
  756. if player.z < z_min then
  757. changed = true
  758. player.z = z_min+2
  759. end
  760. 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", "DE: TELEPORTED: Please stay inside the building zone until your game has ended") end
  761. end
  762. end
  763. end
  764. end
  765. end
  766.  
  767.  
  768. --here you can set the logic which determines if a buildzone was valuable.
  769. --Return true if it is crap and should be replaced
  770. function checkIfBuildzoneIsCrap(buildzone)
  771. if #buildzone.structures < 5 then
  772. print("Buildzone was crap")
  773. return true
  774. end
  775. print("Buildzone was ok")
  776. return false
  777. end
  778.  
  779.  
  780. --Everything that happens after a buildzone was completed
  781. --due to time limit.
  782. function cleanAfterVictory(buildzone)
  783. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,BLOCKS.VICTORY_MARKER.block)
  784. fillRing(buildzone.x,buildzone.y,buildzone.z,buildzone.w,"minecraft:air",0,"replace",BLOCKS.CONSTRUCTION.block,BLOCKS.CONSTRUCTION.data)
  785. for h=0,VICTORY_HEIGHT do
  786. 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)
  787. 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)
  788. 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)
  789. 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)
  790. end
  791. 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)
  792. 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")
  793.  
  794. local wasCrap = checkIfBuildzoneIsCrap(buildzone)
  795. if wasCrap then
  796. --mark this buildzone for replacement
  797. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,"minecraft:air")
  798. end
  799. end
  800.  
  801. --these happen every tick and require the game object
  802. --updates are performed on each Queue (kew) and within each
  803. --of those on each buildzone.
  804. function doPhaseUpdates(game)
  805. for i,kew in ipairs(game.queues) do
  806.  
  807. local minutes = string.format("%02d",math.floor(kew.timer/60))
  808. local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
  809. if kew.timer <= 0 then
  810. minutes = "00"
  811. seconds = "00"
  812. end
  813.  
  814. if kew.phase == 1 then
  815. --waiting phase
  816. if #kew.playerlist == kew.maxplayers and kew.timer > 5 then kew.timer = 5 end
  817. if not DEBUG_MODE and #kew.playerlist == 0 then kew.timer = kew.phases[1].length end
  818.  
  819. displayTitleToGroup(kew.playerlist,"Game starting!")
  820. displayTimeToGroup(kew.playerlist,minutes,seconds)
  821. --show countdown
  822. elseif kew.phase == 2 then
  823. --playing phase
  824. if #kew.playerlist == 0 then timer = 0 end -- finish if all players quit
  825. -- do vocab logic
  826. local victory = updatePlayedZone(kew.buildzone) --currently victory updatePlayedZone returns always false
  827. --
  828. displayTimeToGroup(kew.playerlist,minutes,seconds)
  829.  
  830. elseif kew.phase == 3 then
  831. --end phase
  832. displayTitleToGroup(kew.playerlist,"Use Heimkehrer to return")
  833. displayTimeToGroup(kew.playerlist,minutes,seconds)
  834.  
  835.  
  836. end
  837. end
  838. end
  839.  
  840. --this runs after a buildzone is completed
  841. --it should tally structure types and set scoreboard highscores
  842. --it also rewards all participants with more played score
  843. function processHighscores(kew)
  844. local buildzone = kew.buildzone
  845.  
  846.  
  847.  
  848. --add score to players who finished this game
  849. for _,player in ipairs(kew.playerlist) do
  850. commands.async.scoreboard("players","add",player.name,"played",1)
  851. end
  852. end
  853.  
  854. --function to export a buildzone detail once it is complete
  855. --requires a kew so it can access the playerlist
  856. local function exportKewData(kew)
  857. local buildzone = kew.buildzone
  858. local saved = {}
  859. saved.position =
  860. {
  861. x=buildzone.x,
  862. y=buildzone.y,
  863. z=buildzone.z
  864. }
  865. saved.completed = os.time()
  866. saved.players = {}
  867. for _, player in ipairs(kew.playerlist) do
  868. table.insert(saved.players,player.name)
  869. end
  870. saved.structures = buildzone.structures
  871. saved.totals = tracker.tallyTable(buildzone.structures)
  872. saved.highest = buildzone.highest - buildzone.y
  873.  
  874. fs.makeDir("/records")
  875. local file = fs.open("/records/"..buildzone.x.."_"..buildzone.z,"w")
  876. file.write(json.encodePretty(saved))
  877. file.close()
  878. end
  879.  
  880. --this code runs ONCE at the end of each phase
  881. --what actually happens is specific to which phase the
  882. --particular kew is in.
  883. function doPhaseEnds(game)
  884. for i,kew in ipairs(game.queues) do
  885. if kew.timer <= 0 then
  886. if kew.phase == 1 then
  887. --waiting phase ends goto play phase
  888.  
  889. moveBuildzone(kew.buildzone,game.builds)
  890. teleportToZone(kew.buildzone,kew.playerlist,"TELEPORTED: Your game has started.", "DE: TELEPORTED: Your game has started.")--teleport selected players
  891. cleanBuildzone(kew.buildzone)
  892. prepareBuildzone(kew.buildzone)--prepare build zone
  893. giveItems(kew.playerlist,STARTING_ITEMS) --give starting items
  894. displayTitle(kew.buildzone.selector,"Build!")
  895. kew.victory = false
  896. displayTime(kew.buildzone.selector,0,0)
  897. kew.phase = 2
  898. kew.timer = kew.phases[2].length
  899. elseif kew.phase == 2 then
  900. --playing phase ends goto end phase
  901. processHighscores(kew)
  902. exportKewData(kew)
  903. cleanAfterVictory(kew.buildzone)
  904. kew.phase = 3
  905. displayTime(kew.buildzone.selector,0,0)
  906. kew.timer = kew.phases[3].length
  907. elseif kew.phase == 3 then
  908. --end phase ends goto waiting phase
  909. removePlayersFromKew(game,kew)
  910. kew.phase = 1
  911. displayTime(kew.buildzone.selector,0,0)
  912. kew.timer = kew.phases[1].length
  913. end
  914. end
  915. end
  916. end
  917.  
  918.  
  919. --Replaces everything that is needed to start the game. Does not rebuild the floor, or clear anything away.
  920. --based on the settings it creates a full grid, or a partial grid, or no grid
  921. --it also places the ring, although this is disabled for now
  922. function prepareBuildzone(buildzone)
  923. local bz = buildzone
  924. local x,y,z,w = bz.x,bz.y,bz.z,bz.w
  925. --commands.fill(x,y-1,z,x+w,y-1,z+w,BLOCKS.CAMP_FLOOR)
  926. fillRing(buildzone.x,buildzone.y,buildzone.z,buildzone.w,BLOCKS.CONSTRUCTION.block)
  927. if DO_GRID then
  928. for x=0,6 do
  929. for z=0,6 do
  930. local rand = math.random()*100
  931. --local result, text = commands.testforblock(bz.x+(x*9)+4,bz.y-1,bz.z+(z*9)+4,BLOCKS.CAMP_FLOOR.block)
  932. if rand > GRID_HOLE_CHANCE then --and result then
  933. commands.async.setblock(bz.x+(x*9)+4,bz.y,bz.z+(z*9)+4,BLOCKS.DETECT.block,BLOCKS.DETECT.data,"replace","minecraft:air")
  934. 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)
  935. 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)
  936. --commands.async.setblock(bz.x+(x*9)+4,bz.y-1,bz.z+(z*9)+4,BLOCKS.CAMP_FLOOR.block)
  937. end
  938. end
  939. end
  940. end
  941. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,BLOCKS.CONSTRUCTION.block)
  942. end
  943.  
  944. --deletes everything inside the buildzone
  945. function cleanBuildzone(buildzone)
  946. print("Cleaning buildzone")
  947. for h=0,VICTORY_HEIGHT+20 do
  948. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air")
  949. end
  950. end
  951.  
  952. --moves all players assigned to the queue into the waiting area for the provided game.
  953. --It also changes them to Adventure mode and clears their inventory
  954. function respawnPlayers(game,kew)
  955. 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", "DE: TELEPORTED: Your game ended so you have been returned to the Spawn Point") --put players back in spawn area
  956. for i,player in ipairs(kew.playerlist) do
  957. --table.insert(game.waitlist,player)
  958. respawnPlayer(player,"")
  959. end
  960. kew.playerlist = {}
  961. end
  962.  
  963. function removePlayersFromKew(game,kew)
  964. for _, player in ipairs(kew.playerlist) do
  965. commands.tell(player.name,"Your game is over. Use your Heimkehrer to return to spawn")
  966. end
  967. kew.playerlist = {}
  968. end
  969.  
  970. function respawnPlayer(playername,message)
  971. commands.tell(playername,message)
  972. commands.async.gamemode(2,playername)
  973. commands.async.clear(playername,"minecraft:wool")
  974. commands.async.clear(playername,"minecraft:stone_pickaxe")
  975. end
  976.  
  977. function checkForPlayerInBuildzone(player,buildzone)
  978. local result,message = commands.testfor('@a[name='..player.name..','..buildzone.selector..']')
  979. return result
  980. end
  981.  
  982. function checkForPlayerInWaitzone(player)
  983. local selector = "x="..WAITZONE.x..",y="..WAITZONE.y..",z="..WAITZONE.z..",dx="..WAITZONE.w..",dy=256,dz="..WAITZONE.l
  984. local result,message = commands.testfor('@a[name='..player.name..','..selector..']')
  985. return result
  986. end
  987.  
  988. function checkPlayers(game)
  989. local selector = "x="..WAITZONE.x..",y="..WAITZONE.y..",z="..WAITZONE.z..",dx="..WAITZONE.w..",dy=256,dz="..WAITZONE.l
  990. local loggedIn = getAllPos('m=2,'..selector)
  991. --refresh waitlist
  992. game.waitlist = loggedIn
  993. --check currently playing players
  994. for l,kew in ipairs(game.queues) do
  995. for i,builder in ipairs(kew.playerlist) do
  996. local isPlaying = checkForPlayerInBuildzone(builder,kew.buildzone)
  997. --remove players who are already in kews from the waitlist
  998. for j, player in ipairs(loggedIn) do
  999. if player.name == builder.name then
  1000. table.remove(loggedIn,j)
  1001. end
  1002. end
  1003. --if the game is in progress and the player is not found then remove them from the gamekew
  1004. if not isPlaying and kew.phase == 2 then
  1005. --table.remove(kew.playerlist,i)
  1006. --print("Removed "..builder.name.." from game in progress")
  1007. end
  1008. end
  1009. end
  1010. end
  1011.  
  1012. --adds players who wait in the orange room to slots in waiting buildzones
  1013. function allocateWaiters(game)
  1014. --find free slots
  1015. local freeslots = {}
  1016. for i, kew in ipairs(game.queues) do
  1017. if kew.phase == 1 and #kew.playerlist < kew.maxplayers then
  1018. local slots = kew.maxplayers - #kew.playerlist
  1019. for j=1,slots do
  1020. table.insert(freeslots,kew)
  1021. end
  1022. end
  1023. end
  1024.  
  1025. --RE-ENABLE SECOND SHUFFLETABLE IF YOU WANT RANDOM PLAYER MATCHUPS
  1026. shuffleTable(game.waitlist)
  1027. --shuffleTable(freeslots)
  1028.  
  1029. while #freeslots > 0 and #game.waitlist > 0 do
  1030. local player = table.remove(game.waitlist,1)
  1031. local freeslot = table.remove(freeslots,1).playerlist
  1032. table.insert(freeslot,player)
  1033. end
  1034. end
  1035.  
  1036. --PARTICLE FUNCTIONS
  1037. --particles shown to player while their shape is being checked for match
  1038. function searchParticle(x,y,z)
  1039. commands.async.particle("fireworksSpark",x,y,z,0.01,3,0.01,0.01,100)
  1040. end
  1041. -- particles shown to player on successful vocab match
  1042. function successParticle(x,y,z)
  1043. commands.async.particle("happyVillager",x,y,z,2,2,2,1,1000)
  1044. commands.async.playsound("random.levelup","@a",x,y,z,1,1.2)
  1045. end
  1046. --- particles shown to player on failed vocab match
  1047. function failParticle(x,y,z)
  1048. commands.async.particle("reddust",x,y,z,0.1,0.1,1.5,1,200)
  1049. commands.async.particle("reddust",x,y,z,1.5,0.1,0.1,1,200)
  1050. commands.async.playsound("random.bowhit","@a",x,y,z,1,0.8)
  1051. end
  1052.  
  1053. --makes sure that incoming check requests dont exist already
  1054. function addToChecklist(player,buildzone)
  1055. for _, detector in ipairs(buildzone.waitingForCheck) do
  1056. if detector.x == player.x and detector.y == player.y and detector.z == player.z then
  1057. return false
  1058. end
  1059. end
  1060. table.insert(buildzone.waitingForCheck,player)
  1061. return true
  1062. end
  1063.  
  1064. --removed all barrier blocks from a buildzone which are used to carve space in vocabs
  1065. function cleanBarriers(buildzone)
  1066. for h=0,200 do
  1067. 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")
  1068. end
  1069. end
  1070.  
  1071. --The main chunk of code which deals with stepping on detector blocks and reading the vocab
  1072. function updatePlayedZone(buildzone)
  1073. local victory = false
  1074. local buildzoneSelector = buildzone.selector
  1075. --get all players on diamond, add them to the list of things to check
  1076. local detectLocations = getAllOnBlockType(BLOCKS.DETECT.block,buildzoneSelector)
  1077. for _, player in ipairs(detectLocations) do
  1078. addToChecklist(player,buildzone)
  1079. end
  1080.  
  1081. --DEAL WITH THE DETECTOR AT THE TOP OF THE LIST IF THERE IS ONE
  1082. if #buildzone.waitingForCheck > 0 then
  1083. --DO PARTICLE EFFECTS IF A DETECTING BLOCK THAT IS DETECTING
  1084. for i,loc in ipairs(buildzone.waitingForCheck) do
  1085. searchParticle(loc.x,loc.y+1,loc.z)
  1086. end
  1087. local totalResult = false
  1088. local checked = table.remove(buildzone.waitingForCheck,1)
  1089. local x,y,z,name = checked.x,checked.y,checked.z,checked.name
  1090. for i,vocab in pairs(buildzone.vocab) do
  1091. 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")
  1092. if result then
  1093. --clone in the correct vocab
  1094. 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")
  1095. if DEBUG_MODE then
  1096. print(clonemes[1])
  1097. end
  1098. commands.async.give(name,vocab.reward)
  1099. -- announce vocab success in English
  1100. commands.async.tellraw(name,'["",{"text":"You built a '..vocab.name.. ' and received more building materials!!","color":"green"}]')
  1101. -- announce vocab success in German
  1102. commands.async.tellraw(name,'["",{"text":"DE: You built a '..vocab.name.. ' and received more building materials!!","color":"orange"}]')
  1103. --clear out barrier blocks
  1104. cleanBarriers(buildzone)
  1105.  
  1106. --add the new structure to the records
  1107. table.insert(buildzone.structures,vocab.name) ---CHANGE HERE to make it record the place of the vocab too x, y, z and vocab id
  1108.  
  1109. --- CHECK FOR PERSONAL RECORDS
  1110. --- check if the new structure is the highest
  1111. --- CHANGE here to live detect the contribution of the new structure to the 4 goals and update them
  1112. if y > buildzone.highest then
  1113. buildzone.highest = y
  1114. local personalbest = tracker.getScore(name,"highest")
  1115. if personalbest.count < y - buildzone.y then
  1116. commands.async.tell(name,"You just topped your personal record for highest structure")
  1117. commands.async.scoreboard("players","add",name,"highest",1)
  1118. end
  1119. end
  1120. ---
  1121. ---
  1122. -- CHECK if placing the current structure would result in beating a server-wide record on the 4 goals
  1123. --calculate total structures - FOR GOAL "DENSEST NEIGHBOURHOOD"
  1124. local most = tracker.getScore("Densest_[percent]","highscores")
  1125. if #buildzone.structures > most.count then
  1126. commands.async.scoreboard("players","set","Densest_[percent]","highscores",#buildzone.structures)
  1127. commands.async.say("@a","The record for the Densest Neighbourhood has been topped!")
  1128. end
  1129. --calculate total residential structures
  1130. --calculate total commerical structures
  1131. --calculate total industrial structures
  1132. -- FOR THE GOAL "MOST DIVERSE NEIGHBOURHOOD"
  1133. -- here we need to count how many varieties of buildings there are
  1134. local structures = tracker.tallyTable(buildzone.structures) -- this counts the variety of buildings in a game
  1135. local mostDiverse = tracker.getScore("Most-Diverse_[out-of-40]","highscores")
  1136. if #structures > mostDiverse.count then
  1137. commands.async.scoreboard("players","set","Most-Diverse_[out-of-40]","highscores",#structures)
  1138. commands.async.say("@a","The record for the Most Diverse Neighbourhood has been topped!")
  1139. end
  1140.  
  1141. -- FOR THE GOAL "GREENEST NEIGHBOURHOOD"
  1142. -- here we need to count the number of green vocabsa
  1143.  
  1144. --calculate highest placement -- FOR THE GOAL "TALLEST NEIGHBOURHOOD"
  1145. local highest = tracker.getScore("Tallest_[meters]","highscores")
  1146. if buildzone.highest - buildzone.y >= highest.count then
  1147. commands.async.scoreboard("players","set","Tallest_[meters]","highscores",buildzone.highest - buildzone.y)
  1148. commands.async.say("@a","The record for the Tallest Negihbourhood has been topped!")
  1149. end
  1150.  
  1151.  
  1152. --increase the "how many structures did i build" score for the building player
  1153. commands.async.scoreboard("players","add",name,"built",1)
  1154. commands.async.scoreboard("players","add",name,vocab.name,1) -- use maybe vocab ID instead of name
  1155.  
  1156. totalResult = true
  1157. break
  1158.  
  1159. end
  1160. end
  1161. if totalResult then
  1162. --yey win, do a happy time
  1163. successParticle(x,y,z)
  1164. else
  1165. --no vocab found so do a fail particle
  1166. --announce in English
  1167. commands.async.tellraw(name,'["",{"text":"Your structure is not built correctly, try a different shape.","color":"red"}]')
  1168. -- announce in German
  1169. commands.async.tellraw(name,'["",{"text":"DE: Your structure is not built correctly, try a different shape.","color":"orange"}]')
  1170. failParticle(x,y-1,z)
  1171. end
  1172. end
  1173. return victory
  1174. end
  1175.  
  1176. --Display game information on the monitor
  1177. function debugDisplay(game)
  1178. monitor.clear()
  1179. if blink then
  1180. monitor.setCursorPos(1,1)
  1181. monitor.setTextColor(colors.red)
  1182. monitor.write("Running")
  1183. monitor.setTextColor(colors.white)
  1184. redstone.setOutput("top",true)
  1185. blink = false
  1186. else
  1187. redstone.setOutput("top",false)
  1188. blink = true
  1189. end
  1190. local line = 2
  1191.  
  1192. for i,kew in ipairs(game.queues) do
  1193. monitor.setCursorPos(1,line)
  1194. local minutes = string.format("%02d",math.floor(kew.timer/60))
  1195. local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
  1196. monitor.write("Buildzone "..i.." | Phase: "..kew.phase.." | Time: "..minutes..":"..seconds)
  1197. monitor.setCursorPos(1,line+1)
  1198. for i,player in ipairs(kew.playerlist) do
  1199. monitor.write(player.name.." ")
  1200. end
  1201. line = line +2
  1202. end
  1203.  
  1204. monitor.setCursorPos(1,10)
  1205. for i,player in ipairs(game.waitlist) do
  1206. monitor.write(player.name.." ")
  1207. end
  1208.  
  1209. end
  1210.  
  1211. --BEGIN RUNTIME CODE
  1212. local blink = true
  1213. local game = setup()
  1214. while true do
  1215. update(game)
  1216. if monitor then debugDisplay(game) end
  1217. commands.async.weather("clear",10000)
  1218.  
  1219. local resetbutton = redstone.getInput("left")
  1220. if resetbutton then
  1221. print("reset!")
  1222. for i,kew in ipairs(game.queues) do
  1223. if kew.phase == 2 then
  1224. kew.timer = 5
  1225. end
  1226. end
  1227. end
  1228. sleep(2)
  1229. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement