Advertisement
NanoBob

NanoGlasses V4.0

Jul 21st, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.53 KB | None | 0 0
  1. --NanoGlasses V4.0
  2.  
  3. sensor=peripheral.wrap("left")
  4. glasses=peripheral.wrap("back")
  5. glassesController="NanoBob_"
  6. local pc={
  7.     x=272,
  8.     y=51,
  9.     z=380,
  10. }
  11.  
  12. local guiScale="normal"
  13.  
  14. local screenSizes={
  15. ['normal']={['x']=950,['y']=500,},
  16. }
  17.  
  18. weaponIDs={}
  19.  
  20. weaponNames={"sword","rapier","bow","paxel","cleaver","hammer"}
  21.  
  22.  
  23. local screenx=screenSizes[guiScale].x
  24. local screeny=screenSizes[guiScale].y
  25.  
  26. local distances={}
  27. local locating={}
  28.  
  29.  
  30. function drawPositions()
  31.     local currentPlayers={}
  32.     local players=sensor.getPlayers()
  33.     for _,data in pairs(players) do
  34.         currentPlayers[data.name]=true
  35.     end
  36.     local funcs=sensor.getPlayerByName(glassesController)
  37.     local data=funcs.select("player")
  38.     if data~=nil then
  39.         local playerX=data.position.x+pc.x
  40.         local playerZ=data.position.z+pc.z
  41.         local playerY=data.position.y+pc.y
  42.         for name,__ in pairs(locating) do
  43.             if currentPlayers[name]==true then
  44.                 local funcs=sensor.getPlayerByName(name)
  45.                 local data=funcs.select("player")
  46.                 if data~=nil then
  47.                     local pos=data.position
  48.                     local x=pos.x
  49.                     local z=pos.z
  50.                     local y=pos.y
  51.                     distances[name]={
  52.                         health=funcs.single("living").health,
  53.                         x=math.floor(pc.x+x+0.5),
  54.                         z=math.floor(pc.z+z+0.5),
  55.                         y=math.floor(pc.y+y+0.5),
  56.                         distance=math.floor(math.sqrt((x-playerX)^2+(z-playerZ)^2)+0.5),
  57.                     }
  58.                 end
  59.             end
  60.         end
  61.         local nameIndex=1
  62.         glasses.clear()
  63.         for name,info in pairs(distances) do
  64.             local x=info.x
  65.             local z=info.z
  66.             local height=info.y
  67.             local distance=info.distance
  68.             local health=info.health
  69.             --print(name..":"..x..","..z.." Height :"..height.."  Distance :"..distance.." Health:"..health)
  70.             if whiteList[name] then
  71.                 glasses.addText(5,nameIndex*10-5,name..":"..x..","..z.." Height :"..height.."  Distance :"..distance.." Health:"..health,50000)
  72.             elseif blackList[name] then
  73.                 glasses.addText(5,nameIndex*10-5,name..":"..x..","..z.." Height :"..height.."  Distance :"..distance.." Health:"..health,8000000)
  74.             end
  75.             --stringLength=glasses.getStringWidth(name..": "..x..","..z.."  Distance :"..distance)
  76.             glasses.addBox(0,nameIndex*10-5,400,10,10000000,0.2)
  77.             name=string.sub(name,1,6)
  78.             nameIndex=nameIndex+1
  79.             glasses.sync()
  80.         end
  81.     end
  82. end
  83.  
  84. function getPlayerInventory(playerName)
  85.     local returnTable={}
  86.     local playerFuncs=sensor.getPlayerByName(playerName)
  87.     local all=playerFuncs.all()
  88.     local inventory=all.player.inventory
  89.     for i=1,37 do
  90.         if inventory[i]~=nil then
  91.             returnTable[i]=inventory[i].all()
  92.         else
  93.             returnTable[i]="empty"
  94.         end
  95.     end
  96.     return returnTable
  97. end
  98.  
  99. function getWeapons(playerName)
  100.     local playerFuncs=sensor.getPlayerByName(playerName)
  101.     local playerData=playerFuncs.single("living")
  102.     allSlots=getPlayerInventory(playerName)
  103.     weapons={}
  104.     for id,data in pairs(allSlots) do
  105.         if data~="empty" then
  106.             if weaponIDs[data['id']] then
  107.                 weapons[data['id']]=true
  108.             else
  109.                 loweredString=string.lower(data['name'])
  110.                 for id,name in pairs(weaponNames) do
  111.                     if string.find(loweredString,name)~=nil then
  112.                         weapons[data['id']]=true
  113.                     end
  114.                 end
  115.             end
  116.         end
  117.     end
  118.     return weapons
  119. end
  120.  
  121. function drawWeapons(message)
  122.     local playerFunctions=sensor.getPlayerByName(message)
  123.     local playerData=playerFunctions.single("living")
  124.     print(message)
  125.     armorIndex=0
  126.     if playerData~=nil then
  127.             armor=playerData['armor']
  128.             glasses.clear()
  129.         for armorSlot,data in pairs(armor) do
  130.             glasses.addIcon(10,armorIndex*40+20,data['id'],0)
  131.             armorIndex=armorIndex+1
  132.         end
  133.         weaponIndex=0
  134.         collumnIndex=0
  135.         weapons=getWeapons(message)
  136.         for id,data in pairs(weapons) do
  137.             print(id)
  138.             glasses.addIcon(30+collumnIndex*20,weaponIndex*40+20,id,0)
  139.             weaponIndex=weaponIndex+1
  140.             if weaponIndex==4 then
  141.                 collumnIndex=collumnIndex+1
  142.                 weaponIndex=0
  143.             end
  144.         end
  145.         glasses.sync()
  146.         sleep(5)   
  147.     end
  148. end
  149.  
  150. function drawInventory(message)
  151.     message=string.gsub(message,"inventory ","")
  152.     message=string.gsub(message,"inventory","")
  153.     local inventory=getPlayerInventory(message)
  154.     print(message)
  155.     if inventory~=nil then
  156.         inventoryIndex=0
  157.         collumnIndex=0
  158.         for slot,data in pairs(inventory) do
  159.             if slot<37 and data~="empty" then
  160.                 glasses.addIcon(100+collumnIndex*20+100,inventoryIndex*40+20,data['id'],0)
  161.                 if data~="empty" then
  162.                     inventoryIndex=inventoryIndex+1
  163.                     if inventoryIndex==4 then
  164.                         collumnIndex=collumnIndex+1
  165.                         inventoryIndex=0
  166.                     end
  167.                 end
  168.             end
  169.         end
  170.         glasses.sync()
  171.         sleep(10)
  172.     end
  173. end
  174.  
  175. function handleEvents()
  176.     event,side,player,UUID,message=os.pullEvent()
  177.     if event=="glasses_chat_command" then
  178.         print(message)
  179.         --[[if string.find(message,"whitelist")~=nil then
  180.             local message=string.gsub(message,"whitelist ","")
  181.             message=string.gsub(message,"whitelist","")
  182.             whiteList[message]= not whiteList[message] or true 
  183.         elseif string.find(message,"blacklist")~=nil then
  184.             local message=string.gsub(message,"blacklist ","")
  185.             message=string.gsub(message,"blacklist","")
  186.             blackList[message]= not blackList[message] or true 
  187.         else]]if string.find(message,"locate")~=nil then
  188.             local message=string.gsub(message,"locate ","")
  189.             message=string.gsub(message,"locate","")
  190.             locating[message]= not locating[message] or true       
  191.         elseif string.find(message,"weapons")~=nil then
  192.             local message=string.gsub(message,"weapons ","")
  193.             message=string.gsub(message,"weapons","")
  194.             drawWeapons(message)               
  195.         elseif string.find(message,"inventory")~=nil then
  196.             drawInventory(message)
  197.         end
  198.     end
  199. end
  200.  
  201.  
  202. while true do
  203.     drawPositions()
  204.     --drawPlayers()
  205.     handleEvents()
  206. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement