Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

I'm not sure if this has come up yet although I read through a couple dozen pages so here goes. I have an OK amount of experience with C#, but have no idea what most of the KSPField methods are used for. I'm trying to implement my own ambient sounds for when ships are landed on different celestial bodies, and am wondering how I might go about detecting a) when a ship is landed and B) which celestial body it's landed on. Any advice would be greatly appreciated.

Link to comment
Share on other sites

thanks a lot for replying, my problem is that i don't know how to implement the code in the game or modify the values from existing game files

Well thats a whole nother set of answers really. The best thing to do to learn how these work is to have a go, and look at others source. This link by TaranisElsu has some good startpoints for new modders - http://forum.kerbalspaceprogram.com/threads/56053-Example-plugin-projects-to-help-you-get-started

Link to comment
Share on other sites

I'm trying to implement my own ambient sounds for when ships are landed on different celestial bodies, and am wondering how I might go about detecting a) when a ship is landed and B) which celestial body it's landed on. Any advice would be greatly appreciated.

I would do it somehow like this:


MusicLogic ml = new MusicLogic();
if (FlightGlobals.ActiveVessel.Landed)
{
if (FlightGlobals.ActiveVessel.mainBody.name == "Kerbin")
{
ml.spacePlaylist.Clear();
ml.spacePlaylist.Add(AudioClip clip);
}

else if (FlightGlobals.ActiveVessel.mainBody.name == "Duna")
{
ml.spacePlaylist.Clear();
ml.spacePlaylist.Add(AudioClip clip);
}

}

Link to comment
Share on other sites

Well thats a whole nother set of answers really. The best thing to do to learn how these work is to have a go, and look at others source. This link by TaranisElsu has some good startpoints for new modders - http://forum.kerbalspaceprogram.com/threads/56053-Example-plugin-projects-to-help-you-get-started

Thanks sir, now that i have that example i may be on the right way :D

Link to comment
Share on other sites

I would do it somehow like this:


MusicLogic ml = new MusicLogic();
if (FlightGlobals.ActiveVessel.Landed)
{
if (FlightGlobals.ActiveVessel.mainBody.name == "Kerbin")
{
ml.spacePlaylist.Clear();
ml.spacePlaylist.Add(AudioClip clip);
}

else if (FlightGlobals.ActiveVessel.mainBody.name == "Duna")
{
ml.spacePlaylist.Clear();
ml.spacePlaylist.Add(AudioClip clip);
}

}

Thanks a lot that's exactly what I needed!

Link to comment
Share on other sites

Can I use javascript to create plugins instead of C#? I know KSP uses Unity and I use Unity a lot, and I know you can use C# or Javascript for scripting.

You can use whatever language you like, as long as you can create a proper .NET dll from it. That means no, you can't rly use Unity to create the mod. For example with a Project from MonoDevelop's UnityScript Project category, as mentioned here.

Link to comment
Share on other sites

So I don't know if someone has already pointed this out or not but it is a useful tidbit of info that took me two days to figure out so I figured I post it here for all to see.

you cannot make a persistent double variable using [KSPField(isPersistant = true)] it will just default to zero instead of keeping the value. floats however work fine.

Link to comment
Share on other sites

I have a simple question:

Can I use javascript to create plugins instead of C#?

I know KSP uses Unity and I use Unity a lot, and I know you can use C# or Javascript for scripting.

Bad news: I dont think so.

Good news, C# is almost identical to java script

The only major differences is instead of the keyword "function" you use "void"

and instead of declaring a variable like this "var NewVar : int = 5;" you would use "int NewVar = 5; "

There are of course other minor differences but if you already know JavaScript its just a mater of learning what order things go in.

Link to comment
Share on other sites

I'm trying to make a plugin about kerbals. I tried looking all the codes in the game but I can't find the ones that are about kerbal individuals. Where can I find them?

Vessel.GetVesselCrew() will get you a list of ProtoCrewMember objects in a vessel. Is that the sort of thing, or do you mean the Kerbals in the Astronaut Complex list?

Link to comment
Share on other sites

Vessel.GetVesselCrew() will get you a list of ProtoCrewMember objects in a vessel. Is that the sort of thing, or do you mean the Kerbals in the Astronaut Complex list?

Actually what I'm trying to make is creating a "cockpit" for kerbals in EVA but I'm curious if kerbals in EVA are considered as "spaceships" in the code so that's what I was looking for. Is it quite possible?

Link to comment
Share on other sites

Actually what I'm trying to make is creating a "cockpit" for kerbals in EVA but I'm curious if kerbals in EVA are considered as "spaceships" in the code so that's what I was looking for. Is it quite possible?

Kerbals are technically one part vessels, yes. They're essentially a part with a KerbalEVA PartModule, iirc. I believe adding a first person view would work like adding a normal IVA.

Link to comment
Share on other sites

Actually what I'm trying to make is creating a "cockpit" for kerbals in EVA but I'm curious if kerbals in EVA are considered as "spaceships" in the code so that's what I was looking for. Is it quite possible?

yep, an EVA'd kerbal is a vessel with a crew of one from memory

Link to comment
Share on other sites

Kerbals are technically one part vessels, yes. They're essentially a part with a KerbalEVA PartModule, iirc. I believe adding a first person view would work like adding a normal IVA.
yep, an EVA'd kerbal is a vessel with a crew of one from memory

Thanks for the answers, working on it! :)

Link to comment
Share on other sites

Do you mean dry mass (not including resources) or gross mass (including resources)?

Dry mass is easy: foreach part, part.mass = 0.01 * part.mass

Note that that won't persist, you'll have to do it after each load or vessel switch.

Gross is harder: resource mass per unit is defined in the resource definition. I guess you *could* maybe change them on the fly...But they'd take effect globally...

Link to comment
Share on other sites

Actually what I'm trying to make is creating a "cockpit" for kerbals in EVA but I'm curious if kerbals in EVA are considered as "spaceships" in the code so that's what I was looking for. Is it quite possible?

There was a mod that used to do this that you may be able to use as a reference: CreationMe's BBI First Person View mod. It stopped working a while back and has been missed since. Its thread was lost in one of the forum crashes.

Link to comment
Share on other sites

There was a mod that used to do this that you may be able to use as a reference: CreationMe's BBI First Person View mod. It stopped working a while back and has been missed since. Its thread was lost in one of the forum crashes.

Oh thank you so much! I've been searching this for hours but I couldn't find anything. It is going to help a lot with coding part. I used the mod back then, but it was annoying for me to add a part to the vessel and then have the first person view. I am trying to avoid that in my mod. Thank you so much again!

EDIT: Unfortunately the mod doesn't come with the source code in it :/ So now, my question is (I know I asked a lot of questions for a tiny little mod but I'm new to C# and modding so please don't mind me :( ) how can I set the interior for KerbalEVA vessel? I read B9 interior source codes and also the stock ones and in all of them the interior file is stated in the Part.CFG so the game knows the interior of that part belongs to internal.cfg. But how can I change information of KerbalEVA so I can assign my interior as internal view in its codes?

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