Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local VERSION = '0.4.3'
- DEBUG_MODE = true
- commands.gamerule("doDaylightCycle",false)
- commands.gamerule("doTileDrops",false)
- commands.gamerule("logAdminCommands",false)
- commands.gamerule("commandBlockOutput",false)
- commands.time("set",6000)
- local monitor = peripheral.wrap("right")
- local ox,oy,oz = commands.getBlockPosition()
- commands.scoreboard("objectives","add","VillagerLife","dummy")
- print("Starting 20,000 Blocks")
- print("Computer Co-ordinates ",ox,oy,oz)
- commands.title("@a","times",0,30,30)
- math.randomseed( os.time() )
- SPAWN_VILLAGER = false
- DO_GRID = true
- GRID_HOLE_CHANCE = 30
- NUMBER_OF_BUILDZONES = 1
- NUMBER_OF_VOCAB = 9
- VOCAB_WIDTH = 27
- VOCAB_HEIGHT = 19
- BUILDZONE_WIDTH = 62
- BUILDZONE_FLOOR_HEIGHT = -1
- SPAWN = {x=ox,y=oy+2,z=oz-10}
- VICTORY_HEIGHT = 30
- VICTORY_TOTAL = 50
- VICTORY_SPECIFIC = {name='garden',count=101}
- DEFAULT_REWARD = 'minecraft:emerald 2 0 {display:{Name:"Emerald",Lore:[Trade this to the villager for wool]}}'
- WOOL_PER_EMERALD = 64
- PICKAXE_USES = 10
- BLOCKS = {
- CAMP_FLOOR = 'minecraft:sandstone',
- CONSTRUCTION = 'minecraft:clay',
- RING = 'minecraft:stained_glass_pane 4',
- DETECT = 'minecraft:diamond_block',
- DETECT_DEAD = 'minecraft:obsidian',
- VOCAB_DETECT = "minecraft:quartz_block",
- VOCAB_REPLACE = "minecraft:coal_block",
- VICTORY_MARKER = "minecraft:emerald_block"
- }
- function houseBlock(quant)
- text = 'minecraft:wool '..quant..' 0 {display:{Name:"House Construction Block",Lore:[Place this against a Diamond to build a house]},CanPlaceOn:["minecraft:diamond_block","minecraft:wool","minecraft:gold_block"]}'
- return text
- end
- function waterBlock(quant)
- text = 'minecraft:wool '..quant..' 11 {display:{Name:"Water Construction Block",Lore:[Place this against a Diamond to build a pond or pool]},CanPlaceOn:["minecraft:diamond_block","minecraft:wool","minecraft:gold_block"]}'
- return text
- end
- function gardenBlock(quant)
- text = 'minecraft:wool '..quant..' 13 {display:{Name:"Garden Construction Block",Lore:[Place this against a Diamond to build a pond or pool]},CanPlaceOn:["minecraft:diamond_block","minecraft:wool","minecraft:gold_block"]}'
- return text
- end
- STARTING_ITEMS = {
- houseBlock(15),
- 'stone_pickaxe 1 '..131-PICKAXE_USES..' {CanDestroy:["minecraft:wool"],display:{Name:"Wool Remover",Lore:[Use this to remove up to '..PICKAXE_USES..' pieces of wool]}}'
- }
- REWARDS = {}
- --plain singlehouse rewards
- REWARDS[1] = waterBlock(4)
- REWARDS[2] = waterBlock(4)
- REWARDS[3] = waterBlock(4)
- REWARDS[4] = waterBlock(4)
- --extension rise rewards
- REWARDS[5] = gardenBlock(9)
- REWARDS[6] = gardenBlock(9)
- REWARDS[7] = gardenBlock(9)
- REWARDS[8] = gardenBlock(9)
- --bridge rewards
- REWARDS[9] = gardenBlock(4)
- REWARDS[10] = gardenBlock(4)
- --Filler rewards (very low)
- REWARDS[11] = houseBlock(1)
- REWARDS[12] = houseBlock(1)
- --extention row house rewards
- REWARDS[13] = gardenBlock(4)
- REWARDS[14] = gardenBlock(4)
- REWARDS[15] = gardenBlock(4)
- REWARDS[16] = gardenBlock(4)
- --extension pond rewards
- REWARDS[17] = gardenBlock(9)
- REWARDS[18] = gardenBlock(9)
- REWARDS[19] = gardenBlock(9)
- REWARDS[20] = gardenBlock(9)
- --extention pool rewards
- REWARDS[21] = houseBlock(3)
- REWARDS[22] = houseBlock(3)
- REWARDS[23] = houseBlock(3)
- REWARDS[24] = houseBlock(3)
- --extension garden rewards
- REWARDS[25] = waterBlock(3)
- REWARDS[26] = waterBlock(3)
- REWARDS[27] = waterBlock(3)
- REWARDS[28] = waterBlock(3)
- --extention pool rewards
- REWARDS[29] = houseBlock(3)
- REWARDS[30] = houseBlock(3)
- REWARDS[31] = houseBlock(3)
- REWARDS[32] = houseBlock(3)
- --extention major rewards
- REWARDS[33] = houseBlock(3)
- REWARDS[34] = houseBlock(3)
- REWARDS[35] = houseBlock(3)
- REWARDS[36] = houseBlock(3)
- DEFAULT_NAME = 'default-vocab'
- VOCAB_NAMES = {
- 'single-house-1',
- 'single-house-2',
- 'single-house-3',
- 'single-house-4',
- 'extension-rise-1',
- 'extension-rise-2',
- 'extension-rise-3',
- 'extension-rise-4',
- 'bridge-1',
- 'bridge-2',
- 'filler-water-1',
- 'filler-garden-1',
- 'extension-row-1',
- 'extension-row-2',
- 'extension-row-3',
- 'extension-row-4',
- 'extension-pond-1',
- 'extension-pond-2',
- 'extension-pond-3',
- 'extension-pond-4',
- 'extension-pool-1',
- 'extension-pool-2',
- 'extension-pool-3',
- 'extension-pool-4',
- 'extension-garden-1',
- 'extension-garden-2',
- 'extension-garden-3',
- 'extension-garden-4',
- 'extension-plaza-1',
- 'extension-plaza-2',
- 'extension-plaza-3',
- 'extension-plaza-4',
- 'extension-major-1',
- 'extension-major-2',
- 'extension-major-3',
- 'extension-major-4'
- }
- LOCS = {}
- --########################### LOGIC CODE
- function buildGrid(w)
- local grid = {}
- for x=0,w-1 do
- for z=0,w-1 do
- table.insert(grid,{x=x,z=z})
- print("zone loc at: ",x,z)
- end
- end
- return grid
- end
- LOCS = buildGrid(2)
- function newPlayerData(name,x,y,z)
- local p = {
- name = name,
- x=x,
- y=y,
- z=z
- }
- return p
- end
- local function getAllPos(selector)
- local result, message = commands.tp("@a["..selector.."]","~ ~ ~")
- local names = {}
- if result == true then
- for i,result in ipairs(message) do
- local wordpattern = "[^, ]+"
- local numberpattern = "[%-% ]%d+[%.]%d+"
- local words,numbers = {},{}
- for word in string.gmatch(result, wordpattern) do
- table.insert(words,word)
- end
- for number in string.gmatch(result, 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]
- table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
- end
- end
- return names
- end
- local function shuffleTable( t )
- local rand = math.random
- assert( t, "shuffleTable() expected a table, got nil" )
- local iterations = #t
- local j
- for i = iterations, 2, -1 do
- j = rand(i)
- t[i], t[j] = t[j], t[i]
- end
- end
- local function getAllOnBlockType(block,selector)
- local result, message = commands.exec("execute @a["..selector.."] ~ ~ ~ detect ~ ~-1 ~ "..block.." -1 tp @p[r=1] ~ ~ ~")
- local names = {}
- if result == true then
- for i,result in ipairs(message) do
- local wordpattern = "[^, ]+"
- local numberpattern = "[%-% ]%d+[%.]%d+"
- local words,numbers = {},{}
- for word in string.gmatch(result, wordpattern) do table.insert(words,word) end
- for number in string.gmatch(result, numberpattern) do table.insert(numbers,number) end
- if numbers[1] and numbers[2] and numbers[3] then
- local coords = {
- x = math.floor(numbers[1]),
- y = math.floor(numbers[2]),
- z = math.floor(numbers[3])
- }
- local name = words[2]
- table.insert(names,newPlayerData(name,coords.x,coords.y,coords.z))
- else
- print("Error: Coordinate Numbers were missing")
- end
- end
- end
- return names
- end
- local function spawnVillager(x,y,z)
- 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"]}}} ]}}')
- end
- local function displayTime(selector,minutes,seconds)
- commands.title("@a["..selector.."]","subtitle",'{text:"'..minutes..":"..seconds..'",color:red,bold:false,underlined:false,italic:false,strikethrough:false,obfuscated:false}')
- end
- local function displayTitle(selector,text)
- commands.title("@a["..selector.."]","title",'{text:"'..text..'"}')
- end
- local function displayTitleToGroup(playerlist,text)
- for i,player in ipairs(playerlist) do
- displayTitle("name="..player.name,text)
- end
- end
- local function displayTimeToGroup(playerlist,minutes,seconds)
- for i,player in ipairs(playerlist) do
- displayTime("name="..player.name,minutes,seconds)
- end
- end
- local function teleportToPoint(x,y,z,playerlist)
- for i,player in ipairs(playerlist) do
- player.x = x
- player.y = y
- player.z = z
- commands.tp("@a[name="..player.name.."]",x,y,z)
- end
- end
- local function teleportToZone(buildzone,playerlist)
- teleportToPoint(buildzone.x+(buildzone.w/2),buildzone.y+2,buildzone.z+(buildzone.w/2),playerlist)
- end
- local function giveItems(playerlist,itemlist)
- local given = 0
- for i,player in ipairs(playerlist) do
- commands.async.clear(player.name)
- for j,item in ipairs(itemlist) do
- commands.async.give("@a[name="..player.name.."]",item)
- given = given +1
- end
- end
- return given
- end
- local function makeVocabZones(quant,w)
- local x,y,z = ox,oy,oz+6
- local result = {}
- local namecount = 1
- for i=0,quant-1 do
- for k=0,3 do
- local zpos = i-4
- local ypos = k
- local nextVocab = newVocabZone(x-(2*w)-6,y+(ypos*(VOCAB_HEIGHT+3)),z+((w+1)*zpos),w,REWARDS[namecount] or DEFAULT_REWARD,VOCAB_NAMES[namecount] or DEFAULT_NAME)
- table.insert(result,nextVocab)
- namecount = namecount +1
- end
- end
- return result
- end
- local function findNextLoc(width)
- local x,y,z = 0,0,0
- --local ox,oy,oz = 10000,oy,10000
- for i,loc in ipairs(LOCS) do
- x,y,z = ox+(loc.x*(width+1)),oy,oz+6+(loc.z*(width+1))
- local result,message = commands.testforblock(x,y+BUILDZONE_FLOOR_HEIGHT,z,"minecraft:air")
- --print("next position free is ",loc.x*width,oy,loc.z*width)
- --if result then print("true") else print("false") end
- if result then
- print("using loc: ",loc.x,loc.z)
- return x,y,z
- end
- end
- return ox,oy,oz+6
- end
- function moveBuildzone(buildzone)
- local x,y,z = findNextLoc(buildzone.w)
- local w = buildzone.w
- buildzone.x,buildzone.y,buildzone.z = x,y+BUILDZONE_FLOOR_HEIGHT,z
- buildzone.selector = "x="..x..",y="..y..",z="..z..",dx="..w..",dy=256,dz="..w
- buildzone.structures = {} --a list of all vocabularies which have been contructed
- end
- local function makeBuildzones(quant,vocab,width,height)
- --local x,y,z = ox+(VOCAB_WIDTH*3),oy,oz+6
- local x,y,z = ox,oy,oz+6
- x,y,z = findNextLoc(width)
- return {
- newBuildZone(x,y+height,z,width,vocab)
- }
- --local result = {}
- --for i=0,quant-1 do
- --table.insert(result,newBuildZone(x,y+height,z+(i*(width+20)),width,vocab))
- --end
- --return result
- end
- --########################### GAME MANAGER CODE
- function newVocabZone(x,y,z,w,reward,name)
- local nvz = {}
- nvz.x ,nvz.y ,nvz.z ,nvz.w = x,y,z,w
- nvz.cx = nvz.x - nvz.w - 2
- nvz.cy = nvz.y
- nvz.cz = nvz.z
- nvz.name = name
- nvz.reward = reward
- return nvz
- end
- function newBuildZone(x,y,z,w,vocabZones)
- local nbz = {}
- nbz.x ,nbz.y ,nbz.z ,nbz.w = x,y,z,w
- nbz.selector = "x="..x..",y="..y..",z="..z..",dx="..w..",dy=256,dz="..w
- nbz.structures = {} --a list of all vocabularies which have been contructed
- nbz.vocab = vocabZones
- return nbz
- end
- function newQueue(buildzone,maxplayers)
- local q = {}
- q.timer = 1
- q.phase = 1
- q.victory = false
- q.phases = {
- {
- name = "Selecting Players",
- length = 25,
- displaylength = 15
- },
- {
- name = "Game In Progress",
- length = 5000,
- displaylength = 70
- },
- {
- name = "Round Complete",
- length = 15,
- displaylength = 5
- }
- }
- q.playerlist = {}
- q.maxplayers = maxplayers
- q.buildzone = buildzone
- if DEBUG_MODE then
- --q.phase = 2
- --q.timer = 5000
- end
- return q
- end
- --[[function fillRing(x,y,z,w,block)
- commands.fill(x-1,y,z-1,x+1+w,y,z-1,block)
- commands.fill(x+1+w,y,z-1,x+1+w,y,z+1+w,block)
- commands.fill(x-1,y,z+1+w,x+1+w,y,z+1+w,block)
- commands.fill(x-1,y,z+1+w,x-1,y,z-1,block)
- end]]
- function fillRing(x,y,z,w,block)
- commands.fill(x,y,z,x+w,y,z,block)
- commands.fill(x+w,y,z,x+w,y,z+w,block)
- commands.fill(x,y,z+w,x+w,y,z+w,block)
- commands.fill(x,y,z+w,x,y,z,block)
- end
- function setup()
- local game = {}
- game.vocab = {}
- game.builds = {}
- game.queues = {}
- game.waitlist = {}
- game.spawn = SPAWN
- game.lastClock = os.clock()
- game.nowTime = os.clock()
- --kill all villagers
- commands.exec("kill @e[type=Villager]")
- --buildzone and vocabzone creation
- game.vocab = makeVocabZones(NUMBER_OF_VOCAB,VOCAB_WIDTH)
- game.builds = makeBuildzones(NUMBER_OF_BUILDZONES,game.vocab,BUILDZONE_WIDTH,BUILDZONE_FLOOR_HEIGHT)
- for i,build in ipairs(game.builds) do
- table.insert(game.queues,newQueue(build,4))
- cleanBuildzone(build)
- prepareBuildzone(build)
- end
- for i,vz in ipairs(game.vocab) do
- local x,y,z,w = vz.x,vz.y,vz.z,vz.w
- local cx,cy,cz = vz.cx,vz.cy,vz.cz
- --commands.fill(x,y-1,z,x+w-1,y-1,z+w-1,BLOCKS.VOCAB_DETECT)
- --commands.fill(cx,cy-1,z,cx+w-1,cy-1,cz+w-1,BLOCKS.VOCAB_REPLACE)
- --commands.fill(x,y-1,z,x+w-1,y+10,z+w-1,'minecraft:dirt',"replace","minecraft:air")
- --commands.fill(cx,cy-1,z,cx+w-1,cy+10,cz+w-1,'minecraft:dirt',"replace","minecraft:air")
- --commands.setblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.VOCAB_REPLACE)
- --commands.setblock(x+(math.floor(w/2)),y-1,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD)
- --commands.setblock(cx+(math.floor(w/2)),cy-1,cz+(math.floor(w/2)),BLOCKS.VOCAB_DETECT)
- local detector, message1 = commands.testforblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT)
- local blocker, message2 = commands.testforblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD)
- if not (detector or blocker) then
- for nx=0,2 do
- for nz=0,2 do
- commands.setblock(x+(nx*9)+4,y-1,z+(nz*9)+4,BLOCKS.VOCAB_REPLACE)
- --commands.setblock(x+(nx*9)+4,y,z+(nz*9)+4,BLOCKS.DETECT_DEAD)
- commands.setblock(cx+(nx*9)+4,cy-1,cz+(nz*9)+4,BLOCKS.VOCAB_DETECT)
- end
- end
- commands.setblock(x+(math.floor(w/2)),y,z+(math.floor(w/2)),BLOCKS.DETECT_DEAD)
- end
- end
- if DEBUG_MODE then
- --commands.setblock(x,y,z,'minecraft:redstone_block')
- --commands.setblock(cx,cy,cz,'minecraft:emerald_block')
- for i,build in ipairs(game.builds) do
- build.phase = 2
- build.timer = 5000
- end
- end
- return game
- end
- function update(game)
- local elapsed = updateClock(game)
- --update players
- checkPlayers(game)
- --if not DEBUG_MODE then
- doTimerUpdates(game,elapsed)
- --end
- doPhaseUpdates(game)
- doPhaseEnds(game)
- checkBoundaries(game)
- cullVillagers()
- if #game.waitlist > 0 then allocateWaiters(game) end
- end
- function cullVillagers()
- --add lifetime to villagers
- commands.exec("scoreboard players add @e[type=Villager] VillagerLife 1")
- --cull old villagers
- commands.exec("tp @e[type=Villager,score_VillagerLife_min=50] ~ ~256 ~")
- commands.exec("kill @e[type=Villager,score_VillagerLife_min=50]")
- end
- function updateClock(game)
- game.nowTime = os.clock()
- local elapsed = game.nowTime - game.lastClock
- game.lastClock = game.nowTime
- return elapsed
- end
- function doTimerUpdates(game,elapsed)
- for i,kew in ipairs(game.queues) do
- kew.timer = kew.timer - elapsed
- end
- end
- function checkBoundaries(game)
- for i,kew in ipairs(game.queues) do
- if kew.phase > 1 then
- --boundaries
- local x_min = kew.buildzone.x
- local x_max = kew.buildzone.x+kew.buildzone.w
- local z_min = kew.buildzone.z
- local z_max = kew.buildzone.z+kew.buildzone.w
- local toBeCorrected = {}
- for j,player in ipairs(kew.playerlist) do
- local changed = false
- if player.x > x_max then
- changed = true
- player.x = x_max
- end
- if player.x < x_min then
- changed = true
- player.x = x_min
- end
- if player.z > z_max then
- changed = true
- player.z = z_max
- end
- if player.z < z_min then
- changed = true
- player.z = z_min
- end
- if changed then teleportToPoint(player.x,kew.buildzone.y,player.z,{player}) end
- end
- end
- end
- end
- function cleanAfterVictory(buildzone)
- commands.setblock(buildzone.x,buildzone.y,buildzone.z,BLOCKS.VICTORY_MARKER)
- fillRing(buildzone.x,buildzone.y-1,buildzone.z,buildzone.w,BLOCKS.CAMP_FLOOR)
- for h=0,VICTORY_HEIGHT do
- commands.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air 0","replace","minecraft:diamond_block 0")
- end
- end
- function doPhaseUpdates(game)
- for i,kew in ipairs(game.queues) do
- local minutes = string.format("%02d",math.floor(kew.timer/60))
- local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
- if kew.timer <= 0 then
- minutes = "00"
- seconds = "00"
- end
- if kew.phase == 1 then
- --waiting phase
- if #kew.playerlist == kew.maxplayers and kew.timer > 5 then kew.timer = 5 end
- if not DEBUG_MODE and #kew.playerlist == 0 then kew.timer = kew.phases[1].length end
- displayTitleToGroup(kew.playerlist,"Waiting for Game to Start")
- displayTimeToGroup(kew.playerlist,minutes,seconds)
- --show countdown
- elseif kew.phase == 2 then
- --playing phase
- if #kew.playerlist == 0 then timer = 0 end -- finish if all players quit
- local victory = updatePlayedZone(kew.buildzone) -- do vocab logic
- --check for victory or defeat
- if victory then
- kew.victory = true
- --tell all in zone that victory was achieved
- if kew.timer > 5 then kew.timer = 5 end
- cleanAfterVictory(kew.buildzone)
- end
- --show countdown when time is almost done
- if kew.victory then
- displayTitle(kew.buildzone.selector,"Success!")
- elseif kew.timer < kew.phases[2].displaylength then
- displayTitle(kew.buildzone.selector,"Hurry Up!")
- displayTime(kew.buildzone.selector,minutes,seconds)
- end
- elseif kew.phase == 3 then
- --end phase
- if #kew.playerlist == 0 then kew.timer = 0 end --if playerlist == 0 then timer = 0
- if kew.victory then --show congratulation message if kew.victory
- displayTitle(kew.buildzone.selector,"You Win!")
- else
- displayTitle(kew.buildzone.selector,"Time's Up!")
- end
- displayTime(kew.buildzone.selector,minutes,seconds)
- end
- end
- end
- function forceObserverStatus(x,y,z,playerlist)
- for i,player in ipairs(playerlist) do
- commands.gamemode('spectator',player.name)
- commands.tp(x,y,z,-45,45,0,player.name)
- end
- end
- function doPhaseEnds(game)
- for i,kew in ipairs(game.queues) do
- if kew.timer <= 0 then
- if kew.phase == 1 then
- --waiting phase ends goto play phase
- moveBuildzone(kew.buildzone)
- cleanBuildzone(kew.buildzone)
- prepareBuildzone(kew.buildzone)--prepare build zone
- teleportToZone(kew.buildzone,kew.playerlist)--teleport selected players
- giveItems(kew.playerlist,STARTING_ITEMS) --give starting items
- displayTitle(kew.buildzone.selector,"Build!")
- kew.victory = false
- kew.phase = 2
- kew.timer = kew.phases[2].length
- elseif kew.phase == 2 then
- --playing phase ends goto end phase
- --move players to observation point and mode
- forceObserverStatus(kew.buildzone.x,kew.buildzone.y+25,kew.buildzone.z,kew.playerlist)
- kew.phase = 3
- kew.timer = kew.phases[3].length
- elseif kew.phase == 3 then
- --end phase ends goto waiting phase
- fillRing(kew.buildzone.x,kew.buildzone.y+VICTORY_HEIGHT,kew.buildzone.z,kew.buildzone.w,"minecraft:air")
- respawnPlayers(game,kew)
- kew.phase = 1
- kew.timer = kew.phases[1].length
- end
- end
- end
- end
- --Replaces everything that is needed to start the game. Does not rebuild the floor, or clear anything away.
- --based on the settings it creates a full grid, or a partial grid, or no grid
- --it also places the ring, although this is disabled for now
- function prepareBuildzone(buildzone)
- local bz = buildzone
- local x,y,z,w = bz.x,bz.y,bz.z,bz.w
- --commands.fill(x,y-1,z,x+w,y-1,z+w,BLOCKS.CAMP_FLOOR)
- fillRing(buildzone.x,buildzone.y-1,buildzone.z,buildzone.w,BLOCKS.CONSTRUCTION)
- if DO_GRID then
- for x=0,6 do
- for z=0,6 do
- local rand = math.random()*100
- if rand > GRID_HOLE_CHANCE then
- commands.setblock(bz.x+(x*9)+4,bz.y,bz.z+(z*9)+4,BLOCKS.DETECT)
- end
- end
- end
- end
- fillRing(buildzone.x,buildzone.y+VICTORY_HEIGHT,buildzone.z,buildzone.w,BLOCKS.RING)
- end
- --deletes everything inside the buildzone, except the ring and the floor
- function cleanBuildzone(buildzone)
- print("Cleaning buildzone")
- for h=0,VICTORY_HEIGHT+20 do
- commands.fill(buildzone.x,buildzone.y+h,buildzone.z,buildzone.x+buildzone.w,buildzone.y+h,buildzone.z+buildzone.w,"minecraft:air")
- end
- end
- --moves all players assigned to the queue into the waiting area for the provided game.
- --It also changes them to Adventure mode and clears their inventory
- function respawnPlayers(game,kew)
- teleportToPoint(game.spawn.x,game.spawn.y,game.spawn.z,kew.playerlist) --put players back in spawn area
- for i,player in ipairs(kew.playerlist) do
- table.insert(game.waitlist,player)
- commands.gamemode('adventure',player.name)
- commands.clear(player.name)
- end
- kew.playerlist = {}
- end
- function checkPlayers(game)
- local loggedIn = getAllPos("m=2,name=!Abregado")
- --print("detected players "..#loggedIn)
- --check current waiting players
- for i,waiter in ipairs(game.waitlist) do
- local isPlaying = false
- for j, player in ipairs(loggedIn) do
- if player.name == waiter.name then
- isPlaying = true
- table.remove(loggedIn,j)
- --break
- end
- end
- if not isPlaying then
- table.remove(game.waitlist,i)
- print("Removed "..waiter.name.." from waiting list")
- end
- end
- --check currently playing players
- for l,kew in ipairs(game.queues) do
- for i,builder in ipairs(kew.playerlist) do
- local isPlaying = false
- for j, player in ipairs(loggedIn) do
- if player.name == builder.name then
- isPlaying = true
- builder.x = player.x
- builder.y = player.y
- builder.z = player.z
- table.remove(loggedIn,j)
- --break
- end
- end
- if not isPlaying then
- table.remove(kew.playerlist,i)
- print("Removed "..builder.name.." from game in progress")
- end
- end
- end
- --add remaining players to waitlist
- for i,newPlayer in ipairs(loggedIn) do
- newPlayer.x = game.spawn.x
- newPlayer.y = game.spawn.y
- newPlayer.z = game.spawn.z
- commands.gamemode('adventure',newPlayer.name)
- teleportToPoint(newPlayer.x,newPlayer.y,newPlayer.z,{newPlayer})
- table.insert(game.waitlist,newPlayer)
- print("Added "..newPlayer.name.." to waitlist")
- end
- end
- function allocateWaiters(game)
- --find free slots
- local freeslots = {}
- for i, kew in ipairs(game.queues) do
- if kew.phase == 1 and #kew.playerlist < kew.maxplayers then
- local slots = kew.maxplayers - #kew.playerlist
- for j=1,slots do
- table.insert(freeslots,kew)
- end
- end
- end
- shuffleTable(game.waitlist)
- shuffleTable(freeslots)
- while #freeslots > 0 and #game.waitlist > 0 do
- local player = table.remove(game.waitlist,1)
- local freeslot = table.remove(freeslots,1).playerlist
- table.insert(freeslot,player)
- end
- end
- function updatePlayedZone(buildzone)
- local victory = false
- local buildzoneSelector = buildzone.selector
- --get all players on diamond
- local detectLocations = getAllOnBlockType("minecraft:diamond_block",buildzoneSelector)
- --DO PARTICLE EFFECTS IF ON A DETECTING BLOCK
- for i,loc in ipairs(detectLocations) do
- if i == 1 then
- commands.particle("fireworksSpark",loc.x,loc.y+1,loc.z,0.01,0.01,0.01,0.1,10)
- end
- commands.particle("happyVillager",loc.x,loc.y+1,loc.z,0.1,0.1,0.1,0.1,10)
- end
- if #detectLocations > 0 then
- local x,y,z,name = detectLocations[1].x,detectLocations[1].y,detectLocations[1].z,detectLocations[1].name
- --print(#buildzone.vocab.." vocabs in detected zone")
- for i,vocab in ipairs(buildzone.vocab) do
- 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")
- --print(message[1])
- if result then
- --commands.say("Found vocab "..i)
- print(name.." built vocab "..i)
- 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")
- if DEBUG_MODE then
- print(clonemes[1])
- end
- commands.give(name,vocab.reward)
- commands.playsound("random.levelup",name)
- commands.tellraw(name,'["",{"text":"You built a '..vocab.name.. ' and received more building materials!!","color":"green"}]')
- table.insert(buildzone.structures,vocab.name)
- local count = 0
- for i,struct in ipairs(buildzone.structures) do
- if struct == VICTORY_SPECIFIC.name then
- count = count +1
- end
- --print(struct)
- end
- --SPECIFIC VICTORY CODE
- if count >= VICTORY_SPECIFIC.count then
- victory = true
- print("Specific count victory achieved")
- end
- --TOTAL STRUCTURES VICTORY CODE
- if #buildzone.structures > VICTORY_TOTAL then
- victory = true
- print("Victory")
- for i,struct in ipairs(buildzone.structures) do
- print(struct)
- end
- end
- --HEIGHT VICTORY CODE
- if detectLocations[1].y >= buildzone.y+VICTORY_HEIGHT then
- victory = true
- print("Victory was Triggered at",detectLocations[1].x,detectLocations[1].y,detectLocations[1].z)
- end
- break
- end
- end
- table.remove(detectLocations,1)
- end
- --check that each buildzone has a villager
- local hasVillager,message = commands.testfor("@e[type=Villager,"..buildzoneSelector.."]")
- if hasVillager == false and SPAWN_VILLAGER then
- spawnVillager(buildzone.x+(buildzone.w/4),buildzone.y+1,buildzone.z+(buildzone.w/4))
- end
- return victory
- end
- function debugDisplay(game)
- monitor.clear()
- if blink then
- monitor.setCursorPos(1,1)
- monitor.setTextColor(colors.red)
- monitor.write("Running")
- monitor.setTextColor(colors.white)
- redstone.setOutput("top",true)
- blink = false
- else
- redstone.setOutput("top",false)
- blink = true
- end
- local line = 2
- for i,kew in ipairs(game.queues) do
- monitor.setCursorPos(1,line)
- local minutes = string.format("%02d",math.floor(kew.timer/60))
- local seconds = string.format("%02d",math.floor(kew.timer - (minutes*60)))
- monitor.write("Buildzone "..i.." | Phase: "..kew.phase.." | Time: "..minutes..":"..seconds)
- monitor.setCursorPos(1,line+1)
- for i,player in ipairs(kew.playerlist) do
- monitor.write(player.name.." ")
- end
- line = line +2
- end
- monitor.setCursorPos(1,10)
- for i,player in ipairs(game.waitlist) do
- monitor.write(player.name.." ")
- end
- end
- local blink = true
- local game = setup()
- while true do
- update(game)
- if monitor then debugDisplay(game) end
- commands.weather("clear",10000)
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement