ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: MegaMind on Oct 19, 2021, 09:10 PM

Title: How to use radar to detect other players
Post by: MegaMind on Oct 19, 2021, 09:10 PM
I'm very new to this and I wanted to use a radar to detect other players and give me their distance from the radar. But I don't even know how to get the computer to interact with the radar. I tried looking for videos that could show how to do it but couldn't find any. I was told I should ask for help here, so can someone tell how do something like this or show me video that can do the same?
Title: How to use radar to detect other players
Post by: Lupus590 on Oct 19, 2021, 11:44 PM
What mod is the radar from? CC doesn't have any native ability to detect entities so some peripheral mod must be providing it, there are a few which do so knowing which specific one you are using will be helpful.
Title: How to use radar to detect other players
Post by: MegaMind on Oct 20, 2021, 05:10 AM
Quote from: Lupus590 on Oct 19, 2021, 11:44 PMWhat mod is the radar from? CC doesn't have any native ability to detect entities so some peripheral mod must be providing it, there are a few which do so knowing which specific one you are using will be helpful.
the radar is from "computronics" I saw it combined with a turtle so I assumed it was from the same mod, now I know that they work together but I still don't know what to do to make it talk with the computer.
Title: How to use radar to detect other players
Post by: Lupus590 on Oct 20, 2021, 05:32 AM
I would assume that it has a block form as well as a turtle upgrade form, but I'm not familiar with the mod so I can't say for sure.
Title: How to use radar to detect other players
Post by: MrSevyu on Jun 23, 2022, 08:15 AM
The peripheral must be on any of the sides of your computer (left, right, front, back, top, bottom). Go to Peripheral Basics (http://www.computercraft.info/forums2/index.php?/topic/15062-peripheral-basics/) for more information.
I wrote this sample code. It gets all nearby players and their distance to the radar.

local radar = peripheral.wrap("left")
local players = radar.getPlayers()

local playerName = ""
local distance = 0

for i = 1, #players do
    for k, v in pairs(players) do
        if players[i]["name"] ~= "" or players[i]["name"] ~= nil then
            playerName = players[i]["name"]
        end
        if players[i]["distance"] ~= nil then
            distance = players[i]["distance"]
        end
        print("Player: " .. playerName .. " -- Distance: " .. distance)
    end
end