Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Flag Lock ActionFunction

By: mikeyy on Jul 25th, 2011  |  syntax: Lua  |  size: 2.03 KB  |  views: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     ActionFunction = function(unit, action)
  2.         local result = false
  3.         local actionBp = HeroAIActionTemplates[action.ActionName]
  4.         local aiBrain = unit:GetAIBrain()
  5.  
  6. -- Check to see if there is a nearby flag that we control - if not, then don't continue
  7.         local flags = aiBrain:GetUnitsAroundPoint( categories.FLAG, unit:GetPosition(), 32, 'Ally' )
  8.         if table.empty(flags) then
  9.             return
  10.         end
  11.  
  12.         flags = SortEntitiesByDistanceXZ(unit.Position, flags)
  13. --# 0.27.07 added local flag = false per miri - this SHOULD keep the ai from recasting locks on locked flags
  14.         local flag = false
  15.         for k,v in flags do --Mithy: Add check for being locked before proceeding
  16.             if aiBrain:GetBlipsAroundPoint( categories.HERO, v.Position, 20, 'Enemy' ) > 0 and v.CanBeCaptured and not v.BeingLocked then
  17.                 flag = v
  18.                 break
  19.             end
  20.         end
  21.  
  22.         if not flag then
  23.             return
  24.         end
  25.  
  26.  
  27.  
  28.         local ready = GetReadyAbility(unit, actionBp.Abilities)
  29.         if(ready) then
  30.             result = true
  31.         end
  32.  
  33.         if(result) then
  34.             local captureUnits = flag:GetCaptureList()
  35.             for k,v in captureUnits do
  36.                 if (v == 'ugbportal01')  then
  37.                     local announcement = "Lock Portal flag."
  38.                     AIUtils.AIChat(unit, announcement)
  39.                 elseif (v == 'unbidol01') then
  40.                     local announcement = "Lock Valor flag."
  41.                     AIUtils.AIChat(unit, announcement)
  42.                 else
  43.                 #Do nothing
  44.                 end
  45.             end
  46.  
  47.             --Mithy: Mark this flag as being locked until we're done casting (at which point it will be non-capturable)
  48.             flag.BeingLocked = true
  49.             local endResult = AIAbility.UseTargetedAbility(unit, ready, flag, actionBp.ActionTimeout)
  50.             flag.BeingLocked = nil
  51.             return endResult
  52.         else
  53.             return false
  54.         end
  55.     end,