Advertisement
Illuminatos

Frame-Elevator: Client

Aug 5th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.05 KB | None | 0 0
  1. local pos_modem
  2. local up
  3. local down
  4. local call
  5. local stage
  6. local height
  7.  
  8. function getData()
  9.   write("Position des Modems: ")
  10.   pos_modem=io.read()
  11.   write("Seite des Redstone-Signals 'Hoch': ")
  12.   up=io.read()
  13.   write("Seite des Redstone-Signals 'Runter': ")
  14.   down=io.read()
  15.   write("Seite des Redstone-Signals 'Rufen': ")
  16.   call=io.read()
  17.   write("Stockwerk dieses Clients: ")
  18.   stage=io.read()
  19.   write("Hoehe (y-Wert) dieses Stockwerks: ")
  20.   height=io.read()
  21. end
  22.  
  23. function checkData()
  24.   if(fs.exists("client.cfg")) then
  25.     config=fs.open("client.cfg", "r")
  26.     pos_modem=config.readLine()
  27.     stage=config.readLine()
  28.     up=config.readLine()
  29.     down=config.readLine()
  30.     call=config.readLine()
  31.     height=tonumber(config.readLine())
  32.     config.close()
  33.     print("Alte Konfiguration eingelesen!")
  34.   else
  35.     getData()
  36.     saveData()
  37.   end
  38. end
  39.  
  40. function saveData()
  41.   config=fs.open("client.cfg", "w")
  42.   config.writeLine(pos_modem)
  43.   config.writeLine(stage)
  44.   config.writeLine(up)
  45.   config.writeLine(down)
  46.   config.writeLine(call)
  47.   config.writeLine(height)
  48.   config.close()
  49. end
  50.  
  51. function receiveRedstone()
  52.   while (true) do
  53.     os.pullEvent("redstone")
  54.     if(redstone.getInput(up)) then
  55.       rednet.broadcast("move,"..stage+1)
  56.     elseif(redstone.getInput(down)) then
  57.       rednet.broadcast("move,"..stage-1)
  58.     elseif(redstone.getInput(call)) then
  59.       rednet.broadcast("move,"..stage)
  60.     end
  61.   end
  62. end
  63.  
  64. function logon()
  65.   rednet.broadcast("logon,"..stage..","..height)
  66.   sleep(1)
  67.   id, message, distance = rednet.receive()
  68.   print(message)
  69. end
  70.  
  71. function split(str, pat)
  72.    local t = {}
  73.    local fpat = "(.-)" .. pat
  74.    local last_end = 1
  75.    local s, e, cap = str:find(fpat, 1)
  76.    while s do
  77.       if s ~= 1 or cap ~= "" then
  78.      table.insert(t,cap)
  79.       end
  80.       last_end = e+1
  81.       s, e, cap = str:find(fpat, last_end)
  82.    end
  83.    if last_end <= #str then
  84.       cap = str:sub(last_end)
  85.       table.insert(t, cap)
  86.    end
  87.    return t
  88. end
  89.  
  90. checkData()
  91. rednet.open(pos_modem)
  92. logon()
  93. receiveRedstone()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement