arbarr3

startup

Jan 24th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. function tlen(tabl)
  2.   local count = 0
  3.   for _ in pairs(tabl) do
  4.     count = count+1
  5.   end
  6.   return count
  7. end
  8.  
  9. function getEnts(tabl)
  10.   entArr = {}
  11.   for i,v in pairs(tabl) do
  12.     ent = string.sub(i,0,3)
  13.     if ent ~= "Cow" and ent ~= "Bat" and ent ~= "Ske" and ent ~= "Cre" and ent ~= "Zom" and ent ~= "Sli" and ent ~= "Spi" and ent ~= "End" then
  14.      table.insert(entArr, i)
  15.     end
  16.   end
  17.   return entArr
  18. end
  19.  
  20. function getXYZ(tabl, entName)
  21.   retXYZ = {}
  22.   retXYZ["x"] = math.floor(tabl[entName]["Position"]["X"])
  23.   retXYZ["y"] = math.floor(tabl[entName]["Position"]["Y"])
  24.   retXYZ["z"] = math.floor(tabl[entName]["Position"]["Z"])
  25.   return retXYZ
  26. end
  27.  
  28. function colorOn(col, side)
  29.   rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side),col))
  30. end
  31. function colorOff(col, side)
  32.   rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side),col))
  33. end
  34.  
  35. monitor = peripheral.wrap("top")
  36. monitor.clear()
  37. monitor.setCursorPos(1,1)
  38. monitor.setTextScale(1)
  39.  
  40. os.loadAPI("ocs/apis/sensor")
  41. mySensor = sensor.wrap("right")
  42. alarmIsOn = false
  43.  
  44. while true do
  45. --if true then
  46.   tgts = mySensor.getTargets()
  47.   ents = getEnts(tgts)
  48.  
  49.   maxX, maxY = monitor.getSize()
  50.   currentY = 1
  51.   monitor.clear()
  52.      
  53.   for pos = 1, #ents do
  54.     monitor.setCursorPos(1, currentY)
  55.     entXYZ = getXYZ(tgts, ents[pos])
  56.     monitor.write(ents[pos].." X: "..entXYZ["x"].." Y: "..entXYZ["y"].." Z: "..entXYZ["z"])
  57.     currentY = currentY+1
  58.   end
  59.  
  60.   if #ents == 1 and tgts["arbarr3"] then
  61.      
  62.       ownerPos = getXYZ(tgts, "arbarr3")
  63.       local ownerX = ownerPos["x"]
  64.       local ownerY = ownerPos["y"]
  65.       local ownerZ = ownerPos["z"]
  66.      
  67.       if (ownerX >= -2 and ownerX <= 0) and (ownerY == -2 or ownerY == -3) and (ownerZ >= -1 and ownerZ <= 1) then
  68.         if redstone.getBundledOutput("back") ~= colors.white then
  69.           colorOn(colors.white, "back")
  70.         end
  71.       else
  72.         if redstone.getBundledOutput("back") == colors.white then
  73.           colorOff(colors.white, "back")
  74.         end
  75.       end
  76.       colorOff(colors.red, "back")
  77.       alarmIsOn = false
  78.   elseif #ents > 0 then
  79.     monitor.setCursorPos(1, maxY)
  80.     monitor.setTextColor(colors.red)
  81.     monitor.write("You are in arbarr3's house.  Please leave.")
  82.     monitor.setTextColor(colors.white)
  83.    
  84.     alarmIsOn = true
  85.     colorOn(colors.red, "back")
  86.   else
  87.     colorOff(colors.red, "back")
  88.   end
  89. end
  90.  
  91. print(textutils.serialize(mySensor.getTargets()))
Advertisement
Add Comment
Please, Sign In to add comment