Guest User

ASF CZAR Fix

a guest
Feb 18th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 KB | None | 0 0
  1. -----------------------------------------------------------------------------
  2. --  File     : /mods/ASF_CZAR_fix/hook/units/UAL0216/UEA0303_script.lua
  3. --  Author(s): Resin Smoker
  4. --  Summary  : UEF Supersonic Fighter Script
  5. --  Copyright © 2014   All rights reserved.
  6. -----------------------------------------------------------------------------
  7.  
  8. do
  9.  
  10. --> Triggers all logs to report if flag set true, otherwise use the local flags within each function for specific outputs
  11. local masterDebug = false
  12. --> Localy imported files
  13. local TAirUnit = import('/lua/terranunits.lua').TAirUnit
  14. --> Weapon imported files
  15. local TAAGinsuRapidPulseWeapon = import('/lua/terranweapons.lua').TAAGinsuRapidPulseWeapon
  16. --> Custom imported files
  17.  
  18.     local OldUEA0303 = UEA0303
  19.     UEA0303 = Class(TAirUnit) {
  20.             Weapons = {
  21.             RightBeam = Class(TAAGinsuRapidPulseWeapon) {
  22.                                            
  23.                 OnStartTracking = function(self, label)
  24.                     if masterDebug then
  25.                         LOG('   OnStartTracking')
  26.                     end
  27.                     self.unit:SetRangeMod()                                    
  28.                     TAAGinsuRapidPulseWeapon.OnStartTracking(self, label)
  29.                 end,
  30.                
  31.                 OnStopTracking = function(self, label)                     
  32.                     if masterDebug then
  33.                         LOG('   OnStopTracking')
  34.                     end
  35.                     self.unit:EndRangeMod()                                    
  36.                     TAAGinsuRapidPulseWeapon.OnStopTracking(self, label)
  37.                 end,                           
  38.                                            
  39.             },
  40.             LeftBeam = Class(TAAGinsuRapidPulseWeapon) {},
  41.         },
  42.        
  43.         OnStopBeingBuilt = function(self, builder, layer)
  44.         TAirUnit.OnStopBeingBuilt(self, builder, layer)    
  45.             if not self:IsDead() then
  46.                 --> Global Varibles
  47.                 self.MyWeapon = self:GetWeaponByLabel('RightBeam')
  48.                 self.MyWeapon:ChangeMinRadius(10)
  49.                 self.RangeMod = false                          
  50.                 TAirUnit.OnStopBeingBuilt( self, builder, layer)
  51.             end
  52.         end,
  53.  
  54.         SetRangeMod = function(self)
  55.             if masterDebug then
  56.                 LOG('   SetRangeMod')
  57.             end
  58.             --> Boolean is not already set
  59.             if not self.RangeMod then          
  60.                 --> Ensure self and target are viable
  61.                 if not self:IsDead() and self.MyWeapon:GetCurrentTarget() then
  62.                     --> Resets weapon ranges if target gained is Czar
  63.                     if self.MyWeapon:GetCurrentTarget():GetBlueprint().General.UnitName == "<LOC uaa0310_name>CZAR" then
  64.                         self:ForkThread(self.CzarCheckHeartBeat)                           
  65.                     else
  66.                         if masterDebug then
  67.                             LOG('   Target NOT Czar, range mod aborted')
  68.                         end                                  
  69.                     end
  70.                 else
  71.                     if masterDebug then
  72.                         LOG('   Self or Target "is dead" ')
  73.                     end                
  74.                 end
  75.             else
  76.                 if masterDebug then
  77.                     LOG('   RangeMod already in effect')
  78.                 end            
  79.             end                
  80.         end,
  81.        
  82.         EndRangeMod = function(self)
  83.             if masterDebug then
  84.                 LOG('   EndRangeMod')
  85.             end                
  86.             --> Resets weapon ranges if target is lost
  87.             if not self:IsDead() and self.RangeMod then
  88.                 self.RangeMod = false
  89.                 self:SetSpeedMult(1.0)
  90.                 self:SetTurnMult(1.0)                                      
  91.             end                
  92.         end,
  93.        
  94.         CzarCheckHeartBeat = function(self)
  95.             if masterDebug then
  96.                 LOG('   CzarCheckHeartBeat')
  97.             end        
  98.             self.RangeMod = true
  99.             while self.RangeMod and not self:IsDead() and self.MyWeapon:GetCurrentTarget() and self.MyWeapon:GetCurrentTarget():GetBlueprint().General.UnitName == "<LOC uaa0310_name>CZAR" do     
  100.                 if self:GetDistanceToCzar() <= 25 then
  101.                     self.LastTarget = {}
  102.                     table.insert( self.LastTarget, self.MyWeapon:GetCurrentTarget())
  103.                     IssueClearCommands(self)
  104.                     local x, y ,z = unpack( self:CalculateWorldPositionFromRelative({10, 0, 0}) )
  105.                     IssueMove(self, Vector(x, y, z))
  106.                     self:SetSpeedMult(1.50)
  107.                     self:SetTurnMult(1.50)
  108.                     if masterDebug then
  109.                         LOG('   Moving away from Czar')
  110.                     end                        
  111.                 else
  112.                     self:SetSpeedMult(1.0)
  113.                     self:SetTurnMult(1.0)                
  114.                     if self.LastTaget[1] and not self.LastTaget[1]:IsDead() then
  115.                         IssueAttack(self, self.LastTaget[1])
  116.                     end                
  117.                     if masterDebug then
  118.                         LOG('   Default move and turn rates')
  119.                     end                                                        
  120.                 end
  121.                 --> Short delay between checks
  122.                 WaitSeconds(1)             
  123.             end
  124.             if masterDebug then
  125.                 LOG('   CzarCheckHeartBeat Ended')
  126.             end            
  127.         end,
  128.        
  129.         GetDistanceToCzar = function(self)
  130.             local tpos = self.MyWeapon:GetCurrentTarget():GetPosition()
  131.             local mpos = self:GetPosition()
  132.             local dist = VDist2(mpos[1], mpos[3], tpos[1], tpos[3])
  133.             return dist
  134.         end,                           
  135.        
  136.     }  
  137.     TypeClass = UEA0303
  138. end
Advertisement
Add Comment
Please, Sign In to add comment