Jump to content

Find part modules on vessel in flight scene


Recommended Posts

Hi all

So I've made a fair bit of headway on DCK Shields but am at a loss as to how to find if the active vessel in the flight scene has ModuleDeployRadiators

I can do this in the editor and figured I can use the same sort thing except I do not know how to look for part modules on an active craft in the flight scene

This is what I have for in the editor but need to know the change required to do the same thing in the flight scene on the active vessel

Quote

        public void shieldsDeploy()
        {
             Part root = EditorLogic.RootPart;
             if (!root)
             return;            // find all ModuleDeployableRadiator modules on all parts

            List<ModuleDeployableRadiator> shieldParts = new List<ModuleDeployableRadiator>(200);
            foreach (Part p in EditorLogic.fetch.ship.Parts)
            {
                shieldParts.AddRange(p.FindModulesImplementing<ModuleDeployableRadiator>());
            }
            foreach (ModuleDeployableRadiator shieldPart in shieldParts)
            {
                shieldPart.Extend();
            }
        }
        public void shieldsRetract()
        {
            Part root = EditorLogic.RootPart;
            if (!root)
                return;            // find all ModuleDeployableRadiator modules on all parts
            List<ModuleDeployableRadiator> shieldParts = new List<ModuleDeployableRadiator>(200);
            foreach (Part p in EditorLogic.fetch.ship.Parts)
            {
                shieldParts.AddRange(p.FindModulesImplementing<ModuleDeployableRadiator>());
            }
            foreach (ModuleDeployableRadiator shieldPart in shieldParts)
            {
                shieldPart.Retract();
            }
        }

 

Any help is appreciated

 

Link to comment
Share on other sites

@DoctorDavinci

First hurdle is to get a reference to the Vessel object that you want to examine.  FlightIntegrator.ActiveVesselFI.Vessel  will return the players currently 'in-control' craft (if any).  Others can likely be retrieved from the FlightIntegrator instance(s).

From there it is easy.  Vessel.parts contains a list of parts in the vessel.  Iterate through those and grab a reference to any part-modules you are interested in.

foreach(Part p in vessel.parts)
{
    ModuleDeployableRadiator[] radiators = p.GetComponents<ModuleDeployableRadiator>();
    foreach(ModuleDeployableRadiator r in radiators)
    {
        //do whatever to r here
    }
}

(quickly typed up in notepad, not guaranteed to be correct, but should be very close)

Link to comment
Share on other sites

Just now, Shadowmage said:

@DoctorDavinci

First hurdle is to get a reference to the Vessel object that you want to examine.  FlightIntegrator.ActiveVesselFI.Vessel  will return the players currently 'in-control' craft (if any).  Others can likely be retrieved from the FlightIntegrator instance(s).

From there it is easy.  Vessel.parts contains a list of parts in the vessel.  Iterate through those and grab a reference to any part-modules you are interested in.


foreach(Part p in vessel.parts)
{
    ModuleDeployableRadiator[] radiators = p.GetComponents<ModuleDeployableRadiator>();
    foreach(ModuleDeployableRadiator r in radiators)
    {
        //do whatever to r here
    }
}

(quickly typed up in notepad, not guaranteed to be correct, but should be very close)

Thanx ... It looks like it would work although I already solved the issue ... I went around it by inserting some code into DCK that sets the toggle shields to the Abort action group (Changeable in the config) when you attach the part to the craft in the editor

Saves having a button to press just so you can press another button let alone the way the shields work it is best to set up an action group for toggling their deployment

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...