Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Thanks to The_Duck and kellven. Sadly I am working the next few days, but after that I have nice vacation that I will be pouring into this fun project. GUI and inputs are all worked in I have been saving the actual calculations (which you two have helped out greatly) for last. Eventually the goal is to have a controlled hover from vertical engines, then recreate land-speeders. 8)

Link to comment
Share on other sites

  • 3 weeks later...

Hi guys,

I wish to start developing plugins but have not found any useful resources to help me. I have intermediate knowledge of coding (mainly C++) and was wonderering how you guys learnt? Please could you point me to some kind of explanation of how to get started or tell me how.

Link to comment
Share on other sites

Part.Modules is a PartModuleList

PartModuleList has these:


public PartModule this[int classID] { get; }
public PartModule this[string className] { get; }

Which are indexers is fuzzy memory serves, so if you know the classname of the PartModule:

Part.Modules['MyModuleClassName']

should resolve to the module you\'re looking for.

This is assuming the system is actually implemented that far.

Edit: Forgot that those indexers return a PartModule object. If you want a reference to your actual PartModule subclass, you need to cast it. To do so safely:


//
//class MyModuleClass: PartModule { }
//Part MyPart;
//
MyModuleClass module = MyPart.Modules['MyModuleClass'] as MyModuleClass;
if (module == null)
{
//Error stuff here
}

End of pedantic reminders

Happy Moddings

Link to comment
Share on other sites

  • 2 weeks later...

class ModuleKrTestSpam :PartModule
{
public override void OnActive()
{
print('OnActive');
}
public override void OnAwake()
{
print('OnAwake');
}
public override void OnInactive()
{
print('OnInactive');
}
public override void OnLoad(ConfigNode node)
{
print('OnLoad');
}
public override void OnFixedUpdate()
{
print('OnFiyedUpdate');
}
public override void OnUpdate()
{
print('OnUpdate');
}
public override void OnSave(ConfigNode node)
{
print('OnSave');
}
public override void OnStart(StartState state)
{
print('OnStart:' + state);
}
}

Works, but I\'m too tired to look when what is exactly called.

Link to comment
Share on other sites

Part.Modules is a PartModuleList

PartModuleList has these:


public PartModule this[int classID] { get; }
public PartModule this[string className] { get; }

Which are indexers is fuzzy memory serves, so if you know the classname of the PartModule:

Part.Modules['MyModuleClassName']

err, thanks. Tad over my head, will try to work though that.

should resolve to the module you\'re looking for.

This is assuming the system is actually implemented that far.

Edit: Forgot that those indexers return a PartModule object. If you want a reference to your actual PartModule subclass, you need to cast it. To do so safely:


//
//class MyModuleClass: PartModule { }
//Part MyPart;
//
MyModuleClass module = MyPart.Modules['MyModuleClass'] as MyModuleClass;
if (module == null)
{
//Error stuff here
}

End of pedantic reminders

Happy Moddings

Link to comment
Share on other sites

  • 2 weeks later...

Hey everyone, if anyone knows... Is there any way to actually step through my plugin code? I can usually do this on other projects by setting us VS to run an external program while debugging, or attach the debugger to the process itself, but it seems that KSP.exe won't allow this.

Cheers

Link to comment
Share on other sites

Hey everyone, if anyone knows... Is there any way to actually step through my plugin code? I can usually do this on other projects by setting us VS to run an external program while debugging, or attach the debugger to the process itself, but it seems that KSP.exe won't allow this.

Cheers

Think the only thing you can do is using the print message and refer to the ingame debug log (alt +F2).

Link to comment
Share on other sites

Hi there, new user here, I have a question.

How do I make a GUI window appear without making a new part?

I want to make a basic craft sharing system with dropbox. I want my window to be visible in the editor and while flying. And maybe the save/load menu.

I got 4 years of generic C# experience, blazed through all the example code, but I havn't played with Unity or 3D in general.

Link to comment
Share on other sites

AFAIK you can only load code through a part. I'm not sure exactly when it gets called, but you could try loading your window in the Part class, onEditorUpdate() function.

I've been trying to change the rootpart of a loaded vessel, with very little luck. I've tried rebuilding the parent child heirarchy in vessel.parts, and reordered it in case it expects the rootpart == parts[0]. It seems like problem is that vessel and the rootpart reference the same gameobject, which is readonly, so I can't set it to the new rootpart. Am I missing something? Any Ideas?

Edited by Zool
Link to comment
Share on other sites

Hoping somone can help =) How do I communicate between parts? I have two classes that extend the Part class and I want one of them to keep an eye on the other.

I found this piece of code in the source code for Zoxygen but I'm not entirely sure what it does and if it is what I'm loking for? It seems to go through all parts in the vessel and return an object of that part?


int VPartCnt = PART.vessel.parts.Count;

for (int i = 0; i <= VPartCnt - 1; i++)
{
if (PART.vessel.parts.ElementAt(i).GetType().Name == "LiquidFuelEngine")
{

PART.vessel.parts.ElementAt(i) seems to return the object of the part. But how do I access its methods?

Link to comment
Share on other sites

You should be able to cast the part as the correct class.


int VPartCnt = PART.vessel.parts.Count;

for (int i = 0; i <= VPartCnt - 1; i++)
{
if (PART.vessel.parts.ElementAt(i).GetType().Name == "LiquidFuelEngine")
{LiquidFuelEngine Engine1 = (LiquidFuelEngine)PART.vessel.parts[i];
}

You might be better off using a KSP event though, see the stickied thread on .15 for an example.

Link to comment
Share on other sites

What about taking 'oldstyle' engines and derived classes into account too?


foreach(Part p in PART.vessel.parts)
{
if (p is LiquidFuelEngine)
{
//something
}
else if (p is LiquidEngine)
{
//same again for older engines for compatibility with older part packs and plugins deriving from the simple engine such as MuMech or ElEnergy

Link to comment
Share on other sites

hi guys, got a problem im sure it has a simple fix but i am totally clue less, the problem is that my command pods dont have any kerbonauts in them, in the pod description it says that the pods can seat 3 kerbals each, but none of them show any kerbals. the starter pods show the kerbals, but my extra downloaded ones dont, such as the kosmos pod, nova silisko's bace pod, the MEM pod and others, im not sure why this has happened and i dont know how to fix it, i see videos on YouTube and people have the exact same pods but with kerbonauts inside them. the only anomaly is that my DSM pack pods show their kerbals and thats were i really dont understand whats going on.

please help me even if you have the smallest advice anything will help.

lkj802

Link to comment
Share on other sites

Is it possible to add buttons to a part's right-click menu at runtime? I'm trying to make a PartModule with part.cfg configurable right-click menu entries.

I could probably get away with hardcoding it (a lot of methods with KSPEvent attribute) and showing/hiding them as necessary, but it'd be nice if I could avoid doing that.

Link to comment
Share on other sites

Would it be possible to make a SRB in your active stage fire at a certain altitude? Example: I have retrorockets on my lander and they automatically fire at 400m.

I'm really new to plugin making but I want get into writing plugins.

I think that's a cool idea! I have no idea how to make that happen... yet :blush:

Having a part that can trigger actions at predetermined altitudes or some other condition would be totally fun.

Link to comment
Share on other sites

I think that's a cool idea! I have no idea how to make that happen... yet :blush:

Having a part that can trigger actions at predetermined altitudes or some other condition would be totally fun.

I know it's possible, I know parachutes do it. But how to make an engine do 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...