Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Is there a simple way to find the parent body of a given CelestialBody other than going through all the FlightGlobals.bodies and checking HasParent? I don't see anything relevant in the definition of the CelestialBody class, but maybe it's somewhere else?

Link to comment
Share on other sites

16 hours ago, Benjamin Kerman said:

I have a bit of code for that, already written, that should do the trick for finding a list of all CelestialBodies. 

https://github.com/BenjaminCronin/Ludicrous-Propulsion-Systems/blob/master/Plugin Dev/IIpD_PartModule.cs#L193-L201

@garwel

There is already such a list in FlightGlobals.Bodies, but it's not what I was looking for. Anyway, DMagic's answer worked ok for me.

Link to comment
Share on other sites

Similar to mechjeb's Ascent Navball Guidance I'm trying to set a direction as my target  . Works fine (SAS can use it) but the target /Anti target markers won't show up and I don't get the "Target : Some vessel" UI message. What am I doing wrong?

 

	private DirectionTarget dirTgt = null;

	public  void newDirectionTarget(string name,Vector vec)
        {
            dirTgt = new DirectionTarget(name);
            updateDirection(vec);
        }

        private bool updateDirection(Vector vec)
        {
            if (dirTgt != null)
            {
                dirTgt.Update(new Vector3d(vec.X, vec.Y, vec.Z));
                return true;
            }
            else
                return false;
        }

FlightGlobals.ActiveVessel.targetObject = dirTgt;

 

Link to comment
Share on other sites

Hi all,

I need your assistance to fine-tune the RemoteTech's newly-modernised PID Controller as I have the limited understanding on the workings of this controller. The issue is in certain scenarios, it would take relatively long time to reach the target point. You can reproduce this observation by installing the develop-RT and save zips. The PIDTest vessel is good one to play with as it just takes long time to reach the target point like this picture below.

2Sg9iRX.png 

Any idea on how to shorten this time taken?

Link to comment
Share on other sites

  • 2 weeks later...

In my mod you take an asteroid sample if you are on EVA close to the target asteroid and your relative velocity is small. I just use the naive distance, which means that even if you touch the surface you are still some distance away (the asteroid radius basically).

I just visited the tiny asteroid, it is about 5 meter in radius. What is the largest size (max distance to CoM) asteroid you can encounter?

Link to comment
Share on other sites

On 10/7/2017 at 3:44 PM, Rodhern said:

In my mod you take an asteroid sample if you are on EVA close to the target asteroid and your relative velocity is small. I just use the naive distance, which means that even if you touch the surface you are still some distance away (the asteroid radius basically).

I just visited the tiny asteroid, it is about 5 meter in radius. What is the largest size (max distance to CoM) asteroid you can encounter?

You can probably get the information from the astroid type (A, B, C, D, or E) and use that to calculate the radius of the astroid. I can't comment about the actual distances, you might have to hyperedit to a couple of different types to see (with the plugin running reporting how far the kerb is from said astroid) how big they are. 

Link to comment
Share on other sites

You may find the mass ranges of asteroids of utility. Then you can find the density by comparing the mass and radius of a few asteroids and use that to estimate the radius by size class. Or just use the density you found earlier and the mass of the 'roid to find its approximate radius.

I'm pretty sure the lumps are all about the same height relative to the radius, so the measure should be reasonably accurate.

(ref: https://wiki.kerbalspaceprogram.com/wiki/Asteroid)

Edited by 0111narwhalz
Link to comment
Share on other sites

Hello guys,

 

I have been a couple of times trying to figure out where to start with plugin dev but every time I desist because I end up lost with the huge amount of information in this forum.

I have simple plugin in mind that shows a table of the parts of a ship in VAB in a simple window, like Kerbal Engineer Redux, for 1.2.2 in principle, but I am thinking on testing it also on 1.3 and 1.3.1.

so I have a couple of simple questions:

1) What Unity version 1.2.2 uses? I think it is 5.4.0p4 , but I am not 100% sure.

2) Do you know any simple example of a mod doing a windows in VAB that I could use to figure out how it works. I tried with KER and I got lost :-(

Thanks in advance.

 

Link to comment
Share on other sites

@mihe

  1.  Yep it's the right one.
  2. You can check Real Time Clock, in my sig, it display a clock in all scene (almost). Probably the most simple GUI that can be done :wink:. I have a little more complicated GUI in Antenna Helper if it can help.
Link to comment
Share on other sites

Any idea how to pull the current orbital parameters of a maneuver node/patch conic rendering.

This:

0d6iBD9.png

I thought ManeuverNode.solver.orbit.ApA etc would call it - but this seems to pull the ApA of the original node before it was edited, even after calling ManeuverNode.solver.UpdateFlightPlan() - when the node changes the new ApA doesn't get pulled through. I've also tried ManeuverNode.patch.ApA and ManeuverNode.solver.LastActivePatch.orbit.ApA

What I am basically trying to do is write a solver that will create a maneuver node to circularise an orbit. I know the solver code is wrong, but I can't see where it's going wrong because the figures are never being updated.

 

Edited by severedsolo
Link to comment
Share on other sites

On 12/13/2016 at 10:59 PM, nightingale said:

@DMagic - looks like I inadvertently broke this will adding rounding in to fix another issue.  I tried to be clever and round using the display format, which doesn't work with the P0 display format (because Float.Parse() doesn't have smarts to recognize a percentage).

As a workaround, try using N1 + asPercentage.

Can you confirm that this bug is still there?  I still can't do the percentage

Link to comment
Share on other sites

2 hours ago, linuxgurugamer said:

Can you confirm that this bug is still there?  I still can't do the percentage

I can't really confirm since I'm no long with Squad. :)

But from what I recall I had put in a fix for that, which should've been released by now.  So if it's not working - raise it up as a bug.

Link to comment
Share on other sites

4 hours ago, severedsolo said:

Any idea how to pull the current orbital parameters of a maneuver node/patch conic rendering.

vessel.patchedConicSolver.maneuverNodes[0].nextPatch.ApA or ApR should do it.

Link to comment
Share on other sites

On 10/14/2017 at 7:38 PM, Li0n said:

@mihe

  1.  Yep it's the right one.
  2. You can check Real Time Clock, in my sig, it display a clock in all scene (almost). Probably the most simple GUI that can be done :wink:. I have a little more complicated GUI in Antenna Helper if it can help.

Thanj you Lion !! I am going to check it right now :-)

Link to comment
Share on other sites

  • 4 weeks later...

*Edit: Found the answers for the long question previously posted here on my own. Although the implementation can be further improved, it's done:

https://forum.kerbalspaceprogram.com/index.php?/topic/167548-*

Leaving the original question down here for reference:

Spoiler

 

What began as an attempt to port UpgradesGUI to KSP 1.3.1 became a challenging attempt to achieve similar results through a wholly different method and "new" code because the former proved to be impossible to get working(a straightforward recompile with just a small change of something.title to something.displayName ended with every part with upgrades loading incorrectly, freezing the editor and/or throwing NREs when picked and with the toolbar disappearing there), nor I could manage to just port its core to a new interface, for I couldn't envision how to adapt it to a new interface(maybe all of that were warning calls for giving up, maybe not).

Thus I ended either half way, perhaps almost there or not even 5% into creating a PartModule that displays an UI with Part Upgrades for a part in the Editor for the sake of allowing setting which upgrades to activate for each part, called through a button in the Part's right-click menu, but while the GUI itself is completed, the modules are sorted properly, the PartModules that should be changed likewise, its attempts to interact with PartModule.appliedUpgrades have failed. I barely managed to scrounge the interface code, so maybe I should just give up, and that is a welcome advice as well, but in any case, here are the specific parts of this spaghetti going wrong for reference. Not shown but possibly important is that there is a [KSPField] for persistent storage of a copy of PartModule.appliedUpgrades that should have been changed, but won't(clicking on "Show Upgraded Stats" returns the same full upgrades in Sandbox, except for one case)

Spoiler

 



//The button, which is added to a dynamic size scroll list in the PopupDialog and should evoke the PartUpgrade it refers to.
		var single_upgrade_button = new DialogGUIToggleButton(Generalstate(currentupgrade),currentupgrade.title,OnButtonClick_Upgrade(currentupgrade,modulesthatgetupgraded,thisupgradestate),button_width,button_height);
//This checks whether the Toggle should be on or off. Seems to work alright, but how can OnButtonClick_Upgrade interact correctly with it?
		bool Generalstate(PartUpgradeHandler.Upgrade selectedupgrade)
		{
            modulesthatgetupgraded.Clear();
            // This checks if the current part has the upgrade applied and prints out all partmodules affected
            // so the toggle buttons will be either on or off depending on the state of the upgrade for the part
            foreach (PartModule m in part.Modules)
            {
                if (m.HasUpgrades() && m.upgradesApplied.Contains(selectedupgrade.name))
                {
					thisupgradestate = true;
					modulesthatgetupgraded.Add(m);
                }
            }
            // These modify the persistent list of activated upgrades.
			foreach (string upname in SelectedUpgrades)
			{
                if (selectedupgrade.name == upname && thisupgradestate == false)
                {
                    SelectedUpgrades.Remove(upname);
                    isalreadyinlist = false;
                } else 
                    if (selectedupgrade.name == upname)
				    {
    					thisupgradestate = true;
					    isalreadyinlist = true;
    				}
			}
            if (!isalreadyinlist && thisupgradestate == true)
                SelectedUpgrades.Add(selectedupgrade.name);

            Debug.Log("Enabled = "+thisupgradestate+". "+selectedupgrade.name+" will modify "+modulesthatgetupgraded.Count+" modules.");
            return thisupgradestate;
		}
		// Now this is probably where the first mistake is because it while the toggle changes, leaving the GUI does nothing and there is no message indicating upgradesApplied being altered for each module read from modulesthatgetupgraded(). Likewise it might be needed to do far more extensive coding to support this
		#region  OnButtonClick methods called by the GuiButtons and Toggles
        Callback<bool> OnButtonClick_Upgrade(PartUpgradeHandler.Upgrade thisupgrade, List<PartModule> modulesgettingupgraded, bool UpgradeState)
		{            
            Debug.Log("Upgrade Editor: Toggling " + thisupgrade.name + " to "+UpgradeState);
            PartUpgradeManager.Handler.SetEnabled(thisupgrade.name, UpgradeState);

            // Modifying the upgrades applied list
            foreach (PartModule mmm in modulesgettingupgraded)
            {
                foreach (string upgdr in mmm.upgradesApplied)
                {
                    if (upgdr == thisupgrade.name && UpgradeState == false)
					{
                        mmm.upgradesApplied.Remove(upgdr);
                        SelectedUpgrades.Remove(upgdr);
                        upisalreadyinlist = false;
						Debug.Log("Upgrade Editor: Removing " +upgdr+ " from applied upgrades in " + mmm.name);
					} else 
                        upisalreadyinlist |= upgdr == thisupgrade.name;
                }
                foreach (ConfigNode upgrade in mmm.upgrades)
                {
                    if (upgrade.GetValue("name__") == thisupgrade.name && UpgradeState && !upisalreadyinlist)
                    {
                        mmm.upgradesApplied.Add(thisupgrade.name);
                        SelectedUpgrades.Add(thisupgrade.name);
                        Debug.Log("Upgrade Editor: Adding " + upgrade.name + " to applied upgrades in " + mmm.name);
                    }
                }
                mmm.ApplyUpgrades(StartState.Editor);
            }
            return delegate (bool arg1)
            {
                arg1 = UpgradeState;
            };
		}
// This button evoking a bool in the game itself actually does something upon leaving and entering the GUI. It will erase all upgrades from the part, but the toggle buttons for upgrades remain on despite that.
		void OnButtonClick_ToggleAutoApply(bool taap)
		{
            ToggleAutoApply = taap;
			//Not entirely sure if this is necessary to refresh it.
            ApplyUpgradesEditorAuto = taap;
		}

 

And the output log from this half-baked plugin:

Spoiler

 



(Filename: /home/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

Upgrade Editor: Selected Part is SSTU-SC-TANK-MUS

Upgrade Editor: Number of Upgrades for SSTU-SC-TANK-MUS:22
 
Enabled = True. SSTU-MFT-M1 will modify 1 modules.

Upgrade Editor: Toggling SSTU-MFT-M1 to True
 
...
 
Enabled = True. SSTU-MFT-D6 will modify 1 modules.

Upgrade Editor: Toggling SSTU-MFT-D6 to True
 
...

PartLoader Warning: Variable costmod not found in Part

Enabled = True. SRP0_RCS_AerozineTL7 will modify 3 modules.

Upgrade Editor: Toggling SRP0_RCS_AerozineTL7 to True

 

 

 

There is no Debug message at all from the parts of the code that should modify the list of applied upgrades for each affected module in the part and even after disabling all upgrades in the part through the other toggle the toggle buttons won't change to the "Off" position upon calling the Upgrade Editor menu again. The number of buttons being generated dynamically is what makes this tricky. Each function called by the button must store which upgrade is calling it, whether it will go on or off and what modules must be changed. With ToggleAutoApply off(also stored in a persistent KSPField) the only change is that the Debug message in Generalstate(etc){} will answer "x  will modify 0 modules." for all modules, but still not switch the buttons off and nothing happens. Finally, should anyone be interested in adopting this, it's available here:

https://pastebin.com/LaidWVB8

I 'm not skilled enough to find a solution on my own for this and I really hope this verbose post isn't asking for too much again. So, any suggestions or takers?

 

 

Edited by NotTheRealRMS
Already solved this
Link to comment
Share on other sites

Is there a GameEvent that is triggered when docking? I've added a button to the context menu for docking ports, but I only want that button to be shown on docking ports that are docked.
There is an event `onPartUndock` that I can use to hide the button after undocking, but I can't seem to find an equivalent event to trigger showing the button when docking. 
I can kinda get the desired end result using onVesselPartCountChanged and then checking this.part for ModuleDockingNode and seeing if that has otherNode, but a) that doesn't work on docking ports that are already docked when the scene is loaded and b) if I put a Debug.Log() into that process it shows it making numerous calls (possibly for every part, not sure) so that seems like the wrong way to be going about doing this.

What would be the right way of only showing something on a docking port's context menu when the port is docked?

Link to comment
Share on other sites

@katateochi build your own with an if statement looking at Vessel.Situations. 

https://kerbalspaceprogram.com/api/class_vessel.html#acea90b73d9b4523383503ec82f2f63bb

bool vesselDocked;
OnFixedUpdate()
{
	if(Vessel.Situations == 128)
	{
  		vesselDocked = true;
	}
}

(Note: i don’t know if the above code will work, but its my best guess. I have never worked with enums, I’m just relaying what I found. Official MS documentation here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/enum)

Link to comment
Share on other sites

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