Advertisement
Guest User

fix multiple weapons units attack behavior

a guest
Nov 20th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. --------------------------------------------------------------------------------
  3.  
  4. function gadget:GetInfo()
  5.   return {
  6.     name      = "0fix_bug5",
  7.     desc      = "Fix weapon of bug5 for engine 94.1",
  8.     author    = "PepeAmpere",
  9.     date      = "Jul 28, 2013",
  10.     license   = "no license",
  11.     layer     = 0,
  12.     enabled   = true  --  loaded by default?
  13.   }
  14. end
  15.  
  16. local spSetUnitWeaponState  = Spring.SetUnitWeaponState
  17. local spGetUnitNearestEnemy = Spring.GetUnitNearestEnemy
  18. local spUnitWeaponFire      = Spring.UnitWeaponFire
  19. local spGiveOrderToUnit     = Spring.GiveOrderToUnit
  20. local spGetUnitPosition     = Spring.GetUnitPosition
  21.  
  22. local bugs                  = {}
  23. local needWeaponFix         = {}
  24. local bugUnitDefID          = 0
  25. local darkswarmDefID        = 0
  26. local weaponNumber          = 1
  27.  
  28. Spring.Echo(Game.version)
  29. if (tonumber(Game.version) >= 95) then
  30.     weaponNumber = 2
  31. end
  32.  
  33. function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID)
  34.     if (bugUnitDefID == unitDefID) then
  35.         bugs[unitID] = 0
  36.         needWeaponFix[unitID] = true
  37.     end
  38.     if (darkswarmDefID == unitDefID) then
  39.         spSetUnitWeaponState(builderID,weaponNumber,"range",110)
  40.         bugs[builderID] = 28
  41.         needWeaponFix[builderID] = true
  42.     end
  43. end
  44.  
  45. function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
  46.     if (bugs[unitID]) then
  47.         bugs[unitID] = nil
  48.     end
  49. end
  50.  
  51. function gadget:GameFrame(n)
  52.     if ((n % 30) == 0) then
  53.         for unitID,seconds in pairs(bugs) do
  54.        
  55.             if ((seconds ~= nil) and (seconds ~= 0)) then
  56.                 bugs[unitID] = seconds - 1
  57.                 --Spring.Echo(bugs[unitID])
  58.             end
  59.            
  60.             if (seconds < 1 and needWeaponFix[unitID]) then
  61.                 spSetUnitWeaponState(unitID,weaponNumber,"range",560)
  62.                 needWeaponFix[unitID] = false
  63.             end        
  64.         end
  65.     end
  66. end
  67.  
  68. function gadget:Initialize()    
  69.     for id,unitDef in pairs(UnitDefs) do
  70.         local uName = unitDef.name
  71.         if (uName == "bug5") then
  72.             bugUnitDefID = unitDef.id
  73.         end
  74.         if (uName == "darkswarmunit") then
  75.             darkswarmDefID = unitDef.id
  76.         end
  77.     end
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement