Advertisement
Guest User

reexp

a guest
Sep 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. -- FUNCTIONS
  2. local function clear(z,x)
  3.     if z == nil or x == nil then z = 1 x = 1 end
  4.     term.setCursorPos(x,x)
  5.     term.clear()
  6. end
  7.  
  8. local function printUsage()
  9.     print("Usage: ")
  10.     print[[
  11. reexp <Direction>
  12. reexp <Direction> time
  13. reexp wireless
  14. reexp <Direction> receiver]]
  15. end
  16. local function timer(from, to, ra, text)
  17.     if from == nil or to == nil then print("Please enter the numbers.") return end
  18.     if ra == nil then ra = 1 end
  19.     clear()
  20.     while true do
  21.         print(text, from)
  22.         sleep(ra)
  23.         clear()
  24.         if from > to then
  25.             from = from - ra
  26.             if from == to then
  27.                 break
  28.             end
  29.         elseif from < to then
  30.             from = from + ra
  31.             if from == to then
  32.                 break
  33.             end
  34.         end
  35.     end
  36. end
  37.  
  38. local function openModems()
  39.     for _, sModems in ipairs( peripheral.getNames() ) do
  40.         if peripheral.getType( sModems ) == "modem" then
  41.             if not rednet.isOpen( sModems ) then
  42.                 rednet.open( sModems )
  43.             end
  44.             return true
  45.         end
  46.     end
  47.     print("no modems found, please place one and try again.")
  48.     return false
  49. end
  50.  
  51. local function redraw(text, var1)
  52.         if not text then printError("enter text") end
  53.         clear()
  54.         write(text)
  55.         term.setBackgroundColor( colors.lightGray )
  56.         write(var1)
  57.         term.setBackgroundColor( colors.black )
  58.     end
  59. -- -------VARIABLES
  60. --Dierction
  61. local dirc = {"right", "Right", "Left", "left", "Bottom", "bottom", "Top", "top", "front", "back"}
  62. --VERSION
  63. local version = "1.0"
  64. -- LOCAL
  65. local tArgs = { ... }
  66. if #tArgs > 2 or #tArgs == 0 then
  67.     printUsage()
  68.     return false
  69. end
  70.  
  71.  
  72. local sCommand = tArgs[1]
  73. local nCommand = tArgs[2]  
  74. local function matdir()
  75.     for n, ndir in ipairs( dirc ) do
  76.         if sCommand == ndir then
  77.             return true
  78.         end
  79.     end
  80. end
  81. if #tArgs == 1 then
  82.     for n, ns in ipairs( dirc ) do
  83.         if sCommand == ns then
  84.             clear()
  85.             timer(10, 0, 1, "The explosion after: ")
  86.             print("explosion!!!")
  87.             rs.setOutput(sCommand, true)
  88.             sleep(1)
  89.             rs.setOutput(sCommand, false)
  90.         end
  91.     end
  92. elseif nCommand == "time" and matdir() == true then
  93.     local chTime = 5
  94.     local localTime = "s"
  95.     local conTime = chTime.. localTime
  96.     local maxm = 5
  97.     local lowm = 1
  98.     local maxs = 55
  99.     local lows = 5
  100.     local mrate = 1
  101.     local srate = 5
  102.     local mtos = {}
  103.     redraw("Choose your time: ", conTime)
  104.     while true do
  105.         local e, but = os.pullEvent()
  106.         if e == "key" then
  107.             if but == 200 and localTime == "s" then
  108.                 chTime = chTime + srate
  109.                 if chTime > maxs then chTime = lowm localTime = "m" end
  110.             elseif but == 208 and localTime == "s" then
  111.                 chTime = chTime - srate
  112.                 if chTime < lows then chTime = maxm localTime = "m" end
  113.             elseif but == 200 and localTime == "m" then
  114.                 chTime = chTime + mrate
  115.                 if chTime > maxm then chTime = lows localTime = "s" end
  116.             elseif but == 208 and localTime == "m" then
  117.                 chTime = chTime - mrate
  118.                 if chTime < lowm then chTime = maxs localTime = "s" end
  119.             end
  120.             conTime = chTime.. localTime
  121.             redraw("Choose your time: ", conTime)
  122.         end
  123.    
  124.         if e == "key" and but == 28 then
  125.             if localTime == "s" then
  126.                 timer(chTime, 0, 1, "The Explostion After: ")
  127.                 print("explosion!!!")
  128.                 rs.setOutput(sCommand, true)
  129.                 break
  130.             elseif localTime == "m" then
  131.             local theSin = 0
  132.            
  133.                 for i=1, chTime do
  134.                     theSin = theSin + 60
  135.                     table.insert(mtos, theSin)
  136.                     chTime = mtos[i]
  137.                 end
  138.                 timer(chTime, 0, 1, "The Explostion After: ")
  139.             print("explosion!!!")
  140.             rs.setOutput(sCommand, true)
  141.             break
  142.             end
  143.         end
  144.     end
  145. elseif nCommand == "wireless" and matdir() == true then
  146.     if not openModems() then
  147.         return
  148.     end
  149.     local numberDraw = 0
  150.     redraw("Receiver ID: ", numberDraw)
  151.     while true do
  152.     local e, but = os.pullEvent()
  153.         if e == "key" then
  154.             if but == 200 then
  155.                 numberDraw = numberDraw + 1
  156.                 redraw("Receiver ID: ", numberDraw)
  157.             elseif but == 208 then
  158.                 numberDraw = numberDraw - 1
  159.                 redraw("Receiver ID: ", numberDraw)
  160.             elseif but == 28 then
  161.                 computerID = numberDraw
  162.                 clear()
  163.                 rednet.send(computerID, "Do your work please")
  164.                 local a,c = rednet.receive()
  165.                 clear()
  166.                 if c == "okay!" then
  167.                     print("explosion!!")
  168.                 end
  169.                 break
  170.             end
  171.             if numberDraw < 0 then clear() numberDraw = 0 redraw("Receiver ID: ", numberDraw) end
  172.         end
  173.     end
  174. elseif nCommand == "receiver" and matdir() == true then
  175.     if not openModems() then
  176.         return
  177.     end
  178.     clear()
  179.     print("i'll receive it!!!, receiver on.")
  180.     sleep(3)
  181.     clear()
  182.     local coid, me = rednet.receive()
  183.     if me == "Do your work please" then sleep(0.5) rednet.send(coid, "okay!") end
  184.     rs.setOutput(sCommand, true)
  185. else
  186.     printUsage()
  187.     return
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement