[SOLVED][SCRIPTING] SobGroup_OwnedBy()

It seems the function SobGroup_OwnedBy() returns -1 for the human player instead of 0. Anyone know why this is the case?

It is working for me.
It could be possible the first ‘ship’ in the sobgroup you are checking doesn’t exist.

you could try

SobGroup_CreateIfNotExist( "temp" )
SobGroup_FillShipsByIndexRange( "temp", *sobgroup-to-check*, 0, 1 )
print( "Count: "..SobGroup_Count( "temp" ))
print( "Owner: "..SobGroup_OwnedBy( "temp" ))

just to double check that the first ‘ship’ does exist.

1 Like

I’m using it to check if a ship has been captured. I am able to capture the ship (it turns green in game), but it only registers in the script if I supply -1 as the player index.

function Rule_PlayerWins()
	-- Not sure why owner is -1. Shouldn't it be 0?
	if (SobGroup_OwnedBy("EnyGroup") == -1) then
		questsStatus.d1_ShipHasBeenCaptured = 1
		Objective_SetState(obj_prim_newobj_id, OS_Complete)
		Event_Start( "IntelEvent_Finale" )
		Rule_Add( "Rule_EnableExits" )

This is in a singleplayer campaign mission.

the sobgroup is empty, because ships will leave sobgroups it belongs to unless you use this function: SobGroup_SetSwitchOwnerFlag()

1 Like

Good catch, thanks!