Advertisement
NanoBob

player distance monitor

Sep 14th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. blackList={
  2. ["Doc_Jason"]=true,
  3. }
  4. whiteList={
  5. ['darkbobo00']=true,
  6. ['dark_sjoerd']=true,
  7. ['Lekkerdie']=true,
  8. ['mastersnake20']=true,
  9. ['skye333']=true,
  10. }
  11.  
  12. local pcX=-910
  13. local pcZ=-1833
  14. local distances={}
  15. sensor=peripheral.wrap("left")
  16. monitor=peripheral.wrap("back")
  17.  
  18.  
  19. while true do
  20.   for name,__ in pairs(blackList) do
  21.     data=sensor.getPlayerData(name)
  22.     if data~=nil then
  23.       local pos=data['position']
  24.       local x=pos['x']
  25.       local z=pos['z']
  26.       x=math.floor(pcX+x+0.5)
  27.       z=math.floor(pcZ+z+0.5)
  28.       distance=math.floor(math.sqrt((x-pcX)^2+(z-pcZ)^2)+0.5)
  29.       distances[name]={['x']=x,['z']=z,['d']=distance}
  30.       print(name.." : "..x..","..z..","..distance)
  31.     end
  32.   end
  33.   for name,__ in pairs(whiteList) do
  34.     data=sensor.getPlayerData(name)
  35.     if data~=nil then
  36.       local pos=data['position']
  37.       local x=pos['x']
  38.       local z=pos['z']
  39.       x=math.floor(pcX+x+0.5)
  40.       z=math.floor(pcZ+z+0.5)
  41.       distance=math.floor(math.sqrt((x-pcX)^2+(z-pcZ)^2)+0.5)
  42.       distances[name]={['x']=x,['z']=z,['d']=distance}
  43.       print(name.." : "..x..","..z..","..distance)
  44.     end
  45.   end
  46.  
  47.   local nameIndex=1
  48.   local monitorX,monitorY=monitor.getSize()
  49.   monitor.clear()
  50.   for name,information in pairs(distances) do
  51.     monitor.setCursorPos(1,nameIndex)
  52.     local x=information['x']
  53.     local z=information['z']
  54.     local distance=information['d']
  55.     if whiteList[name] then
  56.         monitor.setTextColor(8192)
  57.     elseif blackList[name] then
  58.         monitor.setTextColor(16384)
  59.     end
  60.     name=string.sub(name,1,6)
  61.     monitor.write(name..": "..x..","..z.."  Distance :"..distance)
  62.     nameIndex=nameIndex+1
  63.   end
  64.   sleep(2)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement