Been working on the shield drone in tandem with other units from 4DC and its really close to working. AKA. it flies around and sacrifices itself to place a personal shield on units that dont already have one.
So far the little drone will move up to a target unit, shoot out its enhancement beam and collect the information to pass the model and LOD to "CreateShield" in Unit.lua.
My code to collect the model spec and pass it to Unit.lua "CreateShield".
-- Define the shield spec
self.DroneShieldSpec = {
ImpactEffects = impactFx,
ImpactMesh = nil,
Mesh = nil,
MeshZ = nil,
Owner = self,
OwnerShieldMesh = bpDisplay[1],
PassOverkillDamage = false,
PersonalShield = true,
RegenAssistMult = 60,
ShieldEnergyDrainRechargeTime = 5,
ShieldMaxHealth = sldHealth,
ShieldRechargeTime = rChgTime,
ShieldRegenRate = sldHealth * 0.01,
ShieldRegenStartTime = 1,
ShieldVerticalOffset = 0,
ShieldSize = 2.5,
CollisionCenterX = bp.CollisionOffsetX or 0,
CollisionCenterY = bp.CollisionOffsetY or 0,
CollisionCenterZ = bp.CollisionOffsetZ or 0,
CollisionSizeX = bp.SizeX * 25.0 or 1,
CollisionSizeY = bp.SizeY * 25.0 or 1,
CollisionSizeZ = bp.SizeZ * 25.0 or 1,
MaintenanceConsumptionPerSecondEnergy = eCost,
}
if myDebug then WARN(' Completed shield spec: '..repr(self.DroneShieldSpec)) end
--Create the personal shield
if myDebug then WARN(' Passing spec to CreateShield in Shield.lua') end
self.CreateShield(self.DroneShieldSpec)
CreateShield (Unit.lua 4405), please notice its here that it calls DestroyShield.
CreateShield = function(self, bpShield)
-- Copy the shield template so we don't alter the blueprint table.
local bpShield = table.deepcopy(bpShield)
self:DestroyShield()
if bpShield.PersonalShield then
self.MyShield = PersonalShield(bpShield, self)
elseif bpShield.AntiArtilleryShield then
self.MyShield = AntiArtilleryShield(bpShield, self)
elseif bpShield.PersonalBubble then
self.MyShield = PersonalBubble(bpShield, self)
elseif bpShield.TransportShield then
self.MyShield = TransportShield(bpShield, self)
else
self.MyShield = Shield(bpShield, self)
end
self:SetFocusEntity(self.MyShield)
self.Trash:Add(self.MyShield)
end,
Below is my F9 log with WARNING indicating that the spec created exists. Along with the destroy error near the end.
WARNING: *** /mods/4DC/hook/lua/sim/Unit.lua SpawnPersonalShield ***
WARNING: Completed shield spec:
WARNING: - CollisionCenterX: 0
WARNING: - CollisionCenterY: 0
WARNING: - CollisionCenterZ: -0.050000000745058
WARNING: - CollisionSizeX: 27.5
WARNING: - CollisionSizeY: 30.000001907349
WARNING: - CollisionSizeZ: 27.5
WARNING: - ImpactEffects: SeraphimShieldHit01
WARNING: - MaintenanceConsumptionPerSecondEnergy: 10
WARNING: - Owner: table: 1EB7A7D0 (skipped)
WARNING: - OwnerShieldMesh: table: 1C825820
WARNING: - AlbedoName: /units/xsl0202/xsl0202_albedo.dds
WARNING: - LODCutoff: 215
WARNING: - LookupName: /effects/entities/PhaseShield/PhaseShieldLookup.dds
WARNING: - MeshName: /units/xsl0202/xsl0202_lod0.scm
WARNING: - NormalsName: /units/xsl0202/xsl0202_normalsTS.dds
WARNING: - Occlude: false
WARNING: - Scrolling: true
WARNING: - SecondaryName:
WARNING: - ShaderName: PhaseShield
WARNING: - Silhouette: false
WARNING: - SpecularName: /units/xsl0202/xsl0202_SpecTeam.dds
WARNING: - PassOverkillDamage: false
WARNING: - PersonalShield: true
WARNING: - RegenAssistMult: 60
WARNING: - ShieldEnergyDrainRechargeTime: 5
WARNING: - ShieldMaxHealth: 1250
WARNING: - ShieldRechargeTime: 60
WARNING: - ShieldRegenRate: 12.5
WARNING: - ShieldRegenStartTime: 1
WARNING: - ShieldSize: 2.5
WARNING: - ShieldVerticalOffset: 0
WARNING: Passing spec to CreateShield in Shield.lua
WARNING: ***Unit.lua CreatShield***
WARNING: Error running lua script: ...gramdata\faforever\gamedata\lua.nx2\lua\sim\unit.lua(4409): attempt to call method `DestroyShield' (a nil value)
stack traceback:
...gramdata\faforever\gamedata\lua.nx2\lua\sim\unit.lua(4409): in function `CreateShield'
...gramdata\faforever\gamedata\lua.nx2\lua\sim\unit.lua(5852): in function `SpawnDroneShield'
...d_shielddronesuperclass\4d_shielddronesuperclass.lua(157): in function <...d_shielddronesuperclass\4d_shielddronesuperclass.lua:122>
Notice the part near the bottom where it is referring to DestroyShield (Unit.lua line 4443). Please notice that the line number in the error code shown are different from the snippet above. This is because I have a slightly modified version of unit.lua so i can log this to be able to trace back events and such. (I dont change what Unit.lua does and yes i have the original backed up) However I'm referring to the standard FAF unit.lua lines that you have available.
DestroyShield = function(self)
if self.MyShield then
self:ClearFocusEntity()
self.MyShield:Destroy()
self.MyShield = nil
end
end,
I know for a fact that self.Shield doesn't exist as the unit being enhanced with a Drone-Shield never had one, nor was capable of having one on its own. What I'm thinking is taking place is that somehow "self" isn't being passed in some way. For what, I'm at a loss as I've come at this from every possible angle I can think of for the last day. Anyone have a suggestion or spot something I've outright missed?
Thanks in advance!
Resin