antonsavov

Untitled

Feb 10th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.02 KB | None | 0 0
  1. local VERSION = '0.0.2 - initut(tm)'
  2.  
  3. print("Starting 20,000 Blocks Tutorial")
  4.  
  5. commands.scoreboard("objectives","add","tut_state","dummy")
  6.  
  7. DEBUG_MODE = true
  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.  
  63. NUMBER_OF_VOCAB = 10
  64. VOCAB_LOCATION = {
  65. x=-47,
  66. y=57,
  67. z=-94
  68. }
  69. VOCAB_WIDTH = 27
  70. VOCAB_HEIGHT = 19
  71. TUTORIAL_VOCABS = {1,2}
  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 waterBlock(quant)
  98. text = BLOCKS.BUILDING_WATER.block..' '..quant..' '..BLOCKS.BUILDING_WATER.data..' {display:{Name:"Water Construction Block",Lore:[Place this against a Diamond to build a pond or pool]},CanPlaceOn:["'..BLOCKS.BUILDING_HOUSE.block..'","'..BLOCKS.PLUG.block..'","'..BLOCKS.DETECT.block..'"]}'
  99. return text
  100. end
  101.  
  102. function gardenBlock(quant)
  103. 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..'"]}'
  104. return text
  105. end
  106.  
  107. STARTING_ITEMS = {
  108. houseBlock(5), gardenBlock(5)
  109. }
  110.  
  111. REWARDS = {}
  112. --plain singlehouse rewards (costs 4 house, -2+1 activators)
  113. REWARDS[1] = gardenBlock(4)
  114. REWARDS[2] = gardenBlock(4)
  115. REWARDS[3] = gardenBlock(4)
  116. REWARDS[4] = gardenBlock(4)
  117. --extension rise rewards (costs 6 house, -2+1 activators)
  118. REWARDS[5] = gardenBlock(7)
  119. REWARDS[6] = gardenBlock(7)
  120. REWARDS[7] = gardenBlock(7)
  121. REWARDS[8] = gardenBlock(7)
  122. --house bridge rewards (costs 6 house, -3+2 activators)
  123. REWARDS[9] = gardenBlock(10)
  124. REWARDS[10] = gardenBlock(10)
  125. --garden bridge (unused)
  126. REWARDS[11] = gardenBlock(7)
  127. REWARDS[12] = gardenBlock(7)
  128. --extention row house rewards (costs 4 house, 1 activators)
  129. REWARDS[13] = houseBlock(6)
  130. REWARDS[14] = houseBlock(6)
  131. REWARDS[15] = houseBlock(6)
  132. REWARDS[16] = houseBlock(6)
  133. --riser 1
  134. REWARDS[17] = houseBlock(1)
  135. --riser 2
  136. REWARDS[18] = houseBlock(1)
  137. --filler garden
  138. REWARDS[19] = houseBlock(1)
  139. --filler house plaza
  140. REWARDS[20] = gardenBlock(3)
  141. --extention-farm (like extension rise) (costs 6 garden, -2 activators)
  142. REWARDS[21] = houseBlock(3)
  143. REWARDS[22] = houseBlock(3)
  144. REWARDS[23] = houseBlock(3)
  145. REWARDS[24] = houseBlock(3)
  146. --extension-garden (like extension row house)rewards (costs 3 garden, 1 activators)
  147. REWARDS[25] = "minecraft:emerald"
  148. REWARDS[26] = "minecraft:emerald"
  149. REWARDS[27] = "minecraft:emerald"
  150. REWARDS[28] = "minecraft:emerald"
  151. --L-shaped small business agriculture (costs 6 garden, -3+2 activators)
  152. REWARDS[29] = "minecraft:emerald 2"
  153. REWARDS[30] = "minecraft:emerald 2"
  154. REWARDS[31] = "minecraft:emerald 2"
  155. REWARDS[32] = "minecraft:emerald 2"
  156. --L-shaped small business urban (costs 6 housing, -3+2 activators)
  157. REWARDS[33] = gardenBlock(6)
  158. REWARDS[34] = gardenBlock(6)
  159. REWARDS[35] = gardenBlock(6)
  160. REWARDS[36] = gardenBlock(6)
  161. --allotments (costs 4 garden, -2 activators)
  162. REWARDS[37] = houseBlock(2)
  163. REWARDS[38] = houseBlock(2)
  164. REWARDS[39] = houseBlock(2)
  165. REWARDS[40] = houseBlock(2)
  166.  
  167. DEFAULT_NAME = 'default-vocab'
  168. VOCAB_NAMES = {
  169. 'freestand-house',
  170. 'freestand-house',
  171. 'freestand-house',
  172. 'freestand-house',
  173. 'dbl-ext-house',
  174. 'dbl-ext-house',
  175. 'dbl-ext-house',
  176. 'dbl-ext-house',
  177. 'bridge-house',
  178. 'bridge-house',
  179. 'bridge-garden',
  180. 'bridge-garden',
  181. 'ext-house',
  182. 'ext-house',
  183. 'ext-house',
  184. 'ext-house',
  185. 'riser-1',
  186. 'riser-2',
  187. 'city-garden',
  188. 'city-plaza',
  189. 'dbl-ext-garden',
  190. 'dbl-ext-garden',
  191. 'dbl-ext-garden',
  192. 'dbl-ext-garden',
  193. 'ext-garden',
  194. 'ext-garden',
  195. 'ext-garden',
  196. 'ext-garden',
  197. 'corner-garden',
  198. 'corner-garden',
  199. 'corner-garden',
  200. 'corner-garden',
  201. 'corner-house',
  202. 'corner-house',
  203. 'corner-house',
  204. 'corner-house',
  205. 'freestand-garden',
  206. 'freestand-garden',
  207. 'freestand-garden',
  208. 'freestand-garden',
  209. 'zoo',
  210. 'bookstore',
  211. 'greenhouse',
  212. 'fablab'
  213. }
  214.  
  215. --PARTICLE FUNCTIONS
  216. function searchParticle(x,y,z)
  217. commands.async.particle("fireworksSpark",x,y,z,0.01,3,0.01,0.01,100)
  218. end
  219.  
  220. function successParticle(x,y,z)
  221. commands.async.particle("happyVillager",x,y,z,2,2,2,1,1000)
  222. commands.async.playsound("random.levelup","@a",x,y,z,1,1.2)
  223. end
  224.  
  225. function failParticle(x,y,z)
  226. commands.async.particle("reddust",x,y,z,0.1,0.1,1.5,1,200)
  227. commands.async.particle("reddust",x,y,z,1.5,0.1,0.1,1,200)
  228. commands.async.playsound("random.bowhit","@a",x,y,z,1,0.8)
  229. end
  230.  
  231. --constructor for player object so that data structure is consistant
  232. function newPlayerData(name,x,y,z)
  233. local p = {
  234. name = name,
  235. x=x,
  236. y=y,
  237. z=z
  238. }
  239. return p
  240. end
  241.  
  242. --return a list of all players in the game world as player objects
  243. local function getNameFromMessage(message)
  244. local names = {}
  245.  
  246. local wordpattern = "[^, ]+"
  247. local numberpattern = "[%-% ]%d+[%.]%d+"
  248. local words,numbers = {},{}
  249.  
  250. for word in string.gmatch(message, wordpattern) do
  251. table.insert(words,word)
  252. end
  253.  
  254. for number in string.gmatch(message, numberpattern) do
  255. table.insert(numbers,number)
  256. end
  257.  
  258. local coords = {
  259. x = math.floor(numbers[1]),
  260. y = math.floor(numbers[2]),
  261. z = math.floor(numbers[3])
  262. }
  263. local name = words[2]
  264. return newPlayerData(name,coords.x,coords.y,coords.z)
  265. end
  266.  
  267.  
  268.  
  269. --constructor for a tutorial zone
  270. function newTutZone(x,y,z,vocabZones)
  271. local ntz = {}
  272. ntz.x ,ntz.y ,ntz.z = x,y,z
  273. ntz.endtime = nil
  274. ntz.player = nil
  275. ntz.clean = false
  276. ntz.vocab = vocabZones
  277. return ntz
  278. end
  279.  
  280. local function resetZone(zone)
  281.  
  282. end
  283.  
  284. --reset all tutorials. Teleports current players back to the incoming zone. clears all tutorial zones of blocks and resets them.
  285. local function resetAllTutorials()
  286. end
  287.  
  288. --check for players and fill if needed
  289. local function checkAndFill(zone)
  290. local iz = INCOMING_ZONE
  291. 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)
  292. if result then
  293. local player = getNameFromMessage(msg[1])
  294. commands.spawnpoint(player.name,TUT_WAIT_AREA.x,TUT_WAIT_AREA.y,TUT_WAIT_AREA.z,TUT_WAIT_AREA.r1,TUT_WAIT_AREA.r2)
  295. local result,msg = commands.scoreboard("players","set",player.name,"tut_state",1)
  296. zone.player = player
  297. zone.endtime = os.clock()+60
  298. end
  299. end
  300.  
  301. --player check vocab update
  302. local function doVocabGameplay(zone)
  303. --commands.tell(zone.player.name,"Doing Vocab Gameplay")
  304.  
  305. end
  306.  
  307. --check for victory and tp players out
  308. local function checkVictoryAndExit(zone)
  309. --commands.tell(zone.player.name,"Doing Victory section")
  310. local victory_length = 5
  311. local endzone_selector = "@p[name="..zone.player.name..",x="..zone.x..",y="..zone.y..",z="..zone.z..",dx="..victory_length..",dy="..REFRESH_ZONE.h..",dz="..REFRESH_ZONE.w.."]"
  312. local result,msg = commands.tp(endzone_selector,OUTGOING_POINT.x,OUTGOING_POINT.y,OUTGOING_POINT.z,OUTGOING_POINT.a,OUTGOING_POINT.b)
  313. if result then
  314. zone.clean = false
  315. commands.spawnpoint(zone.player.name,PLAY_AREA.x,PLAY_AREA.y,PLAY_AREA.z,PLAY_AREA.r1,PLAY_AREA.r2)
  316. commands.scoreboard("players","set",zone.player.name,"tut_state",2)
  317. commands.tell(zone.player.name,"You completed the Tutorial")
  318. zone.player = nil
  319. elseif os.clock() > zone.endtime then
  320. zone.clean = false
  321. commands.tell(zone.player.name,"The tutorial timed out")
  322. 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.."]"
  323. commands.tp(zone_select,TUT_WAIT_AREA.x,TUT_WAIT_AREA.y,TUT_WAIT_AREA.z,TUT_WAIT_AREA.r1,TUT_WAIT_AREA.r2)
  324. zone.player = nil
  325. end
  326. end
  327.  
  328. -- zone clean up
  329. local function cleanZone(zone)
  330. local rz = REFRESH_ZONE
  331. 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")
  332. commands.say("cleaned zone")
  333. zone.clean = true
  334. end
  335.  
  336. --do all logic for tutzones
  337. local function updateTutZones(tuts)
  338. --all empty zones check for players and get if available
  339. for index,zone in ipairs(tuts.zones) do
  340. if zone.player == nil then
  341. checkAndFill(zone)
  342. end
  343. end
  344.  
  345.  
  346. --all zones with player, check vocab update
  347. for index,zone in ipairs(tuts.zones) do
  348. if zone.player then
  349. doVocabGameplay(zone)
  350. end
  351. end
  352.  
  353.  
  354.  
  355. --all zones with players check for victory and tp players out
  356. for index,zone in ipairs(tuts.zones) do
  357. if zone.player then
  358. checkVictoryAndExit(zone)
  359. end
  360. end
  361.  
  362.  
  363. --all empty zones which need cleaning are cleaned up
  364. for index,zone in ipairs(tuts.zones) do
  365. if zone.clean == false then
  366. cleanZone(zone)
  367. end
  368. end
  369.  
  370.  
  371. end
  372.  
  373. --setup a new tuts object
  374. local function setup()
  375. local tuts = {}
  376. tuts.zones = {}
  377. local rz = REFRESH_ZONE
  378. for index = 1, NUMBER_OF_TUT_ZONES do
  379. local newZone = newTutZone(rz.x,rz.y,rz.z+(index*(rz.w+1+WALL_THICKNESS)),{})
  380. table.insert(tuts.zones,newZone)
  381. end
  382.  
  383. --check for vocab zone at vocab location
  384. --build all vocab locations
  385. --store vocab in tuts object
  386.  
  387. return tuts
  388. end
  389.  
  390. local symbols = {
  391. "(X) ",
  392. "(-) "
  393. }
  394. local spin = 1
  395.  
  396. --BEGIN RUNTIME CODE
  397. local blink = true
  398. local tuts = setup()
  399. while true do
  400. term.clear()
  401. print("Controlling Tutorial "..symbols[spin])
  402. spin = spin +1
  403. if spin > #symbols then spin = 1 end
  404.  
  405. updateTutZones(tuts)
  406. commands.async.weather("clear",10000)
  407.  
  408. local resetbutton = redstone.getInput("left")
  409. if resetbutton then
  410. print("reset!")
  411. resetAllTutorials()
  412. end
  413. sleep(0.5)
  414. end
Advertisement
Add Comment
Please, Sign In to add comment