Advertisement
Psyrixx

DCS: World / Dynamic Extraction Team

May 9th, 2013
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.90 KB | None | 0 0
  1. local assetUnit     = Unit.getByName('Downed Pilot')
  2. local assetGroup    = Group.getByName('Downed Pilot')
  3. local rescueUnit    = false
  4. local rescueGroup   = false
  5. local verifyGroup   = false
  6.  
  7. trigger.action.setUserFlag('15', false)
  8. trigger.action.setUserFlag('5000', false)
  9. trigger.action.setUserFlag('5001', false)
  10. trigger.action.setUserFlag('5002', false)
  11. trigger.action.setUserFlag('5003', false)
  12.  
  13. mist.flagFunc.units_in_zones {
  14.     units       = {'Pontiac 1-1', 'Pontiac 1-2', 'Chevy 1-1', 'Chevy 2-1', 'Chevy 3-1', 'Chevy 4-1'},
  15.     zones       = {'RescueBegins'},
  16.     flag        = 5000,
  17.     stopflag    = 15
  18. }
  19.  
  20. mist.flagFunc.units_in_moving_zones {
  21.     units       = {'Delta', 'Echo'},
  22.     zone_units  = {'Downed Pilot'},
  23.     radius      = 10,
  24.     flag        = 5001,
  25.     stopflag    = 15
  26. }
  27.  
  28. mist.flagFunc.units_in_moving_zones {
  29.     units       = {'Downed Pilot', 'Delta', 'Echo'},
  30.     zone_units  = {'Pontiac 1-1', 'Pontiac 1-2', 'Chevy 1-1', 'Chevy 2-1', 'Chevy 3-1', 'Chevy 4-1'},
  31.     zone_type   = 'sphere',
  32.     radius      = 20,
  33.     flag        = 5002,
  34.     req_num     = 2,
  35.     stopflag    = 15
  36. }
  37.  
  38. function generateVerifyGroupData(assetUnit, rescueUnit)
  39.     local assetUnitPosition     = assetUnit:getPosition().p
  40.     local rescueUnitPosition    = rescueUnit:getPosition().p
  41.    
  42.     local rescueUnitHeading     = mist.getHeading(rescueUnit)
  43.     local verifySpawnDistance   = 20
  44.    
  45.     local verifyGroupX          = rescueUnitPosition.x + verifySpawnDistance * math.cos(rescueUnitHeading + math.pi / 2)
  46.     local verifyGroupY          = rescueUnitPosition.z + verifySpawnDistance * math.sin(rescueUnitHeading + math.pi / 2)
  47.     local verifyGroupLeftX      = rescueUnitPosition.x + verifySpawnDistance * math.cos(rescueUnitHeading + (math.pi * 3) / 2)
  48.     local verifyGroupLeftY      = rescueUnitPosition.z + verifySpawnDistance * math.sin(rescueUnitHeading + (math.pi * 3) / 2)
  49.     local leftDistance          = math.sqrt((verifyGroupLeftX - assetUnitPosition.x) ^ 2 + (verifyGroupLeftY - assetUnitPosition.z) ^ 2)
  50.     local rightDistance         = math.sqrt((verifyGroupX - assetUnitPosition.x) ^ 2 + (verifyGroupY - assetUnitPosition.z) ^ 2)
  51.    
  52.     if rightDistance >= leftDistance then
  53.         verifyGroupX = verifyGroupLeftX
  54.         verifyGroupY = verifyGroupLeftY
  55.     end
  56.    
  57.     local verifyGroupData = {
  58.         ["name"] = "VerificationGroup",
  59.         ["taskSelected"] = true,
  60.         ["hidden"] = false,
  61.         ["groupId"] = math.random(1111111,9999999),
  62.         ["visible"] = false,
  63.         ["units"] =
  64.         {
  65.             [1] =
  66.             {
  67.                 ["y"] = verifyGroupY,
  68.                 ["type"] = "Soldier M4",
  69.                 ["name"] = "Delta",
  70.                 ["unitId"] = math.random(1111111,9999999),
  71.                 ["heading"] = rescueUnitHeading,
  72.                 ["playerCanDrive"] = true,
  73.                 ["skill"] = "Average",
  74.                 ["x"] = verifyGroupX,
  75.             }, -- end of [1]
  76.             [2] =
  77.             {
  78.                 ["y"] = verifyGroupY - 1,
  79.                 ["type"] = "Soldier M4",
  80.                 ["name"] = "Echo",
  81.                 ["unitId"] = math.random(1111111,9999999),
  82.                 ["heading"] = rescueUnitHeading,
  83.                 ["playerCanDrive"] = true,
  84.                 ["skill"] = "Average",
  85.                 ["x"] = verifyGroupX - 1,
  86.             }, -- end of [2]
  87.         },
  88.         ["y"] = verifyGroupY,
  89.         ["x"] = verifyGroupX,
  90.         ["start_time"] = 0,
  91.         ["task"] = "Ground Nothing",
  92.     }
  93.    
  94.     return verifyGroupData
  95. end
  96.  
  97. function generateWaypoints(assetUnit, rescueUnit, waypointType)
  98.     local waypoints = {}
  99.     local assetPos  = assetUnit:getPosition().p
  100.     local rescuePos = rescueUnit:getPosition().p
  101.     local verifyPos = Unit.getByName("Delta"):getPosition().p
  102.  
  103.     local assetPoint = {
  104.         ["type"] = "Flyover Point",
  105.         ["ETA"] = 0,
  106.         ["y"] = assetPos.z - 6,
  107.         ["x"] = assetPos.x,
  108.         ["ETA_locked"] = true,
  109.         ["speed"] = 15,
  110.         ["speed_locked"] = true,
  111.     }
  112.  
  113.     local rescuePoint = {
  114.         ["type"] = "Flyover Point",
  115.         ["ETA"] = 0,
  116.         ["y"] = rescuePos.z,
  117.         ["x"] = rescuePos.x,
  118.         ["ETA_locked"] = true,
  119.         ["speed"] = 15,
  120.         ["speed_locked"] = true,
  121.     }
  122.    
  123.     local verifyPoint = {
  124.         ["type"] = "Flyover Point",
  125.         ["ETA"] = 0,
  126.         ["y"] = verifyPos.z,
  127.         ["x"] = verifyPos.x,
  128.         ["ETA_locked"] = true,
  129.         ["speed"] = 15,
  130.         ["speed_locked"] = true,
  131.     }
  132.    
  133.     if waypointType == 'ingress' then
  134.         waypoints[#waypoints+1] = mist.ground.buildWP(verifyPoint, 'Off Road', 20)
  135.         waypoints[#waypoints+1] = mist.ground.buildWP(assetPoint, 'Diamond', 20)
  136.     elseif waypointType == 'egress' then
  137.         waypoints[#waypoints+1] = mist.ground.buildWP(assetPoint, 'Off Road', 20)
  138.         waypoints[#waypoints+1] = mist.ground.buildWP(rescuePoint, 'Diamond', 20)
  139.     elseif waypointType == 'stopPush' then
  140.         waypoints[#waypoints+1] = mist.ground.buildWP(verifyPoint, 'Off Road', 20)
  141.         waypoints[#waypoints+1] = mist.ground.buildWP(assetPoint, 'Diamond', 20)
  142.     end
  143.    
  144.     return waypoints
  145. end
  146.  
  147. function getRescueUnit(rescueUnit)
  148.     if (trigger.misc.getUserFlag('5000') == 1 and not rescueUnit) or (rescueUnit and rescueUnit:inAir()) then
  149.         if Unit.getByName('Pontiac 1-1') and not Unit.getByName('Pontiac 1-1'):inAir() and next(mist.getUnitsInZones({'Pontiac 1-1'}, {'RescueBegins'})) then
  150.             rescueUnit = Unit.getByName('Pontiac 1-1')
  151.         elseif Unit.getByName('Pontiac 1-2') and not Unit.getByName('Pontiac 1-2'):inAir() and next(mist.getUnitsInZones({'Pontiac 1-2'}, {'RescueBegins'})) then
  152.             rescueUnit = Unit.getByName('Pontiac 1-2')
  153.         elseif Unit.getByName('Chevy 1-1') and not Unit.getByName('Chevy 1-1'):inAir() and next(mist.getUnitsInZones({'Chevy 1-1'}, {'RescueBegins'})) then
  154.             rescueUnit = Unit.getByName('Chevy 1-1')
  155.         elseif Unit.getByName('Chevy 2-1') and not Unit.getByName('Chevy 2-1'):inAir() and next(mist.getUnitsInZones({'Chevy 2-1'}, {'RescueBegins'})) then
  156.             rescueUnit = Unit.getByName('Chevy 2-1')
  157.         elseif Unit.getByName('Chevy 3-1') and not Unit.getByName('Chevy 3-1'):inAir() and next(mist.getUnitsInZones({'Chevy 3-1'}, {'RescueBegins'})) then
  158.             rescueUnit = Unit.getByName('Chevy 3-1')
  159.         elseif Unit.getByName('Chevy 4-1') and not Unit.getByName('Chevy 4-1'):inAir() and next(mist.getUnitsInZones({'Chevy 4-1'}, {'RescueBegins'})) then
  160.             rescueUnit = Unit.getByName('Chevy 4-1')
  161.         else
  162.             rescueUnit = false
  163.         end
  164.     end
  165.    
  166.     return rescueUnit
  167. end
  168.  
  169. function spawnVerifyGroup(assetUnit, rescueUnit)
  170.     local verifyGroupData   = generateVerifyGroupData(assetUnit, rescueUnit)
  171.     local verifyGroup       = coalition.addGroup(country.id.USA, Group.Category.GROUND, verifyGroupData)
  172.    
  173.     return verifyGroup
  174. end
  175.  
  176. function main(assetUnit, assetGroup, rescueUnit, verifyGroup, verifyStarted, verifyDone, pushingToEgress)
  177.     local egress            = nil
  178.     local ingress           = nil
  179.     local stopPush          = nil
  180.     local verifyTime        = 600   -- time in seconds (ten minutes)
  181.  
  182.     if next(mist.getUnitsInZones({'Pontiac 1-1', 'Pontiac 1-2', 'Chevy 1-1', 'Chevy 2-1', 'Chevy 3-1', 'Chevy 4-1'}, {'RescueBegins'})) ==  nil then
  183.         trigger.action.setUserFlag('5000', 0)
  184.     end
  185.  
  186.     if trigger.misc.getUserFlag('5001') == 1 and verifyStarted == false then
  187.         mist.scheduleFunction(trigger.action.setUserFlag, {'5003', true}, timer.getTime() + verifyTime) -- Verify Complete Flag
  188.         trigger.action.outText("This is Delta squad. We have made contact with the asset. Give us close air support for ten minutes while we verify his identity.", 40)
  189.         trigger.action.outSound('DeltaSupportRequest.ogg')
  190.        
  191.         verifyStarted = true
  192.     end
  193.    
  194.     rescueUnit = getRescueUnit(rescueUnit)
  195.  
  196.     if rescueUnit then
  197.         rescueUnitVelocity = rescueUnit:getVelocity()
  198.        
  199.         if verifyGroup then
  200.             egress  = generateWaypoints(assetUnit, rescueUnit, 'egress')
  201.  
  202.             if trigger.misc.getUserFlag('5001') == 1 and trigger.misc.getUserFlag('5002') == 1 and trigger.misc.getUserFlag('5003') == 1 then
  203.                 trigger.action.outText("This is Delta squad. We're on board with the asset and ready for dust off.", 40)
  204.                 trigger.action.outSound('ExtractComplete.ogg')
  205.                 trigger.action.setUserFlag('500', false)
  206.                 trigger.action.setUserFlag('15', true)
  207.                 verifyGroup:destroy()
  208.                 assetGroup:destroy()
  209.             elseif trigger.misc.getUserFlag('5001') == 1 and trigger.misc.getUserFlag('5003') == 1 and not pushingToEgress then
  210.                 if rescueUnitVelocity.x < 1 and rescueUnitVelocity.y < 1 and rescueUnitVelocity.z < 1 then
  211.                     pushingToEgress = true
  212.                     mist.goRoute(verifyGroup, egress)
  213.                     mist.scheduleFunction(mist.goRoute, {assetGroup, egress}, timer.getTime() + 5)
  214.                     if not verifyDone then
  215.                         verifyDone = true
  216.                         trigger.action.outText("This is Delta squad. We have verified the identity of the asset. We are pushing to extraction.", 40)
  217.                         trigger.action.outSound('StartPushToExtraction.ogg')
  218.                     else
  219.                         trigger.action.outText("This is Delta squad. We are pushing to extraction.", 40)
  220.                         trigger.action.outSound('ResumePushToExtraction.ogg')
  221.                     end
  222.                 end
  223.             end
  224.         else
  225.             if rescueUnitVelocity.x < 1 and rescueUnitVelocity.y < 1 and rescueUnitVelocity.z < 1 then
  226.                 verifyGroup = spawnVerifyGroup(assetUnit, rescueUnit)
  227.            
  228.                 ingress     = generateWaypoints(assetUnit, rescueUnit, 'ingress')
  229.                 trigger.action.outText("This is Delta squad. We have boots on the ground and we're pushing towards the asset.", 40)
  230.                 trigger.action.outSound('StartPushToAsset.ogg')
  231.                
  232.                 mist.goRoute(verifyGroup, ingress)
  233.             end
  234.         end
  235.     elseif verifyGroup then
  236.         trigger.action.setUserFlag('5002', false)
  237.        
  238.         if pushingToEgress then
  239.             stopPush    = generateWaypoints(assetUnit, assetUnit, 'stopPush')
  240.        
  241.             trigger.action.outText("This is Delta squad. Um - we're not on board yet. Return to the extraction zone for dust off.", 40)
  242.             trigger.action.outSound('StopPushToExtraction.ogg')
  243.             mist.goRoute(verifyGroup, stopPush)
  244.             mist.goRoute(assetGroup, stopPush)
  245.             pushingToEgress = false
  246.         end
  247.        
  248.         if trigger.misc.getUserFlag('5001') == 1 and trigger.misc.getUserFlag('5003') == 1 and not verifyDone then
  249.             trigger.action.outText("This is Delta squad. We have verified the identity of the asset. Return to the extraction zone for dust off.", 40)
  250.             trigger.action.outSound('AssetVerificationComplete.ogg')
  251.             verifyDone = true
  252.         end
  253.     end
  254.    
  255.     if trigger.misc.getUserFlag('15') == 0 and trigger.misc.getUserFlag('999') == 0 then
  256.         mist.scheduleFunction(main, {assetUnit, assetGroup, rescueUnit, verifyGroup, verifyStarted, verifyDone, pushingToEgress}, timer.getTime() + 1)
  257.     end
  258. end
  259.  
  260. main(assetUnit, assetGroup, rescueUnit, verifyGroup, false, false, false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement