Advertisement
antonsavov

Untitled

Mar 3rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 56.37 KB | None | 0 0
  1. local VERSION = '0.8.6 - updated rewards and goals'
  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. CITY_VERSION = 1 -- this denotes which iteration of the map is current. When the map is full, i.e. all buildzones have been played we replace it with an empty one and increase the city vesrion with 1
  12. SPAWN_VILLAGER = false
  13. DO_GRID = true
  14. GRID_HOLE_CHANCE = 0
  15. NUMBER_OF_BUILDZONES = 6
  16. NUMBER_OF_VOCAB = 10
  17. GAME_LENGTH = 600
  18. VOCAB_WIDTH = 27
  19. VOCAB_HEIGHT = 19
  20. 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
  21. BUILDZONE_FLOOR_HEIGHT = -1
  22. SPAWN = {
  23. x=12110,
  24. y=57,
  25. z=-1777,
  26. a1=90,
  27. a2=0
  28. }
  29. FIRSTZONE= {
  30. x=11685,
  31. y=57,
  32. z=-1869
  33. }
  34. WAITZONE = {
  35. x=12093,
  36. y=56,
  37. z=-1779,
  38. w=5,
  39. l=5
  40. }
  41. VICTORY_HEIGHT = 30
  42. VICTORY_TOTAL = 50
  43. VICTORY_SPECIFIC = {name='garden',count=101}
  44.  
  45.  
  46. WOOL_PER_EMERALD = 64
  47. PICKAXE_USES = 40
  48.  
  49. BLOCKS = {
  50. CAMP_FLOOR = {block='minecraft:sandstone',data=0},
  51. CONSTRUCTION = {block='minecraft:diamond_ore',data=0},
  52. RING = {block='minecraft:diamond_ore',data=0},
  53. DETECT = {block='minecraft:red_sandstone',data=0},
  54. DETECT_DEAD = {block='minecraft:obsidian',data=0},
  55. VOCAB_DETECT = {block="minecraft:quartz_block",data=0},
  56. VOCAB_REPLACE = {block="minecraft:coal_block",data=0},
  57. VICTORY_MARKER = {block="minecraft:emerald_block",data=0},
  58. PLUG = {block="minecraft:lapis_ore",data=0},
  59. PHVFLOOR = {block="minecraft:stone_slab",data=3},
  60. BUILDING_HOUSE = {block="minecraft:wool",data=0},
  61. BUILDING_GARDEN = {block="minecraft:wool",data=13},
  62. BUILDING_WATER = {block="minecraft:wool",data=1},
  63. }
  64.  
  65. --contains a list of all posible Buildzones (build a bit later)
  66. LOCS = {}
  67.  
  68. if DEBUG_MODE then
  69. GAME_LENGTH = 12000
  70. NUMBER_OF_BUILDZONES = 1
  71. end
  72.  
  73. --creates a grid of absolute references (0,0) (1,0)
  74. function buildGrid(w,h)
  75. local grid = {}
  76. for x=0,w-1 do
  77. for z=0,h-1 do
  78. table.insert(grid,{x=x,z=z})
  79. end
  80. end
  81. return grid
  82. end
  83.  
  84. --sets where and how big the PHV area is
  85. --second number is along the long edge of PHV starting at the spawn side
  86. --first number is along the short edge of PHV starting from the park side
  87. if DEBUG_MODE then
  88. FIRSTZONE= {
  89. x=5,
  90. y=57,
  91. z=-7
  92. }
  93.  
  94. LOCS = buildGrid(1,3)
  95. else
  96. LOCS = buildGrid(11,27)
  97. end
  98.  
  99. --call these to return a proper minecraft item string including adventure mode properties
  100. function houseBlock(quant)
  101. text = BLOCKS.BUILDING_HOUSE.block..' '..quant..' '..BLOCKS.BUILDING_HOUSE.data..' {display:{Name:"Urban Resource",Lore:[Place this against a Detector to build denser, more urban buildings]},CanPlaceOn:["'..BLOCKS.BUILDING_HOUSE.block..'","'..BLOCKS.PLUG.block..'","'..BLOCKS.DETECT.block..'"]}'
  102. return text
  103. end
  104.  
  105.  
  106. function gardenBlock(quant)
  107. text = BLOCKS.BUILDING_GARDEN.block..' '..quant..' '..BLOCKS.BUILDING_GARDEN.data..' {display:{Name:"Nature Resource",Lore:[Place this against a Detector to build greener, more open buildings]},CanPlaceOn:["'..BLOCKS.BUILDING_HOUSE.block..'","'..BLOCKS.PLUG.block..'","'..BLOCKS.DETECT.block..'"]}'
  108. return text
  109. end
  110.  
  111. STARTING_ITEMS = {
  112. houseBlock(30), gardenBlock(30),
  113. '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]}}'
  114.  
  115. }
  116.  
  117.  
  118.  
  119. DEFAULT_NAME = 'BUILDING'
  120. VOCAB_NAMES = {
  121. 'freestand-house',
  122. 'freestand-house',
  123. 'freestand-house',
  124. 'freestand-house',
  125. 'dbl-ext-house',
  126. 'dbl-ext-house',
  127. 'dbl-ext-house',
  128. 'dbl-ext-house',
  129. 'bridge-house',
  130. 'bridge-house',
  131. 'bridge-garden',
  132. 'bridge-garden',
  133. 'ext-house',
  134. 'ext-house',
  135. 'ext-house',
  136. 'ext-house',
  137. 'riser-1',
  138. 'riser-2',
  139. 'city-garden',
  140. 'city-plaza',
  141. 'dbl-ext-garden',
  142. 'dbl-ext-garden',
  143. 'dbl-ext-garden',
  144. 'dbl-ext-garden',
  145. 'ext-garden',
  146. 'ext-garden',
  147. 'ext-garden',
  148. 'ext-garden',
  149. 'corner-garden',
  150. 'corner-garden',
  151. 'corner-garden',
  152. 'corner-garden',
  153. 'corner-house',
  154. 'corner-house',
  155. 'corner-house',
  156. 'corner-house',
  157. 'freestand-garden',
  158. 'freestand-garden',
  159. 'freestand-garden',
  160. 'freestand-garden'
  161. }
  162.  
  163.  
  164.  
  165. ----------------------------------------------------------------------------------------------------------------
  166. -- the data structure below represents the catalogue of vocabulary as built in minecraft
  167. -- id - is unique for each vocab, starting from 1 going to 40 currently
  168. -- column and row - represent the "physical" location of the vocab model in the catalogue in the minecraft world
  169. -- nameEN and name DE - are names for english and german. for now names must not have spaces, use dashes (-) instead
  170. -- typeEN and typeDE - are the type names, also in english and german such as tech&science spaces
  171. -- height - is how many blocks is this structure tall
  172. -- slots - is how many potential detector stones is this structure occupying as a building, ex. 2 for houses, 3 for corner extenstions, 0 for plazas
  173. -- green - is true or false and is used for easier calculation of the GREENEST GOAL
  174. -- greenSlots - is how many slots are green and is used for easier calculation of the GREENEST GOAL
  175. VOCABS_DATA = {
  176. -- urban houses
  177. {id=1, column=1, row=1,nameEN="SINGLE-FAMILY-HOUSE",nameDE="EINFAMILIENHAUS", typeEN="HOUSES",typeDE="HÄUSER",height=10, slots=2, green=false, greenSlots=0, rewardUrban=false, rewardCount=4},
  178. {id=2, column=1, row=2,nameEN="SINGLE-FAMILY-HOUSE",nameDE="EINFAMILIENHAUS", typeEN="HOUSES",typeDE="HÄUSER",height=10, slots=2, green=false, greenSlots=0, rewardUrban=false, rewardCount=4},
  179. {id=3, column=1, row=3,nameEN="SINGLE-FAMILY-HOUSE",nameDE="EINFAMILIENHAUS", typeEN="HOUSES",typeDE="HÄUSER",height=10, slots=2, green=false, greenSlots=0, rewardUrban=false, rewardCount=4},
  180. {id=4, column=1, row=4,nameEN="SINGLE-FAMILY-HOUSE",nameDE="EINFAMILIENHAUS", typeEN="HOUSES",typeDE="HÄUSER",height=10, slots=2, green=false, greenSlots=0, rewardUrban=false, rewardCount=4},
  181. -- urban businesses
  182. {id=5, column=2, row=1,nameEN="GYM",nameDE="FITNESSSTUDIO", typeEN="BUSINESSES",typeDE="GESCHÄFTE",height=20, slots=5, green=false, greenSlots=0, rewardUrban=false, rewardCount=8},
  183. {id=6, column=2, row=2,nameEN="OFFICE-BUILDING",nameDE="BÜROGEBÄUDE", typeEN="BUSINESSES",typeDE="GESCHÄFTE",height=20, slots=5, green=false, greenSlots=0, rewardUrban=false, rewardCount=8},
  184. {id=7, column=2, row=3,nameEN="HOTEL",nameDE="HOTEL", typeEN="BUSINESSES",typeDE="GESCHÄFTE",height=20, slots=5, green=false, greenSlots=0, rewardUrban=false, rewardCount=8},
  185. {id=8, column=2, row=4 ,nameEN="BANK",nameDE="BANK", typeEN="BUSINESSES",typeDE="GESCHÄFTE",height=20, slots=5, green=false, greenSlots=0, rewardUrban=false, rewardCount=8},
  186. -- urban tech&science spaces
  187. {id=9, column=3, row=1,nameEN="LIBRARY",nameDE="BIBLIOTHEK", typeEN="TECH & SCIENCE SPACES",typeDE="WISSENSCHAFTSGEBÄUDE",height=16, slots=1, green=false, greenSlots=0, rewardUrban=false, rewardCount=10},
  188. {id=10, column=3, row=2,nameEN="FABLAB",nameDE="INNOVATIONSZENTRUM", typeEN="TECH & SCIENCE SPACES",typeDE="WISSENSCHAFTSGEBÄUDE",height=16, slots=1, green=false, greenSlots=0, rewardUrban=false, rewardCount=10},
  189. -- green tech&science spaces
  190. {id=11, column=3, row=3,nameEN="AQUAPONIC-GREENHOUSE",nameDE="AQUAPONIK-GEWÄCHSHAUS", typeEN="TECH & SCIENCE SPACES",typeDE="WISSENSCHAFTSGEBÄUDE",height=16, slots=1, green=true, greenSlots=1, rewardUrban=true, rewardCount=10},
  191. {id=12, column=3, row=4,nameEN="SCIENCE-BRIDGE",nameDE="WISSENSCHAFTSBRÜCKE", typeEN="TECH & SCIENCE SPACES",typeDE="WISSENSCHAFTSGEBÄUDE",height=16, slots=1, green=true, greenSlots=1, rewardUrban=true, rewardCount=10},
  192. -- urban house extensions
  193. {id=13, column=4, row=1,nameEN="HOUSE-EXTENSION",nameDE="HAUSERWEITERUNG", typeEN="EXTENSIONS",typeDE="ERWEITERUNGEN",height=10, slots=1, green=false, greenSlots=0, rewardUrban=false, rewardCount=6},
  194. {id=14, column=4, row=2,nameEN="HOUSE-EXTENSION",nameDE="HAUSERWEITERUNG", typeEN="EXTENSIONS",typeDE="ERWEITERUNGEN",height=10, slots=1, green=false, greenSlots=0, rewardUrban=false, rewardCount=6},
  195. {id=15, column=4, row=3,nameEN="HOUSE-EXTENSION",nameDE="HAUSERWEITERUNG", typeEN="EXTENSIONS",typeDE="ERWEITERUNGEN",height=10, slots=1, green=false, greenSlots=0, rewardUrban=false, rewardCount=6},
  196. {id=16, column=4, row=4,nameEN="HOUSE-EXTENSION",nameDE="HAUSERWEITERUNG", typeEN="EXTENSIONS",typeDE="ERWEITERUNGEN",height=10, slots=1, green=false, greenSlots=0, rewardUrban=false, rewardCount=6},
  197. --risers
  198. {id=17, column=5, row=1,nameEN="DOUBLE-FLOOR-RISER",nameDE="VERSCHIEBUNG-ZWEI-HOCH", typeEN="RISERS",typeDE="VERTIKALE VERSCHIEBUNGEN",height=0, slots=0, green=false, greenSlots=0, rewardUrban=true, rewardCount=8},
  199. {id=18, column=5, row=2,nameEN="SINGLE-FLOOR-RISER",nameDE="VERSCHIEBUNG-EINEN-HOCH", typeEN="RISERS",typeDE="VERTIKALE VERSCHIEBUNGEN",height=0, slots=0, green=false, greenSlots=0, rewardUrban=true, rewardCount=6},
  200. --plazas
  201. {id=19, column=5, row=3,nameEN="CITY-PLAZA",nameDE="STÄDTISCHER PLATZ", typeEN="PLAZAS",typeDE="PLÄTZE",height=0, slots=0, green=false, greenSlots=0, rewardUrban=false, rewardCount=2},
  202. {id=20, column=5, row=4,nameEN="PARK-PLAZA",nameDE="GRÜNER PLATZ", typeEN="PLAZAS",typeDE="PLÄTZE",height=0, slots=0, green=true, greenSlots=1, rewardUrban=true, rewardCount=2},
  203. --green businesses
  204. {id=21, column=6, row=1,nameEN="GREEN-GYM",nameDE="GRÜNES FITNESSSTUDIO", typeEN="BUSINESSES",typeDE="GESCHÄFTE",height=20, slots=5, green=true, greenSlots=5, rewardUrban=true, rewardCount=8},
  205. {id=22, column=6, row=2,nameEN="GREEN-OFFICE-BUILDING",nameDE="GRÜNES BÜROGEBÄUDE", typeEN="BUSINESSES",typeDE="GESCHÄFTE",height=20, slots=5, green=true, greenSlots=5, rewardUrban=true, rewardCount=8},
  206. {id=23, column=6, row=3,nameEN="GREEN-HOTEL",nameDE="GRÜNES HOTEL", typeEN="BUSINESSES",typeDE="GESCHÄFTE",height=20, slots=5, green=true, greenSlots=5, rewardUrban=true, rewardCount=8},
  207. {id=24, column=6, row=4,nameEN="GREEN-BANK",nameDE="GRÜNES BANK", typeEN="BUSINESSES",typeDE="GESCHÄFTE",height=20, slots=5, green=true, greenSlots=5, rewardUrban=true, rewardCount=8},
  208. ---green private garden extensions
  209. {id=25, column=7, row=1,nameEN="HOUSE-GARDEN",nameDE="PRIVATGARTEN", typeEN="EXTENSIONS",typeDE="ERWEITERUNGEN",height=0, slots=0, green=true, greenSlots=1, rewardUrban=true, rewardCount=6},
  210. {id=26, column=7, row=2,nameEN="HOUSE-GARDEN",nameDE="PRIVATGARTEN", typeEN="EXTENSIONS",typeDE="ERWEITERUNGEN",height=0, slots=0, green=true, greenSlots=1, rewardUrban=true, rewardCount=6},
  211. {id=27, column=7, row=3,nameEN="HOUSE-GARDEN",nameDE="PRIVATGARTEN", typeEN="EXTENSIONS",typeDE="ERWEITERUNGEN",height=0, slots=0, green=true, greenSlots=1, rewardUrban=true, rewardCount=6},
  212. {id=28, column=7, row=4,nameEN="HOUSE-GARDEN",nameDE="PRIVATGARTEN", typeEN="EXTENSIONS",typeDE="ERWEITERUNGEN",height=0, slots=0, green=true, greenSlots=1, rewardUrban=true, rewardCount=6},
  213. ---green gathering spaces
  214. {id=29, column=8, row=1,nameEN="OPEN-АIR-CINEMA",nameDE="FREILUFTKINO", typeEN="GATHERING SPACES",typeDE="TREFFPUNKTE",height=8, slots=3, green=true, greenSlots=3, rewardUrban=true, rewardCount=9},
  215. {id=30, column=8, row=2,nameEN="OPEN-AIR-SWIMMING-POOL",nameDE="FREIBAD", typeEN="GATHERING SPACES",typeDE="TREFFPUNKTE",height=8, slots=3, green=true, greenSlots=3, rewardUrban=true, rewardCount=9},
  216. {id=31, column=8, row=3,nameEN="GREEN-CAFE",nameDE="GRÜNES CAFÉ", typeEN="GATHERING SPACES",typeDE="TREFFPUNKTE",height=8, slots=3, green=true, greenSlots=3, rewardUrban=true, rewardCount=9},
  217. {id=32, column=8, row=4,nameEN="PALM-TREE-HOUSE",nameDE="PALMENGARTEN", typeEN="GATHERING SPACES",typeDE="TREFFPUNKTE",height=8, slots=3, green=true, greenSlots=3, rewardUrban=true, rewardCount=9},
  218. ----urban gathering spaces
  219. {id=33, column=9, row=1,nameEN="CINEMA",nameDE="KINO", typeEN="GATHERING SPACES",typeDE="TREFFPUNKTE",height=8, slots=3, green=false, greenSlots=0, rewardUrban=false, rewardCount=9},
  220. {id=34, column=9, row=2,nameEN="CONFERENCE-HALL",nameDE="KONFERENZHALLE", typeEN="GATHERING SPACES",typeDE="TREFFPUNKTE",height=8, slots=3, green=false, greenSlots=0, rewardUrban=false, rewardCount=9},
  221. {id=35, column=9, row=3,nameEN="CAFÉ",nameDE="CAFÉ", typeEN="GATHERING SPACES",typeDE="TREFFPUNKTE",height=8, slots=3, green=false, greenSlots=0, rewardUrban=false, rewardCount=9},
  222. {id=36, column=9, row=4,nameEN="ART-GALLERY",nameDE="KUNSTGALERIE", typeEN="GATHERING SPACES",typeDE="TREFFPUNKTE",height=8, slots=3, green=false, greenSlots=0, rewardUrban=false, rewardCount=9},
  223. ---green-roof houses
  224. {id=37, column=10, row=1,nameEN="GREEN-ROOF-HOUSE",nameDE="GRÜNES EINFAMILIENHAUS", typeEN="HOUSES",typeDE="HÄUSER",height=10, slots=2, green=true, greenSlots=2, rewardUrban=true, rewardCount=4},
  225. {id=38, column=10, row=2,nameEN="GREEN-ROOF-HOUSE",nameDE="GRÜNES EINFAMILIENHAUS", typeEN="HOUSES",typeDE="HÄUSER",height=10, slots=2, green=true, greenSlots=2, rewardUrban=true, rewardCount=4},
  226. {id=39, column=10, row=3,nameEN="GREEN-ROOF-HOUSE",nameDE="GRÜNES EINFAMILIENHAUS", typeEN="HOUSES",typeDE="HÄUSER",height=10, slots=2, green=true, greenSlots=2, rewardUrban=true, rewardCount=4},
  227. {id=40, column=10, row=4,nameEN="GREEN-ROOF-HOUSE",nameDE="GRÜNES EINFAMILIENHAUS", typeEN="HOUSES",typeDE="HÄUSER",height=10, slots=2, green=true, greenSlots=2, rewardUrban=true, rewardCount=4},
  228. }
  229.  
  230.  
  231. DEFAULT_REWARD = houseBlock(4)
  232.  
  233. REWARDS = {}
  234. --[[
  235. --Urban singlehouse rewards (costs 4 house, -2+2 activators)
  236. REWARDS[1] = gardenBlock(4)
  237. REWARDS[2] = gardenBlock(4)
  238. REWARDS[3] = gardenBlock(4)
  239. REWARDS[4] = gardenBlock(4)
  240. --Urban businesses rewards (costs 6 house, -2+1 activators)
  241. REWARDS[5] = gardenBlock(8)
  242. REWARDS[6] = gardenBlock(8)
  243. REWARDS[7] = gardenBlock(8)
  244. REWARDS[8] = gardenBlock(8)
  245. --Urban Tech&Science Spaces bridge rewards (costs 6 house, -3+2 activators)
  246. REWARDS[9] = gardenBlock(10)
  247. REWARDS[10] = gardenBlock(10)
  248. --Green Tech&Science Spaces garden bridge (costs 6 garden, -3+2 activators)
  249. REWARDS[11] = houseBlock(10)
  250. REWARDS[12] = houseBlock(10)
  251. --House extension rewards (costs 4 house, 1 activators)
  252. REWARDS[13] = gardenBlock(6)
  253. REWARDS[14] = gardenBlock(6)
  254. REWARDS[15] = gardenBlock(6)
  255. REWARDS[16] = gardenBlock(6)
  256. --riser 2 (costs 12 house)
  257. REWARDS[17] = houseBlock(6)
  258. --riser 1 (costs 8 house)
  259. REWARDS[18] = houseBlock(4)
  260. --plaza city (costs 4 house, -1 activator)
  261. REWARDS[19] = gardenBlock(2)
  262. --plaza park (costs 4 garden, -1 activator)
  263. REWARDS[20] = houseBlock(2)
  264. --green businesses (costs 6 garden, -2+1 activators)
  265. REWARDS[21] = houseBlock(8)
  266. REWARDS[22] = houseBlock(8)
  267. REWARDS[23] = houseBlock(8)
  268. REWARDS[24] = houseBlock(8)
  269. --extension-private garden rewards (costs 3 garden, -1 activators)
  270. REWARDS[25] = houseBlock(6)
  271. REWARDS[26] = houseBlock(6)
  272. REWARDS[27] = houseBlock(6)
  273. REWARDS[28] = houseBlock(6)
  274. --L-shaped green gathering places (costs 6 garden, -3+3 activators)
  275. REWARDS[29] = houseBlock(9)
  276. REWARDS[30] = houseBlock(9)
  277. REWARDS[31] = houseBlock(9)
  278. REWARDS[32] = houseBlock(9)
  279. --L-shaped urban gathering places (costs 6 house, -3+3 activators)
  280. REWARDS[33] = gardenBlock(9)
  281. REWARDS[34] = gardenBlock(9)
  282. REWARDS[35] = gardenBlock(9)
  283. REWARDS[36] = gardenBlock(9)
  284. --green-roof houses (costs 4 garden, -2+2 activators)
  285. REWARDS[37] = houseBlock(4)
  286. REWARDS[38] = houseBlock(4)
  287. REWARDS[39] = houseBlock(4)
  288. REWARDS[40] = houseBlock(4)
  289. --]]
  290.  
  291. --constructor for player object so that data structure is consistant
  292. function newPlayerData(name,x,y,z)
  293. local p = {
  294. name = name,
  295. x=x,
  296. y=y,
  297. z=z
  298. }
  299. return p
  300. end
  301.  
  302. --return a list of all players in the game world as player objects
  303. local function getAllPos(selector)
  304. local result, message = commands.tp("@a["..selector.."]","~ ~ ~")
  305. local names = {}
  306. if result == true then
  307. for i,result in ipairs(message) do
  308. local wordpattern = "[^, ]+"
  309. local numberpattern = "[%-% ]%d+[%.]%d+"
  310. local words,numbers = {},{}
  311.  
  312. for word in string.gmatch(result, wordpattern) do
  313. table.insert(words,word)
  314. end
  315.  
  316. for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
  317.  
  318. local coords = {
  319. x = math.floor(numbers[1]),
  320. y = math.floor(numbers[2]),
  321. z = math.floor(numbers[3])
  322. }
  323. local name = words[2]
  324. table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
  325. --print("Player Found - getAllPos")
  326. end
  327. end
  328. return names
  329. end
  330.  
  331. --sort table by random
  332. local function shuffleTable( t )
  333. local rand = math.random
  334. assert( t, "shuffleTable() expected a table, got nil" )
  335. local iterations = #t
  336. local j
  337.  
  338. for i = iterations, 2, -1 do
  339. j = rand(i)
  340. t[i], t[j] = t[j], t[i]
  341. end
  342. end
  343.  
  344. --returns a list of player objects containing all players who are standing on the given block, and who also are in the given selection
  345. local function getAllOnBlockType(block,selector)
  346. local result, message = commands.exec("execute @a["..selector.."] ~ ~ ~ detect ~ ~-1 ~ "..block.." -1 tp @p[r=1] ~ ~ ~")
  347. local names = {}
  348. if result == true then
  349. for i,result in ipairs(message) do
  350. local wordpattern = "[^, ]+"
  351. local numberpattern = "[%-% ]%d+[%.]%d+"
  352. local words,numbers = {},{}
  353.  
  354. for word in string.gmatch(result, wordpattern) do table.insert(words,word) end
  355. for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
  356.  
  357. if numbers[1] and numbers[2] and numbers[3] then
  358. local coords = {
  359. x = math.floor(numbers[1]),
  360. y = math.floor(numbers[2]),
  361. z = math.floor(numbers[3])
  362. }
  363. local name = words[2]
  364. table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
  365. print("Found a player - getOnBlock")
  366. else
  367. print("Error: Coordinate Numbers were missing")
  368. end
  369. end
  370. end
  371. return names
  372. end
  373.  
  374. --gives a player a squid egg with their name on it. Removes all spawn eggs first
  375. local function giveSquid(name)
  376. commands.clear(name,'spawn_egg')
  377. 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]}}')
  378. end
  379.  
  380. --returns a list of squid objects and their names
  381. local function getSquids()
  382. local result, message = commands.exec("execute @e[type=Squid] ~ ~ ~ tp @e[r=1] ~ ~ ~")
  383. local names = {}
  384. if result == true then
  385. for i,result in ipairs(message) do
  386. local wordpattern = "[^, ]+"
  387. local numberpattern = "[%-% ]%d+[%.]%d+"
  388. local words,numbers = {},{}
  389.  
  390. for word in string.gmatch(result, wordpattern) do table.insert(words,word) print(word) end
  391. for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
  392.  
  393. if numbers[1] and numbers[2] and numbers[3] then
  394. local coords = {
  395. x = math.floor(numbers[1]),
  396. y = math.floor(numbers[2]),
  397. z = math.floor(numbers[3])
  398. }
  399. local name = words[4]
  400. table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
  401. print("Found a player - getOnBlock "..name)
  402. else
  403. print("Error: Coordinate Numbers were missing")
  404. end
  405. end
  406. end
  407. return names
  408. end
  409.  
  410. local function removePlayerFromKew(game,playername)
  411. for _,kew in pairs(game.queues) do
  412. for index, player in ipairs(kew.playerlist) do
  413. if player.name == playername then
  414. table.remove(kew.playerlist,index)
  415. end
  416. end
  417. if #kew.playerlist == 0 and kew.phase == 2 then
  418. --game can be ended as no players are left
  419. kew.timer = 0
  420. end
  421. end
  422. end
  423.  
  424. local function movePlayerToSpawn(playername)
  425. respawnPlayer(playername)
  426. commands.async.tp(playername,SPAWN.x,SPAWN.y,SPAWN.z,SPAWN.a1,SPAWN.a2)
  427. commands.async.tellraw(playername,'["",{"text":"TELEPORTED: You used your Heimkehrer","color":"blue"}]')
  428. commands.async.tellraw(playername,'["",{"text":"DE: TELEPORTED: You used your Heimkehrer","color":"gold"}]')
  429. end
  430.  
  431. --takes a list of squids and deals with all those players, moving them back to spawn and removing them from game
  432. --also gives them a new squid
  433. local function dealWithSquidders(game,squids)
  434. for _,squid in pairs(squids) do
  435. --remove player from current game if in game
  436. removePlayerFromKew(game,squid.name)
  437. --teleport them back to spawn
  438. movePlayerToSpawn(squid.name)
  439. --give a new squid
  440. giveSquid(squid.name)
  441. --particle effects
  442. --teleport message
  443. end
  444. --kill all squids
  445. if #squids>0 then
  446. commands.tp("@e[type=Squid]",100000,200,100000)
  447. commands.kill("@e[type=Squid]")
  448. os.sleep(#squids*0.2)
  449. end
  450. end
  451.  
  452.  
  453.  
  454.  
  455. --creates a villager with special items
  456. local function spawnVillager(x,y,z)
  457. 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"]}}} ]}}')
  458. end
  459.  
  460. --displays a subtitle of time to a selection of players
  461. local function displayTime(selector,minutes,seconds)
  462. --commands.title("@a["..selector.."]","subtitle",'{text:"Time left: '..minutes..":"..seconds..'",color:red,bold:false,underlined:false,italic:false,strikethrough:false,obfuscated:false}')
  463. commands.async.xp("-1000000L","@a["..selector.."]")
  464. local secondstot = (minutes * 60) + seconds
  465. commands.async.xp(tostring(secondstot).."L","@a["..selector.."]")
  466. end
  467.  
  468. --displays a title to a selection of players
  469. local function displayTitle(selector,text)
  470. commands.async.title("@a["..selector.."]","title",'{text:"'..text..'"}')
  471. end
  472.  
  473. --simply runs displayTitle on a list of players
  474. local function displayTitleToGroup(playerlist,text)
  475. for i,player in ipairs(playerlist) do
  476. displayTitle("name="..player.name,text)
  477. end
  478. end
  479.  
  480. --simply runs displayTime on a list of players
  481. local function displayTimeToGroup(playerlist,minutes,seconds)
  482. for i,player in ipairs(playerlist) do
  483. displayTime("name="..player.name,minutes,seconds)
  484. end
  485. end
  486.  
  487. --teleports a list of players to an exact place and sends them a message about it
  488. local function teleportToPoint(x,y,z,playerlist,clear,textEN, textDE)
  489. for i,player in ipairs(playerlist) do
  490. player.x = x
  491. player.y = y
  492. player.z = z
  493. commands.async.gamemode(2,player.name)
  494. if clear then
  495. commands.async.clear(player.name,"wool")
  496. commands.async.clear(player.name,"stone_pickaxe")
  497. end
  498. commands.tp("@a[name="..player.name.."]",x,y,z)
  499. commands.async.tellraw(player.name,'["",{"text":"'..textEN..'","color":"blue"}]')
  500. commands.async.tellraw(player.name,'["",{"text":"'..textDE..'","color":"gold"}]')
  501. end
  502. end
  503.  
  504. --teleports a list of players to a given buildzone
  505. local function teleportToZone(buildzone,playerlist,textEN, textDE)
  506. teleportToPoint(buildzone.x+2+(buildzone.w/2),buildzone.y+5,buildzone.z+2+(buildzone.w/2),playerlist,true,textEN, textDE)
  507.  
  508. end
  509.  
  510. --gives the same list of items to a list of players
  511. local function giveItems(playerlist,itemlist)
  512. local given = 0
  513. for i,player in ipairs(playerlist) do
  514. --commands.async.clear(player.name)
  515. for j,item in ipairs(itemlist) do
  516. commands.async.give("@a[name="..player.name.."]",item)
  517. given = given +1
  518. end
  519. giveSquid(player.name)
  520. end
  521. return given
  522. end
  523.  
  524. --a multi builder which uses the vocab constructor to create sets of vocab
  525. local function makeVocabZones(quant,w)
  526. local x,y,z = ox,oy,oz+6
  527. local result = {}
  528. local id = 1
  529. for i=0,quant-1 do
  530. for k=0,3 do
  531. local zpos = i-4
  532. local ypos = k
  533. --print("vocab at X")
  534. --print(x-(2*w)-6)
  535. --print("and Z")
  536. --print(z+((w+1)*zpos))
  537. local nextVocab = newVocabZone(
  538. x-(2*w)-6,y+(ypos*(VOCAB_HEIGHT+3)),
  539. z+((w+1)*zpos),
  540. w,
  541. id,
  542. REWARDS[id] or DEFAULT_REWARD,
  543. VOCABS_DATA[id].nameEN or DEFAULT_NAME,
  544. VOCABS_DATA[id].nameDE or DEFAULT_NAME,
  545. VOCABS_DATA[id].typeEN,
  546. VOCABS_DATA[id].typeDE,
  547. VOCABS_DATA[id].height,
  548. VOCABS_DATA[id].slots,
  549. VOCABS_DATA[id].green,
  550. VOCABS_DATA[id].greenSlots,
  551. VOCABS_DATA[id].rewardUrban,
  552. VOCABS_DATA[id].rewardCount
  553. )
  554. table.insert(result,nextVocab)
  555. id = id +1
  556. end
  557. end
  558. return result
  559. end
  560.  
  561. --finds the next free location(or buildzone) for a new game in a given area.
  562. --giving force as True will mean it overrides the first location no matter what
  563. local function findNextLoc(width,zones,force)
  564. local x,y,z = 0,0,0
  565. for i,loc in ipairs(LOCS) do
  566. x,y,z = FIRSTZONE.x+(loc.x*(width+1)),FIRSTZONE.y,FIRSTZONE.z+(-loc.z*(width+1))
  567. --print("testing for available zone at: "..x..", "..y..", "..z)
  568. local result,message = commands.testforblock(x,y+BUILDZONE_FLOOR_HEIGHT,z,"minecraft:air")
  569. --print("testing done")
  570. if force then result = true end
  571. local zonefree = true
  572. for i,zone in ipairs(zones) do
  573. if zone.x == x and zone.z == z then
  574. zonefree = false
  575. end
  576. end
  577. --print("next position free is ",loc.x*width,oy,loc.z*width)
  578. --if result then print("true") else print("false") end
  579. if result and zonefree then
  580. --print("using loc: ",loc.x,loc.z)
  581. return x,y,z
  582. end
  583. end
  584. return nil,nil,nil
  585.  
  586. end
  587.  
  588. --relocates a buildzone to a new coordinate safely
  589. --avoids overlapping with other buildzones
  590. function moveBuildzone(buildzone,zones)
  591. local x,y,z = findNextLoc(buildzone.w,zones)
  592. if x and y and z then
  593. print("moved buildzone from "..buildzone.x..","..buildzone.z.." to "..x..","..y)
  594. local w = buildzone.w
  595. buildzone.x,buildzone.y,buildzone.z = x,y+BUILDZONE_FLOOR_HEIGHT,z
  596. buildzone.selector = "x="..x..",y="..tostring(y-1)..",z="..z..",dx="..w..",dy=256,dz="..w
  597. buildzone.structures = {} --a list of all vocabularies which have been contructed
  598. else
  599. print("buildzone at "..buildzone.x..","..buildzone.z.." stayed where it is")
  600. end
  601. end
  602.  
  603. --multi builder to create sets of buildzones using the buildzone constructor
  604. local function makeBuildzones(quant,vocab,width,height)
  605. local result = {}
  606. for i=1,quant do
  607. --print("locating available slot")
  608. local x,y,z = findNextLoc(width,result)
  609. if x and y and z then
  610. --print("made new buildzone at",x,y,z)
  611. table.insert(result,newBuildZone(x,y+height,z,width,vocab))
  612. else
  613. --print("failed to make new buildzone")
  614. end
  615. end
  616.  
  617. local remaining = NUMBER_OF_BUILDZONES - #result
  618. --print("doing this remaining thing")
  619. for i=1, remaining do
  620. local x,y,z = findNextLoc(width,result,true)
  621. if x and y and z then
  622. --print("forced new buildzone at",x,y,z)
  623. table.insert(result,newBuildZone(x,y+height,z,width,vocab))
  624. else
  625. print("failed to force new buildzone")
  626. end
  627. end
  628.  
  629.  
  630. return result
  631. end
  632.  
  633. --vocab constructor. Enforces some data structure
  634. function newVocabZone(x,y,z,w,id, reward,nameEN, nameDE, typeEN, typeDE, height, slots,green,greenSlots, rewardUrban, rewardCount)
  635. local nvz = {}
  636. nvz.x ,nvz.y ,nvz.z ,nvz.w = x,y,z,w
  637.  
  638. nvz.cx = nvz.x - nvz.w - 2
  639. nvz.cy = nvz.y
  640. nvz.cz = nvz.z
  641. nvz.nameEN = nameEN
  642. nvz.reward = reward
  643. --- new stuff
  644. nvz.id = id
  645. nvz.nameDE = nameDE
  646. nvz.typeEN = typeEN
  647. nvz.typeDE = typeDE
  648. nvz.height = height
  649. nvz.slots = slots or 0
  650. nvz.green = green
  651. nvz.greenSlots = greenSlots
  652. nvz.rewardUrban = rewardUrban
  653. nvz.rewardCount = rewardCount
  654.  
  655. return nvz
  656.  
  657. end
  658.  
  659. --buildzone constructor. Enforces some data structure
  660. function newBuildZone(x,y,z,w,vocabZones)
  661. local nbz = {}
  662. nbz.x ,nbz.y ,nbz.z ,nbz.w = x,y,z,w
  663. nbz.selector = "x="..x..",y="..(y-5)..",z="..z..",dx="..w..",dy=256,dz="..w
  664. nbz.structures = {} --a list of all vocabularies names which have been contructed
  665. nbz.buildings = {} --a list of all vocabularies with full data (x,y,z,id,name) which have been contructed
  666. nbz.filledSlots = 0 --to count how many slots have been filled with buildings. the matrix is 7x7x20 slots. one slot is 9x9x9 blocks big
  667. nbz.greenSlots = 0 --to count how many of the slots are green. the matrix is 7x7x20 slots. one slot is 9x9x9 blocks big
  668. nbz.variety = {} -- this stores how many buildings of each type are there. it is indexed on vocab.id and the value is the number of buildings from type vocab.id
  669. nbz.waitingForCheck = {}
  670. nbz.highest = 0
  671. nbz.vocab = vocabZones
  672.  
  673. return nbz
  674. end
  675.  
  676. --kew constructor. Enforces some data structure
  677. function newQueue(buildzone,maxplayers)
  678. local q = {}
  679. q.timer = 1
  680. q.phase = 1
  681.  
  682. q.victory = false
  683. q.phases = {
  684. {
  685. name = "Selecting Players",
  686. length = 25,
  687. displaylength = 15
  688. },
  689. {
  690. name = "Game In Progress",
  691. length = GAME_LENGTH,
  692. displaylength = 70
  693. },
  694. {
  695. name = "Round Complete",
  696. length = 35,
  697. displaylength = 5
  698. }
  699. }
  700. q.playerlist = {}
  701. q.maxplayers = maxplayers
  702. q.buildzone = buildzone
  703.  
  704. return q
  705. end
  706.  
  707.  
  708. --creates a ring of blocks using coordinates
  709. function fillRing(x,y,z,w,block)
  710. commands.fill(x,y,z,x+w,y,z,block)
  711. commands.fill(x+w,y,z,x+w,y,z+w,block)
  712. commands.fill(x,y,z+w,x+w,y,z+w,block)
  713. commands.fill(x,y,z+w,x,y,z,block)
  714. end
  715.  
  716. function setup()
  717. print("debug: starting setup function.")
  718. local game = {}
  719. game.vocab = {}
  720. game.builds = {}
  721. game.queues = {}
  722. game.waitlist = {}
  723. game.spawn = SPAWN
  724. game.lastClock = os.clock()
  725. game.nowTime = os.clock()
  726.  
  727. --generate vocab rewards
  728. for i=1,40 do
  729. if VOCABS_DATA[i].rewardUrban then
  730. REWARDS[i] = houseBlock(VOCABS_DATA[i].rewardCount)
  731. else
  732. REWARDS[i] = gardenBlock(VOCABS_DATA[i].rewardCount)
  733. end
  734. end
  735.  
  736. --kill all villagers
  737. commands.exec("kill @e[type=Villager]")
  738.  
  739. --buildzone and vocabzone creation
  740. print("debug-setup: making vocab zones.")
  741. game.vocab = makeVocabZones(NUMBER_OF_VOCAB,VOCAB_WIDTH)
  742. print("debug-setup: making building zones.")
  743. game.builds = makeBuildzones(NUMBER_OF_BUILDZONES,game.vocab,BUILDZONE_WIDTH,BUILDZONE_FLOOR_HEIGHT)
  744.  
  745. for i,build in ipairs(game.builds) do
  746. table.insert(game.queues,newQueue(build,4))
  747. end
  748. print("debug-setup: testing for properly setup vocabs.")
  749. for i,vz in ipairs(game.vocab) do
  750. local x,y,z,w = vz.x,vz.y,vz.z,vz.w
  751. local cx,cy,cz = vz.cx,vz.cy,vz.cz
  752.  
  753. local detector, message1 = commands.testforblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT.block)
  754. local blocker, message2 = commands.testforblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD.block)
  755. if not (detector or blocker) then
  756. for nx=0,2 do
  757. for nz=0,2 do
  758. commands.setblock(x+(nx*9)+4,y-1,z+(nz*9)+4,BLOCKS.VOCAB_REPLACE.block)
  759. commands.setblock(cx+(nx*9)+4,cy-1,cz+(nz*9)+4,BLOCKS.VOCAB_DETECT.block)
  760. end
  761. end
  762. commands.setblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD.block)
  763.  
  764. end
  765.  
  766. end
  767.  
  768. print("debug-setup: adding scoreboards.")
  769. for i, name in ipairs(VOCAB_NAMES) do
  770. commands.scoreboard("objectives","add",name,"dummy")
  771. end
  772.  
  773. commands.gamerule("doDaylightCycle",false)
  774. commands.gamerule("keepInventory",true)
  775. commands.gamerule("doTileDrops",false)
  776. commands.gamerule("logAdminCommands",false)
  777. commands.gamerule("commandBlockOutput",false)
  778. commands.time("set",6000)
  779. commands.scoreboard("objectives","add","highscores","dummy","Best Neighbourhoods")
  780. commands.scoreboard("objectives","add","VillagerLife","dummy")
  781. commands.scoreboard("objectives","add","built","dummy", "Structures Built")
  782. commands.scoreboard("objectives","add","highest","dummy", "Personal Highest")
  783. commands.scoreboard("objectives","add","played","dummy","Games Played")
  784.  
  785. commands.title("@a","times",0,30,30) -- what does this do?
  786.  
  787. math.randomseed( os.time() )
  788. commands.scoreboard("objectives","setdisplay","sidebar","highscores")
  789. commands.scoreboard("objectives","setdisplay","list","played")
  790.  
  791. print("time is: "..os.time())
  792. print( "time is: "..textutils.formatTime( os.time(), false ) )
  793. print("day is: "..os.day())
  794. print("computer clock is: "..os.clock())
  795.  
  796. if DEBUG_MODE then
  797. for i,build in ipairs(game.builds) do
  798. build.phase = 2
  799. build.timer = 500
  800. end
  801. end
  802.  
  803. print("Computer Co-ordinates ",ox,oy,oz)
  804. print("20.000 Blocks Active!")
  805.  
  806. return game
  807. end
  808.  
  809. function checkForSquids(game)
  810. --execute on all squids
  811. local squidders = getSquids()
  812. dealWithSquidders(game,squidders)
  813. end
  814.  
  815. --main game loop
  816. --runs the game object through each of these update steps in order
  817. function update(game)
  818. local elapsed = updateClock(game)
  819. --update players
  820. checkPlayers(game)
  821. doTimerUpdates(game,elapsed)
  822. doPhaseUpdates(game)
  823. doPhaseEnds(game)
  824. checkBoundaries(game)
  825. checkForSquids(game)
  826. if #game.waitlist > 0 then allocateWaiters(game) end
  827. end
  828.  
  829. --calculates elapsed time during a game tick
  830. function updateClock(game)
  831. game.nowTime = os.clock()
  832. local elapsed = game.nowTime - game.lastClock
  833. game.lastClock = game.nowTime
  834. return elapsed
  835. end
  836.  
  837. --updates all kews in the game object based on elapsed time
  838. function doTimerUpdates(game,elapsed)
  839. for i,kew in ipairs(game.queues) do
  840. kew.timer = kew.timer - elapsed
  841. end
  842. end
  843.  
  844. --check players are inside their buildzone and move them back if not
  845. function checkBoundaries(game)
  846. for i,kew in ipairs(game.queues) do
  847. if kew.phase ==2 then
  848. --boundaries
  849. local x_min = kew.buildzone.x
  850. local x_max = kew.buildzone.x+kew.buildzone.w
  851. local z_min = kew.buildzone.z
  852. local z_max = kew.buildzone.z+kew.buildzone.w
  853.  
  854. local toBeCorrected = {}
  855.  
  856. for j,player in ipairs(kew.playerlist) do
  857. local listOfOne = getAllPos('m=2,name='..player.name)
  858. if listOfOne and listOfOne[1] then
  859. player.x = listOfOne[1].x
  860. player.y = listOfOne[1].y
  861. player.z = listOfOne[1].z
  862. local changed = false
  863. if player.x > x_max then
  864. changed = true
  865. player.x = x_max-2
  866. end
  867. if player.x < x_min then
  868. changed = true
  869. player.x = x_min+2
  870. end
  871. if player.z > z_max then
  872. changed = true
  873. player.z = z_max-2
  874. end
  875. if player.z < z_min then
  876. changed = true
  877. player.z = z_min+2
  878. end
  879. 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
  880. end
  881. end
  882. end
  883. end
  884. end
  885.  
  886.  
  887. --here you can set the logic which determines if a buildzone was valuable.
  888. --Return true if it is crap and should be replaced
  889. function checkIfBuildzoneIsCrap(buildzone)
  890. if #buildzone.structures < 5 then
  891. print("Buildzone was crap")
  892. return true
  893. end
  894. print("Buildzone was ok")
  895. return false
  896. end
  897.  
  898.  
  899. --Everything that happens after a buildzone was completed
  900. --due to time limit.
  901. function cleanAfterVictory(buildzone)
  902. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,BLOCKS.VICTORY_MARKER.block)
  903. fillRing(buildzone.x,buildzone.y,buildzone.z,buildzone.w,"minecraft:air",0,"replace",BLOCKS.CONSTRUCTION.block,BLOCKS.CONSTRUCTION.data)
  904. for h=0,256-buildzone.y do
  905. 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)
  906. 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)
  907. 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)
  908. 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)
  909. end
  910. 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)
  911. 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")
  912.  
  913. local wasCrap = checkIfBuildzoneIsCrap(buildzone)
  914. if wasCrap then
  915. --mark this buildzone for replacement
  916. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,"minecraft:air")
  917. end
  918. end
  919.  
  920. --these happen every tick and require the game object
  921. --updates are performed on each Queue (kew) and within each
  922. --of those on each buildzone.
  923. function doPhaseUpdates(game)
  924. for i,kew in ipairs(game.queues) do
  925.  
  926. local minutes = string.format("%02d",math.floor(kew.timer/60))
  927. local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
  928. if kew.timer <= 0 then
  929. minutes = "00"
  930. seconds = "00"
  931. end
  932.  
  933. if kew.phase == 1 then
  934. --waiting phase
  935. if #kew.playerlist == kew.maxplayers and kew.timer > 5 then kew.timer = 5 end
  936. if not DEBUG_MODE and #kew.playerlist == 0 then kew.timer = kew.phases[1].length end
  937.  
  938. displayTitleToGroup(kew.playerlist,"Game starting!")
  939. displayTimeToGroup(kew.playerlist,minutes,seconds)
  940. --show countdown
  941. elseif kew.phase == 2 then
  942. --playing phase
  943. if #kew.playerlist == 0 then timer = 0 end -- finish if all players quit
  944. -- do vocab logic
  945. local victory = updatePlayedZone(kew.buildzone) --currently victory updatePlayedZone returns always false
  946. --
  947. displayTimeToGroup(kew.playerlist,minutes,seconds)
  948.  
  949. elseif kew.phase == 3 then
  950. --end phase
  951. displayTitleToGroup(kew.playerlist,"Use Heimkehrer to return")
  952. displayTimeToGroup(kew.playerlist,minutes,seconds)
  953.  
  954.  
  955. end
  956. end
  957. end
  958.  
  959. --this runs after a buildzone is completed
  960. --it should tally structure types and set scoreboard highscores
  961. --it also rewards all participants with more played score
  962. function processHighscores(kew)
  963. local buildzone = kew.buildzone
  964.  
  965.  
  966.  
  967. --add score to players who finished this game
  968. for _,player in ipairs(kew.playerlist) do
  969. commands.async.scoreboard("players","add",player.name,"played",1)
  970. end
  971. end
  972.  
  973. --function to export a buildzone detail once it is complete
  974. --requires a kew so it can access the playerlist
  975. local function exportKewData(kew)
  976. local buildzone = kew.buildzone
  977. local saved = {}
  978. saved.position =
  979. {
  980. x=buildzone.x,
  981. y=buildzone.y,
  982. z=buildzone.z
  983. }
  984. local timestamp = math.floor(os.clock())
  985. --saved.timeCompleted = timestamp
  986. saved.players = {}
  987. for _, player in ipairs(kew.playerlist) do
  988. table.insert(saved.players,player.name)
  989. end
  990. --saved.structures = buildzone.structures
  991. saved.buildings = buildzone.buildings
  992. saved.totals = tracker.tallyTable(buildzone.structures)
  993. --saved.highest = buildzone.highest
  994. saved.stats = {
  995. cityVersion = CITY_VERSION,
  996. height = buildzone.highest,
  997. densityIndex = math.floor(100*buildzone.filledSlots/49), -- the density index is made from built area (filledSlots) over the ground area (7x7 slots = 49)
  998. greenIndex = math.floor(100*buildzone.greenSlots/49), --the green index is made from green area (greenSlots) over the ground area (7x7 slots = 49)
  999. variety = tablelength(buildzone.variety),
  1000. timeCompleted = timestamp,
  1001. gameLength = GAME_LENGTH
  1002. }
  1003.  
  1004. fs.makeDir("/records")
  1005.  
  1006. local file = fs.open("/records/"..timestamp.."at"..buildzone.x.."_"..buildzone.z..".yaml","w")
  1007. file.write(json.encodePretty(saved))
  1008. file.close()
  1009. end
  1010.  
  1011. --this code runs ONCE at the end of each phase
  1012. --what actually happens is specific to which phase the
  1013. --particular kew is in.
  1014. function doPhaseEnds(game)
  1015. for i,kew in ipairs(game.queues) do
  1016. if kew.timer <= 0 then
  1017. if kew.phase == 1 then
  1018. --waiting phase ends goto play phase
  1019.  
  1020. moveBuildzone(kew.buildzone,game.builds)
  1021. teleportToZone(kew.buildzone,kew.playerlist,"TELEPORTED: Your game has started.", "DE: TELEPORTED: Your game has started.")--teleport selected players
  1022. cleanBuildzone(kew.buildzone)
  1023. prepareBuildzone(kew.buildzone)--prepare build zone
  1024. giveItems(kew.playerlist,STARTING_ITEMS) --give starting items
  1025. displayTitle(kew.buildzone.selector,"Build!")
  1026. kew.victory = false
  1027. displayTime(kew.buildzone.selector,0,0)
  1028. kew.phase = 2
  1029. kew.timer = kew.phases[2].length
  1030. elseif kew.phase == 2 then
  1031. --playing phase ends goto end phase
  1032. processHighscores(kew)
  1033. exportKewData(kew)
  1034. cleanAfterVictory(kew.buildzone)
  1035. kew.phase = 3
  1036. displayTime(kew.buildzone.selector,0,0)
  1037. kew.timer = kew.phases[3].length
  1038. elseif kew.phase == 3 then
  1039. --end phase ends goto waiting phase
  1040. removePlayersFromKew(game,kew)
  1041. kew.phase = 1
  1042. displayTime(kew.buildzone.selector,0,0)
  1043. kew.timer = kew.phases[1].length
  1044. end
  1045. end
  1046. end
  1047. end
  1048.  
  1049.  
  1050. --Replaces everything that is needed to start the game. Does not rebuild the floor, or clear anything away.
  1051. --based on the settings it creates a full grid, or a partial grid, or no grid
  1052. --it also places the ring, although this is disabled for now
  1053. function prepareBuildzone(buildzone)
  1054. local bz = buildzone
  1055. local x,y,z,w = bz.x,bz.y,bz.z,bz.w
  1056. --commands.fill(x,y-1,z,x+w,y-1,z+w,BLOCKS.CAMP_FLOOR)
  1057. fillRing(buildzone.x,buildzone.y,buildzone.z,buildzone.w,BLOCKS.CONSTRUCTION.block)
  1058. if DO_GRID then
  1059. for x=0,6 do
  1060. for z=0,6 do
  1061. local rand = math.random()*100
  1062. --local result, text = commands.testforblock(bz.x+(x*9)+4,bz.y-1,bz.z+(z*9)+4,BLOCKS.CAMP_FLOOR.block)
  1063. if rand > GRID_HOLE_CHANCE then --and result then
  1064. commands.async.setblock(bz.x+(x*9)+4,bz.y,bz.z+(z*9)+4,BLOCKS.DETECT.block,BLOCKS.DETECT.data,"replace","minecraft:air")
  1065. 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)
  1066. 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)
  1067. --commands.async.setblock(bz.x+(x*9)+4,bz.y-1,bz.z+(z*9)+4,BLOCKS.CAMP_FLOOR.block)
  1068. end
  1069. end
  1070. end
  1071. end
  1072. commands.async.setblock(buildzone.x,buildzone.y,buildzone.z,BLOCKS.CONSTRUCTION.block)
  1073. end
  1074.  
  1075. --deletes everything inside the buildzone
  1076. function cleanBuildzone(buildzone)
  1077. print("Cleaning buildzone")
  1078. for h=0,VICTORY_HEIGHT+20 do
  1079. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air")
  1080. end
  1081. end
  1082.  
  1083. --moves all players assigned to the queue into the waiting area for the provided game.
  1084. --It also changes them to Adventure mode and clears their inventory
  1085. function respawnPlayers(game,kew)
  1086. 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
  1087. for i,player in ipairs(kew.playerlist) do
  1088. --table.insert(game.waitlist,player)
  1089. respawnPlayer(player,"")
  1090. end
  1091. kew.playerlist = {}
  1092. end
  1093.  
  1094. function removePlayersFromKew(game,kew)
  1095. for _, player in ipairs(kew.playerlist) do
  1096. commands.tell(player.name,"Your game is over. Use your Heimkehrer to return to spawn")
  1097. end
  1098. kew.playerlist = {}
  1099. end
  1100.  
  1101. function respawnPlayer(playername,message)
  1102. commands.tell(playername,message)
  1103. commands.async.gamemode(2,playername)
  1104. commands.async.clear(playername,"minecraft:wool")
  1105. commands.async.clear(playername,"minecraft:stone_pickaxe")
  1106. end
  1107.  
  1108. function checkForPlayerInBuildzone(player,buildzone)
  1109. local result,message = commands.testfor('@a[name='..player.name..','..buildzone.selector..']')
  1110. return result
  1111. end
  1112.  
  1113. function checkForPlayerInWaitzone(player)
  1114. local selector = "x="..WAITZONE.x..",y="..WAITZONE.y..",z="..WAITZONE.z..",dx="..WAITZONE.w..",dy=256,dz="..WAITZONE.l
  1115. local result,message = commands.testfor('@a[name='..player.name..','..selector..']')
  1116. return result
  1117. end
  1118.  
  1119. function checkPlayers(game)
  1120. local selector = "x="..WAITZONE.x..",y="..WAITZONE.y..",z="..WAITZONE.z..",dx="..WAITZONE.w..",dy=256,dz="..WAITZONE.l
  1121. local loggedIn = getAllPos('m=2,'..selector)
  1122. --refresh waitlist
  1123. game.waitlist = loggedIn
  1124. --check currently playing players
  1125. for l,kew in ipairs(game.queues) do
  1126. for i,builder in ipairs(kew.playerlist) do
  1127. local isPlaying = checkForPlayerInBuildzone(builder,kew.buildzone)
  1128. --remove players who are already in kews from the waitlist
  1129. for j, player in ipairs(loggedIn) do
  1130. if player.name == builder.name then
  1131. table.remove(loggedIn,j)
  1132. end
  1133. end
  1134. --if the game is in progress and the player is not found then remove them from the gamekew
  1135. if not isPlaying and kew.phase == 2 then
  1136. --table.remove(kew.playerlist,i)
  1137. --print("Removed "..builder.name.." from game in progress")
  1138. end
  1139. end
  1140. end
  1141. end
  1142.  
  1143. --adds players who wait in the orange room to slots in waiting buildzones
  1144. function allocateWaiters(game)
  1145. --find free slots
  1146. local freeslots = {}
  1147. for i, kew in ipairs(game.queues) do
  1148. if kew.phase == 1 and #kew.playerlist < kew.maxplayers then
  1149. local slots = kew.maxplayers - #kew.playerlist
  1150. for j=1,slots do
  1151. table.insert(freeslots,kew)
  1152. end
  1153. end
  1154. end
  1155.  
  1156. --RE-ENABLE SECOND SHUFFLETABLE IF YOU WANT RANDOM PLAYER MATCHUPS
  1157. shuffleTable(game.waitlist)
  1158. --shuffleTable(freeslots)
  1159.  
  1160. while #freeslots > 0 and #game.waitlist > 0 do
  1161. local player = table.remove(game.waitlist,1)
  1162. local freeslot = table.remove(freeslots,1).playerlist
  1163. table.insert(freeslot,player)
  1164. end
  1165. end
  1166.  
  1167. --PARTICLE FUNCTIONS
  1168. --particles shown to player while their shape is being checked for match
  1169. function searchParticle(x,y,z)
  1170. commands.async.particle("fireworksSpark",x,y,z,0.01,3,0.01,0.01,100)
  1171. end
  1172. -- particles shown to player on successful vocab match
  1173. function successParticle(x,y,z)
  1174. commands.async.particle("happyVillager",x,y,z,2,2,2,1,1000)
  1175. commands.async.playsound("random.levelup","@a",x,y,z,1,1.2)
  1176. end
  1177. --- particles shown to player on failed vocab match
  1178. function failParticle(x,y,z)
  1179. commands.async.particle("reddust",x,y,z,0.1,0.1,1.5,1,200)
  1180. commands.async.particle("reddust",x,y,z,1.5,0.1,0.1,1,200)
  1181. commands.async.playsound("random.bowhit","@a",x,y,z,1,0.8)
  1182. end
  1183.  
  1184. --makes sure that incoming check requests dont exist already
  1185. function addToChecklist(player,buildzone)
  1186. for _, detector in ipairs(buildzone.waitingForCheck) do
  1187. if detector.x == player.x and detector.y == player.y and detector.z == player.z then
  1188. return false
  1189. end
  1190. end
  1191. table.insert(buildzone.waitingForCheck,player)
  1192. return true
  1193. end
  1194.  
  1195. --removes all barrier blocks from a buildzone which are used to carve space in vocabs
  1196. function cleanBarriers(buildzone)
  1197. for h=0,200 do
  1198. 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")
  1199. end
  1200. end
  1201.  
  1202. --The main chunk of code which deals with stepping on detector blocks and reading the vocab
  1203. function updatePlayedZone(buildzone)
  1204. local victory = false
  1205. local buildzoneSelector = buildzone.selector
  1206. --get all players on diamond, add them to the list of things to check
  1207. local detectLocations = getAllOnBlockType(BLOCKS.DETECT.block,buildzoneSelector)
  1208. for _, player in ipairs(detectLocations) do
  1209. addToChecklist(player,buildzone)
  1210. end
  1211.  
  1212. --DEAL WITH THE DETECTOR AT THE TOP OF THE LIST IF THERE IS ONE
  1213. if #buildzone.waitingForCheck > 0 then
  1214. --DO PARTICLE EFFECTS IF A DETECTING BLOCK THAT IS DETECTING
  1215. for i,loc in ipairs(buildzone.waitingForCheck) do
  1216. searchParticle(loc.x,loc.y+1,loc.z)
  1217. end
  1218. local totalResult = false
  1219. local checked = table.remove(buildzone.waitingForCheck,1)
  1220. local x,y,z,name = checked.x,checked.y,checked.z,checked.name
  1221. for i,vocab in pairs(buildzone.vocab) do
  1222. 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")
  1223. if result then
  1224. --clone in the correct vocab
  1225. 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")
  1226. if DEBUG_MODE then
  1227. print(clonemes[1])
  1228. end
  1229. commands.async.give(name,vocab.reward)
  1230. -- announce vocab success in English
  1231. local rewardType = 'green'
  1232. if vocab.rewardUrban then
  1233. rewardType = 'urban'
  1234. end
  1235. print(vocab.typeEN)
  1236. print(vocab.nameEN)
  1237. print(vocab.height)
  1238. print(vocab.slots)
  1239. print(vocab.greenSlots)
  1240. print(vocab.rewardCount)
  1241. print(rewardType)
  1242. commands.async.tellraw(name,'["",{"text":"You built a '..vocab.typeEN..' | '..vocab.nameEN.. ', which is '..vocab.height..' meters tall and gives '..vocab.slots..' density points, '..vocab.greenSlots..' green points and '..vocab.rewardCount..' '..rewardType..' resource!","color":"green"}]')
  1243. -- announce vocab success in German
  1244. commands.async.tellraw(name,'["",{"text":"DE: You built a '..vocab.typeDE..' | '..vocab.nameDE.. ' , which is '..vocab.height..' meters tall and gives '..vocab.slots..' density points, '..vocab.greenSlots..' green points and '..vocab.rewardCount..' '..rewardType..' resource!!","color":"gold"}]')
  1245. --clear out barrier blocks
  1246. cleanBarriers(buildzone)
  1247.  
  1248. --ADD THE NEW STRUCTURE TO THE RECORDS
  1249. table.insert(buildzone.structures,vocab.nameEN) ---CHANGE HERE to make it record the place of the vocab too x, y, z and vocab id
  1250. local building = {id=vocab.id,xpos=x,ypos=y,zpos=z,name=vocab.nameEN,time=os.clock(),player=name}
  1251. table.insert(buildzone.buildings, building)
  1252. --if vocab.green then
  1253. buildzone.greenSlots = buildzone.greenSlots + vocab.greenSlots
  1254. --end
  1255. buildzone.filledSlots = buildzone.filledSlots + vocab.slots
  1256. local newHeight = y + vocab.height - buildzone.y-1 -- the Y coordinate of the highest block above the ground. Our world has its ground at 55 which is in buildzone.y, subtracting 1 to compensate for player height
  1257. if newHeight > buildzone.highest then
  1258. buildzone.highest = newHeight
  1259. end
  1260. -- count variety
  1261. print("adding variety: "..vocab.id)
  1262. local varietyId = vocab.id -- we use a variety id instead of the vocab id because vocab id 1,2,3,4 for example are all houses so it is the same variety
  1263. --we add only one type of house, one type of green house, one type of garden and one type of extension and we skip the two risers
  1264. if vocab.id == 2 or vocab.id == 3 or vocab.id == 4 then varietyId = 1 end-- only one type for the 4 different orientations of the house
  1265. if vocab.id == 14 or vocab.id == 15 or vocab.id == 16 then varietyId = 13 end-- only one type for the 4 different orientations of the house extension
  1266. if vocab.id == 26 or vocab.id == 27 or vocab.id == 28 then varietyId = 25 end-- only one type for the 4 different orientations of the house garden extension
  1267. if vocab.id == 38 or vocab.id == 39 or vocab.id == 40 then varietyId = 37 end-- only one type for the 4 different orientations of the green roof house
  1268. if varietyId ~= 17 and varietyId ~= 18 then --skip the two riser as they ar enot buildings
  1269. if buildzone.variety[varietyId] then
  1270. print("increasing existing item")
  1271. buildzone.variety[varietyId] = buildzone.variety[varietyId] + 1
  1272. else
  1273. print("adding new item")
  1274. buildzone.variety[varietyId] = 1
  1275. end
  1276. end
  1277.  
  1278. --- CHECK FOR PERSONAL RECORDS
  1279. --- check if the new structure is the highest
  1280. --- CHANGE here to live detect the contribution of the new structure to the 4 goals and update them
  1281.  
  1282. local personalbest = tracker.getScore(name,"highest")
  1283. if personalbest.count < newHeight then
  1284. --commands.async.tell(name,"You just topped your personal record for highest structure!")
  1285. commands.async.scoreboard("players","add",name,"highest",1)
  1286. -- announce success in English
  1287. commands.async.tellraw(name,'["",{"text":"You just topped your personal record for highest structure!","color":"green"}]')
  1288. -- announce success in German
  1289. commands.async.tellraw(name,'["",{"text":"DE: You just topped your personal record for highest structure!","color":"gold"}]')
  1290. end
  1291.  
  1292. ---
  1293. ---
  1294. -- CHECK if placing the current structure would result in beating a server-wide record on the 4 goals
  1295. --calculate total slots - FOR GOAL "DENSEST NEIGHBOURHOOD"
  1296. local most = tracker.getScore("Densest_[points]","highscores")
  1297. local Kint = math.floor(100 * buildzone.filledSlots / 49) -- Kint is the density index made from built area (filledSlots) over ground area (7x7 slots = 49)
  1298. if Kint > most.count then
  1299. commands.async.scoreboard("players","set","Densest_[points]","highscores",Kint)
  1300. commands.async.say("@a","The record for the Densest Neighbourhood has been topped!")
  1301. end
  1302.  
  1303. -- FOR THE GOAL "MOST DIVERSE NEIGHBOURHOOD"
  1304. -- here we need to count how many varieties of buildings there are
  1305. --local structures = tracker.tallyTable(buildzone.structures) -- this counts the variety of buildings in a game
  1306. local mostDiverse = tracker.getScore("Most-Diverse_[out-of-26]","highscores")
  1307. local typeCount = tablelength(buildzone.variety)
  1308. print("variety count is: "..typeCount)
  1309. if typeCount > mostDiverse.count then
  1310. commands.async.scoreboard("players","set","Most-Diverse_[out-of-26]","highscores", typeCount)
  1311. commands.async.say("@a","The record for the Most Diverse Neighbourhood has been topped!")
  1312. end
  1313.  
  1314. -- FOR THE GOAL "GREENEST NEIGHBOURHOOD"
  1315. -- here we need to count the number of green vocabs
  1316. local greenest = tracker.getScore("Greenest_[points]","highscores")
  1317. local Gint = math.floor(100*buildzone.greenSlots/49) --Gint is the green index, made from green area (greenSlots) over ground area (7x7 slots = 49)
  1318. if Gint > greenest.count then
  1319. commands.async.scoreboard("players","set","Greenest_[points]","highscores",Gint)
  1320. -- announce success in English
  1321. commands.async.tellraw("@a",'["",{"text":"Awesome! '..name.. ' just topped the record for GREENEST NEIGHBOURHOOD!","color":"green"}]')
  1322. -- announce success in German
  1323. commands.async.tellraw("@a",'["",{"text":"DE: Awesome! '..name.. ' just topped the record for GREENEST NEIGHBOURHOOD!","color":"gold"}]')
  1324. ---commands.async.say("@a","The record for the Densest Neighbourhood has been topped!")
  1325. end
  1326.  
  1327. --calculate highest placement -- FOR THE GOAL "TALLEST NEIGHBOURHOOD"
  1328. local highest = tracker.getScore("Tallest_[meters]","highscores")
  1329. if buildzone.highest > highest.count then
  1330. commands.async.scoreboard("players","set","Tallest_[meters]","highscores",buildzone.highest)
  1331. commands.async.say("@a","The record for the Tallest Negihbourhood has been topped!")
  1332. end
  1333.  
  1334.  
  1335. --increase the "how many structures did i build" score for the building player
  1336. commands.async.scoreboard("players","add",name,"built",1)
  1337. commands.async.scoreboard("players","add",name,vocab.name,1) -- use maybe vocab ID instead of name
  1338.  
  1339. totalResult = true
  1340. break
  1341.  
  1342. end
  1343. end
  1344. if totalResult then
  1345. --yey win, do a happy time
  1346. successParticle(x,y,z)
  1347. else
  1348. --no vocab found so do a fail particle
  1349. --announce in English
  1350. commands.async.tellraw(name,'["",{"text":"Your structure is not built correctly, try a different shape.","color":"red"}]')
  1351. -- announce in German
  1352. commands.async.tellraw(name,'["",{"text":"DE: Your structure is not built correctly, try a different shape.","color":"gold"}]')
  1353. failParticle(x,y-1,z)
  1354. end
  1355. end
  1356. return victory
  1357. end
  1358.  
  1359. -- returns how many items are in a table/list
  1360. function tablelength(T)
  1361. local count = 0
  1362. for _ in pairs(T) do count = count + 1 end
  1363. return count
  1364. end
  1365.  
  1366. --Display game information on the monitor
  1367. function debugDisplay(game)
  1368. monitor.clear()
  1369. if blink then
  1370. monitor.setCursorPos(1,1)
  1371. monitor.setTextColor(colors.red)
  1372. monitor.write("Running")
  1373. monitor.setTextColor(colors.white)
  1374. redstone.setOutput("top",true)
  1375. blink = false
  1376. else
  1377. redstone.setOutput("top",false)
  1378. blink = true
  1379. end
  1380. local line = 2
  1381.  
  1382. for i,kew in ipairs(game.queues) do
  1383. monitor.setCursorPos(1,line)
  1384. local minutes = string.format("%02d",math.floor(kew.timer/60))
  1385. local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
  1386. monitor.write("Buildzone "..i.." | Phase: "..kew.phase.." | Time: "..minutes..":"..seconds)
  1387. monitor.setCursorPos(1,line+1)
  1388. for i,player in ipairs(kew.playerlist) do
  1389. monitor.write(player.name.." ")
  1390. end
  1391. line = line +2
  1392. end
  1393.  
  1394. monitor.setCursorPos(1,10)
  1395. for i,player in ipairs(game.waitlist) do
  1396. monitor.write(player.name.." ")
  1397. end
  1398. end
  1399.  
  1400. --BEGIN RUNTIME CODE
  1401. local blink = true
  1402. local game = setup()
  1403. while true do
  1404. update(game)
  1405. if monitor then debugDisplay(game) end
  1406. commands.async.weather("clear",10000)
  1407.  
  1408. local resetbutton = redstone.getInput("left")
  1409. if resetbutton then
  1410. print("reset!")
  1411. for i,kew in ipairs(game.queues) do
  1412. if kew.phase == 2 then
  1413. kew.timer = 5
  1414. end
  1415. end
  1416. end
  1417. sleep(2)
  1418. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement