Advertisement
Guest User

rcpda for ComputerCraft and CCPortable

a guest
Oct 23rd, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 KB | None | 0 0
  1. local tArgs = {...}
  2. local pdat,tvnt,cnslID,pdamtd = {ln = 0,icn = 1,scrn = {},pda = {},},{},os.computerID()
  3. for i,v in pairs(rs.getSides()) do
  4.     if peripheral.getType(v) == "receiver" then
  5.         pdamtd = peripheral.wrap(v) break
  6. end end
  7. local wrtpdln = function(txtln)
  8.     print(txtln)
  9.     if pdamtd.connected() > 0 then
  10.         for i = 1,math.ceil(#txtln/27) do pdat.ln = pdat.ln+1
  11.             pdat.scrn[pdat.ln] = txtln:sub((i-1)*27+1,i*27)
  12.         end
  13.         local ndx = pdat.ln-19
  14.         for i = 1,20 do
  15.             if pdat.scrn[ndx] then
  16.                 for k,v in pairs(pdat.pda) do pdamtd.setText(i,pdat.scrn[ndx],k) end
  17.             end
  18.             ndx = ndx+1
  19.         end
  20.         for i,v in pairs(pdat.pda) do pdamtd.setIcon(3,i) pdamtd.setTitle("Text Update",i) end
  21.     end
  22. end
  23. local rdpdln = function()
  24.     local txtln = ""
  25.     if pdamtd.connected() > 0 then
  26.         write("input from PDA")
  27.         for i,v in pairs(pdat.pda) do pdamtd.setIcon(5,i) pdamtd.setTitle("Enter Text",i) end
  28.         repeat tvnt = {os.pullEvent()}
  29.             if tvnt[1] == "pda_char" then txtln = txtln..tvnt[3]
  30.             elseif tvnt[1] == "pda_key" and tvnt[3] == 14 then
  31.                 txtln = txtln:sub(1,#txtln-1)
  32.             end
  33.             for i = 0,math.floor(#txtln/27) do
  34.                 pdamtd.setText(i,txtln:sub(i*27+1,(i+1)*27),tvnt[2])
  35.             end
  36.         until tvnt[1] == "pda_key" and tvnt[3] == 28
  37.         for i,v in pairs(pdat.pda) do pdamtd.setIcon(7,i) pdamtd.setTitle("...",i) end
  38.         pdamtd.setTitle("Entered",tvnt[2]) pdamtd.setIcon(6,tvnt[2])
  39.     else write("input>") txtln = read() end
  40.   return txtln
  41. end
  42. local function opnmdm()
  43.     for i,v in pairs(rs.getSides()) do 
  44.         if peripheral.getType(v) == "modem" then
  45.             if not rednet.isOpen(v) then rednet.open(v) end
  46.         return true end
  47.     end
  48. return false end
  49. if pdamtd then
  50.     if tArgs[1] then pdat.chnl = tArgs[1]
  51.     else print("Enter Channel") pdat.chnl = read() end
  52.     local strtfl = fs.open("startup","w")
  53.     strtfl.writeLine("shell.run(\"rcpda\",\""..pdat.chnl.."\")") strtfl.close()
  54.     pdamtd.setChannel(pdat.chnl)
  55.     print([[Test loop activated, use pda
  56. on receiver to connect, press
  57. keys on pda to register pda,
  58. \"X\" on pda to exit]])
  59. else print("No pda receiver present") end
  60. repeat
  61.     tvnt = {os.pullEvent()}
  62.     if tvnt[1] == "pda_connected" then
  63.         pdamtd.setIcon(8,tvnt[2]) pdamtd.setTitle("Connected to terminal"..cnslID,tvnt[2])
  64.         pdamtd.setText(0,"Welcome to C-Provider",tvnt[2])
  65.     elseif tvnt[1] == "pda_key" then pdat.pda[tvnt[2]] = true
  66.         wrtpdln("Key: "..tvnt[3].." pressed on PDA "..tvnt[2]) pdamtd.setIcon(4,tvnt[2])
  67.         pdamtd.alert("Connected to terminal"..cnslID,tvnt[2]) end
  68. until tvnt[1] == "pda_char" and tvnt[3] == "X"
  69. local rcmdlst = {
  70.     [0] = "bmb",[79] = "place",[80] = "back",[81] = "ddn",[75] = "turnLeft",[76] = "tnl",
  71.     [77] = "turnRight",[71] = "placeUp",[72] = "dfd",[73] = "dup",[82] = "placeDown",
  72.     [83] = "drop8",[74] = "rfl",[78] = "slct",[181] = "gpshst",[55] = "gpslct",[28] = "pckup",
  73.     [210] = "place",[211] = "dig",[199] = "dropUp8",[207] = "dropDown8",[201] = "up",[209] = "down",
  74.     [200] = "forward",[208] = "back",[203] = "turnLeft",[205] = "turnRight",[26] = "digUp",
  75.     [27] = "digDown",[51] = "suckUp",[52] = "suckDown",[29] = "trmn8RC",
  76. }
  77. local function setID() wrtpdln("Enter receiver ID") return tonumber(rdpdln()) end
  78. shell.run('clear')
  79. if not opnmdm() then wrtpdln("Modem Access Error") return false end
  80. local rcID = nil
  81. repeat  rcID = setID() until rcID
  82. wrtpdln("Receiver ID set to "..rcID)
  83. wrtpdln("Press \"h\" for help")
  84. for i,v in pairs(pdat.pda) do pdamtd.setIcon(4,i) end
  85. repeat
  86.     tvnt = {os.pullEvent()}
  87.     if tvnt[1] == "pda_key" and rcmdlst[tvnt[3]] then rednet.send(rcID,rcmdlst[tvnt[3]])
  88.         pdamtd.setTitle("Sent \""..rcmdlst[tvnt[3]].."\" to "..rcID,tvnt[2])
  89.         if tvnt[3] == 29 then rcID = setID() end
  90.     elseif tvnt[1] == "rednet_message" then wrtpdln(tvnt[2]..": "..tvnt[3])
  91.         for i,v in pairs(pdat.pda) do pdamtd.setIcon(2,i) pdamtd.setTitle("Message from "..tvnt[2],i) end
  92.         if tvnt[3]:find("^send") then rednet.send(tvnt[2],rdpdln()) end
  93.     elseif tvnt[3] == "S" then rednet.send(rcID,rdpdln())
  94.         pdamtd.setIcon(1,tvnt[2]) pdamtd.setTitle("Rednet Sent",tvnt[2])
  95.     elseif tvnt[3] == "R" then rcID = setID() pdamtd.setIcon(8,tvnt[2])
  96.     elseif tvnt[3] == "h" or tvnt[3] == "H" then
  97.         wrtpdln("Use \"R\" change receiver    Use \"S\" to send text")
  98.         wrtpdln("Change receiver to nil to  exit rcpda")
  99.         wrtpdln("Use numberpad to control   turtles: 284693 to digmove 5 to tunnel, 170 to place  '.' Home End, to drop")
  100.         wrtpdln("Enter, <, >, to suck       Del, [, ] to dig")
  101.         wrtpdln("Direction Keys and PgUp/Dn to move")
  102.     end
  103. until not rcID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement