Jump to content

How To Add Modules To A Part Via A Plugin?


Recommended Posts

I've been searching everywhere for the answer to this question without much success, and I'm sure there will be other people who want the information too, so I'm making a thread. I'm looking for what plugin coding is necessary to add a new module to a part. In my case, I'm trying to add a ModuleScienceExperiment to a part (I DON'T want to add the module from a cfg file). What I'm trying to do is something like this:


public class RUILifeTech005 : PartModule
{
[KSPEvent(guiActive = true, guiName = "Activate", active = true)]
public void Activate()
{
Events["Activate"].active = false;
Events["Deactivate"].active = true;
//Create Science Experiment Module with name, experimentID, experimentActionName, etc.
foreach(ModuleScienceExperiment experiment in part.FindModulesImplementing<ModuleScienceExperiment>())
{
experiment.DeployExperiment();
}
}
}

A solution to the problem would be incredibly useful to me and I'm sure the information would be useful to other people. Thanks.

Link to comment
Share on other sites

I'm confused to why you would want to add a module to a part through a PartModule instead of a KSPAddon, but you want to use Part.AddModule(ConfigNode node)

But yes, ModuleManager is there to do exactly that so I'm pretty sure it would be easier to go ahead that way.

Well the reason was that I don't want the Science Experimented to be accessible unless the player clicks the KSPEvent button, which it would have been if I just added it in the cfg file. I'll have a look at ModuleManager. Thanks.

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...