Jump to content

Limit MechJeb2 Communications RANGE


Voodoo8648

Recommended Posts

Currently, Mech Jeb  is not affected by CommNet. You can still use Smart ASS, and create and execute maneuver nodes, ect using MJ...

Would it be possible for someone to please write a patch to fix this that disables MJ2 control when signal is lost? This issue is known within the MJ2 community but it doesn't seem to be a priority. 

Link to comment
Share on other sites

  • 2 weeks later...

Here's some code I was playing with. It works in that it completely disables the ability for MechJeb to control the craft (you can still use its menus and stuff, it just has no ability to control). It doesn't work in that it simply disables MechJeb all the time. There's some logic failure in there with the CommStatusChange going wrong (I have confirmed, however, that the CommStatusChange event does trip correctly and with the proper boolean when the craft is out of communications). It might also have to do with the fact that I'm not validating whether MechJeb actually exists when this runs, so it might need to start a coroutine and wait for a second or two.

So basically, here's some plugin code that needs some testing/debugging that I'm not particularly interested in doing. Free of charge, public domain. All this needs is for the project to be linked to the normal KSP libraries and MechJeb, this will be compiled as a separate library which you can safely plop anywhere in GameData.

namespace MechCommJebNet {
    [KSPAddon(KSPAddon.Startup.Flight, false)]
    public class Core : MonoBehaviour {
        public void Start() {
            GameEvents.CommNet.OnCommStatusChange.Add(new EventData<Vessel, bool>.OnEvent(this.OnCommStatusChange));
            Vessel vessel = FlightGlobals.ActiveVessel;
            MechJebCore mj = VesselExtensions.GetMasterMechJeb(vessel);
            mj.DeactivateControl = vessel.IsControllable;
        }

        private void OnCommStatusChange(Vessel vessel, bool b) {
            MechJebCore mj = VesselExtensions.GetMasterMechJeb(vessel);
            mj.DeactivateControl = b;
            ScreenMessages.PostScreenMessage("Comm status changed to " + b, 5f, ScreenMessageStyle.UPPER_CENTER);
        }

        public void OnDisable() {
            GameEvents.CommNet.OnCommStatusChange.Remove(new EventData<Vessel, bool>.OnEvent(this.OnCommStatusChange));
        }
    }
}

 

Edited by regex
Link to comment
Share on other sites

On 6/20/2017 at 7:28 PM, regex said:

Here's some code I was playing with. It works in that it completely disables the ability for MechJeb to control the craft (you can still use its menus and stuff, it just has no ability to control). It doesn't work in that it simply disables MechJeb all the time. There's some logic failure in there with the CommStatusChange going wrong (I have confirmed, however, that the CommStatusChange event does trip correctly and with the proper boolean when the craft is out of communications). It might also have to do with the fact that I'm not validating whether MechJeb actually exists when this runs, so it might need to start a coroutine and wait for a second or two.

So basically, here's some plugin code that needs some testing/debugging that I'm not particularly interested in doing. Free of charge, public domain. All this needs is for the project to be linked to the normal KSP libraries and MechJeb, this will be compiled as a separate library which you can safely plop anywhere in GameData.


namespace MechCommJebNet {
    [KSPAddon(KSPAddon.Startup.Flight, false)]
    public class Core : MonoBehaviour {
        public void Start() {
            GameEvents.CommNet.OnCommStatusChange.Add(new EventData<Vessel, bool>.OnEvent(this.OnCommStatusChange));
            Vessel vessel = FlightGlobals.ActiveVessel;
            MechJebCore mj = VesselExtensions.GetMasterMechJeb(vessel);
            mj.DeactivateControl = vessel.IsControllable;
        }

        private void OnCommStatusChange(Vessel vessel, bool b) {
            MechJebCore mj = VesselExtensions.GetMasterMechJeb(vessel);
            mj.DeactivateControl = b;
            ScreenMessages.PostScreenMessage("Comm status changed to " + b, 5f, ScreenMessageStyle.UPPER_CENTER);
        }

        public void OnDisable() {
            GameEvents.CommNet.OnCommStatusChange.Remove(new EventData<Vessel, bool>.OnEvent(this.OnCommStatusChange));
        }
    }
}

 

Thank you! I'll see if I can get this to work. I don't know how to code. 

Do I need to create a notepad file and save this as a .cfg ? 

Is there anything else that I need to do to link this to MJ or the KSP libraries?

Link to comment
Share on other sites

25 minutes ago, Voodoo8648 said:

Do I need to create a notepad file and save this as a .cfg ? 

No, you need to properly compile it, it's C#, not KSP or Module Manager configs. Sarbian left instructions to get you started in the MechJeb thread.

25 minutes ago, Voodoo8648 said:

Is there anything else that I need to do to link this to MJ or the KSP libraries?

Yes, you will link the new project that you create to put this code into to those libraries.

Again, I remind you, this code is not entirely working, there will be some debugging involved. I advise you to get a stock install, remove the asset bundles and possibly prune enough parts to make loading the game super quick (you can get by with just a probe core, some solar panels, and an antenna for this now that Hyperedit isn't needed), and MechJeb. You want it to load as quick as possible because debugging this will involve starting and quitting the game over and over and over.

Good luck!

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