Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local VERSION = '0.0.2 - initut(tm)'
- print("Starting 20,000 Blocks Tutorial")
- commands.scoreboard("objectives","add","tut_state","dummy")
- DEBUG_MODE = true
- local ox,oy,oz = commands.getBlockPosition()
- NUMBER_OF_TUT_ZONES = 3
- WALL_THICKNESS = 2 -- the thickness of the walls between the tutorial zones
- REFRESH_ZONE = {
- x=12317,
- y=55,
- z=-1796,
- w=17,
- l=59,
- h=12
- }
- INCOMING_ZONE = {
- x=12370,
- y=69,
- z=-1716,
- w=3,
- l=3,
- h=3
- }
- OUTGOING_POINT = {
- x=12314,
- y=56,
- z=-1774,
- a=90,
- b=0
- }
- START_POINT_OFFSET = { --this is the offset of starting point for each tutorial zone from the zone's origin
- x=64,
- y=1,
- z=14
- }
- WELCOME_AREA = {
- x=12477,
- y=87,
- z=-1826,
- r1=0,
- r2=0
- }
- PLAY_AREA = {
- x=12113,
- y=57,
- z=-1777,
- r1=90,
- r2=0
- }
- TUT_WAIT_AREA = {
- x=12381,
- y=69,
- z=-1716,
- r1=115,
- r2=0
- }
- NUMBER_OF_VOCAB = 10
- VOCAB_LOCATION = {
- x=-47,
- y=57,
- z=-94
- }
- VOCAB_WIDTH = 27
- VOCAB_HEIGHT = 19
- TUTORIAL_VOCABS = {1,2}
- BLOCKS = {
- CAMP_FLOOR = {block='minecraft:sandstone',data=0},
- CONSTRUCTION = {block='minecraft:diamond_ore',data=0},
- RING = {block='minecraft:diamond_ore',data=0},
- DETECT = {block='minecraft:red_sandstone',data=0},
- DETECT_DEAD = {block='minecraft:obsidian',data=0},
- VOCAB_DETECT = {block="minecraft:quartz_block",data=0},
- VOCAB_REPLACE = {block="minecraft:coal_block",data=0},
- VICTORY_MARKER = {block="minecraft:emerald_block",data=0},
- PLUG = {block="minecraft:lapis_ore",data=0},
- PHVFLOOR = {block="minecraft:stone_slab",data=3},
- BUILDING_HOUSE = {block="minecraft:wool",data=0},
- BUILDING_GARDEN = {block="minecraft:wool",data=13},
- BUILDING_WATER = {block="minecraft:wool",data=1},
- }
- --call these to return a proper minecraft item string including adventure mode properties
- function houseBlock(quant)
- 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..'"]}'
- return text
- end
- function waterBlock(quant)
- 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..'"]}'
- return text
- end
- function gardenBlock(quant)
- 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..'"]}'
- return text
- end
- STARTING_ITEMS = {
- houseBlock(5), gardenBlock(5)
- }
- REWARDS = {}
- --plain singlehouse rewards (costs 4 house, -2+1 activators)
- REWARDS[1] = gardenBlock(4)
- REWARDS[2] = gardenBlock(4)
- REWARDS[3] = gardenBlock(4)
- REWARDS[4] = gardenBlock(4)
- --extension rise rewards (costs 6 house, -2+1 activators)
- REWARDS[5] = gardenBlock(7)
- REWARDS[6] = gardenBlock(7)
- REWARDS[7] = gardenBlock(7)
- REWARDS[8] = gardenBlock(7)
- --house bridge rewards (costs 6 house, -3+2 activators)
- REWARDS[9] = gardenBlock(10)
- REWARDS[10] = gardenBlock(10)
- --garden bridge (unused)
- REWARDS[11] = gardenBlock(7)
- REWARDS[12] = gardenBlock(7)
- --extention row house rewards (costs 4 house, 1 activators)
- REWARDS[13] = houseBlock(6)
- REWARDS[14] = houseBlock(6)
- REWARDS[15] = houseBlock(6)
- REWARDS[16] = houseBlock(6)
- --riser 1
- REWARDS[17] = houseBlock(1)
- --riser 2
- REWARDS[18] = houseBlock(1)
- --filler garden
- REWARDS[19] = houseBlock(1)
- --filler house plaza
- REWARDS[20] = gardenBlock(3)
- --extention-farm (like extension rise) (costs 6 garden, -2 activators)
- REWARDS[21] = houseBlock(3)
- REWARDS[22] = houseBlock(3)
- REWARDS[23] = houseBlock(3)
- REWARDS[24] = houseBlock(3)
- --extension-garden (like extension row house)rewards (costs 3 garden, 1 activators)
- REWARDS[25] = "minecraft:emerald"
- REWARDS[26] = "minecraft:emerald"
- REWARDS[27] = "minecraft:emerald"
- REWARDS[28] = "minecraft:emerald"
- --L-shaped small business agriculture (costs 6 garden, -3+2 activators)
- REWARDS[29] = "minecraft:emerald 2"
- REWARDS[30] = "minecraft:emerald 2"
- REWARDS[31] = "minecraft:emerald 2"
- REWARDS[32] = "minecraft:emerald 2"
- --L-shaped small business urban (costs 6 housing, -3+2 activators)
- REWARDS[33] = gardenBlock(6)
- REWARDS[34] = gardenBlock(6)
- REWARDS[35] = gardenBlock(6)
- REWARDS[36] = gardenBlock(6)
- --allotments (costs 4 garden, -2 activators)
- REWARDS[37] = houseBlock(2)
- REWARDS[38] = houseBlock(2)
- REWARDS[39] = houseBlock(2)
- REWARDS[40] = houseBlock(2)
- DEFAULT_NAME = 'default-vocab'
- VOCAB_NAMES = {
- 'freestand-house',
- 'freestand-house',
- 'freestand-house',
- 'freestand-house',
- 'dbl-ext-house',
- 'dbl-ext-house',
- 'dbl-ext-house',
- 'dbl-ext-house',
- 'bridge-house',
- 'bridge-house',
- 'bridge-garden',
- 'bridge-garden',
- 'ext-house',
- 'ext-house',
- 'ext-house',
- 'ext-house',
- 'riser-1',
- 'riser-2',
- 'city-garden',
- 'city-plaza',
- 'dbl-ext-garden',
- 'dbl-ext-garden',
- 'dbl-ext-garden',
- 'dbl-ext-garden',
- 'ext-garden',
- 'ext-garden',
- 'ext-garden',
- 'ext-garden',
- 'corner-garden',
- 'corner-garden',
- 'corner-garden',
- 'corner-garden',
- 'corner-house',
- 'corner-house',
- 'corner-house',
- 'corner-house',
- 'freestand-garden',
- 'freestand-garden',
- 'freestand-garden',
- 'freestand-garden',
- 'zoo',
- 'bookstore',
- 'greenhouse',
- 'fablab'
- }
- --PARTICLE FUNCTIONS
- function searchParticle(x,y,z)
- commands.async.particle("fireworksSpark",x,y,z,0.01,3,0.01,0.01,100)
- end
- function successParticle(x,y,z)
- commands.async.particle("happyVillager",x,y,z,2,2,2,1,1000)
- commands.async.playsound("random.levelup","@a",x,y,z,1,1.2)
- end
- function failParticle(x,y,z)
- commands.async.particle("reddust",x,y,z,0.1,0.1,1.5,1,200)
- commands.async.particle("reddust",x,y,z,1.5,0.1,0.1,1,200)
- commands.async.playsound("random.bowhit","@a",x,y,z,1,0.8)
- end
- --constructor for player object so that data structure is consistant
- function newPlayerData(name,x,y,z)
- local p = {
- name = name,
- x=x,
- y=y,
- z=z
- }
- return p
- end
- --return a list of all players in the game world as player objects
- local function getNameFromMessage(message)
- local names = {}
- local wordpattern = "[^, ]+"
- local numberpattern = "[%-% ]%d+[%.]%d+"
- local words,numbers = {},{}
- for word in string.gmatch(message, wordpattern) do
- table.insert(words,word)
- end
- for number in string.gmatch(message, numberpattern) do
- table.insert(numbers,number)
- end
- local coords = {
- x = math.floor(numbers[1]),
- y = math.floor(numbers[2]),
- z = math.floor(numbers[3])
- }
- local name = words[2]
- return newPlayerData(name,coords.x,coords.y,coords.z)
- end
- --constructor for a tutorial zone
- function newTutZone(x,y,z,vocabZones)
- local ntz = {}
- ntz.x ,ntz.y ,ntz.z = x,y,z
- ntz.endtime = nil
- ntz.player = nil
- ntz.clean = false
- ntz.vocab = vocabZones
- return ntz
- end
- local function resetZone(zone)
- end
- --reset all tutorials. Teleports current players back to the incoming zone. clears all tutorial zones of blocks and resets them.
- local function resetAllTutorials()
- end
- --check for players and fill if needed
- local function checkAndFill(zone)
- local iz = INCOMING_ZONE
- 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)
- if result then
- local player = getNameFromMessage(msg[1])
- commands.spawnpoint(player.name,TUT_WAIT_AREA.x,TUT_WAIT_AREA.y,TUT_WAIT_AREA.z,TUT_WAIT_AREA.r1,TUT_WAIT_AREA.r2)
- local result,msg = commands.scoreboard("players","set",player.name,"tut_state",1)
- zone.player = player
- zone.endtime = os.clock()+60
- end
- end
- --player check vocab update
- local function doVocabGameplay(zone)
- --commands.tell(zone.player.name,"Doing Vocab Gameplay")
- end
- --check for victory and tp players out
- local function checkVictoryAndExit(zone)
- --commands.tell(zone.player.name,"Doing Victory section")
- local victory_length = 5
- 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.."]"
- local result,msg = commands.tp(endzone_selector,OUTGOING_POINT.x,OUTGOING_POINT.y,OUTGOING_POINT.z,OUTGOING_POINT.a,OUTGOING_POINT.b)
- if result then
- zone.clean = false
- commands.spawnpoint(zone.player.name,PLAY_AREA.x,PLAY_AREA.y,PLAY_AREA.z,PLAY_AREA.r1,PLAY_AREA.r2)
- commands.scoreboard("players","set",zone.player.name,"tut_state",2)
- commands.tell(zone.player.name,"You completed the Tutorial")
- zone.player = nil
- elseif os.clock() > zone.endtime then
- zone.clean = false
- commands.tell(zone.player.name,"The tutorial timed out")
- 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.."]"
- commands.tp(zone_select,TUT_WAIT_AREA.x,TUT_WAIT_AREA.y,TUT_WAIT_AREA.z,TUT_WAIT_AREA.r1,TUT_WAIT_AREA.r2)
- zone.player = nil
- end
- end
- -- zone clean up
- local function cleanZone(zone)
- local rz = REFRESH_ZONE
- 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")
- commands.say("cleaned zone")
- zone.clean = true
- end
- --do all logic for tutzones
- local function updateTutZones(tuts)
- --all empty zones check for players and get if available
- for index,zone in ipairs(tuts.zones) do
- if zone.player == nil then
- checkAndFill(zone)
- end
- end
- --all zones with player, check vocab update
- for index,zone in ipairs(tuts.zones) do
- if zone.player then
- doVocabGameplay(zone)
- end
- end
- --all zones with players check for victory and tp players out
- for index,zone in ipairs(tuts.zones) do
- if zone.player then
- checkVictoryAndExit(zone)
- end
- end
- --all empty zones which need cleaning are cleaned up
- for index,zone in ipairs(tuts.zones) do
- if zone.clean == false then
- cleanZone(zone)
- end
- end
- end
- --setup a new tuts object
- local function setup()
- local tuts = {}
- tuts.zones = {}
- local rz = REFRESH_ZONE
- for index = 1, NUMBER_OF_TUT_ZONES do
- local newZone = newTutZone(rz.x,rz.y,rz.z+(index*(rz.w+1+WALL_THICKNESS)),{})
- table.insert(tuts.zones,newZone)
- end
- --check for vocab zone at vocab location
- --build all vocab locations
- --store vocab in tuts object
- return tuts
- end
- local symbols = {
- "(X) ",
- "(-) "
- }
- local spin = 1
- --BEGIN RUNTIME CODE
- local blink = true
- local tuts = setup()
- while true do
- term.clear()
- print("Controlling Tutorial "..symbols[spin])
- spin = spin +1
- if spin > #symbols then spin = 1 end
- updateTutZones(tuts)
- commands.async.weather("clear",10000)
- local resetbutton = redstone.getInput("left")
- if resetbutton then
- print("reset!")
- resetAllTutorials()
- end
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment