Jump to content

help with ModuleGenerator


Recommended Posts

what i am trying to do is make a generator that has a button to start and stop it. the first one is working, but has no buttons. the second on is just not working.

 MODULE{
name = ModuleGenerator
isAlwaysActive = True
INPUT_RESOURCE
{
name = ElectricCharge
rate = 2
}
OUTPUT_RESOURCE
{
name = Tritium
rate = 10
}
}


MODULE{
name = ModuleGenerator
isAlwaysActive = True
activateGUIName = Enable Deuterium
shutdownGUIName = Disable Deuterium
INPUT_RESOURCE
{
name = ElectricCharge
rate = 2
}
OUTPUT_RESOURCE
{
name = Tritium
rate = 10
}
}

Link to comment
Share on other sites

what i am trying to do is make a generator that has a button to start and stop it. the first one is working, but has no buttons. the second on is just not working.

 MODULE{
name = ModuleGenerator
isAlwaysActive = True
INPUT_RESOURCE
{
name = ElectricCharge
rate = 2
}
OUTPUT_RESOURCE
{
name = Tritium
rate = 10
}
}


MODULE{
name = ModuleGenerator
isAlwaysActive = True
activateGUIName = Enable Deuterium
shutdownGUIName = Disable Deuterium
INPUT_RESOURCE
{
name = ElectricCharge
rate = 2
}
OUTPUT_RESOURCE
{
name = Tritium
rate = 10
}
}

Looks like we have a new comer to KSP modding! :) Well, you could make it with like that with a generator in a cfg. file, or if you want, you could do it with a plugin, though you'd need a program like SharpDevelop. The first issue with what you have there is that isAlwaysActive is set as true, when it should be false, if you want the options to activate and deactivate the generator, so you could make that change to the first one. However, if you were interested in making a plugin, it would be very simple to create one. Like I said, you would need SharpDevelop (version 3.2 or later I think) and create a Class Library file when you load the program. To produce something that looked good you would want a code something like this:


using UnityEngine;

namespace yourpluginname
{
public class yourpluginname : PartModule
{
// anything with "//" before it doesn't do anything, it's just a little note
// of course, you can replace any names for things like class, bool, string, etc.

// a bool is a value that returns true or false
[KSPField(guiActive = true, guiName = "" ,isPersistant = true)]
public bool generatoractive = false;

// a string is a value that is in speech marks, usually a word, a phrase, etc.
[KSPField(guiActive = true, guiName = "" ,isPersistant = true)]
public string generatorstatus = "Generator Inactive";

// a float is a type of number value
[KSPField(guiActive = true, guiName = "" ,isPersistant = true)]
public float totalElectricCharge = 0;

// this creates the buttons to activate and deactivate the generator
[KSPEvent(guiActive = true, guiName = "Activate", active = true)]
public void Activate()
{
Events["Activate"].active = false;
Events["Deactivate"].active = true;
generatoractive = true;
}

[KSPEvent(guiActive = true, guiName = "Deactivate", active = false)]
public void Deactivate()
{
Events["Activate"].active = true;
Events["Deactivate"].active = false;
generatoractive = false;
}

void Update()
{
if(generatoractive)
{
part.RequestResource("ElectricCharge", 2 * TimeWarp.deltaTime);
// this looks complicated but is necessary to check the electric charge amount of the whole vessel by finding and checking each part that contains electric charge
foreach(part partwithcharge in vessel.parts)
{
if(partwithcharge.Resources.Contains("ElectricCharge"))
{
totalElectricCharge += partwithcharge.Resources["ElectricCharge"].amount
}
// this will check if you have any electric charge left
if(totalElectricCharge > 0)
{
part.RequestResource("Tritium", -10 * TimeWarp.deltaTime);
}
// you want it set as 2 and -10 because RequestResource uses up the given resource, so a negative number will make it increase the resource
}
}
}


}
}

And that should work, let me know if you hit any problems.

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