Created
August 27, 2018 13:32
-
-
Save mkarneim/4782482e4d557b344c2bbbb2168f18fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- lobby.lua | |
| -- /lua require('lobby').start({gameName="last-man-standing", arenaName='gold', width=4, height=2, minPlayers=2, maxPlayers=4}) | |
| local pkg = {} | |
| local module = ... | |
| local startGame | |
| local terminate | |
| local playSound | |
| local playNote | |
| local singleton | |
| local log | |
| local notes={c=0.7,d=0.8,e=0.9,f=0.95,g=1.05} | |
| local DELAY = 3 | |
| local spellPos | |
| local gameName | |
| local arenaName | |
| local width | |
| local height | |
| function pkg.start(options) | |
| if not options then | |
| error("Missing mandatory parameter options") | |
| end | |
| if not options.gameName then | |
| error("Missing mandatory parameter options.gameName") | |
| else | |
| gameName = options.gameName | |
| end | |
| if not options.arenaName then | |
| error("Missing mandatory parameter options.arenaName") | |
| else | |
| arenaName = options.arenaName | |
| end | |
| if not options.width then | |
| error("Missing mandatory parameter options.width") | |
| else | |
| width = options.width | |
| end | |
| if not options.height then | |
| error("Missing mandatory parameter options.height") | |
| else | |
| height = options.height | |
| end | |
| if not options.minPlayers then | |
| error("Missing mandatory parameter options.minPlayers") | |
| else | |
| minPlayers = options.minPlayers | |
| end | |
| if not options.maxPlayers then | |
| error("Missing mandatory parameter options.maxPlayers") | |
| else | |
| maxPlayers = options.maxPlayers | |
| end | |
| singleton(module.."."..arenaName) | |
| spellPos = spell.pos:floor() | |
| local corner = Vec3(spellPos.x - width/2, spellPos.y, spellPos.z - width/2) | |
| local delta = Vec3(width, height, width) | |
| local selector = string.format("@e[dx=%s,dy=%s,dz=%s]", delta.x, delta.y, delta.z) | |
| local delay = nil | |
| while true do | |
| sleep(20) | |
| spell.pos = corner | |
| local entities = Entities.find(selector) | |
| local players = {} | |
| --log("Found #%s", #entities) | |
| for _,entity in pairs(entities) do | |
| --log("Found %s", entity.name) | |
| table.insert(players,entity) | |
| end | |
| if minPlayers <= #entities and #players <= maxPlayers then | |
| if not delay then | |
| delay = 0 | |
| else | |
| delay = delay + 1 | |
| end | |
| if delay < 3 then | |
| playSound("countdown") | |
| else | |
| playSound("start") | |
| startGame(players) | |
| end | |
| else | |
| delay = nil | |
| end | |
| end | |
| end | |
| function startGame(players) | |
| local playerNames = {} | |
| for _,player in pairs(players) do | |
| table.insert(playerNames, player.name) | |
| end | |
| spell:execute([[/lua require('%s').start("%s", %s)]], gameName, arenaName, str(playerNames)) | |
| terminate() | |
| end | |
| function terminate() | |
| spell:execute([[/wol spell break byName "%s"]], spell.name) | |
| end | |
| function playSound(name) | |
| if name == "countdown" then | |
| spell:execute([[/playsound minecraft:block.note.bass block @a[r=10] ~ ~ ~ 10]]) | |
| end | |
| if name == "start" then | |
| playNote(notes.c) | |
| playNote(notes.e) | |
| playNote(notes.g) | |
| end | |
| end | |
| function playNote(note) | |
| spell:execute([[ | |
| /playsound minecraft:block.note.pling block @a[r=10] ~ ~ ~ 1 %s | |
| ]], note) | |
| end | |
| function singleton(name) | |
| spell:execute([[/wol spell break byName "%s"]], name) | |
| spell.name = name | |
| end | |
| -- Logs the given message into the chat | |
| function log( message, ...) | |
| local n = select('#', ...) | |
| if n>0 then | |
| message = string.format(message, ...) | |
| end | |
| spell:execute([[ | |
| /say %s | |
| ]], message) | |
| end | |
| return pkg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment