MegiRicky

ciwsControlNGDW

Jul 31st, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.62 KB | None | 0 0
  1. -- Variable initialization
  2. local radar = peripheral.find("sp_radar")
  3. local ar = peripheral.find("arController")
  4. local modem = peripheral.find("modem")
  5. local router = peripheral.find("redrouter")
  6.  
  7. local cannonHitPosChannel = 700
  8. local cannonSourceChannel = 701
  9. local cannonSource
  10. if modem then
  11. modem.open(cannonHitPosChannel)
  12. end
  13.  
  14. local screenWidth, screenHeight, fov, GUIscale
  15. local sourceX, sourceY, sourceZ = 0,0,0
  16. local source = {}
  17. local userID
  18. local friendlyIDs
  19. local widthMagic = 1.125
  20. local projectionDistance = 100
  21. local currentPitch, currentYaw = 0,0
  22. local lockedTarget = nil
  23. local elements = {}
  24. local pInfo = {}
  25. local cannonHitPos = {}
  26. local pitchAdjustments = "1"
  27.  
  28. -- Configuration file paths
  29. local configFile = "ciwsNGDWconfig.txt"
  30. local friendlyIDFile = "friendly_ids.txt"
  31.  
  32. -- Function to read configuration from a file
  33. local function readConfig(filename)
  34. if not fs.exists(filename) then
  35. print("Configuration file '" .. filename .. "' does not exist. Creating it.")
  36. local file = fs.open(filename, "w")
  37.  
  38. print("Input your resolution eg.(1920,1080), default: 3440,1440")
  39. local resolution = io.read()
  40. if resolution == "" then
  41. resolution = "3440,1440"
  42. end
  43. file.writeLine("resolution=" .. resolution)
  44.  
  45. print("Input your FOV eg.(70), default: 70")
  46. local fov = io.read()
  47. if fov == "" then
  48. fov = "70"
  49. end
  50. file.writeLine("fov=" .. fov)
  51.  
  52. print("Input your GUI scale, default: 4")
  53. local guiScale = io.read()
  54. if guiScale == "" then
  55. guiScale = "4"
  56. end
  57. file.writeLine("guiScale=" .. guiScale)
  58.  
  59. print("Input your mode 1:System in world space 2:System on vs ship. Default: 1")
  60. local mode = io.read()
  61. if mode == "" then
  62. mode = "1"
  63. end
  64. file.writeLine("mode=" .. mode)
  65.  
  66. print("Input your ID, default: MegiRicky")
  67. local userID = io.read()
  68. if userID == "" then
  69. userID = "MegiRicky"
  70. end
  71. file.writeLine("userID=" .. userID)
  72.  
  73. if mode == "1" then
  74. print("Input the location of the computer (X,Y,Z)")
  75. local source = io.read()
  76. if source == "" then source = "0,0,0" end
  77. file.writeLine("source=" .. source)
  78. else
  79. file.writeLine("source=ship")
  80. end
  81.  
  82.  
  83. file.close()
  84. end
  85.  
  86. local file = fs.open(filename, "r")
  87. local config = {}
  88. local line = file.readLine()
  89. while line do
  90. local key, value = line:match("^(%w+)=(.*)$")
  91. config[key] = value
  92. line = file.readLine()
  93. end
  94. file.close()
  95. return config
  96. end
  97.  
  98. -- Function to read friendly IDs from a file
  99. local function readFriendlyIDs(filename)
  100. if not fs.exists(filename) then
  101. print("Friendly IDs file '" .. filename .. "' does not exist. Creating it.")
  102. local file = fs.open(filename, "w")
  103. print("Input friendly IDs separated by commas:")
  104. local ids = io.read()
  105. file.write(ids)
  106. file.close()
  107. end
  108.  
  109. local file = fs.open(filename, "r")
  110. local friendlyIDs = {}
  111. if file then
  112. local line = file.readLine()
  113. while line do
  114. for id in string.gmatch(line, "%d+") do
  115. table.insert(friendlyIDs, tonumber(id))
  116. end
  117. line = file.readLine()
  118. end
  119. file.close()
  120. end
  121. return friendlyIDs
  122. end
  123.  
  124. -- Load configuration
  125. local config = readConfig(configFile)
  126. screenWidth, screenHeight = config.resolution:match("(%d+),(%d+)")
  127. screenWidth = tonumber(screenWidth)
  128. screenHeight = tonumber(screenHeight)
  129. fov = tonumber(config.fov)
  130. GUIscale = tonumber(config.guiScale)
  131. local mode = tonumber(config.mode)
  132. userID = config.userID
  133. friendlyIDs = readFriendlyIDs(friendlyIDFile)
  134. local magicNumber = GUIscale/4
  135.  
  136. if mode == 1 then
  137. sourceX, sourceY, sourceZ = string.match(config.source, "(%-?%d+),(%-?%d+),(%-?%d+)")
  138. sourceX = tonumber(sourceX)
  139. sourceY = tonumber(sourceY)
  140. sourceZ = tonumber(sourceZ)
  141. else
  142. local pos = ship.getWorldspacePosition()
  143. sourceX, sourceY, sourceZ = pos.x, pos.y, pos.z
  144. end
  145.  
  146. print("Source X: " .. sourceX)
  147. print("Source Y: " .. sourceY)
  148. print("Source Z: " .. sourceZ)
  149. print("Resolution: " .. screenWidth .. ", " .. screenHeight)
  150. if screenWidth == 3440 and screenHeight == 1440 then widthMagic = 1.125 else widthMagic = 0.92 end
  151. ar.setRelativeMode(true, screenWidth * 4, screenHeight * 4)
  152.  
  153. local function isFriendly(id)
  154. for _, friendlyID in ipairs(friendlyIDs) do
  155. if id == friendlyID then
  156. return true
  157. end
  158. end
  159. return false
  160. end
  161.  
  162. -- Function to project 3D coordinates to 2D screen coordinates
  163. local function projectToScreen(x, y, z, userPos, lookVector)
  164. local dx = x - userPos[1]
  165. local dy = -(y - userPos[2])
  166. local dz = z - userPos[3]
  167.  
  168. local lx, ly, lz = lookVector[1], lookVector[2], lookVector[3]
  169. local playerYaw = math.deg(math.atan2(lz, lx))
  170. local playerPitch = math.deg(math.asin(-ly))
  171. playerYaw = playerYaw + 90
  172. if playerYaw < 0 then
  173. playerYaw = playerYaw + 360
  174. end
  175.  
  176. -- Calculate yaw difference
  177. local targetYaw = math.deg(math.atan2(dz, dx)) + 90
  178. if targetYaw < 0 then
  179. targetYaw = targetYaw + 360
  180. end
  181.  
  182. local yawDiff = targetYaw - playerYaw
  183. if yawDiff > 180 then
  184. yawDiff = yawDiff - 360
  185. elseif yawDiff < -180 then
  186. yawDiff = yawDiff + 360
  187. end
  188.  
  189. if math.abs(yawDiff) > 90 then
  190. return nil, nil
  191. end
  192.  
  193. -- Calculate pitch difference
  194. local distXY = math.sqrt(dx * dx + dz * dz)
  195. local targetPitch = math.deg(math.atan2(dy, distXY))
  196. local pitchDiff = targetPitch - playerPitch
  197.  
  198. local screenDepth = screenWidth / 2 * math.tan(math.rad(fov / 1.125 / 2))
  199. local verticalScreenDepth = screenHeight * math.tan(math.rad(fov / 2))
  200.  
  201. local projectedX, projectedY
  202.  
  203. if yawDiff > 0 then
  204. projectedX = screenWidth / 2 + screenDepth * math.tan(math.rad(math.abs(yawDiff)))
  205. else
  206. projectedX = screenWidth / 2 - screenDepth * math.tan(math.rad(math.abs(yawDiff)))
  207. end
  208.  
  209. if pitchDiff > 0 then
  210. projectedY = screenHeight / 2 + screenHeight * math.tan(math.rad(fov / 0.95 / 2)) * math.tan(math.rad(math.abs(pitchDiff)))
  211. else
  212. projectedY = screenHeight / 2 - screenHeight * math.tan(math.rad(fov / 1.05 / 2)) * math.tan(math.rad(math.abs(pitchDiff)))
  213. end
  214.  
  215. projectedX = math.floor(projectedX / magicNumber)
  216. projectedY = math.floor(projectedY / magicNumber) + 20
  217.  
  218. return projectedX, projectedY
  219. end
  220.  
  221. -- Function to display pitch and yaw of a cannon
  222. local function angleToScreen(pitch, yaw, userPos, lookVector)
  223. local lx, ly, lz = lookVector[1], lookVector[2], lookVector[3]
  224. local playerYaw = math.deg(math.atan2(lz, lx))
  225. local playerPitch = math.deg(math.asin(-ly))
  226. playerYaw = playerYaw + 90
  227. if playerYaw < 0 then
  228. playerYaw = playerYaw + 360
  229. end
  230.  
  231. -- Calculate yaw difference
  232. local yawDiff = yaw - playerYaw
  233. if yawDiff > 180 then
  234. yawDiff = yawDiff - 360
  235. elseif yawDiff < -180 then
  236. yawDiff = yawDiff + 360
  237. end
  238.  
  239. if math.abs(yawDiff) > 90 then
  240. return nil, nil
  241. end
  242.  
  243. -- Calculate pitch difference
  244. local pitchDiff = -pitch + playerPitch
  245.  
  246. local screenDepth = screenWidth / 2 * math.tan(math.rad(fov / 1.125 / 2))
  247. local verticalScreenDepth = screenHeight * math.tan(math.rad(fov / 2))
  248.  
  249. local projectedX, projectedY
  250.  
  251. if yawDiff > 0 then
  252. projectedX = screenWidth / 2 + screenDepth * math.tan(math.rad(math.abs(yawDiff)))
  253. else
  254. projectedX = screenWidth / 2 - screenDepth * math.tan(math.rad(math.abs(yawDiff)))
  255. end
  256.  
  257. if pitchDiff > 0 then
  258. projectedY = screenHeight / 2 + screenHeight * math.tan(math.rad(fov / 0.95 / 2)) * math.tan(math.rad(math.abs(pitchDiff)))
  259. else
  260. projectedY = screenHeight / 2 - screenHeight * math.tan(math.rad(fov / 1.05 / 2)) * math.tan(math.rad(math.abs(pitchDiff)))
  261. end
  262.  
  263. projectedX = math.floor(projectedX / magicNumber)
  264. projectedY = math.floor(projectedY / magicNumber) + 20
  265.  
  266. return projectedX, projectedY
  267. end
  268.  
  269. local function mouseAim(userPos, lookVector)
  270. lookTarget = {}
  271.  
  272. local lx, ly, lz = lookVector[1], lookVector[2], lookVector[3]
  273. local playerYaw = math.deg(math.atan2(lz, lx))
  274. local playerPitch = math.deg(math.asin(-ly))
  275. playerYaw = playerYaw + 90
  276. if playerYaw < 0 then
  277. playerYaw = playerYaw + 360
  278. end
  279.  
  280. local yawRad = math.rad(playerYaw)
  281. local pitchRad = math.rad(playerPitch)
  282.  
  283. local dx = projectionDistance * math.cos(pitchRad) * math.sin(yawRad)
  284. local dz = -projectionDistance * math.cos(pitchRad) * math.cos(yawRad)
  285. local dy = -projectionDistance * math.sin(pitchRad)
  286.  
  287. local targetX = userPos[1] + dx
  288. local targetY = userPos[2] + dy
  289. local targetZ = userPos[3] + dz
  290. lookTarget = { x = targetX, y = targetY, z = targetZ }
  291. return lookTarget
  292. end
  293.  
  294.  
  295. local function isWithinRenderDistance(projectedX, projectedY, centerX, centerY, maxdx, maxdy, maxd)
  296. local dx = projectedX - centerX / magicNumber
  297. local dy = projectedY - centerY / magicNumber
  298.  
  299. if dx < maxdx then
  300. if dy < maxdy then
  301. local distance = math.sqrt(dx * dx + dy * dy)
  302. if distance <= maxd then
  303. return true
  304. else
  305. return false
  306. end
  307. else
  308. return false
  309. end
  310. else
  311. return false
  312. end
  313. end
  314.  
  315. -- Function to check for overlap and adjust positions
  316. local function filterElements(elements)
  317. table.sort(elements, function(a, b) return a.mass > b.mass end) -- Sort by mass
  318. local filteredElements = {}
  319.  
  320. for i, element in ipairs(elements) do
  321. local overlap = false
  322. for _, filteredElement in ipairs(filteredElements) do
  323. local dx = math.abs(element.screenX - filteredElement.screenX)
  324. local dy = math.abs(element.screenY - filteredElement.screenY)
  325. if dx < 800 / GUIscale and dy < 800 / GUIscale then
  326. overlap = true
  327. element.renderInfo = false
  328. break
  329. end
  330. end
  331.  
  332. table.insert(filteredElements, element)
  333.  
  334. end
  335.  
  336. return filteredElements
  337. end
  338.  
  339. -- Function to render elements in parallel
  340. local function renderElements(elements, cannonHitPos, pInfo, lockedTarget)
  341. local tasks = {}
  342. for _, element in ipairs(elements) do
  343. table.insert(tasks, function()
  344. local color = element.color
  345. if lockedTarget and element.id == lockedTarget.id then
  346. color = 0xFF0000 -- Red color for locked target
  347. end
  348. ar.horizontalLineWithId("frame_top_" .. element.id, element.screenX - element.frameSize, element.screenX + element.frameSize, element.screenY - element.frameSize, color)
  349. ar.horizontalLineWithId("frame_bottom_" .. element.id, element.screenX - element.frameSize, element.screenX + element.frameSize, element.screenY + element.frameSize, color)
  350. ar.verticalLineWithId("frame_left_" .. element.id, element.screenX - element.frameSize, element.screenY - element.frameSize, element.screenY + element.frameSize, color)
  351. ar.verticalLineWithId("frame_right_" .. element.id, element.screenX + element.frameSize, element.screenY - element.frameSize, element.screenY + element.frameSize, color)
  352. if element.renderInfo then
  353. ar.drawString("dist: " .. element.distance, element.screenX - 15, element.screenY - 200 / GUIscale, color)
  354. ar.drawString("mass: " .. math.floor(element.mass / 1000) .. "k", element.screenX - 15, element.screenY - 340 / GUIscale, color)
  355. ar.drawString("speed: " .. element.speed, element.screenX - 15, element.screenY - 480 / GUIscale, color)
  356. ar.drawString("id: " .. element.id, element.screenX - 15, element.screenY - 620 / GUIscale, color)
  357. end
  358. end)
  359. end
  360. parallel.waitForAll(table.unpack(tasks))
  361. end
  362.  
  363. local function lockHighestThreatTarget(elements, centerX, centerY, radius)
  364. local highestThreat = nil
  365. local highestThreatLevel = -1
  366.  
  367. for _, element in ipairs(elements) do
  368. if element.id then
  369. local dx = element.screenX - centerX / magicNumber
  370. local dy = element.screenY - centerY / magicNumber
  371. local distance = math.sqrt(dx * dx + dy * dy)
  372.  
  373. if distance <= radius / GUIscale then
  374. local threatLevel = element.mass -- Use mass as a proxy for threat level
  375. if isFriendly(element.id) then threatLevel = -1 end
  376. if threatLevel > highestThreatLevel then
  377. highestThreat = element
  378. highestThreatLevel = threatLevel
  379. end
  380. end
  381. end
  382. end
  383.  
  384. return highestThreat
  385. end
  386.  
  387. local function modemMessage()
  388. while true do
  389. if modem then
  390. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  391. if channel == cannonHitPosChannel then
  392. cannonHitPos = message
  393. end
  394. else
  395. sleep()
  396. end
  397. end
  398. end
  399.  
  400. local function aimCannon(targetPos,targetVel,sourceX,sourceY,sourceZ,currentPitch,currentYaw)
  401. if sourceX and sourceY and sourceZ and currentPitch and currentYaw then
  402.  
  403. local dx = targetPos.x - sourceX
  404. local dy = targetPos.y - sourceY
  405. local dz = targetPos.z - sourceZ
  406. local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
  407.  
  408. local estimateTime = distance / (6*20)
  409. local estimateX = targetPos.x + targetVel.x * estimateTime
  410. local estimateY = targetPos.y + targetVel.y * estimateTime
  411. local estimateZ = targetPos.z + targetVel.z * estimateTime
  412.  
  413. local dx = estimateX - sourceX
  414. local dy = estimateY - sourceY
  415. local dz = estimateZ - sourceZ
  416.  
  417. local horizontalDistance = math.sqrt(dx * dx + dz * dz)
  418. local pitch = math.deg(math.atan2(dy, horizontalDistance))
  419.  
  420. local yaw = math.deg(math.atan2(-dx, dz))
  421. yaw = yaw + 180
  422.  
  423.  
  424. local pitchAdjustments = {
  425. {min = 50, max = 100, increment = 0.5},
  426. {min = 180, max = 250, increment = 1},
  427. {min = 250, max = 300, increment = 2},
  428. {min = 50, max = 100, increment = 0.5},
  429. {min = 180, max = 250, increment = 1},
  430. {min = 250, max = 300, increment = 2},
  431. {min = 300, max = 350, increment = 3},
  432. {min = 350, max = 400, increment = 3.7},
  433. {min = 400, max = 450, increment = 4.3},
  434. {min = 450, max = 500, increment = 5},
  435. {min = 500, max = 550, increment = 5.9},
  436. {min = 550, max = 600, increment = 6.6},
  437. {min = 600, max = 650, increment = 7.5}
  438. }
  439.  
  440. for _, adjustment in ipairs(pitchAdjustments) do
  441. if distance > adjustment.min and distance <= adjustment.max then
  442. pitch = pitch + adjustment.increment
  443. break -- Exit the loop once the correct range is found
  444. end
  445. end
  446. print(" targetPos: "..math.floor(targetPos.x).." , "..math.floor(targetPos.y).." , "..math.floor(targetPos.z))
  447. print(" source: "..sourceX.." , "..sourceY.." , "..sourceZ.." , ")
  448. print("Current: "..math.floor(currentPitch).." , "..math.floor(currentYaw))
  449. print("target: "..math.floor(pitch).." , "..math.floor(yaw))
  450.  
  451. local deltaYaw = yaw - currentYaw
  452. local deltaYaw = (deltaYaw + 180) % 360 - 180
  453. local deltaPitch = pitch - currentPitch
  454. --turning
  455. local yaw_tolerance = 1
  456. local pitch_tolerance = 1
  457. if math.abs(deltaYaw) > yaw_tolerance then
  458. if deltaYaw < 0 then
  459. print("Turning left")
  460. router.setOutput("right", false)
  461. if math.abs(deltaYaw) < 5 then
  462. local turnTime = math.abs(deltaYaw) / 24
  463. print("turnTime: "..turnTime)
  464. router.setOutput("left", true)
  465. sleep(turnTime)
  466. router.setOutput("left",false)
  467. else
  468. router.setOutput("left", true)
  469. end
  470. elseif deltaYaw > 0 then
  471. print("Turning right")
  472. router.setOutput("left", false)
  473. if math.abs(deltaYaw) < 5 then
  474. local turnTime = math.abs(deltaYaw) / 24
  475. router.setOutput("right", true)
  476. sleep(turnTime)
  477. router.setOutput("right",false)
  478. else
  479. router.setOutput("right", true)
  480. end
  481. end
  482. else
  483. router.setOutput("right", false)
  484. router.setOutput("left", false)
  485. end
  486.  
  487. if math.abs(deltaPitch) > pitch_tolerance then
  488. if deltaPitch > 0 then
  489. print("Adjusting pitch up")
  490. router.setOutput("front", false)
  491. if math.abs(deltaPitch) < 5 then
  492. local turnTime = math.abs(deltaPitch) / 24
  493. router.setOutput("top", true)
  494. sleep(turnTime)
  495. router.setOutput("top", false)
  496. else
  497. router.setOutput("top", true)
  498. end
  499. else
  500. print("Adjusting pitch down")
  501. router.setOutput("top", false)
  502. if math.abs(deltaPitch) < 5 then
  503. local turnTime = math.abs(deltaPitch) / 24
  504. router.setOutput("front", true)
  505. sleep(turnTime)
  506. router.setOutput("front", false)
  507. else
  508. router.setOutput("front", true)
  509. end
  510. end
  511. else
  512. router.setOutput("front", false)
  513. router.setOutput("top", false)
  514. end
  515. end
  516. end
  517.  
  518. local function targetLockAndAim()
  519. while true do
  520. currentPitch,currentYaw = cannonHitPos[6],cannonHitPos[7]
  521. source = cannonHitPos[5]
  522. if pInfo.nickname then
  523.  
  524. lockedTarget = lockHighestThreatTarget(elements, screenWidth / 2, screenHeight / 2, 1000)
  525. if lockedTarget then
  526. print("Locked target ID: " .. lockedTarget.id)
  527. lockedTargetScan = radar.scanForShips(5000)
  528. for _, object in ipairs(lockedTargetScan) do
  529. if object.id == lockedTarget.id then
  530. -- Update the locked target information
  531. lockedTarget.pos = object.pos
  532. lockedTarget.velocity = object.velocity
  533. break
  534. end
  535. end
  536. if lockedTarget.pos then
  537. print(textutils.serialize(lookTarget.pos))
  538. aimCannon(lockedTarget.pos,lockedTarget.velocity,source.x, source.y, source.z,currentPitch, currentYaw)
  539. end
  540. else
  541. lookTarget = mouseAim(pInfo.pos, pInfo.lookVector)
  542.  
  543. print(source)
  544. aimCannon(lookTarget, {x=0, y=0, z=0}, source.x, source.y, source.z, currentPitch, currentYaw)
  545. end
  546. end
  547. sleep(0.01)
  548. end
  549. end
  550.  
  551. -- Update the main function to remove target locking and aiming
  552. local function main()
  553. while true do
  554. local playerList = radar.scanForPlayers(1000)
  555. if cannonHitPos then
  556. print("received")
  557. end
  558.  
  559. for _, player in ipairs(playerList) do
  560. local playerName = player.nickname
  561. local playerPosition = player.pos
  562. local lookAngle = player.look_angle
  563.  
  564. if player.nickname == userID then
  565. pInfo = {
  566. nickname = player.nickname,
  567. pos = player.pos,
  568. lookVector = lookAngle
  569. }
  570. end
  571. end
  572.  
  573. if pInfo.nickname then
  574. local objectList = radar.scanForShips(10000)
  575. ar.clear()
  576.  
  577. elements = {}
  578. for _, object in ipairs(objectList) do
  579. local objX, objY, objZ = object.pos.x, object.pos.y, object.pos.z
  580. local screenX, screenY = projectToScreen(objX, objY, objZ, pInfo.pos, pInfo.lookVector)
  581. local distance = math.floor(math.sqrt((object.pos.x - pInfo.pos[1]) ^ 2 + (object.pos.y - pInfo.pos[2]) ^ 2 + (object.pos.z - pInfo.pos[3]) ^ 2))
  582. local speed = math.floor(math.sqrt(object.velocity.x ^ 2 + object.velocity.y ^ 2 + object.velocity.z ^ 2))
  583. local color
  584. if isFriendly(object.id) then
  585. color = 0x009cff -- Friendly, blue color
  586. elseif object.mass < 10000 then
  587. color = 0x999999 -- type unknown/low threat
  588. elseif object.mass < 100000 then
  589. if speed > 40 then
  590. -- high speed low mass, potential missile
  591.  
  592. local missileVector = {object.velocity.x, object.velocity.y, object.velocity.z}
  593. local toPlayerVector = {pInfo.pos[1] - objX, pInfo.pos[2] - objY, pInfo.pos[3] - objZ}
  594. local dotProduct = missileVector[1] * toPlayerVector[1] + missileVector[2] * toPlayerVector[2] + missileVector[3] * toPlayerVector[3]
  595. if dotProduct > 0 then
  596. color = 0xff5600 -- missile coming, high threat
  597. else
  598. color = 0xFFFF00 -- potential threat
  599. end
  600. else
  601. color = 0x00FF00 -- low mass low speed, low threat
  602. end
  603. elseif object.mass < 1000000 then
  604. color = 0xfff700 -- Medium sized vehicle, fighter jet, tanks, helicopter
  605. else
  606. color = 0xffc300 -- Large sized vehicle, ships, strategic bomber
  607. end
  608.  
  609. if screenX and screenY and isWithinRenderDistance(screenX, screenY, screenWidth / 2, screenHeight / 2, 4000 / GUIscale, 4800 / GUIscale, 3200 / GUIscale) then
  610. table.insert(elements, {
  611. id = object.id,
  612. screenX = screenX,
  613. screenY = screenY,
  614. frameSize = 20,
  615. color = color,
  616. distance = distance,
  617. mass = object.mass,
  618. speed = speed,
  619. velocity = object.velocity,
  620. renderInfo = true
  621. })
  622. end
  623. end
  624.  
  625. local filteredElements = filterElements(elements)
  626.  
  627. for _, element in ipairs(elements) do
  628. local found = false
  629. for _, filteredElement in ipairs(filteredElements) do
  630. if element.id == filteredElement.id then
  631. found = true
  632. break
  633. end
  634. end
  635. if not found then
  636. element.renderInfo = false
  637. end
  638. end
  639.  
  640. renderElements(filteredElements, cannonHitPos, pInfo, lockedTarget)
  641. end
  642.  
  643. sleep(0.05) -- Adjust the sleep time as needed to balance performance and responsiveness
  644. end
  645. end
  646.  
  647. local function hitMark()
  648. while true do
  649. if cannonHitPos and modem then
  650. local playerList = radar.scanForPlayers(1000)
  651. for _, player in ipairs(playerList) do
  652. local playerName = player.nickname
  653. local playerPosition = player.pos
  654. local lookAngle = player.look_angle
  655.  
  656. if player.nickname == userID then
  657. pInfo = {
  658. nickname = player.nickname,
  659. pos = player.pos,
  660. lookVector = lookAngle
  661. }
  662. end
  663. end
  664.  
  665. if cannonHitPos[4] == "coordinate" then
  666. if cannonHitPos then
  667. objX, objY, objZ = cannonHitPos[1], cannonHitPos[2], cannonHitPos[3]
  668. end
  669. if objX and objY and objZ then
  670. local screenX, screenY = projectToScreen(objX, objY, objZ, pInfo.pos, pInfo.lookVector)
  671. if screenX and screenY then
  672. ar.clearElement("CrossHair")
  673. ar.drawStringWithId("CrossHair","X", screenX, screenY, 0xFF0000)
  674. end
  675. end
  676. elseif cannonHitPos[3] == "degree" then
  677. print("pitch: "..cannonHitPos[1])
  678. print("yaw: "..cannonHitPos[2])
  679. local screenX, screenY = angleToScreen(cannonHitPos[1], cannonHitPos[2], pInfo.pos, pInfo.lookVector)
  680. if screenX and screenY then
  681. ar.clearElement("CrossHair")
  682. ar.drawStringWithId("CrossHair","X", screenX, screenY, 0xFF0000)
  683. end
  684. end
  685. end
  686. sleep()
  687. end
  688. end
  689.  
  690. -- Main loop
  691. parallel.waitForAny(
  692. modemMessage,
  693. main,
  694. hitMark,
  695. targetLockAndAim
  696. )
  697.  
Advertisement
Add Comment
Please, Sign In to add comment