libraryaddict

Untitled

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