libraryaddict

Untitled

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