Generating a SobGroup list of all active ships

I’m currently working on a new, smoother, version of the scripts for the fuel and ammunition management in my mod that would be centered in a single ship controlling everything rather than having each ship update its own custom code. The idea is to set up a few tables to get a table of ammunition and fuel for every affected ship (strike crafts) controlled by the player and update the whole thing with a lot less loops and functions than if everything had to be done individually. If I get something to work reliably, it could be a better and simpler way to implement these features into future mods.

I’m pretty sure that the tables as managed in LUA would allow the whole thing, but I’m currently having an issue: the CustomGroup argument seems to only contain the relevant ship when you reach the Update part of the custom code, and the whole idea behind the new version would be to eliminate this Update part in my ships. I would want to do either one of these two options:

  • Being able to make and refresh the individual selection of every ship from a SobGroup. For example, if I had 5 flights of Interceptors, I would want to be able, after making a SobGroup with all the Interceptors, to make five SobGroups with one of the flights in each. And, of course, update this every cycle so I could get for every run of the Update, that would come from the Mothership, the individual SobGroups.
  • Have each relevant unit create its own SobGroup with only itself included in the SobGroup, in the Create part of the custom code.

I tried creating yet another SobGroup including all the Interceptors that have already been listed and then removing said SobGroup from a SobGroup including all the Interceptors, period. However, the SobGroup_FillShipsByType function doesn’t include the docked ships, which prevents the system from working properly.

Any ideas for an algorithm I could use to solve that problem? Thanks!

1 Like

You could make an array of sob groups. The “create” function in custom code would add a new group to the array. Then you simply loop through the array and do what you want. This is how my platform docking scripts work out what ship they are docked with.

1 Like

The custom code lua scripts are all in the same scope. This means you can:

  • Define a table/array in a main file: CustomCodeShips = {}.

  • Define create function:

    function Create_CustomCodeShip(CustomGroup, playerIndex, shipID)
    CustomCodeShips[shipID] = {} – this would contain whatever variables you need to change
    end

  • Define update function (on the mothership?):

    function Mothership_CustomUpdate(CustomGroup, playerIndex, shipID)
    – loop through ships
    end

2 Likes

The array of SobGroups was what I had settled on, but the problem is how to make sure that each strike craft unit is automatically put in a single SobGroup with a proper name (this is relatively easy) without using the Update part of the custom code (harder since the ship is docked when the Create part runs and the CustomGroup function doesn’t work either in Create).
@radar3301
This is pretty much what I’m doing ATM, but as said to Dom2, the problem is elsewhere, AKA identifying the ship in the Create part of the script, when neither CustomGroup nor FillByShipType work properly.

I would make the sobgroup name something like

"strike_craft"..shipID

That way you know it will be unique each time.

This is not the issue. Making unique dynamic SobGroup names is straightforward and was solved a long time ago. The problem lies in getting the ship to be inside the SobGroup.

I need a way to select the individual craft without using the Update part of a customcode, knowing that:

  • the CustomGroup parameter will NOT work in the Create section of the customcode.
  • the FillShipsByType function will NOT select the docked ships, so will not select the strike craft.

Hmmmm

Would this be able to filter by docked status…?

SobGroup_FilterInclude()

I do not know about this instruction, it seems to be one of the new things added in RM, but is there instructions on helping it, I’m not finding details in the Karos Graveyard?

For example:

SobGroup_FilterInclude("PlayerStrikeCraftNearOffice", "PlayerShipsNearOffice", "displayFamily", "Fighter")

Arguments:

  1. SobGroup to fill/create
  2. Source SobGroup
  3. Filter parameter, e.g. “displayFamily”, “DockFamily”, or perhaps command or “DOCKSTATE”
  4. Filter value, e.g. “DOCKED”

A related function:

SobGroup_FilterExclude("GrowSelection_Moving", "GrowSelection_AssaultEnemy", "CurrentCommand", "COMMAND_Idle")
3 Likes

I’ll give it a shot. Thanks!