Derek1017

d

Feb 27th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.46 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2. --This is licensed under the "Do Whatever the Heck You Want" license.
  3. --So do whatever you want with it. Burn it to CDs and sell it for tree fiddy in the ghetto. I don't really care. So long as I'm not responsible for whatever becomes of your course of action.
  4. --Constants--
  5. gSide = "back" --The side the glasses bridge is on.
  6. sSide = "top" --The side the sensor is on.
  7. rX=2 --Position of the radar, X Coords.
  8. rY=2 --Position of the radar, Y Coords.
  9. rW=85 --Width of the radar.
  10. rH=85 --Height of the radar.
  11. rB=0x000000 --Color of the radar.
  12. rA=.7 --Transparency of the radar.
  13. friends={"ironicbear32","Shaeress42","CeilingLeo"} --Your friends, displayed as a different color than typical entities.
  14. owner="skarlitz" --You.
  15. chR=1 --The radius of the crosshairs. (Integer only please! Decimals don't do much. Also, try not to use the number '2'. The program doesn't like that radius.)
  16. chC=0xCCCCCC --The color of the crosshairs.
  17. oC=0x009999 --The color of the owner. (You)
  18. pC=0xFFFF00 --The color of other players.
  19. hC=0xFF0000 --The colors for hostile entities.
  20. fC=0x00FF00 --The colors for friendly entities.
  21. sT=4 --The tier of your proximity sensor. (1-4)
  22. --End Constants--
  23. --Notes--
  24. --This experiment is from my Aedric Playground, my hall of random garbage in Minecraft. And that's the only place it's been tested. So be warned. I'm not responsible for hackers.
  25. --Entities will NOT show up at the corners of the GUI. Not a bug on my behalf. The radar sensor from OCS scans in a sphere, rather than a cube (Which would've made much more sense IMHO, given Minecraft is set in a cubic world), so yeah.
  26. --The numbers 2 and 0 do not work well for the crosshairs, though I suppose 0 could be interpreted as an "Off" for the crosshairs. So yeah. If you don't want the crosshairs, just use 0 for the radius.
  27. --This radar is relative to the sensor, not you. Best used as an upper hand on intruders. Maybe you could edit the script so that a wireless sensor turtle follows you and transmits coords to another computer which then displays then on your monitor?
  28. --End Notes--
  29. function createGui()
  30. --Clear the current GUI. (if there is any)
  31. glasses.clear()
  32. --Add the main box.
  33. glasses.addBox(rX,rY,rW,rH,rB,rA)
  34. --Add the crosshairs.
  35. if chR%2==0 then --The if statement is here to keep your crosshairs from looking funky when you use odds/evens with the current code. Works well with all numbers save for 2 and 0.
  36.   glasses.addBox((((rW/2)+rX)-chR),(rH/2)+rY,chR*2,1,chC,rA) --Horizontal crosshair. (Even radius)
  37.   glasses.addBox((rW/2)+rX,(((rH/2)+rY)-chR),1,chR*2,chC,rA) --Verticle crosshair. (Even radius)
  38. else
  39.   glasses.addBox((((rW/2)+rX)-chR),(rH/2)+rY,chR*2+1,1,chC,rA) --Horizontal crosshair.
  40.   glasses.addBox((rW/2)+rX,(((rH/2)+rY)-chR),1,chR*2+1,chC,rA) --Verticle crosshair.
  41. end
  42. end
  43. function convCoords(x,z) --Here we convert a sensor-relative coordinate into something that fits on the radar. Neat!
  44.  
  45. local x2=((rW/2)+rX)+((rW/(sT*16))*x)
  46. local y2=((rH/2)+rY)+((rH/(sT*16))*z)
  47. return {x2,y2}
  48. end
  49. function loadPeripherals() --Load necessary peripherals.
  50. prox=sensor.wrap(sSide)
  51. glasses=peripheral.wrap(gSide)
  52. end
  53. function markEntityNew(coorda,diplo) --Mark an entity
  54. x=coorda[1]
  55. y=coorda[2]
  56. if diplo=="owner" then
  57.   ent = glasses.addBox(x,y,1,1,oC,1)
  58. elseif diplo=="friend" then
  59.   ent = glasses.addBox(x,y,1,1,fC,1)
  60. elseif diplo=="player" then
  61.   ent = glasses.addBox(x,y,1,1,pC,1)
  62. elseif diplo=="foe" then
  63.   ent = glasses.addBox(x,y,1,1,hC,1)
  64. else
  65.   print("The programmer made an error. Darn.")
  66. end
  67. return ent
  68. end
  69. function continuouslyUpdateGui() --convCoords is very useful here.
  70. local firsttrun = true
  71. while true do
  72.  
  73.   initTargets = prox.getTargets()
  74.   targets={}
  75.   for targetName,targetInfo in pairs(initTargets) do
  76.    coords=convCoords(targetInfo.Position.X,targetInfo.Position.Z)
  77.    if targetName==owner then
  78.         table.insert(targets,markEntityNew(coords,"owner"))
  79.    elseif targetInfo.Name=="Player" and targetName~=owner then
  80.         for fn,friend in pairs(friends) do
  81.          if targetName==friend then
  82.           table.insert(targets,markEntityNew(coords,"friend"))
  83.          else
  84.           table.insert(targets,markEntityNew(coords,"player"))
  85.          end
  86.         end
  87.    else
  88.    table.insert(targets,markEntityNew(coords,"foe"))
  89.    end
  90.   end
  91.   if firstrun==false then
  92.    for tn,t in pairs(targets2) do
  93.    t.delete()
  94.    end
  95.   end
  96.   sleep(.1)
  97.  
  98.   initTargets = prox.getTargets()
  99.   targets2={}
  100.   for targetName,targetInfo in pairs(initTargets) do
  101.    coords=convCoords(targetInfo.Position.X,targetInfo.Position.Z)
  102.    if targetName==owner then
  103.         table.insert(targets2,markEntityNew(coords,"owner"))
  104.    elseif targetInfo.Name=="Player" and targetName~=owner then
  105.         for fn,friend in pairs(friends) do
  106.          if targetName==friend then
  107.           table.insert(targets2,markEntityNew(coords,"friend"))
  108.          else
  109.           table.insert(targets2,markEntityNew(coords,"player"))
  110.          end
  111.         end
  112.    else
  113.    table.insert(targets2,markEntityNew(coords,"foe"))
  114.    end
  115.   end
  116.   for tn,t in pairs(targets) do
  117.    t.delete()
  118.   end
  119.   sleep(.1)
  120.   firstrun = false
  121.   end
  122. end
  123. --I like putting all the little tidbits into functions with clever names, so I can see the program laid out as a step-by-step process, rather than a bunch of rambling code.
  124. loadPeripherals() --So first we start out peripherals.
  125. createGui() --And then we make our radar.
  126. continuouslyUpdateGui() --And then we merely update the GUI for new entities. Woot!
Add Comment
Please, Sign In to add comment