Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local entDet = peripheral.wrap("playerDetector_1")
- local yaw = peripheral.wrap("left")
- local pitch = peripheral.wrap("right")
- local mon = peripheral.find("monitor")
- local blockReader = peripheral.wrap("blockReader_1")
- local relYaw, relPitch = blockReader.getBlockData().CannonYaw, blockReader.getBlockData().CannonPitch
- local isTarget = ""
- function setYaw()
- local canYaw = blockReader.getBlockData().CannonYaw
- local rev = 1
- if relYaw < 0 then
- rev = -1
- end
- while math.abs(canYaw - relYaw) >= 2 do
- canYaw = blockReader.getBlockData().CannonYaw
- yaw.setTargetSpeed(60*rev)
- end
- yaw.setTargetSpeed(0)
- end
- function setPitch()
- local canPitch = blockReader.getBlockData().CannonPitch
- local rev = 1
- if relPitch < 0 then
- rev = -1
- end
- while math.abs(canPitch - relPitch) >= 2 do
- canPitch = blockReader.getBlockData().CannonPitch
- pitch.setTargetSpeed(60*rev)
- end
- pitch.setTargetSpeed(0)
- end
- function checkTarget(name)
- local buffer = name
- for _, entity in ipairs(entDet.getPlayersInRange(30)) do
- if buffer == entity then
- return buffer
- end
- end
- return ""
- end
- function calculateAngles(x, y, z)
- local cannonPitch = blockReader.getBlockData().CannonPitch
- local cannonYaw = blockReader.getBlockData().CannonYaw
- local distance = math.sqrt((x - 8.5)^2 + (y - 67)^2 + (z - 363.5)^2)
- relPitch = (math.asin((y - 67) / distance)) * 57.296
- local playerYaw = entDet.getPlayerPos(isTarget).yaw
- relYaw = relYaw + playerYaw
- print(relYaw.. "yaw")
- print(relPitch.. "pitch")
- local yawDifference = math.abs(cannonYaw - relYaw)
- local pitchDifference = math.abs(cannonPitch - relPitch)
- if yawDifference <= 2 and pitchDifference <= 2 then
- print("Target")
- else
- parallel.waitForAll(setYaw, setPitch)
- end
- end
- while true do
- if checkTarget(isTarget) ~= "" then
- local table = entDet.getPlayerPos(isTarget)
- calculateAngles(table.x, table.y, table.z)
- else
- for _, entity in ipairs(entDet.getPlayersInRange(30)) do
- if entity.name ~= "MyName" then
- isTarget = entity
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment