Cephei

The official unoffical "help a fellow plugin developer" thread

Recommended Posts

On 1/6/2019 at 9:20 AM, nightingale said:

The short version is that you have to use the TutorialScenario (there are some very old examples if you search github).

An alternative is to build your own dialog boxes using KerbalInstructor (that's what provides the picture).  This is what Contract Configurator does, although it uses the old GUI system and is...  overly complex.

Took me a while, but I managed to figure out how to use the KerbalInstructor technique in the new dialog framework:

https://github.com/SteveBenz/ColonizationByNerm/blob/master/src/PopupMessageWithKerbal.cs

That's a class that will display a quick modal dialog with a message in it.

  • Like 1

Share this post


Link to post
Share on other sites

Does anyone know of a way to get an ExperienceTrait from the name of a trait?

Share this post


Link to post
Share on other sites
2 hours ago, DeltaDizzy said:

Does anyone know of a way to get an ExperienceTrait from the name of a trait?

Ugly, but I'm not aware of a better way.

            for (int index = 0; index < GameDatabase.Instance.ExperienceConfigs.Categories.Count; ++index)
            {
                if (traitStr == GameDatabase.Instance.ExperienceConfigs.Categories[index].Name)
                {
                    Type type = KerbalRoster.GetExperienceTraitType(traitStr) ?? typeof(ExperienceTrait);
                    return ExperienceTrait.Create(type, GameDatabase.Instance.ExperienceConfigs.Categories[index], null);
                }
            }

Share this post


Link to post
Share on other sites

Hey yall, new Kerbaler here.
I think I finally got the right versions of Mono/NET/Unity/PartTool installed...  did a wiki dll & part and it put HelloWorld in the kerbal F12 console. 
great

So many tuts & howtos are outdated,
COULD SOMEONE RECOMMEND a 1.6 small plugin mod that  I could look over the source, to learn how things are c# coded in KSP mods? 

Its so frustrating when you try researching how to do stuff,
and using tutorial code doesnt work because its several years & versions old.

Share this post


Link to post
Share on other sites

 

5 hours ago, Bimbie said:

Hey yall, new Kerbaler here.
I think I finally got the right versions of Mono/NET/Unity/PartTool installed...  did a wiki dll & part and it put HelloWorld in the kerbal F12 console. 
great

So many tuts & howtos are outdated,
COULD SOMEONE RECOMMEND a 1.6 small plugin mod that  I could look over the source, to learn how things are c# coded in KSP mods? 

Its so frustrating when you try researching how to do stuff,
and using tutorial code doesnt work because its several years & versions old.

I'm a new modder too, so I think I can give you the answer:  No.  KSP can be extended in so many wildly different ways that any one small mod would very probably not be relevant for anything you'd ever want to do.

KSP has poop for documentation, and the API's are all over the place.  You live and die by examples.  As an illustration of this point, I found people using 3 different API's for getting all the parts of a ship in the VAB.  The most obvious thing (if you just look at the API docs) actually returns not only the parts that are in the ship, but those that are just dragged off to the side.  You just gotta know.  And the means of getting parts in the editor are completely different than what you do in the Flight scene, and what you do in the flight scene varies depending on whether you're talking about loaded or unloaded ships.  There's no end of stuff like that.

There are things that make some sense after you've been at it for a while, but you never know where the next land mine will be.

What you need to do is get good at finding other mods that do similar things to what you want to do and reverse engineering them.  Get good at searching for API's on github.

And then come back here when you get totally stumped.  I never would have guessed that  'KerbalInstructor' was any kind of way to get a talking kerbal in my dialogs, but once Nightingale pointed the way, I was set to go.  I bet there's another way (something similar to how the Kerbals in the lower right of the screen are drawn), but if there's no example of that, I've got absolutely no shot at discovering it myself.

I would say that the tutorials I found in the sticky posts here are the forums have been helpful in getting a basic grounding.  I've not yet found one that was uselessly out of date, either.  If you haven't done it already, you should follow the post on how to set up the Unity debugger.  That's an immense help in mod development.

  • Like 1

Share this post


Link to post
Share on other sites

Does anyone know how to the the anomolies for the transitions between orbits in patchedConicsSolver's flight plan?

 

Edit: To add on, I am programming an external orbit viewer. I can draw individual orbits, but I am not sure where to get all the required data. patchedConicSolver.flightPlan only seems to have the orbits created by maneuver nodes, not by gravity assists and stuff. 

 

Edit 2: I have figured out most of the orbit stuff I need to know, but I still can't figure out how to get the anomalies for the orbit patches ends/starts. 

Edited by c4ooo

Share this post


Link to post
Share on other sites

I'm trying to create an experience where the player needs to go to a particular spot on a body in order to gather a certain resource.  Two ways to do that present themselves:

  1. Create waypoints, then create a special gathering module that will only work if it's near one of my waypoints.  Can anybody point me at good examples of how to create waypoints?
  2. Do what MKS does and create an actual asteroid-like craft.

#1 was my first thought - but I'd love to find a recent example of code doing a waypoint - both how to create them and how to sense that the ship is near one.

I stumbled on #2 while looking for a way to do #1.  It actually seems like it might be a lot of fun, but I'm worried that the resources will turn up on hillsides and start rolling away from the player as soon as they get near.

Share this post


Link to post
Share on other sites
10 hours ago, NermNermNerm said:

I'm trying to create an experience where the player needs to go to a particular spot on a body in order to gather a certain resource.  Two ways to do that present themselves:

  1. Create waypoints, then create a special gathering module that will only work if it's near one of my waypoints.  Can anybody point me at good examples of how to create waypoints?

Look how Waypoint Manager do it. It creates waypoints and tracks distance to them (among other things).

Share this post


Link to post
Share on other sites
Posted (edited)

So, I'm trying to read a config node from a file but it fails for no apparent reason :/ I know that the code should work since I've used it for AVC already but it doesn't seem to run for MiniAVC. I've added "a few" debug lines to see whats going on:

public static void LoadConfig()
{
  Debug.Log("Mini-AVC: LoadConfig()");
  if (!File.Exists(configPath))
  {
    Debug.Log("Mini-AVC: Config not found");
    return;
  }

  ConfigNode LoadNodeFromFile = ConfigNode.Load(configPath);
  ConfigNode node = LoadNodeFromFile.GetNode("MINI-AVC");
  Debug.Log($"Mini-AVC: HasNode UPDATE_FREQUENCY: {node.HasNode("UPDATE_FREQUENCY")}");

  var te = node.GetNodes();
  foreach (var item in te)
  {
    var t = item.name;
    Debug.Log($"Mini-AVC: NodeName = {t}");
  }
  if(node.HasNode("UPDATE_FREQUENCY"))
  {
    try
    {
      ConfigNode _temp = new ConfigNode();
      _temp = node.GetNode("UPDATE_FREQUENCY");

      AvcInterval = Int32.Parse(_temp.GetValue("MinTimeBetweenAvcRuns"));
      Debug.Log($"Mini-AVC: HasValue AvcRunsNext: {_temp.HasValue("AvcRunsNext")}");
      if (_temp.HasValue("AvcRunsNext"))
      {
        NextRun = DateTime.Parse(_temp.GetValue("AvcRunsNext"));
        Debug.Log($"Mini-AVC: NextRun = {NextRun}");
      }                    
    }
    catch { }
  }
  ConfigLoaded = true;
  Debug.Log("Mini-AVC: Config loaded");
}

And I got this output:

Mini-AVC: LoadConfig()

Mini-AVC: HasNode UPDATE_FREQUENCY: False

Mini-AVC: NodeName = UPDATE_FREQUENCY

Mini-AVC: HasValue AvcRunsNext: False

Basically, I cannot get the node "UPDATE_FREQUENCY" but when I list every node inside of the "MINI-AVC" config node, it shows me there is one called "UPDATE_FREQUENCY"...

I've already tried to rewrite these lines by hand just to be sure there are no copy&paste issues. Someone got an idea what's going on there and how to solve this issue?

edit: well, the issue disappeared for the same reason it appeared: none o_O

Edited by 4x4cheesecake

Share this post


Link to post
Share on other sites

How do I find the amount of available science points (the value shown at the KSC)?

Share this post


Link to post
Share on other sites

@garwel I think ResearchAndDevelopment.Science gives you the amount of science you currently have.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, DMagic said:

@garwel I think ResearchAndDevelopment.Science gives you the amount of science you currently have.

Thanks. It's actually ResearchAndDevelopment.Instance.Science.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now