Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. os.loadAPI("json")
  2. local commandBlock = peripheral.wrap("bottom")
  3.  
  4. local DatabaseFile = ""
  5. local Database = ""
  6. local daysLeft = 0
  7. local saveDaysLeft = 0
  8. local pvp = false
  9. local currentDay = 0
  10. local IsRunning = false
  11.  
  12. function MainGame()
  13.  
  14. if fs.exists("Database.db") then
  15. DatabaseFile = fs.open("Database.db", "w")
  16. Database = textutils.unserialize(DatabaseFile.readAll())
  17. DatabaseFile.close()
  18. else
  19. DatabaseFile = fs.open("Database.db", fs.exists("Database.db") and "a" or "w")
  20. Database['Settings']['DEBUG'] = false
  21. Database['Settings']['playTime'] = 2160
  22. Database['Settings']['savePlayTime'] = 504
  23. Database['Settings']['maxLifes'] = 3
  24. Database['Settings']['JailPos'] = "X Y Z"
  25. Database['Settings']['SpawnPos'] = "X Z"
  26. Database['Settings']['IsRunning'] = false
  27. DatabaseFile.write(textutils.serialize(Database))
  28. DatabaseFile.close()
  29. end
  30. OnStart()
  31. while currentDay <= Database['Settings']['playTime'] and IsRunning == true do
  32. OnDraw()
  33. OnUpdate()
  34. sleep(0.5)
  35. end
  36. OnStop()
  37. end
  38.  
  39. function OnUpdate()
  40. if Database['Settings']['playTime'] - currentDay >= 0 then
  41. daysLeft = Database['Settings']['playTime'] - currentDay
  42. else
  43. daysLeft = 0
  44. end
  45.  
  46. if Database['Settings']['savePlayTime'] - currentDay >= 0 then
  47. saveDaysLeft = Database['Settings']['savePlayTime'] - currentDay
  48. doCommand("scoreboard players set @a deaths 0")
  49. else
  50. saveDaysLeft = 0
  51. if pvp == false then
  52. doCommand("tell @a Pvp is now Allowed!")
  53. doCommand("gamrule keepInventory false")
  54. pvp = true
  55. end
  56. end
  57.  
  58. if os.time() == 12 then
  59. currentDay = currentDay + 1
  60. end
  61.  
  62. if saveDaysLeft == 0 then
  63. doCommand("gamemode 2 @a[score_deaths_min=" .. maxLifes .. "]")
  64. doCommand("clear @a[score_deaths_min=" .. maxLifes .. "]")
  65. end
  66.  
  67. if saveDaysLeft >= 0 then
  68. doCommand("gamemode 2 @a[score_kills_min=1]")
  69. doCommand("clear @a[score_kills_min=1]")
  70. doCommand("tell @a[score_kills_min=1] You are disqualified!")
  71. doCommand("spawnpoint @a[score_kills_min=1] " .. JailPos)
  72. doCommand("kill @a[score_kills_min=1]")
  73. end
  74. end
  75.  
  76. function OnDraw()
  77. local w, h = term.getSize()
  78. term.setBackgroundColor(colors.lightBlue)
  79. term.clear()
  80. term.setCursorPos(1, 1)
  81. printL("Day: " .. tostring(currentDay) .. " / " .. tostring(Database['Settings']['playTime']))
  82. printR("Day's Left: " .. tostring(daysLeft))
  83. term.setCursorPos(1, 2)
  84. printL("Save Day's: " .. tostring(saveDaysLeft))
  85. end
  86.  
  87. function doCommand(cmd)
  88. doCommand(cmd)
  89. if Database['Settings']['DEBUG'] == false then
  90. commandBlock.runCommand()
  91. end
  92. end
  93.  
  94. function OnStart()
  95. doCommand("gamerule commandBlockOutput false")
  96. doCommand("time set 0")
  97. doCommand("gamerule keepInventory true")
  98. doCommand("scoreboard objectives add deaths deathCount Deaths")
  99. doCommand("scoreboard objectives add kills playerKillCount Kills")
  100. doCommand("scoreboard players reset @a")
  101. doCommand("spreadplayers " .. SpawnPos .. " 500 5000 0 @a")
  102. end
  103.  
  104. function OnStop()
  105. doCommand("tell @a The Game is Over!")
  106. doCommand("tell @a We will Anouce you via Email if you have Won")
  107. term.clear()
  108. end
  109.  
  110. function printL(msg)
  111. local w, h = term.getSize()
  112. local x, y = term.getCursorPos()
  113. term.setCursorPos(x, y)
  114. term.write(msg)
  115. end
  116.  
  117. function printC(msg)
  118. local w, h = term.getSize()
  119. local x, y = term.getCursorPos()
  120. x = math.max(math.floor((w / 2) - (#msg / 2)), 0)
  121. term.setCursorPos(x, y)
  122. term.write(msg)
  123. end
  124.  
  125. function printR(msg)
  126. local w, h = term.getSize()
  127. local x, y = term.getCursorPos()
  128. x = math.max(math.floor((w - #msg)), 0)
  129. term.setCursorPos(x, y)
  130. term.write(msg)
  131. end
  132. MainGame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement