Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Sadly no luck with that one either, that list is empty all the times. Both with all parts filtered out and without any parts filtered out.

Did you try PartLoader.LoadedPartsList? I can attest to that one being filled with every available part, and though I've only looked at the name and category fields, I suspect they're all filled.

Link to comment
Share on other sites

Did you try PartLoader.LoadedPartsList? I can attest to that one being filled with every available part, and though I've only looked at the name and category fields, I suspect they're all filled.

Yes checked those - none of those fields are filled except for the name and the category.

Link to comment
Share on other sites

Stupid newbie here again with another silly question.

Is is possible to dynamically add [KSPEvent] attributes and functions at runtime?

I have searched the forum, but I can find no clear solution.

The problem: My OrionEngine part does not use the resource system (for complicated reasons I won't go into now. Suffice it to say that discrete nuclear bombs do not act like liquid rocket fuel). Instead, it uses OrionMagazines for fuel.

These magazines come in various strengths, all are OrionMagazine modules but the bomb strength is set by the parts.cfg. When you right-click on the Orion engine, a pop up menu appears. In the menu you can turn on and off the various magazine types. So if you want a fast lift-off, you turn on the 400 megaNewton bomb magazines, and turn off the 0.88MN, 3.5MN, and 10MN. Then all the 400MN magazines currently attached will feed the engine. All of this works fine.

What is not fine is that the [KSPEvent] functions are hard coded in the OrionEngine code. This makes it impossible for a user to create their own OrionMagazine by editing a part.cfg file. They can create the magazine, but it will not appear on the OrionEngine pop-up menu. Not unless they are willing to edit the code and recompile the plugin.

What I want is for the the OrionEngine to find all the part types of Class OrionMagazine at run-time, and dynamically create [KSPEvent] menu entries. I managed to get the PartLoader to spit out a list of the OrionMagazines, but I'm not sure how to proceed from there.

My fall-back position is to hard code ten or fifteen generic [KSPEvent] in OrionEngine and make them data driven. And hope the user does not try to add more magazine types than the number of generic slots I've supplied.

Edited by nyrath
Link to comment
Share on other sites

Curious whether there's a list anywhere of the types that a PluginConfiguration will serialize. I know it works for value types and some non-value types (e.g. Vector3), but my custom classes wouldn't serialize.

Link to comment
Share on other sites

So I've been trying to modify a part's material at runtime. Unsuccessfully.

I tried things like this:

using System;
using UnityEngine;
using System.Collections.Generic;

namespace KSPTestMod
{
public class TestMod : Part
{
protected override void onEditorUpdate()
{
if(Input.GetKeyDown("space")){
renderer.material.color = Color.black;
}



base.onEditorUpdate();
}
}
}

It gives me a Nullreference exception in the debug.

Link to comment
Share on other sites

Is is possible to dynamically add [KSPEvent] attributes and functions at runtime?

Adding them should be easy enough, this.Events.Add(new BaseEvent()). The trick would be getting unique behaviour out of them when event functions aren't called with any arguments you can check to determine the name of the calling event.

One alternative is to write a PartModule that handles the event and add that instead (part.AddModule), as the adding function returns a reference you can then set which fuel container it should apply to.

Curious whether there's a list anywhere of the types that a PluginConfiguration will serialize. I know it works for value types and some non-value types (e.g. Vector3), but my custom classes wouldn't serialize.

If it's the same as the persistence file then it would be: string, bool, int, float, Vector2, Vector3, Vector4 or Quaternion and anything that implements iConfigNode.

It gives me a Nullreference exception in the debug.

There's no renderer attached to the GameObject that your part-derived class (a component) is attached to, so renderer will return null. You need to grab the renderers from the child objects of the parts of the model that have meshes. You could use FindModelTransform(s) if you know what they're called or FindModelComponent(s) to grab all mesh renderers on the model.

Link to comment
Share on other sites

There's no renderer attached to the GameObject that your part-derived class (a component) is attached to, so renderer will return null. You need to grab the renderers from the child objects of the parts of the model that have meshes. You could use FindModelTransform(s) if you know what they're called or FindModelComponent(s) to grab all mesh renderers on the model.

OHMYGOD thank you so much!!

Finally I got it working.

using System;
using UnityEngine;
using System.Collections.Generic;

namespace KSPTestMod
{
public class TestMod : Part
{
protected override void onEditorUpdate()
{
PDebug.Log(name);
if(Input.GetKeyDown("space")){
Renderer[] r = this.FindModelComponents<Renderer>();
PDebug.Log(r.Length);
for(int i = 0; i < r.Length; i++){
r[i].material.mainTexture = null;
r[i].material.color = Color.black;
}

}




base.onEditorUpdate();
}
}
}

The problem I'm facing now is that it resets the renderer's color and texture upon launch. If someone could explain to me why that is I'd be extremely grateful.

Link to comment
Share on other sites

The problem I'm facing now is that it resets the renderer's color and texture upon launch. If someone could explain to me why that is I'd be extremely grateful.

The model is reloaded on each new scene, onEditorUpdate presumably only gets called in the editor so you'll need to call the code in another function that runs in the flight scene if you want to do it there (or save and reapply).

I'd consider grabbing just MeshRenderer components rather than all renderers as it's also used for things like LineRenderers and particle effects. Also, it's worth considering if you really need to extend Part. There are callbacks on Part and GameEvents that allow you to create functions that only run in the editor in a PartModule derived class.

Link to comment
Share on other sites

Also, it's worth considering if you really need to extend Part. There are callbacks on Part and GameEvents that allow you to create functions that only run in the editor in a PartModule derived class.

So what you mean is that I could extend the partmodule class and have the same functionality?

I'm very new to unity and C# btw, so sorry if I'm asking obvious questions.

Link to comment
Share on other sites

Adding them should be easy enough, this.Events.Add(new BaseEvent()). The trick would be getting unique behaviour out of them when event functions aren't called with any arguments you can check to determine the name of the calling event.

One alternative is to write a PartModule that handles the event and add that instead (part.AddModule), as the adding function returns a reference you can then set which fuel container it should apply to.

Thanks! I'll give those a try.

Link to comment
Share on other sites

I would like to know where the debug menu settings are stored. For example, if "gravity hack" is done on a flight, quicksaved, then reloaded, the gravity has returned in full force. This must mean that the "no gravity" setting is not stored in the save file, so is it written somewhere in a file at all or only stored in memory?

If the latter, then is it accessible through the API somehow? (i.e. could a plugin detect that it has been enabled)

The same question goes for the other settings as well, like infinite fuel.

Thanks!

Link to comment
Share on other sites

The same question

http://forum.kerbalspaceprogram.com/showthread.php/35336-Question-about-the-debug-menu

So what you mean is that I could extend the partmodule class and have the same functionality?

I don't know the full extent of what you're doing but yes, you can almost always get the same functionality with PartModule.

Link to comment
Share on other sites

I don't know the full extent of what you're doing but yes, you can almost always get the same functionality with PartModule.

Thanks, I haven't made up my mind yet as to what I want to make. I'll see when my exams are over. Maybe a docking port that discriminates rotation for people with OCD like me.

Link to comment
Share on other sites

Hey people, I'm wondering if anyone can help me out. I'm trying to develop a plugin for a part that converts a particular resource into another. I know how to program the part to request a resource, but how can I program it to convert resources? At the moment I've basically got a part that consumes the input resource and continues to produce the output resource even though the input resource has run out. How can I solve this issue?

Thanks. :)

Link to comment
Share on other sites

Hey people, I'm wondering if anyone can help me out. I'm trying to develop a plugin for a part that converts a particular resource into another. I know how to program the part to request a resource, but how can I program it to convert resources? At the moment I've basically got a part that consumes the input resource and continues to produce the output resource even though the input resource has run out. How can I solve this issue?

Thanks. :)

Taking a look at the ModuleGenerator class would be a start.

As for getting your output to stop, i'd do:


if (myInputResource != 0) //If my input amount does not equal zero.
{
generateOutputResource(); //Generate my resources.
}
else
{
print("Log: My input has run dry.");
}

This is just an example of how it can be done.

Edited by udk_lethal_d0se
Link to comment
Share on other sites

Taking a look at the ModuleGenerator class would be a start.

As for getting your output to stop, i'd do:


if (myInputResource != 0) //If my input amount does not equal zero.
{
generateOutputResource(); //Generate my resources.
}
else
{
print("Log: My input has run dry.");
}

This is just an example of how it can be done.

Thanks so much! Can't believe I didn't think of it myself, it seems so obvious now! :P Again, thanks!

Link to comment
Share on other sites

So I've been looking at the docking node code, but I just can't seem to find where the docking port magnetism is implemented. I'll keep looking, but by any chance, does anyone know where this happens?

Link to comment
Share on other sites

Anyone know how to access any hud elements? Perhaps changing and/or adding more waypoints in the navigation ball?

So, without reading every word of every page of this ungainly thread, has anyone responded to this or have any info on the HUD components and how to work with them? I've not seen any plugins do this, nor anyone discussing it, but I'm still rather new here.

I'm planning/hoping to create a Heads-Up Compass, that shows which way the player's view is facing, as opposed to just the vessel's heading. Also, I'd like to be able to modify the existing HUD display components and/or make them individually moveable/zoomable. For instance, moving the gauges to a secondary monitor would be very nice - like good flight sims.

I'm an experienced web (PHP/HTML/CSS/JS) programmer, but I'm just now learning C#, so any tips that anyone can offer would be awesome. :cool:

Link to comment
Share on other sites

I'm currently trying to get my head around the GUI stuff provided by the KSP API, and I've set myself the task of getting a small button icon working in the bottom left portion of the screen which opens and minimises the window when pressed. Like those you see with Chatterer and ISA MapSat.

Would someone be able to describe how to go about doing this or point me in the right direction? I've been trawling over the source code for both plugins but having a bit of trouble trying to understand it.

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