Advertisement
morrtz

Automatic Movement

Aug 10th, 2014
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. --Polygon zones
  2. local polyzone =
  3. {
  4. }
  5.  
  6.  
  7. --Dynamic Movement Table
  8. local AutoMovement =
  9. {
  10. }
  11.  
  12.  
  13. --Populate polyzones from mission
  14. local int = 1
  15. for GName, Data in pairs(mist.DBs.groupsByName) do
  16.     if Data.category == "vehicle" then
  17.         if string.sub(GName,1,string.len("POLYZONE"))=="POLYZONE" then
  18.             polyzone[int] = GName
  19.             AutoMovement[GName] = "stop"
  20.             int = int+1
  21.         end
  22.     end
  23. end
  24.  
  25.  
  26. --Run polygon continues test for units
  27. for i,name in pairs(polyzone) do
  28.     for k,v in pairs({"red","blue"}) do
  29.             mist.flagFunc.units_in_polygon
  30.             {
  31.             units = {'['..v..'][helicopter]','['..v..'][plane]'},
  32.             zone = mist.getGroupPoints(name),
  33.             flag = v..name,
  34.             req_num = 1,
  35.             interval = 10,
  36.             toggle = true
  37.             }
  38.     end
  39. end
  40.  
  41. --movement manager
  42. function MoveManager()
  43.     for i, PZName in pairs(polyzone) do
  44.         local movement = {}    
  45.         for k,v in pairs({"red","blue"}) do
  46.             if trigger.misc.getUserFlag(v..PZName) == 1 then
  47.                 table.insert(movement,v)
  48.             end
  49.         end
  50.        
  51.            
  52.         if (#movement == 2 or #movement == 0) and AutoMovement[PZName] ~= "stop" then
  53.             AutoMovement[PZName] = "stop"
  54.             GoToRoute(PZName,movement)
  55.         elseif #movement == 1 and AutoMovement[PZName] ~= movement[1] then
  56.             AutoMovement[PZName] = movement[1]
  57.             GoToRoute(PZName,AutoMovement[PZName])
  58.         end
  59.         trigger.action.outText("movement:"..#movement.."/n"..mist.utils.tableShow(movement).."/nAutomovement:/n"..mist.utils.tableShow(AutoMovement), 10)
  60.     end
  61.     timer.scheduleFunction(MoveManager,  {}, timer.getTime() + 10)
  62. end
  63.  
  64.  
  65. --Moving groups in polyzone
  66. function GoToRoute(path,coa)
  67.     for GName, GTable in pairs(mist.DBs.groupsByName) do
  68.         if GTable.category == "vehicle" then
  69.             local unitName = GTable.units[1].unitName
  70.             local unit = Unit.getByName(unitName)
  71.             if unit then
  72.                 local pos = unit:getPosition().p
  73.                 local zone = mist.getGroupPoints(path)
  74.                 if mist.pointInPolygon(pos, zone) and coa == "stop" then
  75.                     mist.groupRandomDistSelf(GName, 1)
  76.                 elseif mist.pointInPolygon(pos, zone) and GTable.coalition == coa then
  77.                     ReturnToRoute(GName,coa..path)
  78.                 elseif mist.pointInPolygon(pos, zone) and (GTable.coalition ~= coa and coa~="stop") then
  79.                     mist.groupRandomDistSelf(GName, 1)
  80.                 end
  81.             end
  82.         end
  83.     end
  84. end
  85.  
  86. MoveManager()
  87. --mist.scheduleFunction(MoveManager, {}, timer.getTime() + 10, 7200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement