Jump to content

KSPAction not showing in editor?


Recommended Posts

I'm trying to write a simple plugin to add "Control From Here" support for Command Modules and Docking Ports to Action Groups, so I don't have to go around looking for the part to right-click upon, I borrowed a bit of code from "Tweakable Everything" as a reference, but when I run KSP, it doesn't show up in the editor, and I can't figure out why.


 

@PART[*]:HAS[@MODULE[ModuleCommand]]
{
	MODULE
	{
		Name = ControlFromHere
	}
}

@PART[*]:HAS[@MODULE[ModuleDockingNode]]
{
	MODULE
	{
		Name = ControlFromHere
	}
}

 

 

/* Control From Here - a module plugin for Kerbal Space Program
 * Author: William "Xyphos" Scott
 * Date: April 4, 2017
 * Licence: PUBLIC DOMAIN
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
namespace ControlFromHere
{
    public class ControlFromHere : PartModule
    {
// ReSharper disable once InconsistentNaming
        private const string CFH = "MakeReferenceTransform";

        private ModuleCommand _command;
        private ModuleDockingNode _dock;

        public override void OnStart(StartState state)
        {
            _command = part.Modules.GetModule<ModuleCommand>();
            _dock = part.Modules.GetModule<ModuleDockingNode>();
            
            base.OnStart(state);
        }

        [KSPAction(guiName = "Control From Here")]
        public void DoControl(KSPActionParam param)
        {
            if (_command != null
                && _command.Events.Contains(CFH)
                && _command.Events[CFH].active)
            {
                _command.MakeReference();
                return;
            }

            if (_dock != null
                && _dock.Events.Contains(CFH)
                && _dock.Events[CFH].active)
                _dock.MakeReferenceTransform();
        }
    }
}
Link to comment
Share on other sites

Nevermind, I figured it out; it was a problem in the CFG file, I capitalized "Name" when it should have been all-lowercase.
also, I over-engineered the code so I simplified it.

 

/* Control From Here - a module plugin for Kerbal Space Program
 * Author: William "Xyphos" Scott
 * Date: April 4, 2017
 * Licence: PUBLIC DOMAIN
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
namespace ControlFromHere
{
    public class ControlFromHere : PartModule
    {
        [KSPAction("Control From Here")]
        public void ControlFromHereAction(KSPActionParam param)
        {
           vessel.SetReferenceTransform(part, true);
        }
    }
}

 

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