Don't like ads? PRO users don't see any ads ;-)
Guest

Mavor 5

By: a guest on Sep 22nd, 2012  |  syntax: None  |  size: 3.18 KB  |  hits: 24  |  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. #****************************************************************************
  2. #**
  3. #**  File     :  /cdimage/units/UEB2401/UEB2401_script.lua
  4. #**  Author(s):  John Comes
  5. #**
  6. #**  Summary  :  UEF Experimental Artillery Script
  7. #**
  8. #**  Copyright © 2005 Gas Powered Games, Inc.  All rights reserved.
  9. #****************************************************************************
  10.  
  11. local TStructureUnit = import('/lua/terranunits.lua').TStructureUnit
  12. local TIFArtilleryWeapon = import('/lua/terranweapons.lua').TIFArtilleryWeapon
  13. local DefaultProjectileWeapon = import('/lua/sim/DefaultWeapons.lua').DefaultProjectileWeapon
  14.  
  15. UEB2401 = Class(TStructureUnit) {
  16.     Weapons = {
  17.         MainGun = Class(TIFArtilleryWeapon) {
  18.             FxMuzzleFlashScale = 3,
  19.            
  20.             IdleState = State(TIFArtilleryWeapon.IdleState) {
  21.                 OnGotTarget = function(self)
  22.                     TIFArtilleryWeapon.IdleState.OnGotTarget(self)
  23.                     if not self.ArtyAnim then
  24.                         self.ArtyAnim = CreateAnimator(self.unit)
  25.                         self.ArtyAnim:PlayAnim(self.unit:GetBlueprint().Display.AnimationOpen)
  26.                         self.unit.Trash:Add(self.ArtyAnim)
  27.                     end
  28.                 end,
  29.             },
  30.             CreateProjectileAtMuzzle = function(self, muzzle)
  31.  
  32.                 -- Updates FiringRandomness
  33.  
  34.                 self.unit.CurrentAccuracy = self.unit.MyWeapon:GetFiringRandomness()
  35.                 if self.unit.CurrentAccuracy >= 0.01 then
  36.                     self.unit.MyWeapon:SetFiringRandomness(self.unit.CurrentAccuracy - 0.02)
  37.                 end
  38.  
  39.                 --Updates MuzzleVelocityRandom
  40.  
  41.                 self.unit.CurrentRandom = self.unit.MyWeapon:GetMuzzleVelocityRandom()
  42.                 if self.unit.CurrentRandom >= 0.1 then
  43.                     self.unit.MyWeapon:SetMuzzleVelocityRandom(self.unit.CurrentRandom - 0.1)
  44.                 end
  45.  
  46.                 -- Resets FiringRandomness if the target has changed
  47.  
  48.                 if not self.unit:IsDead() and self.unit.MyWeapon:GetCurrentTarget() then
  49.                     self.unit.CurrentTarget = self.unit.MyWeapon:GetCurrentTarget():GetEntityId()
  50.                 if self.unit.OldTarget == nil then
  51.  
  52.                 -- Inputs new values into table
  53.  
  54.                     self.unit.OldTarget = self.unit.CurrentTarget
  55.                 elseif self.unit.OldTarget ~= self.unit.CurrentTarget then
  56.                     self.unit.MyWeapon:SetFiringRandomness(self.unit.MyWeapon:GetBlueprint().FiringRandomness)
  57.                     self.unit.MyWeapon:SetMuzzleVelocityRandom(self.unit.MyWeapon:GetBlueprint().MuzzleVelocityRandom)
  58.  
  59.                 -- Inputs new target values into OldTarget
  60.  
  61.                     self.unit.OldTarget = self.unit.CurrentTarget
  62.                 end
  63.             end
  64.             TIFArtilleryWeapon.CreateProjectileAtMuzzle(self, muzzle)
  65.             end,
  66.  
  67.             OnLostTarget = function(self)
  68.  
  69.                 --Resets Statistics if target is lost
  70.  
  71.             if not self.unit:IsDead() then
  72.                 self.unit.MyWeapon:SetFiringRandomness(self.unit.MyWeapon:GetBlueprint().FiringRandomness)
  73.                 self.unit.MyWeapon:SetMuzzleVelocityRandom(self.unit.MyWeapon:GetBlueprint().MuzzleVelocityRandom)
  74.             end
  75.             TIFArtilleryWeapon.OnLostTarget(self)
  76.             end,
  77.         },
  78.     },
  79.     OnStopBeingBuilt = function(self,builder,layer)
  80.         TStructureUnit.OnStopBeingBuilt(self)
  81.         self.MyWeapon = self:GetWeaponByLabel('MainGun')
  82.     end,
  83. }
  84. TypeClass = UEB2401