Advertisement
BrandenKP

Nifty Sensor Attributes

May 30th, 2014
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. --Nifty Sensor Attributes v.03a
  2. --Comprehensive player stat monitoring program.
  3. --Designed to give the most important information, typically to track a player or give an upper hand in PVP.
  4. --Requires the "OpenPeripherals" sensor, Terminal Glasses, and an Advanced Monitor.
  5.  
  6. m = peripheral.wrap("right")
  7. -- m for monitor, must be adjusted on an individual basis.
  8. s = peripheral.wrap("top")
  9. -- s for sensor
  10. g = peripheral.wrap("left")
  11. -- g for glasses
  12. sensorPositionX = -306
  13. -- X coordinate in the world, used for calibration
  14. sensorPositionY = 29
  15. -- Y coordinate in the world, used for calibration
  16. sensorPositionZ = 570
  17. -- Z coordinate in the world, used for calibration
  18. playername = nil
  19. -- set playername nil to start
  20.  
  21. function updateScreen()
  22.     while true do
  23.     sleep(0.1)
  24.     tempPlayerName = playername
  25.     if tempPlayerName == nil then
  26.         g.clear()
  27.         print("cleared")
  28.     elseif tempPlayerName ~= nil then
  29.         if s.getPlayerData(tempPlayerName) == nil then
  30.             repeat
  31.                 g.clear()
  32.                 g.addText(10,10,"Invalid name")
  33.                 print("Invalid name")
  34.                 tempPlayerName = playername
  35.                 if tempPlayerName == nil then
  36.                     break
  37.                     end
  38.                 until s.getPlayerData(tempPlayerName) ~= nil
  39.             break
  40.             end
  41.     print(s.getPlayerData(tempPlayerName)["health"])
  42.             a = math.floor(sensorPositionX+s.getPlayerData(tempPlayerName)["position"]["x"])
  43.             b = math.floor(sensorPositionY+s.getPlayerData(tempPlayerName)["position"]["y"])
  44.             c = math.floor(sensorPositionZ+s.getPlayerData(tempPlayerName)["position"]["z"])
  45.                 print(a)
  46.                 print(b)
  47.                 print(c)
  48.             g.clear()
  49.             g.addText(10,10,a)
  50.             g.addText(10,20,b)
  51.             g.addText(10,30,c)
  52.             sleep(0.1)
  53.     end
  54.     end
  55. end
  56.  
  57. function startup()
  58.     term.redirect(m)
  59.     term.clear()
  60.     term.setCursorPos(1,1)
  61.     print("ready")
  62. end
  63.  
  64. function eventHandle()
  65. while true do
  66.     sleep(0.1)
  67.     evt,command = os.pullEvent("chat_command")
  68.         if command == "stop" then
  69.             print("command stopped")
  70.             break
  71.         elseif command == "clear" then
  72.             playername = nil
  73.             print("command cleared")
  74.             --g.clear()
  75.         elseif command ~= "clear" then
  76.             playername = command
  77.             print("got name")
  78.             --print("Current health:")
  79.             --g.addIcon(30,10,2421,2)
  80.             --Inventory = playerData.inventory
  81.             --"Weapon" = playerData.heldItem
  82.             --do print("Current weapon:") end
  83.             --for key,value in pairs(playerData.heldItem) do print(key,value)
  84.         end
  85.     end
  86. end
  87.  
  88. startup()
  89. while true do
  90. parallel.waitForAny(eventHandle, updateScreen)
  91. sleep(0.1)
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement