Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Some ideas:

- Search for editor mods and inspect their source. There are a bunch of Part Filters, for example.

- Get into KSP's internals like us others. The object browser does have quite some hits for "Editor"

- The KSP API doc does in fact contain an EditorLogic class that has an "public ShipConstruct ship;" that might be useful for you.

Thanks, thats exactly what I needed to start off :)

Specially the github page seems to be a well better documentation than the wiki pages are, specially if it comes to coding something (unfortunally...)

I already did some research in the api using the object browser, but with that overhelming mass of stuff in there it is impossible to get a good starting point just by looking into it. Maybe a nice class diagram on the wiki would help people like me starting off :) (if I have some spare time, I'll create one and surely share it with the community)

Talking 'bout editor mods, I was looking for subassembly source files, but unfortunally did not find any... this seemed to be a good start for me, as subassembly also handles loading parts which might become handy some day. Any hints where the sources are hidden? Am I just to blind to find them?

Link to comment
Share on other sites

Chrison, you might want to look at Mission Controller Extended. Does that, + missions.

http://forum.kerbalspaceprogram.com/threads/43645-%28KSP-0-21%29-Mission-Controller-Extended-%28MC-Version-20-2%29-%28FORK%29-%28ALPHA%29

Faark, yeah, my best bet right now is on setting engine configuration to trawl through fxgroup 'running', delete all emitters with "flame" and then add the appropriate ones....but I'm puzzled why SaveEffects and LoadEffects don't seem to work.

Link to comment
Share on other sites

Hi,

I'm trying to create a module that inherits from ModuleScienceExperiment and then overrides some of its behaviour.

The aim is so I can then convert a resource "Experimental Results" into science points. I intend to do this by intercepting the experimentAction call doing some stuff (modifying the baseValue of x science experemnet based on number of experimental results) then calling the ModuleScienceExperiment function.

I belive the function i need to 'override' is ModuleScienceExperiment.DelpoyAction(KspActionPara actPara). However, this function is not virtual or abstract.

But this is not nescaraly a problem as I think i can use

new public void DelpoyAction(KspActionPara actPara){

some new stuff

base.DelpoyAction(actPara);

}

However, either

o DelpoyAction is not the action called by the gui system

o The gui call is going straight to the base class because new isnt really overrunning the base function

o or I need to override [KSPAction(?????)]

[Question] Does anyone know how to override the [KSPAction(???)] when you don't know what ???? is?

[Question] Is it even possible to complete override a parent class?

My aim is basically to modify the base class without breaking needing to see its inner functioning. Now I thought it would have been possible by basivcly going though the class's signiture from the dll and just adding:

public override Somefunction(paras){

donewstuff();

base.Somefunction(paras);

}

However, I think [KSPAction(???)] type defs int the original code may make this impossible. But i dont know enough about coding to say for sure...

Any help, advice or points to programming tutorials related to this type of issue (hell even the actual name of what these ([KSPAction("Shutdown Generator")]) type of definitions are would be helpful cause then I'd be able to google it.

Thanks

Swifty

Link to comment
Share on other sites

Do you really have to use ModuleScienceExperiment? Maybe implementing IScienceDataContainer in your own PartModule will do it?

Anyway, lets start with the "new" when declaring a member. Its sth completely different from "override". You might want to check out those links. The short version: "new" does pretty much nothing but tells your compiler to disable a warning since you actually want to do sth that looks wrong.

Though admittedly its kind of confusing when using Unity, since they use a somewhat different technique for their MonoBehavior-Messages.

So, beside from not using this PartModule, the best approach seems to work with KSPs even&action system. KSPAction is just an attribute. KSP looks them up at runtime and uses them to create the Events (right click ui) / Actions (=> action groups) properties for your part module. You might be able to simply disable them, eg. on Awake of your module... and re-disable them every time ModuleScienceExperiment might activate them, again. I don't see a way to entirely remove them, sadly.

Link to comment
Share on other sites

Faark,

Thank you for your reply. Your explanation of KSPAction & events is really appreciated.

I went away after that post and got my book on CSharp and read about inheritance etc. Having done that I relised how simple what I was trying to do really is:

public class SciLabZeroG : ModuleScienceExperiment
{

[KSPEvent(active =true, guiActive =true, guiName = "Deploy")]
new public void DeployExperiment()
{
print("Deploying Experiment");
base.DeployExperiment();
}
[KSPEvent(active =true, guiActive =true, guiName = "Review Data")]
new public void ReviewDataEvent()
{
print("Reviewing Data");
base.ReviewDataEvent();
}
[KSPEvent(active =true, guiActive =true, guiName = "Reset")]
new public void ResetExperiment()
{
print("Resetting");
base.ResetExperiment();
}
[KSPEvent(active =true, externalToEVAOnly =true, guiActive =true, guiActiveUnfocused = true, guiName = "Reset")]
new public void ResetExperimentExternal()
{
print("Resetting External");
base.ResetExperimentExternal();
}
}

With the above code you can now 'intercept' the players actions. Do some stuff and then call ModuleScienceExperimets without having to mess with the base module at all. Even better you can then modify the experiment whilst its in the memory. i.e. experiment.baseValue = 999999; etc

So now I have a very crude systems that uses a ModuleGenerator to convert scienceExperiments into Experimental results and then changes the basevalue of the given experiment based upon how many experimental results you have.

Hopefully by the end of the day I'll have refined it enough to make a thread about my plans.

------------------Edit below ---------------------------

Arrrhhhh!!!!

The above had been working all day but now I get:

[Error] Action "Deploy Experiment" already defined.

I just can't think why it would have worked earlier and then all of a sudden stopped.

:-(

Edited by Swifty
Link to comment
Share on other sites

Thanks pizzaoverhead. I can't overload as the method is not virtual, abstract or already an override.

Do you think the problem is caused by using new? I'd thought it was down to the KSPEvent/KSPAction attributes.

I'd kind of thought using new was just like a different scope or namespace.

Link to comment
Share on other sites

Welp, I'm having headaches...

I'm trying to create data storage drives for SCIENCE! (you can read more from my signature, last page of the mod thread)...

The drives will function similarly to a command pod's ability to store EVA reports from different environments, but with a focus on "external" equipment- Mystery Goo and such. The intention is to create a way to store data gathered from one set of equipment, leaving it free to be used in a different environment; instead of having data from "external" experiments stored directly on the equipment used.

The capacity of the drives will also be dependant on the size of each experiment stored (the "Mits" value of each experiment). For instance, the Basic Data Drive, which has a capacity of 20 Mits, can hold either one 20-Mit experiment or 4 5-Mit ones.

Attempting to store the same results (i.e- them being from the same equipment and environment) from experiments will result in only the most current one being stored (like with EVAs/Crew Reports). Results from the same experiment/equipment but from different environments will be stored alongside each other.

These drives will of course have an energy requirement similar to stock probe parts.

That said, I've been trying to figure how to code this most of the day... Lets just say I haven't done scripting, ever...

Anyone feel like helping? Message me if you're interested!

Link to comment
Share on other sites

Ok... So... As per my previous post, I've been trying to figure out how Mits are handled...

As far as I've managed to gather, Mits are used for antennae transmissions where each packet the antenna sends is 2 Mits of the data being sent.

Mits don't seem to be an actual resource that can be accumulated, however...

Based on several experiments, I have determined that 1Mit is equal to 0.3 science when all other variables are ignored and the experiment is performed for the first time, on the Launchpad.

I have no idea where I'm going with this however...

Edited by BananaDealer
Link to comment
Share on other sites

  • 2 weeks later...
I have been working on a set of examples that I hope people will find useful for learning how to write plug-ins for KSP and as a starting point for their mods: http://forum.kerbalspaceprogram.com/threads/56053 and https://github.com/taraniselsu/TacExamples

I hope that helps.

Sir, you might just have saved my bacon.

Link to comment
Share on other sites

i dont think anyone else (except devs and mods) know either

this thread will have 150% more people posting once the docs are up. before then no one will even really bother writing anything...

so i guess we\'ll just have to wait for now patiently for the big bang of new parts appearing out of nowhere ;P

hey anyone wanna team up with me?? i can write c++ (and c# doesnt look that different) but i have no clue about 3d designing and all that

would like to make some parts though and if you dont know programming.... :)

Hello, I am a 17 year old dutch student and i have wanted to make kps parts for some time now but i dont have any programming skills.

i do know programs like sketchup inside out and i have used it quite a lot for various projects.

I am willing to learn other 3D modelling softwares if sketchup doent let me create nice looking parts

if you wanna work together, write me an email

demy_msn-ac@hotmail.com

cya ;)

Link to comment
Share on other sites

How would I check to see if the user is in IVA or not? Did some searching and checked the wiki but didn't find anything. I'm sure there's a simple check (i.e. isIVA) or something, but I'm missing it so far.

if (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA)

https://github.com/taraniselsu/TacLifeSupport/blob/master/Source/LifeSupportController.cs#L475

Link to comment
Share on other sites

Hello, everyone!

I am working on a project the result of which would be a joystick/controller system with feedback from KSP. The feedback surely needs some communication with KSP and that requires to create a plugin. I was wondering if anyone here could show me how to get the following done:

I need to make a plugin that would allow to receive an access to the vessel's speed which it can pass to.. say a simple Label object in C#.

Thanks in advance!

Link to comment
Share on other sites

Sorry about this post, but I'm trying to set up a fix for a part that got updated for .22. It's an escape pod (the SpaceTech escape pod, Which was updated by Joe Beauchamp). I'm trying to get it so that way Kerbals can grab onto it in order to board. Are there any parameters I have to adjust at all?

Edited by MD5Ray01
Link to comment
Share on other sites

Hello, everyone!

I am working on a project the result of which would be a joystick/controller system with feedback from KSP. The feedback surely needs some communication with KSP and that requires to create a plugin. I was wondering if anyone here could show me how to get the following done:

I need to make a plugin that would allow to receive an access to the vessel's speed which it can pass to.. say a simple Label object in C#.

Thanks in advance!

You could pull the surface velocity and store it like this:

 string velocity = FlightGlobals.ActiveVessel.GetSrfVelocity ().ToString ();

Not tested that, but should work.

Also, had another question for everyone: How do you set up an event listener for a part's events (i.e. toggle gear, toggle antenna)? Searched for this and I can't find anything for KSP, though the few Unity things I found didn't seem to help much.

Link to comment
Share on other sites

Anyone here who can tell me how to determine if the frame of reference is orbit or surface?

Vessel.IsLandedOrSplashed should work (except a few frames right after spawning a vessel, though that could be handled via Vessel.Situation). ProtoVessel has sth similar.

Link to comment
Share on other sites

How can I programmatically add a stock part to the ship in the editor? For example, if I have a ship consisting of just a probe core, and I want to attach a stock fuel tank to it. I don't want to load something onto the cursor (EditorLogic.PartSelected()), because I need to add several parts parts at once (fuel lines, specifically).

I see PartLoader.Instantiate(), EditorLogic.SpawnPart(), and part.AddChild(), but I haven't had much luck so far with those, nor can I find any documentation or examples.

I've also thought about copying the current ship in memory, modifying my copy, and then saving it as a new file with ShipConstruction.SaveShip() and then loading it back, but that seems silly.

Can anyone point me in the right direction?

Link to comment
Share on other sites

ljdp: See forum.kerbalspaceprogram.com/threads/54348-Any-way-to-toggle-gear-solar-panels-from-code

hab136: Have you checked out public ShipConstruct EditorLogic.ship ... that and its add method looks promising.

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