Auto-recall works wierd in-game Topic is solved

Auto-recall works wierd in-game

Postby FunkOff » 16 Jan 2014, 05:01

The auto-recall works funny. I just killed a guy with auto recall (I never seen it used before). The guy's ACU was close to death, and it just disappeared and made an explosion noise when it had around 2000 hp left.

Here's the code I used in my "Recall enabled" mod which recalled the ACU in a more smooth way. This code amends the DoTakeDamage function of the ACU unit.

Code: Select all
    DoTakeDamage = function(self, instigator, amount, vector, damageType)
      WARN('acu take damage')
        local preAdjHealth = self:GetHealth()
        self:AdjustHealth(instigator, -amount)
        local health = self:GetHealth()
        if( health <= 0 ) then
         if self:DoIHaveAnEnhancement() then
            self:Recall()
            return
            elseif( damageType == 'Reclaimed' ) then
                self:Destroy()
            else
                local excessDamageRatio = 0.0
                # Calculate the excess damage amount
                local excess = preAdjHealth - amount
                local maxHealth = self:GetMaxHealth()
                if(excess < 0 and maxHealth > 0) then
                    excessDamageRatio = -excess / maxHealth
                end
                self:Kill(instigator, damageType, excessDamageRatio)
            end
        end
        if EntityCategoryContains(categories.COMMAND, self) then
            local aiBrain = self:GetAIBrain()
            if aiBrain then
                aiBrain:OnPlayCommanderUnderAttackVO()
            end
        end
    end,


Here are the other functions that the function above calls.
Code: Select all
   
   ##new for recall, lets me know if I have an enhancement
   DoIHaveAnEnhancement = function(self)
      WARN('DoIHaveanEnhancement')
       local enh = self:GetBlueprint().Enhancements
      if enh then
         for k,v in enh do
            if self:HasEnhancement(k) then
               return true
            end
         end
      end
   end,
   
   #recalls the commander
   Recall = function(self)
      WARN('recalling')
      SetInvincible(self, true)
      self:HideBone(0, true)
      self:PlayTeleportOutEffects()
      self:StunAllMyArmyUnits()
      Warp(self,   self.SpawnPoint, self:GetOrientation())
      WaitSeconds(30)
      self:ReSpawn()
   end,
   
   #stuns all the units in the army
   StunAllMyArmyUnits = function(self)
      WARN('stunning all my units')
      local aiBrain = self:GetAIBrain()
      local units = aiBrain:GetListOfUnits(categories.ALLUNITS - categories.WALL - categories.COMMAND, false)
      for i,u in units do
         u:SetStunned(30)
      end
   end,
   
   ReSpawn = function(self)
      WARN('respawning')
      self:WarpInEffectThread()
      local enh = self:WhatEnhancementsDoIHave()
      local enhbp = self:GetBlueprint().Enhancements
      for m,n in enhbp do
         for o,p in enh do
            if p.RemoveEnhancements and p.Prerequisite == m then
               self:CreateEnhancement(p)
            end
         end
      
      end
   end,
   
   WhatEnhancementsDoIHave = function(self)
      WARN('whatenhancementdoIhave')
      local enh = self:GetBlueprint().Enhancements
      local TheOnesIHave = {}
      if enh then
         for k,v in enh do
            if self:HasEnhancement(k) then
               table.insert(TheOnesIHave, k)
            end
         end
      end
      return TheOnesIHave
   end,
   


Note that my mod only recalled ACUs that had upgrades/enhancements. You should mess with the code slightly and make it so upgrades are not required to recall. You can put the script anywhere using this format: ACUUnit.DoTakeDamage = ModifiedFunction(args) so that only the ACUs with the recall item purchased will have the recall ability.
FunkOff
Supreme Commander
 
Posts: 1863
Joined: 26 Aug 2011, 17:27
Has liked: 14 times
Been liked: 43 times
FAF User Name: FakeOff

Re: Auto-recall works wierd in-game

Postby FunkOff » 16 Jan 2014, 05:08

Here is the code for auto-recall in the mod presently:
Code: Select all
    AddAutoRecall = function(self)
        self.DoDeathWeapon = function(self)
            local aiBrain = self:GetAIBrain()
            aiBrain:OnAutoRecall()
            self:PlayTeleportOutEffects()
            self:CleanupTeleportChargeEffects()
            self:StopUnitAmbientSound('TeleportLoop')
            self:PlayUnitSound('TeleportEnd')
            self:Destroy()           
        end
    end,


The teleport out effects look dumb and the death noise plays because this mods the death weapon, which is dumb lol.

Instead, do this:
Code: Select all
AddAutoRecall = function(self)
   self.DoTakeDamage = function(self, instigator, amount, vector, damageType)
        local preAdjHealth = self:GetHealth()
        self:AdjustHealth(instigator, -amount)
        local health = self:GetHealth()
        if( health <= 0 ) then
         self:Recall()
         return
            elseif( damageType == 'Reclaimed' ) then
                self:Destroy()
            else
                local excessDamageRatio = 0.0
                # Calculate the excess damage amount
                local excess = preAdjHealth - amount
                local maxHealth = self:GetMaxHealth()
                if(excess < 0 and maxHealth > 0) then
                    excessDamageRatio = -excess / maxHealth
                end
                self:Kill(instigator, damageType, excessDamageRatio)
            end
        end
        if EntityCategoryContains(categories.COMMAND, self) then
            local aiBrain = self:GetAIBrain()
            if aiBrain then
                aiBrain:OnPlayCommanderUnderAttackVO()
            end
        end
    end,

   self.Recall = function(self)
      WARN('recalling')
      SetInvincible(self, true)
      self:HideBone(0, true)
      self:PlayTeleportOutEffects()
      self:StunAllMyArmyUnits()
      Warp(self,   self.SpawnPoint, self:GetOrientation())
      WaitSeconds(2) 
      aiBrain:OnAutoRecall()
                self:Destroy()   
   end,
   


This code will give the game 2 seconds to process the teleportation effects and will NOT activate the death weapon. The ACU will be returned to the spawn point for 2 seconds, but will be invisible and invincible and players won't notice.
FunkOff
Supreme Commander
 
Posts: 1863
Joined: 26 Aug 2011, 17:27
Has liked: 14 times
Been liked: 43 times
FAF User Name: FakeOff

Re: Auto-recall works wierd in-game

Postby FunkOff » 17 Jan 2014, 19:12

Bump.
FunkOff
Supreme Commander
 
Posts: 1863
Joined: 26 Aug 2011, 17:27
Has liked: 14 times
Been liked: 43 times
FAF User Name: FakeOff

Re: Auto-recall works wierd in-game  Topic is solved

Postby Ze_PilOt » 18 Jan 2014, 14:56

Your solution was over-complicated, but the problem is real :)

New update should not play the death weapon anymore.
Nossa wrote:I've never played GPG or even heard of FA until FAF started blowing up.
User avatar
Ze_PilOt
Supreme Commander
 
Posts: 8985
Joined: 24 Aug 2011, 18:41
Location: fafland
Has liked: 18 times
Been liked: 376 times
FAF User Name: Ze_PilOt

Re: Auto-recall works wierd in-game

Postby FunkOff » 18 Jan 2014, 17:38

Can you at least add this line?

self:PlayTeleportOutEffects()

It makes a cool little teleport out effect
FunkOff
Supreme Commander
 
Posts: 1863
Joined: 26 Aug 2011, 17:27
Has liked: 14 times
Been liked: 43 times
FAF User Name: FakeOff


Return to Galactic War

Who is online

Users browsing this forum: No registered users and 1 guest