Got missile redirection working for the URA0206 Vampire stealth fighter, will be included in the next update!
In /hook'd unit.lua
##########################################################################################
## --Unit intel
##########################################################################################
GetEnabledIntels = function(self)
local Intels = {}
if self.IntelDisables and table.getsize(self.IntelDisables) > 0 then
for id, value in self.IntelDisables do
if not Intels[id] then
Intels[id] = false
end
local intelenabled = self:IsIntelEnabled(id)
if intelenabled then
Intels[id] = true
else
Intels[id] = nil
end
end
end
return Intels
end,
Superclass called by the stealth unit...
----------------------------------------------------------------------------
-- File : /mods/4DFAF/lua/4D_CloakRedirect/4D_CloakRedirect.lua
--
-- Author : Resin_Smoker
--
-- Summary : 4D_SDR: Allows a structure so enhanced to resist enemy fire.
--
-- Special Thanks: Mithy for his redirect script
-- Copyright © 2024 4DFAF, All rights reserved.
----------------------------------------------------------------------------
--
-- The following is required in the units script for Struture Damage Resistance (SDR)
-- This calls into action the SDR scripts for AStructureUnit
--
-- local CAirUnit = import('/lua/cybranunits.lua').CAirUnit
-- CAirUnit = import('/mods/4DC_V0.81/lua/CustomAbilities/4D_CloakRedirect/4D_CloakRedirect.lua').CloakRedirect( CAirUnit )
--
----------------------------------------------------------------------------
### Start of CloakRedirect(SuperClass) ###
function CloakRedirect(SuperClass)
return Class(SuperClass) {
OnCollisionCheck = function(self, other, firingWeapon)
-- Cloaking allows 50% chance to avoid anti-air missiles
if self and not ( self:IsDead() or self:BeenDestroyed() ) then
local EffectUnit = false
local EffectsIntels = { 'CloakStealth', 'Cloak', 'CloakField', 'RadarStealth', 'RadarStealthField' }
local EnabledIntels = self:GetEnabledIntels()
for IntelType, Param in EnabledIntels do
if table.find(EffectsIntels, IntelType) then
EffectUnit = true
break
end
end
--check if unit is in field.
if not EffectUnit then
for id, IntelType in EffectsIntels do
if self:IsInField(IntelType) then
EffectUnit = true
break
end
end
end
if EffectUnit then
if ( other:GetBlueprint().Physics.TrackTarget or EntityCategoryContains(categories.MISSILE, other) ) and Random(1, 2) == 1 then
if other:GetLauncher() then
-- Projectile returns to launcher
other:SetNewTarget(other:GetLauncher())
other:TrackTarget(true)
other.DamageData.CollideFriendly = true
other.DamageData.DamageFriendly = true
other.DamageData.DamageSelf = true
other:SetLifetime(10)
other.Redirector = self
-- *** Mithy's Function *** Hook projectile's DoDamage to set (living) redirector to instigator on impact
local prevDoDamage = other.DoDamage
other.DoDamage = function(self, instigator, damageData, targetEntity)
--This should always allow the projectile to damage its launcher
instigator = self.Redirector or self
prevDoDamage(self, instigator, damageData, targetEntity)
end
else
-- Projectile passes thru and losses tracking
other:TrackTarget(false)
end
return false
else
-- Projectile impacts normally
return true
end
end
return SuperClass.OnCollisionCheck(self, other, firingWeapon)
end
end,
}
end
### End of CloakRedirect(SuperClass) ###
Keep in mind that the above script only applies to the unit calling the SuperClass. Hence all of the stock units won't have this ability unless modified to use the SuperClass.
Enjoy!
Resin