libraryaddict

Untitled

Apr 21st, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.37 KB | None | 0 0
  1. --Admin console - To be controlled only for official events, also controls everything..
  2. IDBlue = 0
  3. IDRed = 0
  4. IDBlueDoor = 0
  5. IDRedDoor = 0
  6. IDSnowGenerate = 0
  7. IDSnowSpread = 0
  8. IDResetRed = 0
  9. IDResetBlue = 0
  10. IDBlueMonitor = 0
  11. IDRedMonitor = 0
  12. Password = "123"
  13. Hot1 = ""
  14. Hot2 = ""
  15. Hot3 = ""
  16. Hot4 = ""
  17. function CheckID(IDa)
  18.   if IDa == IDBlue or IDa == IDRed or IDa == IDResetRed or IDa == IDResetBlue then
  19.     return true
  20.   else
  21.     return false
  22.   end
  23. end
  24.  
  25. function hotBox(event)
  26.   if not Hot2 then Hot2 = event elseif not Hot3 then Hot3 = event elseif not Hot4 then Hot4 = event end
  27.   term.setCursorPos(1,10)
  28.   lib.clearLine()
  29.   Hot1 = Hot2
  30.   Hot2 = Hot3
  31.   Hot3 = Hot4
  32.   Hot4 = ""
  33.   lib.fillLine(X)
  34.   lib.layout(Hot1, "X")
  35.   lib.layout(Hot2, "X")
  36.   lib.layout(Hot3, "X")
  37.   lib.fillLine(X)
  38. end
  39. lib.Clear()
  40. lib.fillLine()
  41. lib.layout("Welcome to the admin console")
  42. lib.fillLine()
  43. lib.layout()
  44. lib.layout("Please type in password to carry on")
  45. print("")
  46. while true do
  47.   event,param1,param2 = os.pullEventRaw()
  48.   if event == "char" then
  49.     echo = echo..param1
  50.     fake = string.rep("*", string.len(echo))
  51.     lib.clearLine()
  52.     lib.layout(fake)
  53.     lib.cursor(-1)
  54.   elseif event == "key" then
  55.     if param1 == 1 then -- esc
  56.       echo = ""
  57.       lib.clearLine()
  58.       lib.layout()
  59.       lib.cursor(-1)
  60.     elseif param1 == 28 then -- enter
  61.       if echo == password then
  62.         lib.Clear()
  63.         hotBox("Admin Console entered")
  64.         break
  65.       else
  66.         lib.clearLine()
  67.         lib.layout("Incorrect password")
  68.         lib.cursor(-1)
  69.         echo = ""
  70.         hotBox("Idiot typed wrong pass")
  71.       end
  72.     elseif param1 == 14 then -- backspace
  73.       echo = string.sub(echo, 1, -2)
  74.       fake = string.rep("*", string.len(echo))
  75.       lib.clearLine()
  76.       lib.layout(fake)
  77.       lib.cursor(-1)
  78.     end
  79.   elseif event == "terminate" then
  80.     echo = ""
  81.     lib.clearLine()
  82.     lib.layout("[602]Error while trying to process \"terminate\"")
  83.     lib.cursor(-1)
  84.     hotBox("Idiot tried to terminate Admin Console")
  85.   elseif event == "disk" then
  86.     echo = ""
  87.     lib.clearLine()
  88.     lib.layout("Bastard. The mods will logblock you")
  89.     lib.cursor(-1)
  90.   elseif event == "rednet_message" and CheckID(param1) then
  91.     local teamcolor, message = lib.tagView(param2)
  92.     if message == "Snow" then
  93.       hotBox(teamcolor.." started the snow repair")
  94.       Snow()
  95.     elseif message == "force" then
  96.       hotBox(teamcolor.." forced start the game")
  97.       lib.send(IDRedDoor, "Open")
  98.       lib.send(IDBlueDoor, "Open")
  99.     elseif message == "ResetMatch" then
  100.       --Scoreboard FreeForAll reset
  101.     elseif message == "ready" then
  102.       hotBox("Team "..teamcolor.." is ready")
  103.       lib.send(IDBlueMonitor, teamcolor.."Ready")
  104.       lib.send(IDRedMonitor, teamcolor.."Ready")
  105.     elseif message == "Button pushed" then
  106.       hotBox(teamcolor.." button was pushed. Attempting to repair")
  107.       Snow()
  108.     end
  109.   end
  110. end
  111.  
  112. function Snow()
  113.   lib.send(IDSnowGenerate, "Start")
  114.   lib.send(IDSnowSpread, "Start")
  115.   Hot4 = "Admin console started engines"
  116.   hotBox()
  117. end
  118.  
  119. function Busy()
  120.   lib.send(IDBlue, "Busy")
  121.   lib.send(IDRed, "Busy")
  122. end
  123.  
  124. function Busy()
  125.   lib.send(IDBlue, "Not Busy")
  126.   lib.send(IDRed, "Not Busy")
  127. end
  128.  
  129. --Now in control mode
  130. function Welcome()
  131.   BlueReady = false
  132.   RedReady = false
  133.   lib.Clear()
  134.   lib.fillLine()
  135.   lib.layout("Welcome to the admin console")
  136.   lib.fillLine()
  137.   lib.layout()
  138.   lib.layout("Press 1. to repair, 2. To start a match")
  139.   lib.layout("3. To stop the match, 4. To start a tournament")
  140.   lib.layout("5. Stop the doors and repair from working")
  141.   lib.layout("6. Delete high scores, 7. Stop the tournament")
  142.   lib.layout()
  143.   lib.fillLine("X")
  144.   lib.layout("X")
  145.   lib.layout("X")
  146.   lib.layout("X")
  147.   lib.fillLine("X")
  148.   hotBox()
  149.   while true do
  150.     event,param1 = os.pullEvent()
  151.     if event == "char" then
  152.       if param1 == "1" then
  153.         Snow()
  154.       elseif param1 == "2" then
  155.         BeginMatch()
  156.         break
  157.       elseif param1 == "3" then
  158.         StopMatch()
  159.         break
  160.       elseif param1 == "4" then
  161.         StartTourny()
  162.         break
  163.       elseif param1 == "5" then
  164.         LockDown()
  165.         break
  166.       elseif param1 == "6" then
  167.         lib.send(IDBlueMonitor, "DeleteScore")
  168.         lib.send(IDRedMonitor, "DeleteScore")
  169.         hotBox("Admin console deleted High Score")
  170.       elseif param1 == "7" then
  171.         StopTourny()
  172.         break
  173.       end
  174.     elseif event == "rednet_message" then
  175.     end
  176.   end
  177. end
  178.  
  179. function StartTourny()
  180.   lib.Clear()
  181.   lib.fillLine()
  182.   lib.layout("Welcome to the Tourny maker")
  183.   lib.fillLine()
  184.   lib.layout()
  185.   lib.layout()
  186.   lib.layoutOrder("Number of teams: ")
  187.   local x,y = term.getCursorPos()
  188.   term.setCursorPos(23,y-1)
  189.   GamesNo = lib.readLimit(3)
  190.   lib.cursor(1)
  191.   lib.layoutOrder("Number of rounds per game: ")
  192.   local x,y = term.getCursorPos()
  193.   term.setCursorPos(33,y-1)
  194.   RoundsNo = lib.readLimit(1)
  195.   lib.cursor(1)
  196.   repeat
  197.     term.setCursorPos(1, 8)
  198.     lib.layoutOrder("Deathmatch or Timetrials: ")
  199.     local x,y = term.getCursorPos()
  200.     term.setCursorPos(32, y-1)
  201.     StyleNo = lib.readLimit(10)
  202.     lib.cursor(1)
  203.   until StyleNo == "Deathmatch" or StyleNo == "Timetrials"
  204.   if StyleNo == "Timetrials" then
  205.     lib.layoutOrder("How long should each round be: ")
  206.     local x,y = term.getCursorPos()
  207.     term.setCursorPos(37,y-1)
  208.     TimeNo = lib.readLimit(1)
  209.     lib.cursor(1)
  210.   end
  211.   Tourny()
  212. end
  213.  
  214. function Tourny()
  215.   --Write stuff to tell the screen
  216.   lib.send(IDBlueMonitor, "Tourny")
  217.   lib.send(IDRedMonitor, "Tourny")
  218.   lib.Clear()
  219.   lib.fillLine()
  220.   lib.layout("Tourny Mode")
  221.   lib.fillLine()
  222.   lib.layout()
  223.   lib.layout()
  224.   lib.layout("Welcome to Tourny Mode, Press \"S\" to start the tourny")
  225.   lib.layout("You can also press \"B\" to assign one point to blue team")
  226.   lib.layout("Or press \"R\" to assign a point to red team")
  227.   lib.layout("Please dont terminate the program..")
  228.   lib.fillLine()
  229.   hotBox("Entered Tourny Mode")
  230.  
  231.   while true do
  232.     event,param1,param2 = os.pullEvent()
  233.     if event == "rednet_message" then
  234.       if CheckID(param1) then
  235.         if param2 == "Red ready" then            
  236.           RedReady = true
  237.           hotBox("Red signaled they are ready")
  238.           lib.send(IDBlueMonitor, "RedReady")
  239.           lib.send(IDRedMonitor, "RedReady")
  240.         elseif param2 == "Blue ready" then
  241.           BlueReady = true
  242.           hotBox("Blue signaled they are ready")
  243.           lib.send(IDBlueMonitor, "BlueReady")
  244.           lib.send(IDRedMonitor, "BlueReady")
  245.         elseif param2 == "Red repair" then
  246.           hotBox("Red tried to repair. Denied")
  247.           lib.send(IDRed, "Denied")
  248.         elseif param2 == "Blue repair" then
  249.           hotBox("Blue tried to repair. Denied")
  250.           lib.send(IDBlue, "Denied")
  251.         elseif param2 == "Red force" then
  252.           hotBox("Red tried to force start. Denied")
  253.           lib.send(IDRed, "Denied")
  254.         elseif param2 == "Blue force" then
  255.           hotBox("Blue tried to force start. Denied")
  256.           lib.send(IDBlue, "Denied")
  257.         elseif lib.tagView(param2) == "Team" then
  258.           local a,s,d = lib.tagView(param2)
  259.           hotBox("Team "..s.." picked team name: "..d)
  260.           lib.send(IDBlueMonitor, param2)
  261.           lib.send(IDRedMonitor, param2)
  262.         end
  263.       end
  264.     end
  265.   end
  266. end
Advertisement
Add Comment
Please, Sign In to add comment