Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Is there a way to get the status of an asteroid for a plugin? For example, if it has entered Kerbins sphere of influence?

I believe it is just a "Vessel" so the mainBody property should indicate what SOI it is in...

Link to comment
Share on other sites

How do you read a PartModule's Field's value?

I've got this to loop through all the fields on a partmodule


foreach (BaseField field in module.Fields)
{
if (field.guiActive)
{
Debug.Log((part.name + " - " + field.guiName));
}
}

but now I would like to actually read the values of each field.

edit: nvm

field.GetValue(module)

does it, the needing to pass in the partmodule confused me.

Edited by Xty
Link to comment
Share on other sites

Could anyone tell me how I could get the information listed in a parts 'more information' frame in the editor, when a ship is in flight?

That would be the GetInfo() string from the PartModule.


public class YourClass : PartModule
{
public override string GetInfo()
{
return base.GetInfo();
}
}

Then just set some other string equal to that and display it in flight somehow, a screen message, a field in the right-click menu, etc...

Link to comment
Share on other sites

Hi everyone, I'm having a hard time understanding how I can load a parameter from the cfg file of a module.

I mean:


MODULE
{
name = MyModule
aDouble = value
}

I would like to have a field called aDouble in my class and read it from the cfg file, but I can't find how to do that :(

Link to comment
Share on other sites

Hi everyone, I'm having a hard time understanding how I can load a parameter from the cfg file of a module.

I mean:


MODULE
{
name = MyModule
aDouble = value
}

I would like to have a field called aDouble in my class and read it from the cfg file, but I can't find how to do that :(

Add [KSPField] attributes to public fields in your PartModule code, they will automatically be fetched by KSP. However, it's porbably important to know KSPField does not support doubles, use floats.

Link to comment
Share on other sites

Add [KSPField] it's porbably important to know KSPField does not support doubles, use floats.

THAT WAS IT!? THE TYPE!? :'(

Thank you very much, I just found out why I wasted one night awake ^^

Link to comment
Share on other sites

Sorry if this has been answered in this thread already, but if I wanted to tweak somebody's source code and recompile it, what do I need? I'm on Windows 7. (I actually want to look into adding Toolbar functionality to a slightly outdated mod.)

Link to comment
Share on other sites

Sorry if this has been answered in this thread already, but if I wanted to tweak somebody's source code and recompile it, what do I need? I'm on Windows 7. (I actually want to look into adding Toolbar functionality to a slightly outdated mod.)

Just a C# IDE and a copy of KSP, possibly Unity (but not necessarily).

You can use one of the free versions of Visual C# (Like Visual C# Express 2010), or SharpDevelop (that is also open source). Make sure to add the references to UnityEngine and Assembly-CSharp, both located in the KSP installation folder (KSP/KSP_Data/Managed).

You can grab Unity on their site.

Link to comment
Share on other sites

My advice would be to ignore it and use a textured plane or GUIText if you want good results.

This is what I ended up having to do, just because of a problem I didn't know about before I started - KSP configured its drawing layers so that they have distance cutoffs for rendering, and they're set such that if I try to label something with giant letters really far away, the letters refuse to render if they're more than about 1.2 million meters or so from the flight camera (I'm not sure how the heck they get things like the distant Mun to render then - maybe that's on a different layer).

But anyway I had to do it with 2d text objects where I project the 3D coordinates into viewport coordinates to figure out where to put the text. You were right, that's what I eventually had to do.

Link to comment
Share on other sites

Why exactly would you change it? (I'm not exactly sure what it does precisely too)

It appears to be the name that is displayed in the editor in the list of the part's module.

When your right click, you get a list of the things it supports, like "Gimbal", "Control surface"... and of course "ClassNameOfMyModuleDirectlyFromTheFile". GUIname seems to be the string that is displayed there instead of the class name... I guess.

Link to comment
Share on other sites

It appears to be the name that is displayed in the editor in the list of the part's module.

When your right click, you get a list of the things it supports, like "Gimbal", "Control surface"... and of course "ClassNameOfMyModuleDirectlyFromTheFile". GUIname seems to be the string that is displayed there instead of the class name... I guess.

It probably goes through that, but that's not what it does. IIRC, it takes the class name of the PartModule, removes "Module" at the beginning if there is one, and then inserts a space after each camel case.

Link to comment
Share on other sites

It probably goes through that, but that's not what it does. IIRC, it takes the class name of the PartModule, removes "Module" at the beginning if there is one, and then inserts a space after each camel case.

... which is great news for me, since my modules don't follow that naming convention nor are in camel case :P

Well, this issue can wait anyway. Thank you chris :)

Link to comment
Share on other sites

Sorry to bother everyone again, but what is the correct place to execute some code just before the flight begins?

As of now I am doing:


public override void OnStart(PartModule.StartState state)
{
if (!(state == StartState.PreLaunch)) return;
// stuff
}

But I am getting all sorts of strange glitches, like KSPFields that inexplicably have no value anymore.

Link to comment
Share on other sites

How do I sort through vessel types? I am making a pug in that warns you when there is an imminent asteroid collision with Kerbin, but I need to know how to sort out the asteroids and the space objects from the other vessels. Is there a dictionary type thing in C# as there is in Python?

Link to comment
Share on other sites

Does anybody want to help me with writing a hardware interface for MechJeb? I'm not a programmer and some tasks take much more time from me than from somebody who knows exactly what he is doing. Feel free to contact me!

Link to comment
Share on other sites

How do I sort through vessel types? I am making a pug in that warns you when there is an imminent asteroid collision with Kerbin, but I need to know how to sort out the asteroids and the space objects from the other vessels. Is there a dictionary type thing in C# as there is in Python?

You should look into LINQ. For example:


List<Vessel> allVessels = ...
IEnumerable<Vessel> spaceObjectVessels = allVessels.Where(v => v.vesselType == VesselType.SpaceObject);
IEnumerable<Vessel> nonSpaceObjectVessels = allVessels.Where(v => v.vesselType != VesselType.SpaceObject);

Link to comment
Share on other sites

Does anybody know how I could make a ship uncontrollable?

I tried disabling the ModuleCommand of the command pod / cockpit / whatever, but it just keeps working. I'm not a big fan of removing and readding the ModuleCommand because I've seen that doing this can break references at times, but I will if need be.

Link to comment
Share on other sites

Does anybody know how I could make a ship uncontrollable?

I tried disabling the ModuleCommand of the command pod / cockpit / whatever, but it just keeps working. I'm not a big fan of removing and readding the ModuleCommand because I've seen that doing this can break references at times, but I will if need be.

Check out the InputLockManager class.

Link to comment
Share on other sites

So I have done some research on Linq and other things. I don't whether to use IEnumerable or a foreach method for the vessel sorting. her is the code I have so far.

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

namespace Asteroid_Warning
{
public class asteroidWarning
{
List<Vessel> allVessels = new List<Vessels>;
foreach(VesselType.SpaceObject in Vessels);
{

}
}

I don't know if the VesselType syntax is correct, and I think that the code isn't right. Though if I knew everything, I wouldn't be posting here. :)

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