MegiRicky

laserSightNGDW

Jul 30th, 2024 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. local raycaster = peripheral.find("raycaster")
  2. local modem = peripheral.find("modem")
  3.  
  4. local cannonHitPosChannel = 700
  5. if modem then
  6. modem.open(cannonHitPosChannel)
  7. end
  8.  
  9. if not raycaster then
  10. print("No raycaster found.")
  11. return
  12. end
  13.  
  14. local max_distance = 300
  15.  
  16. local function castRay()
  17. local var1 = 0
  18. local var2 = 0
  19. local var3 = 1
  20. local euler_mode = false
  21. local immediate_execution = true
  22. local check_for_blocks_in_world = true
  23.  
  24. local result = raycaster.raycast(max_distance, {var1, var2, var3}, euler_mode, immediate_execution)
  25.  
  26. -- Check the result
  27. if result.is_block and result.block_type ~= "block.minecraft.air" then
  28. print("Block hit at:")
  29. print("Hit position: " .. result.hit_pos[1] .. ", " .. result.hit_pos[2] .. ", " .. result.hit_pos[3])
  30. print("Block type: " .. result.block_type)
  31. print("Distance: " .. result.distance)
  32. elseif result.is_entity then
  33. print("Entity hit at:")
  34. print("Hit position: " .. result.hit_pos[1] .. ", " .. result.hit_pos[2] .. ", " .. result.hit_pos[3])
  35. print("Entity ID: " .. result.id)
  36. print("Entity type: " .. result.descriptionId)
  37. print("Distance: " .. result.distance)
  38. elseif result.ship_id then
  39. print("No hit detected within " .. max_distance .. " blocks.")
  40. print("Hit position: "..result.hit_pos[1].." , "..result.hit_pos[2].." , "..result.hit_pos[3])
  41. end
  42.  
  43. -- Insert "coordinate" text into the hit_pos table at the fourth position
  44. if result.hit_pos then
  45. table.insert(result.hit_pos, 4, "coordinate")
  46. print(textutils.serialize(result.hit_pos))
  47. modem.transmit(700, 0, result.hit_pos)
  48. print("transmitting")
  49. end
  50. end
  51.  
  52. -- Cast the ray and return the hit coordinates
  53. while true do
  54. castRay()
  55. sleep(0.01)
  56. end
  57.  
Advertisement
Add Comment
Please, Sign In to add comment