Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

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. 

Link to comment
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.)

Link to comment
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.

Link to comment
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?

Link to comment
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.  

Link to comment
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!
 

Link to comment
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
Link to comment
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 :(

Link to comment
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
Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
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...

Link to comment
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
Link to comment
Share on other sites

  • 3 weeks later...

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
Link to comment
Share on other sites

  • 3 weeks later...

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
Link to comment
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. 

Link to comment
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?

Link to comment
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
Link to comment
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.
Link to comment
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.

Link to comment
Share on other sites

Is there any "official" way on how to get the different vectors from the navball (Pro/Retrograde, radialIn/Out, Anti/Normal etc)? I have found some old forum posts (one and two) but the github links that are there are dead. I have also found this code on github, which seems to get the NavBall class through GameObject.Find(""); but when I try the same method, I get a null object. Do I have to manually calculate the vectors, or is there a way to somehow read them from somewhere? 

 

Edit: I want the navball vectors because I want to render a navball in a separate desktop application. I already have the navball pitch/yaw/roll rotation correctly rendered, now I just need the vectors.

Edited by c4ooo
Link to comment
Share on other sites

@c4ooo You can use the similarly brute force GameObject.FindObjectsOfType<NavBall>() to get the NavBall instance (it might not be active or present immediately after a scene loads, so you may have to wait a bit to do this). But I don't know about how accessible or not the target vectors are.

Edited by DMagic
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...