Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

2 minutes ago, Tralfagar said:

My question for you guys isn't technical programming this time, but general mod-keeping.  When do you guys release your 1.2-compatible versions?  If you put it out before 1.2 officially drops, how do you keep issues between it and someone playing 1.1.3 from happening?

Large, red lettering on the OP, maybe the use of some version-checking... I dunno.

Link to comment
Share on other sites

1 minute ago, Tralfagar said:

@0111narwhalz Do you mean the .version file?  In my tests, it seemed like that was ignored (I had set the minimum version to 2.2 and it loaded the plugin).

The .version file does nothing unless you have AVC installed (or the mod comes with MiniAVC).  Even then it will just give you a warning.

Link to comment
Share on other sites

11 hours ago, Sharpy said:

Interestingly:   equipMode = physic makes the chute behave 100% nice rightclick-wise, but the kerbal movement gets all kinds of wonky (as if really drunk...)

Was working on the same problem with @SpannerMonkey(smce) but I stopped as 1.2 in play now. You can check out what I had so far here

I had the auto equip from the first slot of KIS inventory on Eject  by doing this

        public void GetKISInventory()
        {
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                var kis = FlightGlobals.ActiveVessel.rootPart.FindModuleImplementing<ModuleKISInventory>();
                kis.items[0].Equip();
                ChuteAdded = true;
            }

This method however will cause you to need to compile against KIS which you may or may not want to do - see this issue

As for activating a part in code, check this out, never got around to seeing if it would apply to a chute

 

Link to comment
Share on other sites

Hi all, just a quick one. Does anyone know how I can go about rendering my own context menu vector line as seen below; I've had a look at the KSP API's UI section but can't find what I'm looking for, or have clearly missed something.

AeYehDSl.png

Thanks in advance for your help.

Edited by udk_lethal_d0se
Link to comment
Share on other sites

Hi Everyone!

I'm looking for a vessel.findWorldCenterOfMass() replacement in V1.2 pre-release

The function seems to have gone AWOL.  If anyone can help it would be wonderful.

Cheers

 

EDIT:  I was looking for something that would return a Vector3 - and was wondering if I could swap it for vessel.CoM?

 

Edited by Z-Key Aerospace
Link to comment
Share on other sites

On 9/19/2016 at 9:56 AM, Sharpy said:

How to deploy a chute?

I've added a KIS EVA item, a wearable parachute.

0bYqcld.png

And it works fine... on the ground.

The problem is the bounding box for registering right-click seems to lag behind the kerbal. While walking, that's not a problem, as it's at worst several centimeters off, upper half of the chute not registering clicks or so. But when falling 200m/s, the actual click may register if I'm clicking several meters above the falling kerbal. This is a kind of an issue.

How can I fix this? I guess the rightclick issue may be hard to solve, too ingrained into the engine,  but if the chute was to be activated by key (e.g. bound to a Brakes action group), or staged, or triggered through KIS Inventory action - that would work. But how do I do it? It can't be done in VAB, as the chute is usually stowed in some container, and only appears physically in the world once the kerbal equips it.

Actually that would be one more solution: that the parachute initially starts in the ACTIVE state, instead of STOWED - the kerbal wears an already armed parachute, and it deploys as soon as pressure and altitude are right, without taking any action.  (it's just an entry in KIS inventory before equipping, so it won't deploy before being equipped.)

But how do I do any of these things? Preferably just by .cfg file option, but if that's not possible, a plugin?

You may want to take alook at the mod I just released/revived: EVA Parachutes & Ejection Seats

Link to comment
Share on other sites

On 9/21/2016 at 2:33 PM, Z-Key Aerospace said:

Hi Everyone!

I'm looking for a vessel.findWorldCenterOfMass() replacement in V1.2 pre-release

The function seems to have gone AWOL.  If anyone can help it would be wonderful.

Cheers

 

EDIT:  I was looking for something that would return a Vector3 - and was wondering if I could swap it for vessel.CoM?

 

Yes.  Vessel.CoM. replaces this.

Link to comment
Share on other sites

Hi, I started with the development of my first plugin one week ago. What I have so far is a simple window showing some text, which is only visible in the VAB.
Now, I want to add a button at the bottom of the screen inside the VAB. A click on the button should show or hide this window. Can someone help me with this?

Thanks is advance,
haselnuss

Edited by haselnuss
Link to comment
Share on other sites

34 minutes ago, haselnuss said:

Hi, I started with the development of my first plugin one week ago. What I have so far is a simple window showing some text, which is only visible in the VAB.
Now, I want to add a button at the bottom of the screen inside the VAB. A click on the button should show or hide this window. Can someone help me with this?

Thanks is advance,
haselnuss

Have a look at the source for Tac Life Support and Kerbal engineer redux for some examples.

Link to comment
Share on other sites

2 hours ago, udk_lethal_d0se said:

Have a look at the source for Tac Life Support and Kerbal engineer redux for some examples.

I installed both plugins in KSP. The structure of the window of Tac Life Support, which is shown in the VAB, is simpler than the window of Kerbal engineer redux. So I thought, it should be easier to find the lines I am looking for in the source code of Tac Life Support. I was wrong. Can you name the files, which contain the lines for the button in the VAB? The word "button" is used in so many files. I don't know, where to start.

Link to comment
Share on other sites

2 hours ago, udk_lethal_d0se said:

Have a look at the source for Tac Life Support and Kerbal engineer redux for some examples.

I installed both plugins in KSP. The structure of the window of Tac Life Support, which is shown in the VAB, is simpler than the window of Kerbal engineer redux. So I thought, it should be easier to find the lines I am looking for in the source code of Tac Life Support. I was wrong. Can you name the files, which contain the lines for the button in the VAB? The word "button" is used in so many files. I don't know, where to start.

Link to comment
Share on other sites

Hi guys, do you know how I can check if a craft in the editor has unsaved changes?  
I have a (sortof) working solution, but's it not very nice!  I can check if the current craft has had a craft file created with;

File.Exists(ShipConstruction.GetSavePath (craft_name));

and if it exists I can read it with File.ReadAllText
Then (assuming that file exists) I can save the current craft to a temp location with 

EditorLogic.fetch.ship.SaveShip().Save(temp_path)

and then read that file, take both strings and do a SHA256Managed digest and see if they are the same or not.

That works for any changes made to the craft, but doesn't take any changes in the crafts description into account. But mostly it's horrible because having to use a temp file. I haven't found a way to just get the craft as a string without that interim step. ship.SaveShip().toString() gives me something like a craft file, but the whole thing is inside an extra set of { } braces and the 'header' section is in reverse order to how it is once saved normally, so I'd have to process it before comparing it.
There must be an easier way to check if there are unsaved changes! 

Edited by katateochi
Link to comment
Share on other sites

1 hour ago, haselnuss said:

I installed both plugins in KSP. The structure of the window of Tac Life Support, which is shown in the VAB, is simpler than the window of Kerbal engineer redux. So I thought, it should be easier to find the lines I am looking for in the source code of Tac Life Support. I was wrong. Can you name the files, which contain the lines for the button in the VAB? The word "button" is used in so many files. I don't know, where to start.

Have a look here, should give you a good start. The file naming is pretty self explanatory. EditorController.cs

https://github.com/KSP-RO/TacLifeSupport/blob/master/Source/EditorController.cs

Link to comment
Share on other sites

6 hours ago, haselnuss said:

Hi, I started with the development of my first plugin one week ago. What I have so far is a simple window showing some text, which is only visible in the VAB.
Now, I want to add a button at the bottom of the screen inside the VAB. A click on the button should show or hide this window. Can someone help me with this?

Thanks is advance,
haselnuss

I'm also pretty new at this (so resident Gurus, please shout at me if my answer is wrong!), but I've found a couple ways of doing what you want. 
The first way is just to add a public static bool variable to the window class and then wrap the actions inside OnGUI in an if that checks if it's set to true.  

[KSPAddon(KSPAddon.Startup.EditorAny, false)]
public class TestWindow : MonoBehaviour
{
	public Rect win_pos = new Rect (100, 100, 200, 200);
	public static bool visible = true;

	public static void toggle(){
		visible = !visible;
	}

	void OnGUI(){
		if(visible){
			win_pos = GUILayout.Window (42, win_pos, DrawWindow, "test window");
		}
	}

	private void DrawWindow(int windowID){
		GUILayout.Label ("some content");
	}
}


In another window/script you can then have a button that toggles it;  

if (GUILayout.Button ("test toggle visible")) {
	TestWindow.toggle ();
}

 


The other way is actually to create or destroy the window.  This time you don't need the visible variable, and you also don't need the attribute tag line. But you do need a Start and OnDestroy methods to set and unset a public static variable to reference the instance of the window.

public class TestWindow : MonoBehaviour
{
	public static TestWindow instance = null;
	public Rect win_pos = new Rect (100, 100, 200, 200);

	void Start(){
		TestWindow.instance = this;
	}

	void OnDestroy(){
		TestWindow.instance = null;
	}

	void OnGUI(){
		win_pos = GUILayout.Window (42, win_pos, DrawWindow, "test window");
	}

	private void DrawWindow(int windowID){
		GUILayout.Label ("some content");
	}
}

Then on the toggle open/close button do this;

if (GUILayout.Button ("test open/close")) {
	if(TestWindow.instance == null){
		gameObject.AddOrGetComponent<TestWindow> ();
	}else{
		GameObject.Destroy (TestWindow.instance);
	}
}

 

The first way literally toggles visibility, but the instance of the window is still there.  The second way creates and destroys an instance of the window.

Link to comment
Share on other sites

On 25/09/2016 at 6:25 PM, haselnuss said:

I installed both plugins in KSP. The structure of the window of Tac Life Support, which is shown in the VAB, is simpler than the window of Kerbal engineer redux. So I thought, it should be easier to find the lines I am looking for in the source code of Tac Life Support. I was wrong. Can you name the files, which contain the lines for the button in the VAB? The word "button" is used in so many files. I don't know, where to start.

This should be a short version :

 

 

Link to comment
Share on other sites

I am trying to get access a unity ParticleSystem through my plugin, and jet_particle = part.GetComponent<ParticleSystem>(); doesn't seem to grab the ParticleSystem.

The ParticleSystem in the unity scene is directly under the game object in the hierarchy. (jet_particle is an instance of ParticleSystem.)

 

I am sure the solution is obvious, I am just not seeing it. Any help would be greatly appreciated.

Link to comment
Share on other sites

@sarbian, nvm I figured out what I was doing wrong, I am just using a model_multi_particle effect now. Now if I can figure out why it is always turned on to half power when I load the craft I will be good. :)

Spoiler

    EFFECTS
    {
        jettison
        {
            AUDIO
            {
                channel = Ship
                clip = Low_Expectations/Sounds/Jettison_Module
                volume = 0.0 0.0
                volume = 0.1 0.0
                volume = 0.5 0.025
                volume = 1.0 0.1
                pitch = 0.0 0.75
                pitch = 1.0 1.5
                loop = false
            }
            
            MODEL_MULTI_PARTICLE
            {
                modelName = Squad/FX/Monoprop_small
                transformName = Emitter
                emission = 0.0 1.0
                speed = 5.0 5.0
                localRotation = 0, 0, 0
            }
 

        }    
            
    }

Is always on, for some reason. Not at full power, like when I trigger the event, but it is always on to a lesser degree.

If I figure this out, I will be sure to post what I find.

Edited by Electr0ninja
Link to comment
Share on other sites

Figured it out, I was using the wrong particle effect, Working code below, I just has to call the effect through the plugin.

Spoiler

    EFFECTS
    {
        jettison_audio
        {
            AUDIO
            {
                channel = Ship
                clip = Low_Expectations/Sounds/Jettison_Module
                volume = 0.0 0.0
                volume = 0.1 0.0
                volume = 0.5 0.025
                volume = 1.0 0.1
                pitch = 0.0 0.75
                pitch = 1.0 1.5
                loop = false
            }

        }
        
        jettison_particle{
            PREFAB_PARTICLE
            {
                  prefabName = fx_exhaustFlame_white_tiny
                  transformName = Emitter
                  emission = 1.0 1.0
                  speed = 5.0 5.0
                  localOffset = 1, 0, 0
                  
            }
    }
        
    }

 

Link to comment
Share on other sites

I'm trying to create a vessel on the launchpad from the spacecenter or editor scenes.

I think I'm on the right track with ShipConstruction.PutShipToGround, but I'm having trouble locating the correct Transform for the second argument.

The following Gist demonstrates the issue; has anyone else tried doing something like this or run into a similar problem?

Gist

Link to comment
Share on other sites

10 minutes ago, haselnuss said:

Is it possible to update my plugin while KSP is running to test a new version?

There is something somewhere on the forum that allows that for some specific cases. But in the end it is easier to have a copy of KSP with few parts and no Internals that loads fast.

Edited by sarbian
Link to comment
Share on other sites

11 hours ago, haselnuss said:

Is it possible to update my plugin while KSP is running to test a new version?

Yes:

There's a comment that says it still works in 1.2 pre.  I haven't used it lately but I used to use it a lot.

I wholly agree about having a separate KSP instance for development with only the bare minimum installed (and graphics tuned down), but even that can get frustrating to constantly reload.

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