
In ādata\ship\kus_dronefrigate\kus_dronefrigate.luaā the game is indexing a table called drone_attacking
using a variable called k
. The problem is that k
starts at 0 and goes to 13, but Lua tables are indexed starting with 1 not 0, and thus k
should go from 1 to 14.
What I did was create a new variable:
local kIndex = k + 1
and used that for the table indices instead.

Further, all the drone frigates should not be sharing the same drone_attacking
table. Otherwise one ship will override the others, and things get confusing. Instead, each ship needs its own place to store this data. What I did was this:
drone_attacking["kus_drone" .. tostring(shipID)] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
You have to make sure to create this sobgroup when each ship is built, and delete it when the ship dies.

Next, the sobgroup name for each drone in ādata\ship\kus_dronefrigate\kus_dronefrigate.luaā needs to be changed from this:
"kus_drone" .. tostring(shipID) .. tostring(k)
to this:
"kus_drone_" .. tostring(shipID) .. "_" .. tostring(k)
Since the shipID
and the value for k
are both numbers, there will be confusion when the combined number is the same for two different ships. So you have to separate the numbers with a text character such as the underscore.

In ādata\ship\kus_drone0\kus_drone0.luaā there needs to be an additional line:
SobGroup_CreateIfNotExist("temp")
This is because thereās no guarantee that this sobgroup has been created already in a custom game rule. If it has not already been created, then the game will crash when loading this ship.
Hereās my final version of this script:
drone_attacking = {}
function Start_DroneFrigate(CustomGroup, playerIndex, shipID)
SobGroup_SetSpeed(CustomGroup, 0.9)
local r = random(1, 6)
FX_StartEvent(CustomGroup, "dronelaunch_sfx" .. r)
end
function Do_DroneFrigate(CustomGroup, playerIndex, shipID)
SobGroup_CreateIfNotExist("dronefrigate_temp")
SobGroup_CreateIfNotExist("dronefrigate_temp1")
SobGroup_CreateIfNotExist("dronefrigate_temp2")
SobGroup_Clear("dronefrigate_temp2")
SobGroup_GetSobGroupBeingCapturedGroup(CustomGroup, "dronefrigate_temp2")
for k = 0, 13, 1 do
local sobname = "kus_drone_" .. tostring(shipID) .. "_" .. tostring(k)
SobGroup_CreateIfNotExist(sobname)
SobGroup_Clear("dronefrigate_temp")
SobGroup_Clear("dronefrigate_temp1")
SobGroup_GetSobGroupDockedWithGroup(CustomGroup, "dronefrigate_temp")
SobGroup_FillShipsByType("dronefrigate_temp1", "dronefrigate_temp", "kus_drone"..k)
SobGroup_SobGroupAdd(sobname, "dronefrigate_temp1")
if SobGroup_Count(sobname) == 0 and
SobGroup_IsDoingAbility(CustomGroup, AB_Hyperspace) == 0 and
SobGroup_IsDoingAbility(CustomGroup, AB_HyperspaceViaGate) == 0 and
SobGroup_AreAllInRealSpace(CustomGroup) == 1 and
SobGroup_IsDoingAbility(CustomGroup, AB_Dock) == 0 and
SobGroup_IsDoingAbility(CustomGroup, AB_Retire) == 0 and
SobGroup_Count("dronefrigate_temp2") == 0 then
local CreateGroup = SobGroup_CreateShip(CustomGroup, "kus_drone"..k)
SobGroup_SobGroupAdd(sobname, CreateGroup)
if k == 0 or k == 4 or k == 8 or k == 12 then
FX_StartEvent(CustomGroup, "dronelaunch1")
elseif k == 1 or k == 5 or k == 9 or k == 13 then
FX_StartEvent(CustomGroup, "dronelaunch2")
elseif k == 2 or k == 6 or k == 10 then
FX_StartEvent(CustomGroup, "dronelaunch3")
elseif k == 3 or k == 7 or k == 11 then
FX_StartEvent(CustomGroup, "dronelaunch4")
end
break
else
SobGroup_SwitchOwner(sobname, playerIndex)
if SobGroup_IsDockedSobGroup(sobname, CustomGroup) == 1 and
SobGroup_IsDoingAbility(CustomGroup, AB_Hyperspace) == 0 and
SobGroup_IsDoingAbility(CustomGroup, AB_HyperspaceViaGate) == 0 and
SobGroup_AreAllInRealSpace(CustomGroup) == 1 and
SobGroup_IsDoingAbility(CustomGroup, AB_Dock) == 0 and
SobGroup_IsDoingAbility(CustomGroup, AB_Retire) == 0 and
SobGroup_Count("dronefrigate_temp2") == 0 then
SobGroup_Launch(sobname, CustomGroup)
if k == 0 or k == 4 or k == 8 or k == 12 then
FX_StartEvent(CustomGroup, "dronelaunch1")
elseif k == 1 or k == 5 or k == 9 or k == 13 then
FX_StartEvent(CustomGroup, "dronelaunch2")
elseif k == 2 or k == 6 or k == 10 then
FX_StartEvent(CustomGroup, "dronelaunch3")
elseif k == 3 or k == 7 or k == 11 then
FX_StartEvent(CustomGroup, "dronelaunch4")
end
break
end
end
end
end
function Finish_DroneFrigate(CustomGroup, playerIndex, shipID)
SobGroup_SetSpeed(CustomGroup, 1)
local r = random(1,6)
FX_StartEvent(CustomGroup, "droneretract_sfx"..r)
for k = 0, 13, 1 do
local sobname = "kus_drone_" .. tostring(shipID) .. "_" .. tostring(k)
if SobGroup_Empty(sobname) == 0 then
SobGroup_AbilityActivate(sobname, AB_Targeting, 0)
SobGroup_AbilityActivate(sobname, AB_Attack, 0)
SobGroup_DockSobGroupAndStayDocked(sobname, CustomGroup)
end
end
end

function Create_DroneFrigate(CustomGroup, playerIndex, shipID)
SobGroup_SetSwitchOwnerFlag(CustomGroup, 0)
SobGroup_CreateIfNotExist("dronefrigate_temp")
SobGroup_CreateIfNotExist("dronefrigate_temp1")
SobGroup_CreateIfNotExist("dronefrigate_temp2")
local shipname = "kus_drone_" .. tostring(shipID)
drone_attacking[shipname] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
for k = 0, 13, 1 do
local sobname = shipname .. "_" .. tostring(k)
SobGroup_CreateIfNotExist(sobname)
end
end
function Update_DroneFrigate(CustomGroup, playerIndex, shipID)
SobGroup_CreateIfNotExist("dronefrigate_temp2")
SobGroup_Clear("dronefrigate_temp2")
SobGroup_GetSobGroupBeingCapturedGroup(CustomGroup, "dronefrigate_temp2")
if Player_GetLevelOfDifficulty(playerIndex) > 0 then
local playerIndex_ai = 0
local enemyships = 0
while playerIndex_ai < Universe_PlayerCount() do
if Player_IsAlive(playerIndex_ai) == 1 then
local distance = 4000
if SobGroup_FillProximitySobGroup("dronefrigate_temp1", "Player_Ships"..playerIndex_ai, CustomGroup, distance) == 1 then
if AreAllied(playerIndex, playerIndex_ai) == 0 then
enemyships = 1
end
end
end
playerIndex_ai = playerIndex_ai + 1
end
if enemyships > 0 then
if SobGroup_IsDoingAbility(CustomGroup, AB_Custom) == 0 then
SobGroup_CustomCommand(CustomGroup)
end
end
end
local shipname = "kus_drone_" .. tostring(shipID)
for k = 0, 13, 1 do
local sobname = shipname .. "_" .. tostring(k)
if SobGroup_Empty(sobname) == 0 then
if SobGroup_IsDockedSobGroup(sobname, CustomGroup) == 0 and
SobGroup_IsDoingAbility(sobname, AB_Parade) == 0 and
SobGroup_IsDoingAbility(sobname, AB_Dock) == 0 then
SobGroup_ParadeSobGroup(sobname, CustomGroup, 0)
end
if SobGroup_GetDistanceToSobGroup(sobname, CustomGroup) > 950 then
SobGroup_TakeDamage(sobname, 1)
elseif SobGroup_GetDistanceToSobGroup(sobname, CustomGroup) > 275 then
SobGroup_AbilityActivate(sobname, AB_Targeting, 0)
SobGroup_AbilityActivate(sobname, AB_Attack, 0)
else
SobGroup_AbilityActivate(sobname, AB_Targeting, 1)
SobGroup_AbilityActivate(sobname, AB_Attack, 1)
SobGroup_GuardSobGroup (sobname, CustomGroup)
end
if SobGroup_IsDoingAbility(CustomGroup, AB_Hyperspace) == 1 or
SobGroup_IsDoingAbility(CustomGroup, AB_HyperspaceViaGate) == 1 or
SobGroup_AreAllInRealSpace(CustomGroup) == 0 or
SobGroup_IsDoingAbility(CustomGroup, AB_Dock) == 1 or
SobGroup_IsDoingAbility(CustomGroup, AB_Retire) == 1 or
SobGroup_Count("dronefrigate_temp2") > 0 or
SobGroup_OwnedBy(sobname) ~= playerIndex then
SobGroup_TakeDamage(sobname, 1)
SobGroup_DockSobGroupInstant(sobname, CustomGroup)
end
local kIndex = k + 1
local kDrone = drone_attacking[shipname][kIndex]
if SobGroup_IsDoingAbility(CustomGroup, AB_Attack) == 1 then
if (kDrone == 1) or (kDrone == DefensiveROE) then
SobGroup_SetROE(sobname, OffensiveROE)
drone_attacking[shipname][kIndex] = OffensiveROE
end
else
if (kDrone == 1) or (kDrone == OffensiveROE) then
SobGroup_SetROE(sobname, DefensiveROE)
drone_attacking[shipname][kIndex] = DefensiveROE
end
end
end
end
end
function Destroy_DroneFrigate(CustomGroup, playerIndex, shipID)
local shipname = "kus_drone_" .. tostring(shipID)
for k = 0, 13, 1 do
local sobname = shipname .. "_" .. tostring(k)
if SobGroup_Empty(sobname) == 0 then
SobGroup_TakeDamage(sobname, 1)
end
end
drone_attacking[shipname] = nil
end
function SobGroup_GetDistanceToSobGroup(sg_Group1, sg_Group2)
if SobGroup_Empty(sg_Group1) == 0 and SobGroup_Empty(sg_Group2) == 0 then
local t_position1 = SobGroup_GetPosition(sg_Group1)
local t_position2 = SobGroup_GetPosition(sg_Group2)
local li_distance = floor(sqrt((t_position1[1]  t_position2[1])*(t_position1[1]  t_position2[1]) + (t_position1[2]  t_position2[2])*(t_position1[2]  t_position2[2]) + (t_position1[3]  t_position2[3])*(t_position1[3]  t_position2[3])))
return li_distance
else
return 0
end
end
The drone frigate is definitely a lot more lethal after these changes.