Advertisement
MisterErwin

Portal API

Jun 24th, 2013
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. local portals = {
  2. [1] = {owner="HUB(X)";   id=137},
  3. [2] = {owner="JG"; id=147},
  4. [3] = {owner="Erwin"; id=138},
  5. [4] = {owner="maze farm"; id=0}
  6. }
  7.  
  8. function showPortals()
  9.   send("clearButtons")
  10.   ix = 1
  11.   for i=1,#portals do
  12.     if i % 2 ~= 0 then
  13.       send ("addButton 1 ".. ix .. " false 4 p:".. portals[i].owner)
  14.       print (i .. " @ 1 " .. ix)
  15.     else
  16.       send ("addButton m ".. ix .." false 4 p:" .. portals[i].owner)
  17.       print (i .. " @ 9 " .. ix)
  18.       ix = ix + 2
  19.     end
  20.   end
  21.  
  22.  
  23.  
  24.   send("printButtons")
  25. end
  26.  
  27. function openPortals(p2owner)
  28.   pid = getPortal(p2owner)
  29.   if pid == 0 or pid == 1 then
  30.     print ("Portal " .. p2owner .. " ex. nicht!")
  31.     return
  32.   end
  33.   print ("opening @ " .. p2owner )
  34.   p = portals[pid]
  35.  
  36.  
  37.  
  38.   send("setCursorPos 4 m")
  39.   send("write <Portal>")
  40.  
  41.   print ("freezing b/c a portal is beeing created! ")
  42.   print (p.id)
  43.  
  44.   sa =  rednet.send(portals[1].id, "OPEN")
  45.   sb =  rednet.send(p.id, "OPEN")
  46.   sleep(4)
  47.   sa =  rednet.send(portals[1].id, "CLOSE")
  48.   sb =  rednet.send(p.id, "CLOSE")
  49.  
  50.   send ("clearLine")
  51. end
  52.  
  53. function getPortal(owner)
  54.   for i=1,#portals do
  55.     if portals[i].owner == owner then
  56.       return i
  57.     end
  58.   end
  59.   return 0
  60. end
  61.  
  62. function getPortalbyID(id)
  63.   for i=1, #portals do
  64.     if portals[i].id == id then
  65.        return portals[i]
  66.     end
  67.   end
  68.   return nil
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement