Jump to content

Any way to toggle gear/solar panels from code?


Recommended Posts

Hello.

I'm looking for solution to control retractable parts from a plugin.

For example: If your surface velocity reaches 10m/s, panels retracts to avoid breaking.

Unfortunately I'm stuck at this point:

PartModule[] parts = (FindObjectsOfType(typeof(PartModule)) as PartModule[]);

foreach(PartModule p in parts)
{
if(p.vessel == FlightGlobals.ActiveVessel)
{
if (p.ClassName == "ModuleDeployableSolarPanel")
{

//p.part.SendEvent(" whichEvent? ")
//
}
}
}

Thank you!

Link to comment
Share on other sites

One way to do it would be sth like that:


foreach( var part in vessel /* maybe FlightGlobals.ActiveVessel */){
foreach( var modDepSolPanel in part.Modules.OfType<ModuleDeployableSolarPanel>() ){
modDepSolPanel.Retract();
}
}

If you want to use events, one way to get the event ID might be to check the save files. The current save system is pretty inefficient and saves a lot of useless data about evens & actions.

Link to comment
Share on other sites

blizzy78, thanks, this is way better.

I can't find that method, so i used a same one

vessel.parts.OfType<ModuleDeployableSolarPanel>();

but it didn't work. I'll figure out it later, anyway i understood how to control parts from code, that's all i wanted, thanks guys!

Edited by EvilKot
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...