Advertisement
antonsavov

Untitled

Mar 9th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.51 KB | None | 0 0
  1. local VERSION = '0.1.0 - rewards and messages match the actual game'
  2.  
  3. print("Starting 20.000 Blocks Tutorial")
  4.  
  5. commands.scoreboard("objectives","add","tut_state","dummy")
  6.  
  7. DEBUG_MODE = false
  8. local ox,oy,oz = commands.getBlockPosition()
  9.  
  10. NUMBER_OF_TUT_ZONES = 3
  11. WALL_THICKNESS = 2 -- the thickness of the walls between the tutorial zones
  12. REFRESH_ZONE = {
  13. x=12317,
  14. y=55,
  15. z=-1796,
  16. w=17,
  17. l=59,
  18. h=12
  19. }
  20. INCOMING_ZONE = {
  21. x=12370,
  22. y=69,
  23. z=-1716,
  24. w=3,
  25. l=3,
  26. h=3
  27. }
  28. OUTGOING_POINT = {
  29. x=12314,
  30. y=56,
  31. z=-1774,
  32. a=90,
  33. b=0
  34. }
  35. START_POINT_OFFSET = { --this is the offset of starting point for each tutorial zone from the zone's origin
  36. x=64,
  37. y=1,
  38. z=14
  39. }
  40.  
  41. WELCOME_AREA = {
  42. x=12477,
  43. y=87,
  44. z=-1826,
  45. r1=0,
  46. r2=0
  47. }
  48. PLAY_AREA = {
  49. x=12113,
  50. y=57,
  51. z=-1777,
  52. r1=90,
  53. r2=0
  54. }
  55. TUT_WAIT_AREA = {
  56. x=12381,
  57. y=69,
  58. z=-1716,
  59. r1=115,
  60. r2=0
  61. }
  62. TUT_TIMEOUT_SECONDS = 600
  63. NUMBER_OF_VOCAB = 10
  64. VOCAB_LOCATION = {
  65. x=0,
  66. y=57,
  67. z=5
  68. }
  69. VOCAB_WIDTH = 27
  70. VOCAB_HEIGHT = 19
  71. TUTORIAL_VOCABS = {1,2,3,4,9,10,11,12,37,38,39,40,25,26,27,28}
  72.  
  73.  
  74. BLOCKS = {
  75. CAMP_FLOOR = {block='minecraft:sandstone',data=0},
  76. CONSTRUCTION = {block='minecraft:diamond_ore',data=0},
  77. RING = {block='minecraft:diamond_ore',data=0},
  78. DETECT = {block='minecraft:red_sandstone',data=0},
  79. DETECT_DEAD = {block='minecraft:obsidian',data=0},
  80. VOCAB_DETECT = {block="minecraft:quartz_block",data=0},
  81. VOCAB_REPLACE = {block="minecraft:coal_block",data=0},
  82. VICTORY_MARKER = {block="minecraft:emerald_block",data=0},
  83. PLUG = {block="minecraft:lapis_ore",data=0},
  84. PHVFLOOR = {block="minecraft:stone_slab",data=3},
  85. BUILDING_HOUSE = {block="minecraft:wool",data=0},
  86. BUILDING_GARDEN = {block="minecraft:wool",data=13},
  87. BUILDING_WATER = {block="minecraft:wool",data=1},
  88. }
  89.  
  90.  
  91. --call these to return a proper minecraft item string including adventure mode properties
  92. function houseBlock(quant)
  93. text = BLOCKS.BUILDING_HOUSE.block..' '..quant..' '..BLOCKS.BUILDING_HOUSE.data..' {display:{Name:"House Construction Block",Lore:[Place this against a Diamond to build a house]},CanPlaceOn:["'..BLOCKS.BUILDING_HOUSE.block..'","'..BLOCKS.PLUG.block..'","'..BLOCKS.DETECT.block..'"]}'
  94. return text
  95. end
  96.  
  97. function gardenBlock(quant)
  98. text = BLOCKS.BUILDING_GARDEN.block..' '..quant..' '..BLOCKS.BUILDING_GARDEN.data..' {display:{Name:"Garden Construction Block",Lore:[Place this against a Diamond to build a pond or pool]},CanPlaceOn:["'..BLOCKS.BUILDING_HOUSE.block..'","'..BLOCKS.PLUG.block..'","'..BLOCKS.DETECT.block..'"]}'
  99. return text
  100. end
  101.  
  102.  
  103.  
  104. PICKAXE_USES = 40
  105. pickaxe = 'stone_pickaxe 1 '..131-PICKAXE_USES..' {CanDestroy:["'..BLOCKS.BUILDING_HOUSE.block..'"],display:{Name:"Resource Remover",Lore:[Use the pickaxe to remove up to '..PICKAXE_USES..' resource blocks]}}'
  106.  
  107.  
  108. STARTING_ITEMS = {
  109. houseBlock(10), gardenBlock(10),pickaxe
  110. }
  111.  
  112. REWARDS = {}
  113. --[[--plain singlehouse rewards (costs 4 house, -2+1 activators)
  114. REWARDS[1] = gardenBlock(4)
  115. REWARDS[2] = gardenBlock(4)
  116. REWARDS[3] = gardenBlock(4)
  117. REWARDS[4] = gardenBlock(4)
  118. --extension rise rewards (costs 6 house, -2+1 activators)
  119. REWARDS[5] = gardenBlock(7)
  120. REWARDS[6] = gardenBlock(7)
  121. REWARDS[7] = gardenBlock(7)
  122. REWARDS[8] = gardenBlock(7)
  123. --house bridge rewards (costs 6 house, -3+2 activators)
  124. REWARDS[9] = gardenBlock(10)
  125. REWARDS[10] = gardenBlock(10)
  126. --garden bridge (unused)
  127. REWARDS[11] = gardenBlock(7)
  128. REWARDS[12] = gardenBlock(7)
  129. --extention row house rewards (costs 4 house, 1 activators)
  130. REWARDS[13] = gardenBlock(3)
  131. REWARDS[14] = gardenBlock(3)
  132. REWARDS[15] = gardenBlock(3)
  133. REWARDS[16] = gardenBlock(3)
  134. --riser 1
  135. REWARDS[17] = houseBlock(1)
  136. --riser 2
  137. REWARDS[18] = houseBlock(1)
  138. --filler garden
  139. REWARDS[19] = houseBlock(1)
  140. --filler house plaza
  141. REWARDS[20] = gardenBlock(3)
  142. --extention-farm (like extension rise) (costs 6 garden, -2 activators)
  143. REWARDS[21] = houseBlock(3)
  144. REWARDS[22] = houseBlock(3)
  145. REWARDS[23] = houseBlock(3)
  146. REWARDS[24] = houseBlock(3)
  147. --extension-garden (like extension row house)rewards (costs 3 garden, 1 activators)
  148. REWARDS[25] = "minecraft:emerald"
  149. REWARDS[26] = "minecraft:emerald"
  150. REWARDS[27] = "minecraft:emerald"
  151. REWARDS[28] = "minecraft:emerald"
  152. --L-shaped small business agriculture (costs 6 garden, -3+2 activators)
  153. REWARDS[29] = "minecraft:emerald 2"
  154. REWARDS[30] = "minecraft:emerald 2"
  155. REWARDS[31] = "minecraft:emerald 2"
  156. REWARDS[32] = "minecraft:emerald 2"
  157. --L-shaped small business urban (costs 6 housing, -3+2 activators)
  158. REWARDS[33] = gardenBlock(6)
  159. REWARDS[34] = gardenBlock(6)
  160. REWARDS[35] = gardenBlock(6)
  161. REWARDS[36] = gardenBlock(6)
  162. --allotments (costs 4 garden, -2 activators)
  163. REWARDS[37] = houseBlock(4)
  164. REWARDS[38] = houseBlock(4)
  165. REWARDS[39] = houseBlock(4)
  166. REWARDS[40] = houseBlock(4)
  167. --]]
  168.  
  169. DEFAULT_NAME = 'default-vocab'
  170. --[[
  171. VOCAB_NAMES = {
  172. 'freestand-house',
  173. 'freestand-house',
  174. 'freestand-house',
  175. 'freestand-house',
  176. 'dbl-ext-house',
  177. 'dbl-ext-house',
  178. 'dbl-ext-house',
  179. 'dbl-ext-house',
  180. 'bridge-house',
  181. 'bridge-house',
  182. 'bridge-garden',
  183. 'bridge-garden',
  184. 'ext-house',
  185. 'ext-house',
  186. 'ext-house',
  187. 'ext-house',
  188. 'riser-1',
  189. 'riser-2',
  190. 'city-garden',
  191. 'city-plaza',
  192. 'dbl-ext-garden',
  193. 'dbl-ext-garden',
  194. 'dbl-ext-garden',
  195. 'dbl-ext-garden',
  196. 'ext-garden',
  197. 'ext-garden',
  198. 'ext-garden',
  199. 'ext-garden',
  200. 'corner-garden',
  201. 'corner-garden',
  202. 'corner-garden',
  203. 'corner-garden',
  204. 'corner-house',
  205. 'corner-house',
  206. 'corner-house',
  207. 'corner-house',
  208. 'freestand-garden',
  209. 'freestand-garden',
  210. 'freestand-garden',
  211. 'freestand-garden',
  212. 'zoo',
  213. 'bookstore',
  214. 'greenhouse',
  215. 'fablab'
  216. }
  217. --]]
  218.  
  219. VOCABS_DATA = {
  220. -- urban houses
  221. {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},
  222. {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},
  223. {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},
  224. {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},
  225. -- urban businesses
  226. {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},
  227. {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},
  228. {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},
  229. {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},
  230. -- urban tech&science spaces
  231. {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},
  232. {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},
  233. -- green tech&science spaces
  234. {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},
  235. {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},
  236. -- urban house extensions
  237. {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},
  238. {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},
  239. {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},
  240. {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},
  241. --risers
  242. {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},
  243. {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},
  244. --plazas
  245. {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},
  246. {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},
  247. --green businesses
  248. {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},
  249. {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},
  250. {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},
  251. {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},
  252. ---green private garden extensions
  253. {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},
  254. {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},
  255. {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},
  256. {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},
  257. ---green gathering spaces
  258. {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},
  259. {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},
  260. {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},
  261. {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},
  262. ----urban gathering spaces
  263. {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},
  264. {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},
  265. {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},
  266. {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},
  267. ---green-roof houses
  268. {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},
  269. {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},
  270. {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},
  271. {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},
  272. }
  273.  
  274.  
  275. --PARTICLE FUNCTIONS
  276. function searchParticle(x,y,z)
  277. commands.async.particle("fireworksSpark",x,y,z,0.01,3,0.01,0.01,100)
  278. end
  279.  
  280. function successParticle(x,y,z)
  281. commands.async.particle("happyVillager",x,y,z,2,2,2,1,1000)
  282. commands.async.playsound("random.levelup","@a",x,y,z,1,1.2)
  283. end
  284.  
  285. function failParticle(x,y,z)
  286. commands.async.particle("reddust",x,y,z,0.1,0.1,1.5,1,200)
  287. commands.async.particle("reddust",x,y,z,1.5,0.1,0.1,1,200)
  288. commands.async.playsound("random.bowhit","@a",x,y,z,1,0.8)
  289. end
  290.  
  291. --vocab constructor. Enforces some data structure
  292. function newVocabZone(x,y,z,w,id, reward,nameEN, nameDE, typeEN, typeDE, height, slots,green,greenSlots, rewardUrban, rewardCount)
  293. local nvz = {}
  294. nvz.x ,nvz.y ,nvz.z ,nvz.w = x,y,z,w
  295.  
  296. nvz.cx = nvz.x - nvz.w - 2
  297. nvz.cy = nvz.y
  298. nvz.cz = nvz.z
  299. nvz.nameEN = nameEN
  300. nvz.reward = reward
  301. --- new stuff
  302. nvz.id = id
  303. nvz.nameDE = nameDE
  304. nvz.typeEN = typeEN
  305. nvz.typeDE = typeDE
  306. nvz.height = height
  307. nvz.slots = slots
  308. nvz.green = green
  309. nvz.greenSlots = greenSlots
  310. nvz.rewardUrban = rewardUrban
  311. nvz.rewardCount = rewardCount
  312.  
  313. return nvz
  314.  
  315. end
  316.  
  317. --a multi builder which uses the vocab constructor to create sets of vocab
  318. local function makeVocabZones(quant,w)
  319. local x,y,z = VOCAB_LOCATION.x, VOCAB_LOCATION.y, VOCAB_LOCATION.z
  320. local result = {}
  321. local id = 1
  322. for i=0,quant-1 do
  323. for k=0,3 do
  324. local zpos = i-4
  325. local ypos = k
  326. --print("vocab at X")
  327. --print(x-(2*w)-6)
  328. --print("and Z")
  329. --print(z+((w+1)*zpos))
  330. local nextVocab = newVocabZone(
  331. x-(2*w)-6,y+(ypos*(VOCAB_HEIGHT+3)),
  332. z+((w+1)*zpos),
  333. w,
  334. id,
  335. REWARDS[id] or DEFAULT_REWARD,
  336. VOCABS_DATA[id].nameEN or DEFAULT_NAME,
  337. VOCABS_DATA[id].nameDE or DEFAULT_NAME,
  338. VOCABS_DATA[id].typeEN,
  339. VOCABS_DATA[id].typeDE,
  340. VOCABS_DATA[id].height,
  341. VOCABS_DATA[id].slots,
  342. VOCABS_DATA[id].green,
  343. VOCABS_DATA[id].greenSlots,
  344. VOCABS_DATA[id].rewardUrban,
  345. VOCABS_DATA[id].rewardCount
  346. )
  347. table.insert(result,nextVocab)
  348. id = id +1
  349. end
  350. end
  351. return result
  352. end
  353.  
  354. --constructor for player object so that data structure is consistant
  355. function newPlayerData(name,x,y,z)
  356. local p = {
  357. name = name,
  358. x=x,
  359. y=y,
  360. z=z
  361. }
  362. return p
  363. end
  364.  
  365. local function printall(text,zone)
  366. local text = text..": "
  367. for i,_ in pairs(zone) do
  368. if i == "waitingForCheck" then
  369. text = text..i..", "
  370. end
  371. end
  372. --print(text)
  373. end
  374.  
  375. --return a list of all players in the game world as player objects
  376. local function getNameFromMessage(message)
  377. local names = {}
  378.  
  379. local wordpattern = "[^, ]+"
  380. local numberpattern = "[%-% ]%d+[%.]%d+"
  381. local words,numbers = {},{}
  382.  
  383. for word in string.gmatch(message, wordpattern) do
  384. table.insert(words,word)
  385. end
  386.  
  387. for number in string.gmatch(message, numberpattern) do
  388. table.insert(numbers,number)
  389. end
  390.  
  391. local coords = {
  392. x = math.floor(numbers[1]),
  393. y = math.floor(numbers[2]),
  394. z = math.floor(numbers[3])
  395. }
  396. local name = words[2]
  397. return newPlayerData(name,coords.x,coords.y,coords.z)
  398. end
  399.  
  400.  
  401.  
  402. --constructor for a tutorial zone
  403. function newTutZone(x,y,z,vocabZones)
  404. local ntz = {}
  405. ntz.x ,ntz.y ,ntz.z = x,y,z
  406. ntz.endtime = nil
  407. ntz.waitingForCheck = {}
  408. ntz.player = nil
  409. ntz.clean = false
  410. ntz.vocab = vocabZones
  411.  
  412. printall("New zone",ntz)
  413. sleep(1)
  414.  
  415. return ntz
  416. end
  417.  
  418. local function resetZone(zone)
  419.  
  420. end
  421.  
  422.  
  423.  
  424.  
  425. --reset all tutorials. Teleports current players back to the incoming zone. clears all tutorial zones of blocks and resets them.
  426. local function resetAllTutorials()
  427. end
  428.  
  429.  
  430. --gives the same list of items to a list of players
  431. local function giveItems(playerlist,itemlist)
  432. local given = 0
  433. for i,player in ipairs(playerlist) do
  434. --commands.async.clear(player.name)
  435. for j,item in ipairs(itemlist) do
  436. commands.async.give("@a[name="..player.name.."]",item)
  437. given = given +1
  438. end
  439. --giveHomecomer(player.name)
  440. end
  441. return given
  442. end
  443.  
  444. --check for players and fill if needed
  445. local function checkAndFill(zone)
  446. local iz = INCOMING_ZONE
  447. local result,msg = commands.tp("@p[x="..iz.x..",y="..iz.y..",z="..iz.z..",dx="..iz.w..",dy="..iz.h..",dz="..iz.l.."]",zone.x+START_POINT_OFFSET.x,zone.y+START_POINT_OFFSET.y,zone.z+START_POINT_OFFSET.z,90,0)
  448. if result then
  449. local player = getNameFromMessage(msg[1])
  450. commands.spawnpoint(player.name,TUT_WAIT_AREA.x,TUT_WAIT_AREA.y,TUT_WAIT_AREA.z,TUT_WAIT_AREA.r1,TUT_WAIT_AREA.r2)
  451. local result,msg = commands.scoreboard("players","set",player.name,"tut_state",1)
  452. zone.player = player
  453. commands.clear(player.name)
  454. giveItems({player},STARTING_ITEMS) --give starting items
  455. zone.endtime = os.clock()+TUT_TIMEOUT_SECONDS
  456. end
  457. end
  458.  
  459. --check for victory and tp players out
  460. local function checkVictoryAndExit(zone)
  461. --commands.tell(zone.player.name,"Doing Victory section")
  462. local victory_length = 2
  463. local endzone_selector = "@p[name="..zone.player.name..",x="..zone.x..",y="..(zone.y+6)..",z="..(zone.z+math.floor(REFRESH_ZONE.w/2))..",dx="..victory_length..",dy="..REFRESH_ZONE.h..",dz="..REFRESH_ZONE.w.."]"
  464. local result,msg = commands.tp(endzone_selector,OUTGOING_POINT.x,OUTGOING_POINT.y,OUTGOING_POINT.z,OUTGOING_POINT.a,OUTGOING_POINT.b)
  465. if result then
  466. zone.clean = false
  467. commands.spawnpoint(zone.player.name,PLAY_AREA.x,PLAY_AREA.y,PLAY_AREA.z,PLAY_AREA.r1,PLAY_AREA.r2)
  468. commands.scoreboard("players","set",zone.player.name,"tut_state",2)
  469. --tell the player they succeeded
  470. --commands.tell(zone.player.name,"You completed the Tutorial")
  471. --announce in English
  472. commands.async.tellraw(zone.player.name,'["",{"text":"Bravo! You completed the building tutorial!","color":"white"}]')
  473. -- announce in German
  474. commands.async.tellraw(zone.player.name,'["",{"text":"Bravo! Du hast das Tutorial abgeschlossen!","color":"gold"}]')
  475. ---
  476. --clear players inventory
  477. commands.clear(zone.player.name)
  478. zone.player = nil
  479. elseif os.clock() > zone.endtime then
  480. zone.clean = false
  481. commands.tell(zone.player.name,"The tutorial timed out")
  482. local zone_select = "@p[name="..zone.player.name..",x="..zone.x..",y="..zone.y..",z="..zone.z..",dx="..REFRESH_ZONE.l..",dy="..REFRESH_ZONE.h..",dz="..REFRESH_ZONE.w.."]"
  483. commands.tp(zone_select,TUT_WAIT_AREA.x,TUT_WAIT_AREA.y,TUT_WAIT_AREA.z,TUT_WAIT_AREA.r1,TUT_WAIT_AREA.r2)
  484. commands.clear(zone.player)
  485. zone.player = nil
  486. end
  487. end
  488.  
  489. -- zone clean up
  490. local function cleanZone(zone)
  491. local rz = REFRESH_ZONE
  492. commands.clone(rz.x,rz.y,rz.z,rz.x+rz.l,rz.y+rz.h,rz.z+rz.w,zone.x,zone.y,zone.z,"replace")
  493. --commands.say("cleaned zone")
  494. zone.clean = true
  495. end
  496.  
  497. --returns a list of player objects containing all players who are standing on the given block, and who also are in the given selection
  498. local function getAllOnBlockType(block,selector)
  499. local result, message = commands.exec("execute @a["..selector.."] ~ ~ ~ detect ~ ~-1 ~ "..block.." -1 tp @p[r=1] ~ ~ ~")
  500. local names = {}
  501. if result == true then
  502. for i,result in ipairs(message) do
  503. local wordpattern = "[^, ]+"
  504. local numberpattern = "[%-% ]%d+[%.]%d+"
  505. local words,numbers = {},{}
  506.  
  507. for word in string.gmatch(result, wordpattern) do table.insert(words,word) end
  508. for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
  509.  
  510. if numbers[1] and numbers[2] and numbers[3] then
  511. local coords = {
  512. x = math.floor(numbers[1]),
  513. y = math.floor(numbers[2]),
  514. z = math.floor(numbers[3])
  515. }
  516. local name = words[2]
  517. table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
  518. --print("Found a player - getOnBlock")
  519. else
  520. --print("Error: Coordinate Numbers were missing")
  521. end
  522. end
  523. end
  524. return names
  525. end
  526.  
  527. --makes sure that incoming check requests dont exist already
  528. function addToChecklist(player,zone)
  529. for _, detector in ipairs(zone.waitingForCheck) do
  530. if detector.x == player.x and detector.y == player.y and detector.z == player.z then
  531. printall("before return false",zone)
  532. return false
  533. end
  534. end
  535. printall("before table add",zone)
  536. table.insert(zone.waitingForCheck,player)
  537. return true
  538. end
  539.  
  540. --removed all barrier blocks from a buildzone which are used to carve space in vocabs
  541. function cleanBarriers(buildzone)
  542. for h=0,50 do
  543. commands.async.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+REFRESH_ZONE.w,buildzone.y+h,buildzone.z+REFRESH_ZONE.l,"minecraft:air",0,"replace","minecraft:barrier")
  544. end
  545. end
  546.  
  547. --The main chunk of code which deals with stepping on detector blocks and reading the vocab. Modified for tutorial
  548. function doVocabGameplay(zone)
  549. local selector = "x="..zone.x..",y="..(zone.y-5)..",z="..zone.z..",dx="..REFRESH_ZONE.l..",dy="..REFRESH_ZONE.h..",dz="..REFRESH_ZONE.w
  550.  
  551. local victory = false
  552. --get all players on diamond, add them to the list of things to check
  553. local detectLocations = getAllOnBlockType(BLOCKS.DETECT.block,selector)
  554. for _, player in ipairs(detectLocations) do
  555. addToChecklist(player,zone)
  556. end
  557. --if zone and zone.waitingForCheck then print("found waiting for check") else print("found nothing") end
  558. --DEAL WITH THE DETECTOR AT THE TOP OF THE LIST IF THERE IS ONE
  559. if #zone.waitingForCheck > 0 then
  560. --DO PARTICLE EFFECTS IF A DETECTING BLOCK THAT IS DETECTING
  561. for i,loc in ipairs(zone.waitingForCheck) do
  562. searchParticle(loc.x,loc.y+1,loc.z)
  563. end
  564. local totalResult = false
  565. local checked = table.remove(zone.waitingForCheck,1)
  566. local x,y,z,name = checked.x,checked.y,checked.z,checked.name
  567. for i,vocab in pairs(zone.vocab) do
  568. local vx,vy,vz,vx1,vy1,vz1 = vocab.x, vocab.y, vocab.z, vocab.x+vocab.w, vocab.y+VOCAB_HEIGHT, vocab.z+vocab.w
  569. local dx,dy,dz = x-math.floor(vocab.w/2),y-1,z-math.floor(vocab.w/2)
  570. --print("Comparing "..vx..","..vy..","..vz.." with "..dx..","..dy..","..dz)
  571. local result,message = commands.testforblocks(vx,vy,vz,vx1,vy1,vz1,dx,dy,dz,"masked")
  572. --print(message[1])
  573. if result then
  574. --clone in the correct vocab
  575. 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")
  576. if DEBUG_MODE then
  577. print(clonemes[1])
  578. end
  579. commands.async.give(name,vocab.reward)
  580. -- announce vocab success in English
  581. local rewardType = 'nature'
  582. local rewardTypeDE = 'grüne'
  583. if vocab.rewardUrban then
  584. rewardType = 'urban'
  585. rewardTypeDE = 'urbane'
  586. end
  587. 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"}]')
  588. -- announce vocab success in German
  589. commands.async.tellraw(name,'["",{"text":"Du hast ein '..vocab.typeDE..' | '..vocab.nameDE.. ' gebaut, das '..vocab.height..' Meter hoch ist und dir '..vocab.slots..' Punkte für die Dichte einbringt, jedoch '..vocab.greenSlots..' Punkte für Grünflächen und '..vocab.rewardCount..' '..rewardTypeDE..' Ressourcen!","color":"gold"}]')
  590. --clear out barrier blocks
  591. cleanBarriers(zone)
  592.  
  593. totalResult = true
  594. break
  595.  
  596. end
  597. end
  598. if totalResult then
  599. --yey win, do a happy time
  600. successParticle(x,y,z)
  601. else
  602. --no vocab found so do a fail particle
  603. --announce in English
  604. commands.async.tellraw(name,'["",{"text":"The shape you have built does not match any shape in the catalogue, try a different one.","color":"red"}]')
  605. -- announce in German
  606. commands.async.tellraw(name,'["",{"text":"Die Kombination, die du gebaut hast passt leider zu keinem Gebäude, versuche es mit einer anderen Form.","color":"gold"}]')
  607. failParticle(x,y-1,z)
  608. end
  609. end
  610. return victory
  611. end
  612.  
  613. --do all logic for tutzones
  614. local function updateTutZones(tuts)
  615. --all empty zones check for players and get if available
  616. for index,zone in ipairs(tuts.zones) do
  617. if zone.player == nil then
  618. printall("fill zone "..index,zone)
  619. checkAndFill(zone)
  620. end
  621. end
  622.  
  623.  
  624. --all zones with player, check vocab update
  625. for index,zone in ipairs(tuts.zones) do
  626. if zone.player then
  627. printall("gameplay "..index,zone)
  628. doVocabGameplay(zone)
  629. end
  630. end
  631.  
  632.  
  633.  
  634. --all zones with players check for victory and tp players out
  635. for index,zone in ipairs(tuts.zones) do
  636. if zone.player then
  637. printall("exit "..index,zone)
  638. checkVictoryAndExit(zone)
  639. end
  640. end
  641.  
  642.  
  643. --all empty zones which need cleaning are cleaned up
  644. for index,zone in ipairs(tuts.zones) do
  645. if zone.clean == false then
  646. printall("clean "..index,zone)
  647. cleanZone(zone)
  648. end
  649. end
  650.  
  651.  
  652. end
  653.  
  654. --setup a new tuts object
  655. local function setup()
  656. local tuts = {}
  657. tuts.zones = {}
  658.  
  659. --generate vocab rewards
  660. for i=1,#VOCABS_DATA do
  661. if VOCABS_DATA[i].rewardUrban then
  662. REWARDS[i] = houseBlock(VOCABS_DATA[i].rewardCount)
  663. else
  664. REWARDS[i] = gardenBlock(VOCABS_DATA[i].rewardCount)
  665. end
  666. end
  667.  
  668. tuts.vocabs = makeVocabZones(NUMBER_OF_VOCAB,VOCAB_WIDTH)
  669. --print(type(tuts.vocabs),#tuts.vocabs)
  670. local rz = REFRESH_ZONE
  671. --local vocab_subset = {}
  672. --for i=1, 40 in ipairs(TUTORIAL_VOCABS) do
  673. -- table.insert(vocab_subset,tuts.vocabs[value])
  674. --end
  675.  
  676. for index = 1, NUMBER_OF_TUT_ZONES do
  677. local newZone = newTutZone(rz.x,rz.y,rz.z+(index*(rz.w+1+WALL_THICKNESS)),tuts.vocabs)
  678. table.insert(tuts.zones,newZone)
  679. end
  680.  
  681. --check for vocab zone at vocab location
  682. --build all vocab locations
  683.  
  684. --store vocab in tuts object
  685.  
  686. return tuts
  687. end
  688.  
  689.  
  690.  
  691. local symbols = {
  692. "(X) ",
  693. "(-) "
  694. }
  695. local spin = 1
  696.  
  697. --BEGIN RUNTIME CODE
  698. local blink = true
  699. local tuts = setup()
  700. while true do
  701. if not DEBUG_MODE then
  702. term.clear()
  703. print("Controlling Tutorial "..symbols[spin])
  704. spin = spin +1
  705. if spin > #symbols then spin = 1 end
  706. end
  707. updateTutZones(tuts)
  708. commands.async.weather("clear",10000)
  709.  
  710. local resetbutton = redstone.getInput("left")
  711. if resetbutton then
  712. print("reset!")
  713. resetAllTutorials()
  714. end
  715. sleep(0.5)
  716. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement