Jump to content

Replace one part with another


Recommended Posts

I want to make a mod that lets players replace 2 connected docking ports with a single structurally stronger part.

If this is possible? Any tips on how to get started on this kind of mod helps. I already know C# but nothing about modding KSP.

Thanks :)

Link to comment
Share on other sites

Is it possible? I wouldn't say no, but this isn't going to be simple as far as I can see.

I'm assuming the purpose of this mod would be to increase the structural strength of the connection. On the one side I would like to help you get starting on modding but I'm kinda wondering if this particular mod will be worth the effort it would take to get it to work.

If you really want to make this for a specific reason I'm willing to give you some tips where you could get started, without any guarantee of success from my side. If you want this just because you thought it was an easy thing to start out with, maybe look for another mod idea.

But I'm a cynic and maybe you should ignore me. Why don't you first pitch the idea in the Add-on Requests and Support section (also explain what what you think the the practical use of this mod will be) and gauge the responses.

Link to comment
Share on other sites

Thanks for your input PrivateFlip. This is the first time I've tried to write a KSP mod, but no I didn't think it would be easy. I've got plenty of C# and game development experience but none for Unity/KSP.

You're exactly right about what I was thinking. My original idea was building docking port derivatives that a kerbal on EVA could bolt together, creating a stronger connection between the pieces. I don't think that'll be worth the effort at least for now.

I've got a fall back idea that I think may work. It goes like this: create a more rigid structure by making a few connections using whatever the Unity version of a rigid joint is between the part one of the docking ports is attached to and the part that the other docking port is attached to.

That may be confusing, here's an example:

you have a 3 kerbal pod with a docking port connected to a 1 kerbal lander can with a docking port, the stack looks like:

pod | port | port | can

You EVA with a kerbal and berth the connection. Internally the code attaches 3 invisible rigid joints between the 3 kerbal pod and the lander can; the joints are spread out 180 degrees from each other along the outer radius of the docking port.

I think this second version is more tenable. Unfortunately my ignorance coupled with a frustrating lack of documentation, lack of a debugger and minutes long load KSP, do the action and check the log test cycle makes for very slow going.

Thanks for reading my ramblings. If you have any suggestions I'd love to hear them.

Link to comment
Share on other sites

Well, it always depend on how perfect your solution is meant to be. For your example... replacing 2 docking ports isn't very hard. Just unload the vessel, modify its protoVessel.protoPartSnapshots (its basically the same as your save file) and load it again. Ofc there would still be a lot of room for "optimizations"...

I'm not sure to have understand your second part. But you can improve your loading times a lot for your dev environment by removing unnecessary stuff from gamedata. Mine contains only my mod, 4 stock parts, mechjeb, a single flag and some props/sounds/etc. Btw, that reminds me to add a "automatically load savegame X" helper...

Link to comment
Share on other sites

Thanks for your input PrivateFlip. This is the first time I've tried to write a KSP mod, but no I didn't think it would be easy. I've got plenty of C# and game development experience but none for Unity/KSP.

Ah. I'd mistaken you for a beginning programmer, please read my previous response in that light.

You're exactly right about what I was thinking. My original idea was building docking port derivatives that a kerbal on EVA could bolt together, creating a stronger connection between the pieces. I don't think that'll be worth the effort at least for now.

I've got a fall back idea that I think may work. It goes like this: create a more rigid structure by making a few connections using whatever the Unity version of a rigid joint is between the part one of the docking ports is attached to and the part that the other docking port is attached to.

That may be confusing, here's an example:

you have a 3 kerbal pod with a docking port connected to a 1 kerbal lander can with a docking port, the stack looks like:

pod | port | port | can

You EVA with a kerbal and berth the connection. Internally the code attaches 3 invisible rigid joints between the 3 kerbal pod and the lander can; the joints are spread out 180 degrees from each other along the outer radius of the docking port.

I think this second version is more tenable. Unfortunately my ignorance coupled with a frustrating lack of documentation, lack of a debugger and minutes long load KSP, do the action and check the log test cycle makes for very slow going.

Thanks for reading my ramblings. If you have any suggestions I'd love to hear them.

Like Faark said Install a dedicated modding instance of ksp and unload the majority of standard parts.

As for documentation Documentation for the KSP API and Plugin Posting Rules And Official Documentation.

Although my suggestion where to start would have been in the same direction as Faark mentioned, his quick tips are already far more detailed and knowledgeable then the cues I can and could have supplied you.

Link to comment
Share on other sites

A system for allowing a part to consist of more than one model was added a version or two ago. It makes the parts act as if they were one, and can be done solely by cfg editing. Just add multiple MODEL {} sections to the cfg. There's likely to be a way to do it in code too.

You could programatically replace the individual docking ports with a combined model, removing the docking module as you go. Right-click > Lock / Unlock on a docking port perhaps? R4M0N has a nice example of adding a button to the right-click menu of a part here if you need it.

Link to comment
Share on other sites

Thanks, Is there example code or a mod that I can look at that shows how to do this?

I don't know, but learning it yourself should be doable, step by step.

- Create the part that replaces your 2 docking ports

- Build two rockets with either original and your replacement parts

- Compare both save files and find how you have to change a save file to replace those parts (edit the text file, load quicksave, repeat until your successful)

- Try to do the same changes via a ProtoVessel

- Add finally you can polish your UI stuff. Personally i would prefer not to change to original parts cfgs but instead add a part module to them after the initial load, but the easier cfg-edit to add a module is a good start as well.

Link to comment
Share on other sites

A system for allowing a part to consist of more than one model was added a version or two ago. It makes the parts act as if they were one, and can be done solely by cfg editing. Just add multiple MODEL {} sections to the cfg. There's likely to be a way to do it in code too.

I've actually been spending quite a bit of time searching for that capability, but I don't believe it's a Part or PartModule level item, I think it might use a Unity command to merge the two meshes. Regardless, it doesn't look nearly as simple to do in a plugin as it looks in the cfg file.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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