Posted 08 July 2013 - 06:30 PM
So, out of curiosity, I wrote a messy little program to serve as an entity radar for my base. So this is my little contribution to the CC community for the awesome mods that I use. I guess. Every little bit helps, I suppose!
So here you are. It's (very) well documented. And very simple. Just run the script and you've got a preset radar, though, if you feel that you need to customize, just edit the constants, or the script itself.
And here's a screenshot of the radar. The dots are relative to the sensor, not the player. I am the cyan dot, and the monsters are the red dots. And the radar is on the LEFT. It just shows how it compliments the minimap. As said, the dots are relative to the sensor, however with the proper tweaks, you can make the radar display the dots relative to you.
So here you are. It's (very) well documented. And very simple. Just run the script and you've got a preset radar, though, if you feel that you need to customize, just edit the constants, or the script itself.
os.loadAPI("ocs/apis/sensor")
--This is licensed under the "Do Whatever the Heck You Want" license.
--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.
--Constants--
gSide = "back" --The side the glasses bridge is on.
sSide = "top" --The side the sensor is on.
rX=2 --Position of the radar, X Coords.
rY=2 --Position of the radar, Y Coords.
rW=85 --Width of the radar.
rH=85 --Height of the radar.
rB=0x000000 --Color of the radar.
rA=.7 --Transparency of the radar.
friends={"ironicbear32","Shaeress42","CeilingLeo"} --Your friends, displayed as a different color than typical entities.
owner="skarlitz" --You.
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.)
chC=0xCCCCCC --The color of the crosshairs.
oC=0x009999 --The color of the owner. (You)
pC=0xFFFF00 --The color of other players.
hC=0xFF0000 --The colors for hostile entities.
fC=0x00FF00 --The colors for friendly entities.
sT=4 --The tier of your proximity sensor. (1-4)
--End Constants--
--Notes--
--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.
--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.
--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.
--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?
--End Notes--
function createGui()
--Clear the current GUI. (if there is any)
glasses.clear()
--Add the main box.
glasses.addBox(rX,rY,rW,rH,rB,rA)
--Add the crosshairs.
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.
glasses.addBox((((rW/2)+rX)-chR),(rH/2)+rY,chR*2,1,chC,rA) --Horizontal crosshair. (Even radius)
glasses.addBox((rW/2)+rX,(((rH/2)+rY)-chR),1,chR*2,chC,rA) --Verticle crosshair. (Even radius)
else
glasses.addBox((((rW/2)+rX)-chR),(rH/2)+rY,chR*2+1,1,chC,rA) --Horizontal crosshair.
glasses.addBox((rW/2)+rX,(((rH/2)+rY)-chR),1,chR*2+1,chC,rA) --Verticle crosshair.
end
end
function convCoords(x,z) --Here we convert a sensor-relative coordinate into something that fits on the radar. Neat!
local x2=((rW/2)+rX)+((rW/(sT*16))*x)
local y2=((rH/2)+rY)+((rH/(sT*16))*z)
return {x2,y2}
end
function loadPeripherals() --Load necessary peripherals.
prox=sensor.wrap(sSide)
glasses=peripheral.wrap(gSide)
end
function markEntityNew(coorda,diplo) --Mark an entity
x=coorda[1]
y=coorda[2]
if diplo=="owner" then
ent = glasses.addBox(x,y,1,1,oC,1)
elseif diplo=="friend" then
ent = glasses.addBox(x,y,1,1,fC,1)
elseif diplo=="player" then
ent = glasses.addBox(x,y,1,1,pC,1)
elseif diplo=="foe" then
ent = glasses.addBox(x,y,1,1,hC,1)
else
print("The programmer made an error. Darn.")
end
return ent
end
function continuouslyUpdateGui() --convCoords is very useful here.
local firsttrun = true
while true do
initTargets = prox.getTargets()
targets={}
for targetName,targetInfo in pairs(initTargets) do
coords=convCoords(targetInfo.Position.X,targetInfo.Position.Z)
if targetName==owner then
table.insert(targets,markEntityNew(coords,"owner"))
elseif targetInfo.Name=="Player" and targetName~=owner then
for fn,friend in pairs(friends) do
if targetName==friend then
table.insert(targets,markEntityNew(coords,"friend"))
else
table.insert(targets,markEntityNew(coords,"player"))
end
end
else
table.insert(targets,markEntityNew(coords,"foe"))
end
end
if firstrun==false then
for tn,t in pairs(targets2) do
t.delete()
end
end
sleep(.1)
initTargets = prox.getTargets()
targets2={}
for targetName,targetInfo in pairs(initTargets) do
coords=convCoords(targetInfo.Position.X,targetInfo.Position.Z)
if targetName==owner then
table.insert(targets2,markEntityNew(coords,"owner"))
elseif targetInfo.Name=="Player" and targetName~=owner then
for fn,friend in pairs(friends) do
if targetName==friend then
table.insert(targets2,markEntityNew(coords,"friend"))
else
table.insert(targets2,markEntityNew(coords,"player"))
end
end
else
table.insert(targets2,markEntityNew(coords,"foe"))
end
end
for tn,t in pairs(targets) do
t.delete()
end
sleep(.1)
firstrun = false
end
end
--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.
loadPeripherals() --So first we start out peripherals.
createGui() --And then we make our radar.
continuouslyUpdateGui() --And then we merely update the GUI for new entities. Woot!
And here's a screenshot of the radar. The dots are relative to the sensor, not the player. I am the cyan dot, and the monsters are the red dots. And the radar is on the LEFT. It just shows how it compliments the minimap. As said, the dots are relative to the sensor, however with the proper tweaks, you can make the radar display the dots relative to you.