Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("json")
- local commandBlock = peripheral.wrap("bottom")
- local DatabaseFile = ""
- local Database = ""
- local daysLeft = 0
- local saveDaysLeft = 0
- local pvp = false
- local currentDay = 0
- local IsRunning = false
- function MainGame()
- if fs.exists("Database.db") then
- DatabaseFile = fs.open("Database.db", "w")
- Database = textutils.unserialize(DatabaseFile.readAll())
- DatabaseFile.close()
- else
- DatabaseFile = fs.open("Database.db", fs.exists("Database.db") and "a" or "w")
- Database['Settings']['DEBUG'] = false
- Database['Settings']['playTime'] = 2160
- Database['Settings']['savePlayTime'] = 504
- Database['Settings']['maxLifes'] = 3
- Database['Settings']['JailPos'] = "X Y Z"
- Database['Settings']['SpawnPos'] = "X Z"
- Database['Settings']['IsRunning'] = false
- DatabaseFile.write(textutils.serialize(Database))
- DatabaseFile.close()
- end
- OnStart()
- while currentDay <= Database['Settings']['playTime'] and IsRunning == true do
- OnDraw()
- OnUpdate()
- sleep(0.5)
- end
- OnStop()
- end
- function OnUpdate()
- if Database['Settings']['playTime'] - currentDay >= 0 then
- daysLeft = Database['Settings']['playTime'] - currentDay
- else
- daysLeft = 0
- end
- if Database['Settings']['savePlayTime'] - currentDay >= 0 then
- saveDaysLeft = Database['Settings']['savePlayTime'] - currentDay
- doCommand("scoreboard players set @a deaths 0")
- else
- saveDaysLeft = 0
- if pvp == false then
- doCommand("tell @a Pvp is now Allowed!")
- doCommand("gamrule keepInventory false")
- pvp = true
- end
- end
- if os.time() == 12 then
- currentDay = currentDay + 1
- end
- if saveDaysLeft == 0 then
- doCommand("gamemode 2 @a[score_deaths_min=" .. maxLifes .. "]")
- doCommand("clear @a[score_deaths_min=" .. maxLifes .. "]")
- end
- if saveDaysLeft >= 0 then
- doCommand("gamemode 2 @a[score_kills_min=1]")
- doCommand("clear @a[score_kills_min=1]")
- doCommand("tell @a[score_kills_min=1] You are disqualified!")
- doCommand("spawnpoint @a[score_kills_min=1] " .. JailPos)
- doCommand("kill @a[score_kills_min=1]")
- end
- end
- function OnDraw()
- local w, h = term.getSize()
- term.setBackgroundColor(colors.lightBlue)
- term.clear()
- term.setCursorPos(1, 1)
- printL("Day: " .. tostring(currentDay) .. " / " .. tostring(Database['Settings']['playTime']))
- printR("Day's Left: " .. tostring(daysLeft))
- term.setCursorPos(1, 2)
- printL("Save Day's: " .. tostring(saveDaysLeft))
- end
- function doCommand(cmd)
- doCommand(cmd)
- if Database['Settings']['DEBUG'] == false then
- commandBlock.runCommand()
- end
- end
- function OnStart()
- doCommand("gamerule commandBlockOutput false")
- doCommand("time set 0")
- doCommand("gamerule keepInventory true")
- doCommand("scoreboard objectives add deaths deathCount Deaths")
- doCommand("scoreboard objectives add kills playerKillCount Kills")
- doCommand("scoreboard players reset @a")
- doCommand("spreadplayers " .. SpawnPos .. " 500 5000 0 @a")
- end
- function OnStop()
- doCommand("tell @a The Game is Over!")
- doCommand("tell @a We will Anouce you via Email if you have Won")
- term.clear()
- end
- function printL(msg)
- local w, h = term.getSize()
- local x, y = term.getCursorPos()
- term.setCursorPos(x, y)
- term.write(msg)
- end
- function printC(msg)
- local w, h = term.getSize()
- local x, y = term.getCursorPos()
- x = math.max(math.floor((w / 2) - (#msg / 2)), 0)
- term.setCursorPos(x, y)
- term.write(msg)
- end
- function printR(msg)
- local w, h = term.getSize()
- local x, y = term.getCursorPos()
- x = math.max(math.floor((w - #msg)), 0)
- term.setCursorPos(x, y)
- term.write(msg)
- end
- MainGame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement