Advertisement
antonsavov

Untitled

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