Mikali
#1
Is there a way to collect all ships into a single sobgroup? the “Player_Ships0” sobgroup ignores ships in hyperspace or that are docked. Thanks.
You could try
Player_GetShipsByFilterInclude( <Player_Index>, <Output_SobGroup>, "NoFilter", "" )
I haven’t tried it though.
Mikali
#3
Thanks!
Unfortunately, now I find out that SobGroup_SplitGroupFromGroup does not properly count docked ships (I think because they occupy the same coordinates and get lumped into the same sobgroup as the carrier), and my code depends on that. 
Is there another way to isolate each ship and work on it?
There could be a few ways to count all ships.
First would be to count all sobgroups that are created
local SobNum = SobGroup_SplitGroupFromGroup(SobGroupOut, SobGroupToSplit, NumberToSplit, SobGroupFrom)
local Count = 0
for i = 0, SobNum - 1 do
Count = Count + SobGroup_Count( SobGroupFrom..i )
end
Another possible way would be to edit the SobGroup_SplitGroupFromGroup function and add each found unit to a new sobgroup.
-- add after line 134 & 121
SobGroup_SobGroupAdd(SobGroupOut.."ALL", "TempSobGroup1")
-- add after line 95
SobGroup_CreateIfNotExist(SobGroupOut.."ALL")
then use
local SobNum = SobGroup_SplitGroupFromGroup(SobGroupOut, SobGroupToSplit, NumberToSplit, SobGroupFrom)
local Count = SobGroup_Count(SobGroupOut.."ALL")
Mikali
#5
Sorry I misspoke. I am not really trying to count them. I am trying to determine things like shiptype, position, subsystems, etc. With SobGroup_SplitGroupFromGroup I can’t separate ships that share the same position, such as docked ships.
That would require editing the function . I could do that , but won’t be able to till next week end .
To get a better understand ,would you prefer it to return a higher count then you inputed, to account for the ships that are docked ? If not , would you rather it returned the carrier before or after the ships that are docked ?
Mikali
#7
Not sure what you mean. I think docked ships should be returned in the same way as other ships. In my script I have an (non-working obviously) extra loop that checks whether ship A is docked with ship B.
Do you have a general idea of what you’re going to do? I could try rewriting it myself if you give me a hint.
The part of the function where the interval is less the .2 , i would rewrite that section to use sobgroup_fillshipsbyindex i think its called to the go thru each ship and add it to a new sobgroup . It may require increasing the index used for the while loop and increasing the sobnum so as not to cause issue with the rest of the code .
Mikali
#9
Do you mean, because two ships with the same index can’t dock with each other?
No . The first while loop in the function uses a varible called index to limit how many groups it will split from the main group .
Mikali
#11
Do you mean SobGroup_FillShipsByIndexRange? Yeah, I don’t understand what that function does.
(This might be a better function to use the the split group from group)
If i remember correctly its
( OutputGroup, FromGroup, StartPos, Count )
And will fill the output group with the ships in from group at startpos to a limit of count .
So if you want the first three ships from player ships you would use ( output, “Player_Ships0”, 0, 3 )
To use it to go thru each ship in a group
for x = 0, SobGroup_Count ( "Player_Ships0" )- 1 do
SobGroup_FillShipsByIndexRange ( outgroup, "Player_Ships0", x, 1 )
-- output only contains one ship ( possibly more if its a squadron like hgn_interceptor )
end
1 Like
Mikali
#13
Okay, I will try that.
Another idea I had was to create custom code for each ship that adds their ship IDs to a big table. And then use a gametype script to iterate through the table. But that would produce a very large table full of dead ships etc.
function SobGroup_Seperate ( outgroup, fromgroup )
local count = SobGroup_Count ( fromgroup )- 1
for x = 0, count do
SobGroup_CreateIfNotExist ( outgroup..x )
SobGroup_FillShipsByIndexRange ( outgroup..x, fromgroup, x, 1 )
end
end
Above function will seperate a group of ships each to there own group .
The returned groups can be accessed using outgroup…“0” , outgroup…“1”, etc .
Might help.
2 Likes
Mikali
#15
Your code works very well! Thank you!
The only issue (which existed before as well) is that the script does not take into account squadron sizes. I.e. it splits up Hgn Scout into three squadrons of one ship instead of one squadron of three ships, and sometimes three squadrons of three ships. Do you know of a solution to this?
Not at the moment I cant think of anything .
[Edit]
Try
function SobGroup_Seperate ( outgroup, fromgroup )
local c,i,n = SobGroup_Count ( fromgroup ), 0, 0
SobGroup_CreateIfNotExist ( "temp" )
while i < c do
SobGroup_FillShipsByIndexRange ( "temp", fromgroup, i, 1 )
if SobGroup_Count ( "temp" ) >= 1 then
SobGroup_CreateIfNotExist ( outgroup..n )
SobGroup_SobGroupAdd ("temp", outgroup..n ) -- this could be around the wrong way
i = i + SobGroup_Count ( "temp" )
n = n + 1
else
i = i +1
end
end
end
Should work if the fillshipsbyindexrange returns 3 squadrons of 3 ships
[Edit2]
Made some changes incase there is an empty index
1 Like
Mikali
#17
Works great after you switch those two parameters around! Thanks!