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.