Cephei

The official unoffical "help a fellow plugin developer" thread

Recommended Posts

In 1.3.x I had a little helper that I used to speed up development testing by jumping me from the main menu to the scene I needed to be at, but in 1.4.x it doesn't work, or rather it jumps to the right scene, but (ie in an editor) none of the assets are present and most buttons don't function.
This was the helper I used before

[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class DevTools : MonoBehaviour
{
    public void Start(){
        HighLogic.SaveFolder = "test_save";            
        GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);
        EditorDriver.StartEditor(EditorFacility.SPH);            
    }
}

Any ideas how to load a specific scene in 1.4.x?

Share this post


Link to post
Share on other sites

@katateochi I wouldn't jump to any scene other than the Space Center scene, and I would also make sure that you delay loading from the main menu for a second or so (start a coroutine from the Start method with a yield for WaitForSeconds(1) before loading). Some things in KSP could be depending on a specific load order to work right.

I guess you could make a script that starts in the Main Menu, waits a second or so, then loads a save file to the Space Center scene, then load another script that waits another second, then go to the scene you want, it would only add a few seconds to the load time, but it would ensure that everything is loaded in the standard order.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks @DMagic! I had tried the coroutine approach but wasn't successful with that either (perhaps because I was still attempting a jump direct to SPH).
For the moment I've given up and am using @Malah's Quick Mods, quick start & quick goto (now maintained by the mod-machine aka @linuxgurugamer) as that does what I need. So I could dig through that code and find the way, but actually using quick mods works better as I don't need that helper code in my codebase. 

Share this post


Link to post
Share on other sites

[So glad I found this thread!]

I have a vessel and have identified a cupola part within it.  I have the vessel crew members.  I wish to determine whether the cupola part in the vessel is occupied by a Kerbal or not.  How?  (Appreciated.)

Share this post


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

[So glad I found this thread!]

I have a vessel and have identified a cupola part within it.  I have the vessel crew members.  I wish to determine whether the cupola part in the vessel is occupied by a Kerbal or not.  How?  (Appreciated.)

part.protoModuleCrew.Count

if it's not equal to zero then the part is occupied.

  • Like 1

Share this post


Link to post
Share on other sites

How to make some function be called on value change in UI_FloatRange bar?

[KSPField(guiName = "ExampleSelect", isPersistant = false, guiActive = true, guiActiveEditor = true)]
[UI_FloatRange(stepIncrement = 1f, maxValue = 10f, minValue = 0f)]
public float selectedValue;

[KSPField(guiName = "Info", isPersistant = false, guiActive = true, guiActiveEditor = true)]
[UI_Label()]
public string descText = "here is selected value description";

//change descText based on selectedValue

if(selectedValue > 5f){
	descText = "value is big";
} else {
	descText = "value is small";
}

What I need is text change based on value in select bar. (same as stock fuel bar or thrust limiter in parts info)

Are there any ways to do this?

Share this post


Link to post
Share on other sites
3 hours ago, voviks said:

How to make some function be called on value change in UI_FloatRange bar?

What I need is text change based on value in select bar. (same as stock fuel bar or thrust limiter in parts info)

Are there any ways to do this?

You need to add a callback for when the field is changed,something like this.  

Share this post


Link to post
Share on other sites

Hello Everyone!
I'm very new to modding and I'm hoping someone can help me over a hopefully small hurdle. I'm trying to work through the "Tutorial-Creating your first module" on the Kerbal Space Program Wiki.

Here is where I'm stuck.
1. Used "Setting up Visual Studio" from the Kerbal Space Program Wiki.  Using .NET Framework 3.5 with Visual Studio 2015
2. Referenced both KSP_INSTALL_FOLDER\KSP_Data\Managed\Assembly-CSharp.dll and KSP_INSTALL_FOLDER\KSP_Data\Managed\UnityEngine.dll. Both dlls are showing along with there paths. I'm using KSP 1.4.3.
3. My source code
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace MyKSPProject
{
    /// <summary>
    /// My first part!
    /// </summary>
    public class HelloKerbinMod : PartModule
    {
        /// <summary>
        /// Called when the part is started by Unity.
        /// </summary>
        public override void OnStart(StartState state)
        {
            // Add stuff to the log
            print("Hello, Kerbin!");
        }
    }
}

4. My error

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0246    The type or namespace name 'PartModule' could not be found (are you missing a using directive or an assembly reference?)    MyKSPProject    C:\MyKSPProject\MyKSPProject\HelloKerbinMod.cs    12    Active

Thanks to all in advance for any help!
 

Share this post


Link to post
Share on other sites

Thanks to recent help from Li0n, I have enough now working to be able to make a release this month.

I'm going for the icing on the cake regarding KerbalEVA and AddFlag.  The question is in two parts:

  1. The vesselName "Tiger Kerman" isEVA():true.  It has a Part, "kerbalEVAfemale (Tiger Kerman)".  I want to add a flag if it has no flags, but I cannot see how to convert to KerbalEVA (to AddFlag); nor do I see any relevant Parts or Modules.
  2. In the other case, the vessel is some kind of ship and it may contain 1 or more crew members.  In this case, I want to add a single flag to any Kerbal that does not already possess a flag.

So, in the first case, a lone Kerbal on EVA is having its flag supply replenished to a level of 1.  In the second case, the Kerbals in question are crew members embedded within the vessel.

How to proceed in each case?  (I will be deeply grateful and will be acknowledging contributions in the credits upon publication.)  Thanks.

Edited by Hotel26

Share this post


Link to post
Share on other sites
On 5/22/2018 at 2:48 AM, Damian Storm said:

4. My error

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0246    The type or namespace name 'PartModule' could not be found (are you missing a using directive or an assembly reference?)    MyKSPProject    C:\MyKSPProject\MyKSPProject\HelloKerbinMod.cs    12    Active

Do you have more info in the console windows when you try to build ? Because it does look like Assembly-CSharp.dll is not actually linked :(

Share this post


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

like Assembly-CSharp.dll is not actually linked

@Damian Storm  yes, sometimes a small yellow exclamation mark appears in the References list on a DLL to indicate some problem (in the path).  Open the references section in the project in the Solution Explorer and check again that the library is references and also does NOT have this little exclamation mark.

If you hover over it (when there's the '!'), VS may show you the specific error as a tip.  Usual best thing is to simply delete the reference and add it again and verify no error.  Lastly, and I think this is true for VS 2015, when you add the reference, if you use the dialog that has a Browse button, if the library you want is conveniently shown in a list, ignore that selection but use the Browse button instead to navigate specifically to the location of your reference.  It works better.

Edited by Hotel26

Share this post


Link to post
Share on other sites

Are there any wordsmiths around ? I'm currently making a pretty large contract pack and in order to cut down on the time to release I'd like to collaborate with someone that can write more than 2 bland lines for a contract description and the contract finished message. I would write a sentence or two as the scaffolding and the writer briefly expands on it.

It doesn't have to be a novel as some poor souls did (props to them) but more like a mission related tweet , something around 250 characters . I mean imagine taking the huge amount of time and effort of landing a rover on Moho and all you get is a generic bland "Congratulations you achieved the objective." . It's anticlimactic and it robs the space race of it's spirit of it's unbridled enthusiasm.

Besides crediting the co-author all I can offer is free hosting for some websites or an online radio station. I'd love to offer some cash but unfortunately that just opens to many cans of worms.

Share this post


Link to post
Share on other sites

It's been quite a while (almost a year) since i last did some coding in KSP.

To cut the story short : i tried searching and it didn't help. I guess my case is a little specific.

When i start my VS 2017 Community and look at offered project templates, there is no "Class Library (.NET Framework)" i need to make a plugin. Note that my VS 2017 install is running purely from OFFLINE installer created using vs_community.exe as so :

vs_community.exe --layout c:\vs2017offline --add [one.of.many.packages]

Note that i used multiple --add command line arguments and that running the above does download packages. What i'm having issue with is that i can't guess which package(s) will cause IDE to show "Class Library (.NET Framework)" template. If i load old project (which i want to avoid using as "template") i can edit project preferences and i can see "class library" option. If i choose "blank project" template, project preferences are not available.

Online/download from IDE is not an option since i want to save on network usage on any subsequent reinstalls, so i want a single download of all required packages and then actual install on target machine. Note also that due to KSP being switched to Unity 2017 and me needing to have debugging facilities (Tools for Unity VS2017 package) forced me to abandon VS2015 (which did not suffer from the above problem).

References:

Create and offline installation folder @  MS

Visual Studio Community 2017 component directory @ MS, i used this in conjuction with UI for selecting workloads and then to figure out what packages i need (so far i did not see option to create local copy of packages from UI as i can with command line).

Currently, i'm trying to download whatever is missing from VS installer UI, hoping to identify missing packages...

Share this post


Link to post
Share on other sites

UPDATE: i managed to make desired (minimal size) installation just for plugin development.

First i used this to download required packages :

vs_Community.exe --layout c:\vs2017offline --passive --wait --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.Net.Component.3.5.DeveloperTools --add Microsoft.Net.Component.4.7.1.TargetingPack --add Microsoft.VisualStudio.Component.NuGet --add Microsoft.VisualStudio.Component.Roslyn.Compiler --add Microsoft.VisualStudio.Component.Roslyn.LanguageServices --add Microsoft.VisualStudio.Component.Static.Analysis.Tools --add Microsoft.VisualStudio.Component.Unity

Above will load everything EXCEPT Unity3D package, i downloaded it separately. Command line will cause IDE to show so download progress will be visible.

To install (similar command line) , run :
 

PUSHD C:\vs2017offline

vs_setup.exe --passive --norestart --wait --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.Net.Component.3.5.DeveloperTools --add Microsoft.Net.Component.4.7.1.TargetingPack --add Microsoft.VisualStudio.Component.NuGet --add Microsoft.VisualStudio.Component.Roslyn.Compiler --add Microsoft.VisualStudio.Component.Roslyn.LanguageServices --add Microsoft.VisualStudio.Component.Static.Analysis.Tools --add Microsoft.VisualStudio.Component.Unity

POPD

Note that Unity3D package can be included entirely (shortening the "--add" packages command line) to just two entries.

Also, above install command line supresses reboot, it may be needed to reboot after installing.

Edited by fatcargo
additional info
  • Like 1

Share this post


Link to post
Share on other sites

hey guys! 

I need some help with the kerbalroster
I would like to access all kerbals, no matter if they are assigned, active, dead or missing, to do so, I wanted to access the kerbalroster. But I dont know how to accomplish that... I'm still a bit clumsy with C# and I read in the API that the constructor of the kerbalRoster needs a game.mode, which confuses me a bit.

Do I need to call the constructor or how do I acces the roster?


After looking through some plugins:
HighLogic.CurrentGame.CrewRoster;

Edited by stoani96

Share this post


Link to post
Share on other sites

Hello there would not be a part tool for KSP 1.4x version it would be nice to create my first KSP mod

 

Edited by Sprize

Share this post


Link to post
Share on other sites

I'm new to the whole addon development scene, and I'd like some help with something.

I'm preparing a mission control party for my friends and I, so I've installed Houston [https://github.com/tcannonfodder/houston] and Telemachus continued [

]

However, these plugins seem to rely on tiles.kerbalmaps.com which no longer seems to be working.

I was wondering if someone could help me change references to this website with another like http://ksp.deringenieur.net/

Thank you in advance.

 

edit: I'm dumb. I found the answer to the issue. My bad.

Edited by crocogator12
I found answer

Share this post


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

I am new to modding KSP and have looked through the beginner's guide. But I couldn't find how to display on-screen text like this: 

https://imgur.com/a/mRLXK1

How do I do this?

I'm going to point you towards https://kerbalspaceprogram.com/api/class_screen_message.html#a12eebe030a5c4c5a774615a07494989f, which I believe is what those are from. 

I usually set the duration to 10 seconds, which works nicely. 

  • Like 1

Share this post


Link to post
Share on other sites

I have what I hope is a relatively simple problem to solve. I just want to know what a vessel's targeted object is doing. I tried the following:

if (vessel.targetObject.GetVessel().situation == Vessel.Situations.ORBITING) {
  // stuff
}

It's never true. It seems that "vessel.targetObject.GetVessel().situation" always equals "Vessel.Situations.FLYING", whether it is orbiting, escaping, sub-orbital, or whatever. I'm sure I am making some sort of simple obvious mistake. Anyone know what I messed up?

Share this post


Link to post
Share on other sites

 

@Doxel

Try this....

-------------------------

var target = vessel.targetObject.GetVessel();

if (target.situation == vessel.situations.orbiting){do something}

---------------------------

Although the vessel.situations.orbiting may not be correct, when you type it in vs should give you a list of functions

Edited by DoctorDavinci

Share this post


Link to post
Share on other sites
5 hours ago, DoctorDavinci said:

var target = vessel.targetObject.GetVessel();

if (target.situation == vessel.situations.orbiting){do something}

I tried splitting it out into two bits like that, but no luck. It still matches to Situations.FLYING for anything off the ground even when it should be Situations.ORBITING. And I am getting the autocomplete suggestion list, so it is definitely Vessel.Situations.ORBITING.

A bit of testing determined that I can get an orbiting body to register as orbiting if I am within a kilometer of it, but otherwise it just returns flying no matter what. This makes it sound like the game can only figure out the situation of a loaded object, but I know that can't be right because the Tracking Station lists every vessel's situation correctly when none of them are loaded.

Any other ideas? I am at a loss.

EDIT:

Okay, little more testing, and it turns out it isn't being near the vessel that I am trying to read the situation of, it's just having seen another vessel. Any other vessel. When I first start up KSP and launch a vessel, everything comes up as Situations.FLYING. If I switch to any other vessel and come back, everything comes up correctly. I have no idea what could possibly cause this and am thus compelled to blame dark wizards.

If anyone has an idea, please let me know. In the mean time I am going to declare Vessel.Situations and all of its enumerations to be officially cursed by evil spirits and try another avenue of attack. I plan on making use of the patched conics system. As long as the next conic is not escaping or crashing, I will assume the targeted vessel is in orbit. Wish me luck.

EDIT:

Patched conics work but it's awkward and I have to test for a lot more edge cases that the conics don't differentiate between. If anyone knows how to get the situation variable to work right for unloaded vessels, I would still appreciate hearing from you.

Edited by Doxel
Because of dark wizards.

Share this post


Link to post
Share on other sites

@Doxel For unloaded vessels you have to check the protovessel situation: vessel.protovessel.situation, or something like that.

It should give the correct value, though I'm not sure if it gives the correct value for a loaded vessel, so you might need to check if the vessel is loaded before checking its situation.

  • Like 1

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