Advertisement
VikeStepFTB

CCGames: giveItem

Dec 20th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. -- Peripherals
  2. s = peripheral.wrap("front") --Wrapping Sensor
  3.  
  4. -- Relative Coordinates (integer coord when closest to sensor but still on block)
  5. relX = 0 -- relative x coord to sensor
  6. relY = 2 -- relative y coord to sensor
  7. relZ = -1 -- relative z coord to sensor
  8.  
  9. -- Helper Functions
  10. function rnd(num) -- floors a positive number, ceils a negative number
  11.     if num >= 0 then
  12.         return math.floor(num)
  13.     else
  14.         return math.ceil(num)
  15.     end
  16. end
  17.  
  18. function isCorrectPos(pos,x,y,z) -- Compares position vectors to see if same
  19.     if rnd(pos.x) == x and rnd(pos.y) == y and rnd(pos.z) == z then
  20.         return true
  21.     else
  22.         return false
  23.     end
  24. end
  25.  
  26. function inInv(inv,id) -- checks if an item is in the inventory
  27.     local there = false -- true if item is in inventory
  28.     for i = 1, table.getn(inv) do
  29.         if inv[i].id == id then
  30.             there = true
  31.         end
  32.     end
  33.     return there
  34. end
  35.  
  36. while true do
  37.     n=table.getn(s.getPlayerNames()) -- amount of nearby players
  38.     if n > 0 then
  39.         for i = 1, n do
  40.             local p=s.getPlayerNames()[i] -- player name
  41.             local pos=s.getPlayerData(p).position -- coordinate vector of player
  42.             local inv=s.getPlayerData(p).inventory -- inventory data of player
  43.             if isCorrectPos(pos,relX,relY,relZ) and not(inInv(inv,1311) or inInv(inv,1312)) then
  44.                 rs.setOutput("left",true) -- Command Block give Remote
  45.                 rs.setOutput("back",true) -- Command Block give Terminal Glasses
  46.             else
  47.                 rs.setOutput("left",false)
  48.                 rs.setOutput("back",false)
  49.             end  
  50.         end
  51.     end
  52.   sleep(0) -- allow time for program to yield
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement