Advertisement
Marlingaming

Hovercraft Autopilot Script MC

Aug 21st, 2022 (edited)
910
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1. StartingCords = {}
  2. FirstStart = true
  3. ReAfMiss = false
  4. Gunship = false
  5. Transport = false
  6. GroundAtObj = false
  7. Package = false
  8. BombBay = false
  9. DeployCargo = false
  10. BombingRun = false
  11. MissionCompleted = false
  12. EnableWeapons = false
  13.  
  14. function onTick()
  15.     Orders = input.getBool(1)
  16.     if Orders == true then
  17.         GetDetails()
  18.     end
  19. end
  20.  
  21. function GetDetails()
  22.     X1 = input.getNumber(1)
  23.     Y1 = input.getNumber(2)
  24.     X2 = input.getNumber(3)
  25.     Y2 = input.getNumber(4)
  26.     if MissionCompleted == true and ReAfMiss == true then
  27.         X2 = StartingCords[1]
  28.         Y2 = StartingCords[2]
  29.     end
  30.     if FirstStart = true then
  31.         FirstStart = false
  32.         StartingCords = {X1,Y1}
  33.     end
  34.     Package = true
  35.     CHeading = input.getNumber(5)
  36.     Height = input.getNumber(6)
  37.     Ground = input.getBool(2)
  38.     GunshipMission = input.getBool(3)
  39.     GroundAtObj = input.getBool(4)
  40.     Transport = input.getBool(5)
  41.     BombsLoaded = input.getBool(6)
  42.     CargoLoaded = input.getBool(7)
  43.     MissionType = input.getNumber(8) '0-Gunship,1=BombingRun,2-Transport'
  44.     if MissionType == 1 then
  45.         Package = BombsLoaded
  46.     elseif MissionType == 2 then
  47.         Package = CargoLoaded
  48.     end
  49.     Heading = 0
  50.     XD = X1 - X2
  51.     YD = Y1 - Y2
  52.     AXD = math.arct(XD)
  53.     AYD = math.arct(YD)
  54.     Dir = 0
  55.     Move = false
  56.     Land = false
  57.     Dis = 1000
  58.     Q = 1
  59.     if XD > 0 and YD > 0 then
  60.         Q = 1
  61.     else if XD < 0 and YD > 0 then
  62.         Q = 2
  63.     else if XD < 0 and YD < 0 then
  64.         Q = 3
  65.     else if XD > 0 and YD < 0 then
  66.         Q = 4
  67.     end
  68.     Dis = math.sqrt(math.pow(XD,2)+math.pow(YD,2))
  69.     DegAt = (math.atan(AXD/AYD)) * 180/math.pi
  70.     if Q == 1 then
  71.         Heading = DegAt
  72.     elseif Q == 2 then
  73.         Heading = (180 - DegAt)XD - 1
  74.     elseif Q == 3 then
  75.         Heading = 180 + DegAt
  76.     elseif Q == 4 then
  77.         Heading = (360 - DegAt)x - 1
  78.     end
  79.     Heading = Heading - 90
  80.     if Heading < 90 then
  81.         Heading = Heading + 270
  82.     end
  83.     TDegrees = CHeading - Heading
  84.     if TDegrees < 90 then
  85.         TDegrees = TDegrees + 270
  86.     end
  87.     if CHeading - 5 < Heading and CHeading + 5 > Heading then
  88.         Move = true
  89.     else
  90.         Move = false
  91.     end
  92.     if Dis < 6 and GroundAtObj == true and Package == true then
  93.         Land = true
  94.     elseif Package == false then
  95.         Land = false
  96.     end
  97.     if Land == true and Package == true and MissionType == 2 and Height < 5 then
  98.         DeployCargo = true
  99.     elseif Dis < 10 and Height > 10 and Package == true and MissionType == 1 then
  100.         BombBay = true
  101.     end
  102.     if MissionCompleted == false and Dis < 300 then
  103.         EnableWeapons = true
  104.     else
  105.         EnableWeapons = false
  106.     end
  107.     output.setBool(1,Land)
  108.     output.setBool(2,Move)
  109.     output.setBool(3,BombBay)
  110.     output.setBool(4,DeployCargo)
  111.     output.setBool(5,EnableWeapons)
  112.     output.setNumber(3,TDegrees)
  113.     CheckMission()
  114. end
  115.  
  116. function CheckMission()
  117.     if MissionType == 2 and Land == false and Package == false then
  118.         MissionCompleted = true
  119.     elseif MissionType == 1 and Package == false then
  120.         MissionCompleted = true
  121.     end
  122.     if MissionCompleted == true then
  123.         BombBay = false
  124.         DeployCargo = false
  125.     end
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement