Marlingaming

CC Tweaked Security Turtle Script

Feb 25th, 2022 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. local Mode = 0--0 = Sleep, 1 = Holstered, 2 = Engaging
  2. local Aggression = 0
  3. --Inventory Setup, 1 = Weapon, 2 = Speaker, 3= Modem, 4= Detector
  4. local Staff = {}
  5. local Direction = "N"
  6.  
  7. function GetDirection(player)
  8. local X1, Y1, Z1 = gps.getPosition()
  9. local X2, Y2, Z2 = SearchArea_Player(player)
  10. if X1 > X2 then
  11. Direction = "W"
  12. elseif X1 < X2 then
  13. Direction = "E"
  14. elseif Z1 > Z2 then
  15. Direction = "S"
  16. elseif Z1 < Z2 then
  17. Direction = "N"
  18. end
  19. end
  20.  
  21. function GiveWarning()
  22. turtle.select(2)
  23. turtle.equipLeft()
  24. local Speaker = peripheral.find("speaker")
  25. Speaker.playSound("block.note_block.bit")
  26. turtle.unequipLeft()
  27. end
  28.  
  29. function ApproachPlayer(player)
  30. GetDirection(player)
  31. local Cords = SearchArea_Player(player)
  32. Cords[4] = Direction
  33. shell.run("Mover",Cords)
  34. end
  35.  
  36. function WarnPlayer(player)
  37. ApproachPlayer(player)
  38. GiveWarning()
  39. end
  40.  
  41. function Attack()
  42. turtle.select(1)
  43. turtle.equipLeft()
  44. turtle.attack()
  45. turtle.unequipLeft()
  46. end
  47.  
  48. function SearchArea_Player(player)
  49. local R = {}
  50. turtle.select(4)
  51. turtle.equipLeft()
  52. local Detector = peripheral.find("playerDetector")
  53. local Pos = Detector.getPlayerPos(player)
  54. R = {Pos.x,Pos.y,Pos.z}
  55. turtle.unequipLeft()
  56. return R
  57. end
  58.  
  59. function Engage(player)
  60. for i = 1, 4 do
  61. local Cords = SearchArea_Player(player)
  62. GetDirection(player)
  63. Cords[4] = Direction
  64. shell.run("Mover",Cords)
  65. Attack()
  66. end
  67. end
  68.  
  69.  
  70. function Startup()
  71. turtle.select(3)
  72. assert(turtle.equipRight())
  73. peripherals.find("modem",rednet.open)
  74. end
  75.  
  76. if tArg[1] == "start" then
  77. Startup()
  78. elseif tArg[1] == "Idle" then
  79.  
  80. elseif tArg[1] == "Respond" then
  81. Aggression = tArg[3]
  82. if Aggression == 1 then
  83. WarnPlayer(tArg[2])
  84. elseif Aggression > 1 then
  85. for q = 1, 15 do
  86. Engage(tArg[2])
  87. end
  88. end
  89. end
Add Comment
Please, Sign In to add comment