Guest User

Untitled

a guest
Feb 2nd, 2014
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -----------------------------------------------------------------------------
  2. --  File     : /units/UAL0216/UAL0216_script.lua
  3. --
  4. --  Author(s): Eddy, EbolaSoup, Resin Smoker, Optimus Prime, Vissroid
  5. --
  6. --  Summary  : Aeon T2 Artillery Bot Script
  7. --
  8. --  Copyright © 2011 4DC_V0.82 All rights reserved.
  9. -----------------------------------------------------------------------------
  10.  
  11. -- Misc Lua called
  12. local AWalkingLandUnit = import('/lua/aeonunits.lua').AWalkingLandUnit
  13. local EffectUtils = import('/lua/EffectUtilities.lua')
  14. local EffectTemplate = import('/lua/EffectTemplates.lua')
  15.  
  16. --4DC Specific Lua called
  17. local Deflector = import('/mods/4DC_V0.82/lua/CustomAbilities/4D_DeflectorShield/DeflectorShield.lua')
  18.  
  19. -- Weapon Local lua called
  20. local CannonWeapon = import('/mods/4DC_V0.82/lua/4D_weapons.lua').UAL0216_CannonWeapon
  21.  
  22. UAL0216 = Class(AWalkingLandUnit) {
  23.     Weapons = {
  24.         MainWeapon = Class(CannonWeapon) {
  25.  
  26.             OnCreate = function(self)
  27.                 self.MainWeaponRecoilAnimator = CreateAnimator(self.unit)
  28.                 CannonWeapon.OnCreate(self)
  29.             end,
  30.  
  31.             PlayRackRecoil = function(self, rackList)
  32.                 CannonWeapon.PlayRackRecoil(self, rackList)
  33.                 if not self.unit:IsDead() and self.unit.Deployed then
  34.                     -- Perform recoil shake
  35.                     self.unit:ShakeCamera(0.5, 0.25, 0.25, 0.25)
  36.                     -- Steam effect from weapon vents
  37.                     self.ExhaustEffects = EffectUtils.CreateBoneEffects( self.unit, 'Bot_Arm_Right1', self.unit:GetArmy(), EffectTemplate.WeaponSteam01 )
  38.                     self.MainWeaponRecoilAnimator:PlayAnim(self:GetBlueprint().AnimationRecoil):SetRate(self:GetBlueprint().AnimationRecoilRate or 1)
  39.                 else
  40.                     -- Perform recoil shake
  41.                     self.unit:ShakeCamera(0.25, 0.125, 0.125, 0.125)
  42.                 end
  43.             end,
  44.        },
  45.     },
  46.  
  47.     OnCreate = function(self,builder,layer)
  48.         AWalkingLandUnit.OnCreate(self)
  49.         -- Creating Global Variables
  50.         self.MyWeapon = self:GetWeaponByLabel('MainWeapon')
  51.         self.WepBP = self.MyWeapon:GetBlueprint()
  52.         -- Setup of the deployment animation
  53.         self.DeployAnim = CreateAnimator(self)
  54.         self.DeployAnim:PlayAnim(self:GetBlueprint().Display.AnimationArtyDeploy)self.DeployAnim:SetRate(0)
  55.         self.Trash:Add(self.DeployAnim)
  56.         -- Setup of the deflector animation
  57.         self.DeflectorAnim = CreateAnimator(self)
  58.         self.DeflectorAnim:PlayAnim(self:GetBlueprint().Display.AnimationDeflectorDeploy)self.DeflectorAnim:SetRate(0)
  59.         self.Trash:Add(self.DeflectorAnim)     
  60.         -- Booleans to record unit state and prevent the toggles from being used while changing modes
  61.         self.ModeChange = false
  62.         self.Deployed = false
  63.         self.Moving = false
  64.         -- Halt Econ
  65.         self:SetMaintenanceConsumptionActive()
  66.         -- Initialize the deflector
  67.         if EntityCategoryContains(categories.DEFLECTOR, self) then
  68.             self:ForkThread(self.KickstartDeflector)
  69.         end
  70.     end,
  71.        
  72.     OnScriptBitSet = function(self, bit)
  73.         AWalkingLandUnit.OnScriptBitSet(self, bit)
  74.         self:ForkThread(self.testMe)
  75.         if not self:IsDead() and bit == 0 then     
  76.             self:ForkThread(self.DeflectorOn)                      
  77.         elseif not self:IsDead() and bit == 1 then
  78.             if not self.Deployed and not self.ModeChange then
  79.                 self:ForkThread(self.DeployArty)
  80.             end
  81.         end
  82.     end,
  83.  
  84.     OnScriptBitClear = function(self, bit)
  85.         AWalkingLandUnit.OnScriptBitClear(self, bit)
  86.         if not self:IsDead() and bit == 0 then
  87.             self:ForkThread(self.DeflectorOff)         
  88.         elseif not self:IsDead() and bit == 1 then
  89.             if self.Deployed and not self.ModeChange then
  90.                 self:ForkThread(self.UnDeployArty)
  91.             end
  92.         end
  93.     end,
  94.  
  95.     OnMotionHorzEventChange = function(self, new, old)
  96.         -- Updates the gloabal variable for when the Meson movement changes
  97.         if not self:IsDead() and new == 'Stopped' then
  98.             self.Moving = false
  99.         elseif not self:IsDead() then
  100.             self.Moving = true
  101.         end
  102.         AWalkingLandUnit.OnMotionHorzEventChange(self, new, old)
  103.     end,
  104.  
  105.     DeployArty = function(self)
  106.         self.ModeChange = true
  107.         self.MyWeapon:SetEnabled(false)
  108.         IssueClearCommands({self})
  109.         while not self:IsDead() and self.Moving do
  110.             -- Delay till the bot has stopped moving
  111.             WaitSeconds(1)
  112.         end
  113.         if not self:IsDead() then
  114.             -- Deploy cannon for long range artillery support
  115.             self:SetImmobile(true)
  116.             self.MyWeapon:ChangeProjectileBlueprint(self.WepBP.SecondaryProjectileId)
  117.             self.MyWeapon:AddDamageMod(692.5)
  118.             self.MyWeapon:AddDamageRadiusMod(1.75)
  119.             self.MyWeapon:ChangeMaxRadius(60)
  120.             self.MyWeapon:ChangeMinRadius(10)
  121.             self.MyWeapon:ChangeRateOfFire(0.275)
  122.             self.MyWeapon:SetFiringRandomness(0.675)
  123.             self.DeployAnim:SetRate(0.5)
  124.             WaitFor(self.DeployAnim)
  125.             if not self:IsDead() then
  126.                 self.Deployed = true
  127.                 self.ModeChange = false
  128.                 self.MyWeapon:SetEnabled(true)
  129.             end
  130.         end
  131.     end,
  132.  
  133.     UnDeployArty = function(self)
  134.         self.ModeChange = true
  135.         self.MyWeapon:SetEnabled(false)
  136.         IssueClearCommands({self})
  137.         while not self:IsDead() and self.Moving do
  138.             -- Delay till the bot has stopped moving
  139.             WaitSeconds(1)
  140.         end
  141.         if not self:IsDead() then
  142.             -- Enable bot mode
  143.             self.MyWeapon:ChangeProjectileBlueprint(self.WepBP.ProjectileId)
  144.             self.MyWeapon:AddDamageMod(-692.5)
  145.             self.MyWeapon:AddDamageRadiusMod(-1.75)
  146.             self.MyWeapon:ChangeMaxRadius(self.WepBP.MaxRadius)
  147.             self.MyWeapon:ChangeMinRadius(self.WepBP.MinRadius)
  148.             self.MyWeapon:ChangeRateOfFire(self.WepBP.RateOfFire)
  149.             self.MyWeapon:SetFiringRandomness(self.WepBP.FiringRandomness)
  150.             self.DeployAnim:SetRate(-0.5)
  151.             WaitFor(self.DeployAnim)
  152.             if  not self:IsDead() then
  153.                 self:SetImmobile(false)
  154.                 self.Deployed = false
  155.                 self.ModeChange = false
  156.                 self.MyWeapon:SetEnabled(true)
  157.             end
  158.         end
  159.     end,
  160.    
  161.     DeflectorOn = function(self)
  162.         self.DeflectorAnim:SetRate(2)
  163.         WaitFor(self.DeflectorAnim)
  164.         self.Deflector:EnableDeflector()
  165.     end,
  166.    
  167.     DeflectorOff = function(self)
  168.         self.Deflector:DisableDeflector()
  169.         self.DeflectorAnim:SetRate(-2)
  170.         WaitFor(self.DeflectorAnim)    
  171.     end,   
  172.    
  173.     KickstartDeflector = function(self)    
  174.         local bp = self:GetBlueprint()             
  175.         self.Deflector = Deflector.Deflector_Entity {
  176.             CollisionCenterX = bp.Defense.Deflector.CollisionCenterX or 1,
  177.             CollisionCenterY = bp.Defense.Deflector.CollisionCenterY or 1,
  178.             CollisionCenterZ = bp.Defense.Deflector.CollisionCenterZ or 1,
  179.             CollisionShape = bp.Defense.Deflector.CollisionShape or 'Box',
  180.             CollisionSizeX = bp.Defense.Deflector.CollisionSizeX or 1,
  181.             CollisionSizeY = bp.Defense.Deflector.CollisionSizeY or 1,
  182.             CollisionSizeZ = bp.Defense.Deflector.CollisionSizeZ or 1,
  183.             DeflectorMesh = bp.Defense.Deflector.DeflectorMesh,    
  184.             FactionName = bp.General.FactionName,
  185.             ImpactEffects = bp.Defense.Deflector.MeshScale or 1,
  186.             MeshScale = bp.Defense.Deflector.MeshScale or 1,           
  187.             Owner = self,                              
  188.             OwnerAttachBone = bp.Defense.Deflector.OwnerAttachBone,
  189.             OwnerFXBone = bp.General.OwnerFXBone,                              
  190.             PositionOffsetX = bp.Defense.Deflector.PositionOffsetX or 0,
  191.             PositionOffsetY = bp.Defense.Deflector.PositionOffsetY or 0,
  192.             PositionOffsetZ = bp.Defense.Deflector.PositionOffsetZ or 0,
  193.             SizeSphere = bp.Defense.Deflector.SizeSphere or 1,
  194.             StartOn = bp.Defense.Deflector.StartOn,
  195.         }
  196.         self.Trash:Add(self.Deflector) 
  197.     end,           
  198.  
  199. }
  200. TypeClass = UAL0216
RAW Paste Data