Jump to content

Enable/Disable probe core through plugin


Recommended Posts

I am writing a plugin to add a lower power mode to probe cores and need away to disable control whilst it's enabled then allow control when it is then disabled. So I need to be able to enable/disable control but the gui button needs to still be accessible

Here is my code currently up to this point

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProbeLowPower
{
    public class ProbeLowPower : PartModule
    {
        [KSPField(isPersistant = true)]
        public bool lowPowerMode;
        [KSPField(isPersistant = false)]
        public float lowPowerRatio;
        public double normalRate;
        public double lowPowerRate;
        public ModuleResource moduleResource;

        public override void OnLoad(ConfigNode node)
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                foreach (ModuleResource modres in this.part.GetComponent<ModuleCommand>().inputResources)
                {
                    if (modres.name == "ElectricCharge")
                    {
                        moduleResource = modres;
                        normalRate = modres.rate;
                        lowPowerRate = normalRate * lowPowerRatio;
                    }
                }

                print("AWAKE, Low Power Mode: " + lowPowerMode);
                if (lowPowerMode)
                    moduleResource.rate = lowPowerRate;
                else
                    moduleResource.rate = normalRate;

            }         
        }

        [KSPEvent(active = true, guiActive = true, guiActiveEditor = false, guiActiveUnfocused = false, guiName = "Low Power Mode: Disabled")]
        public void activateLPM()
        {
            lowPowerMode = true;
            moduleResource.rate = lowPowerRate;
            this.part.isControlSource = false; //This doesn't work as the stock ModuleCommand overites it every frame
            Events["activateLPM"].active = false;
            Events["deactivateLPM"].active = true;
        }

        [KSPEvent(active = false, guiActive = true, guiActiveEditor = false, guiActiveUnfocused = false, guiName = "Low Power Mode: Enabled")]
        public void deactivateLPM()
        {
            lowPowerMode = false;
            moduleResource.rate = normalRate;
            this.part.isControlSource = true; //This doesn't work as the stock ModuleCommand overites it every frame
            Events["activateLPM"].active = true;
            Events["deactivateLPM"].active = false;
        }
    }
}

 

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