Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

This has probably been asked many times before, but this is a big thread. How can I make a right click menu appear when I right click on a part? Like with the fuel lines, when you right click you have a button to transfer fuel. I didn't find it on the wiki.

Another question - is there any way for a fuel tank to hold different mixtures of fuel? For example, a fuel tank with a 1000 capacity could hold 500 oxidizer and 500 liquid fuel, or 1000 oxidizer with 0 liquid fuel, or other combinations. Engines could take different oxidizer/liquid fuel ratios, but it would change its isp.

Thanks in advance.:)

Link to comment
Share on other sites

This has probably been asked many times before, but this is a big thread. How can I make a right click menu appear when I right click on a part? Like with the fuel lines, when you right click you have a button to transfer fuel. I didn't find it on the wiki.

Just use a [KSPEvent] attribute over a public void to create a part menu action, else, you can just display a field by having a KSPField where guiActive = true.

Another question - is there any way for a fuel tank to hold different mixtures of fuel? For example, a fuel tank with a 1000 capacity could hold 500 oxidizer and 500 liquid fuel, or 1000 oxidizer with 0 liquid fuel, or other combinations. Engines could take different oxidizer/liquid fuel ratios, but it would change its isp.

Thanks in advance.:)

Not stock, but you could code that. I believe PParts/MFS/RealFuels does that.

Link to comment
Share on other sites

How can I know if the ship is in physical timewarp or not?

I found TimeWarp.WarpMode, but I can only get high or low, which isn't very informative.

you found it, if only there was documentation :) . Low is physwarp and High is the other one, and TimeWarp.CurrentRate gives you the multiplier.

If you're going to affect the rate of warp in your plugin (ie. use SetRate) be careful how far it shifts in one step - if the step is too large, eg going from 10000000x to 10x in one go you can end up with floating point errors entering into orbits.

Link to comment
Share on other sites

you found it, if only there was documentation :) . Low is physwarp and High is the other one

Ok cool. I suspected it was like this, I just wanted confirmation. Also thanks for the tip on setting it :)

Link to comment
Share on other sites

A quick question on ScenarioModules & persistence. I'm looking into adding persistence to my mod, and was looking into ScenarioModule. I found it also extends from MonoBehavior, meaning it can also handle OnUpdate & OnFixedUpdate. However, I've noticed alot of the other plugins out there separate their game logic in a MonoBehavior, and their persistence in a different ScenarioModule.

Is there a reason for this? If I were to do both game updates and saving/loading from the same class, will I be doing something that will summon the Kraken to destroy my Config nodes?

Link to comment
Share on other sites

Right now, I am handling my persistence using the OnLoad and OnSave of my part modules. However, I'm only doing part modules, so I don't know if it applies to your mod too.

I followed the explanation they gave me here, and it's working without a flaw at the moment.

I don't know if this is different for scenario modules and mono behaviours, though.

Link to comment
Share on other sites

I found it also extends from MonoBehavior, meaning it can also handle OnUpdate & OnFixedUpdate. However, I've noticed alot of the other plugins out there separate their game logic in a MonoBehavior, and their persistence in a different ScenarioModule.

Is there a reason for this?

No, you can do your saving and loading in ScenarioModule without problems. You probably mean FixedUpdate and Update though.

Link to comment
Share on other sites

No, you can do your saving and loading in ScenarioModule without problems. You probably mean FixedUpdate and Update though.

The question is not whether I can save from ScenarioModule, but if I can do game update logic from there; all the examples I've seen only do loading & saving from their ScenarioModule. Ah well, might as well see if it will work the same way I see if my rockets will fly... with lots and lots of explosions.

And yes, I do mean Update() and not OnUpdate(). Sorry, too used to PartModules (Interesting to note that even in the ScenarioModule, it will be Update() & FixedUpdate(), but OnLoad() & OnSave(). "I don't always think of being consistent, but when I do, I light up an SRB instead")

Link to comment
Share on other sites

Originally Posted by ThermalShark viewpost-right.png

My problem has been solved (for now), but if wanted to drain 30 LiquidFuel from a tank, without ever affecting other parts, i could not use RequestResource because if the tank only had 20 LF, i would drain 10 from other parts. In that case the only option would be to directly modify PartResource.amount, right? (maybe disabling crossfeed could not be an option, because i could need to transfer unrelated resources through the part, or if i needed fuel lines to not be able to pump from the part.)

And again, I don't think you want to do that unless it'S for a very specific type of thing where you absolutely need to do that and there's no other solution. You really don't want to be bypassing resource flow, because incidentally you might drain something that flow logic wouldn't allow and that's not always good.

Hello chris, I am doing that very specific type of thing and there is no other solution. Just wandering if anybody has any answer to ThermalShark's question, because otherwise I'm just going to go and lock all teh things.

(I'm simulating a leak in a tank, so of course I want to drain only from that tank bypassing flow. If no one knows of a more elegant solution, I'm just going to set the flow mode of the resource in the tank and call it a day)

Link to comment
Share on other sites

In this particular case it's justified IMO; for the same reason RF simulates boiloff by directly changing tank amounts.

However, it only works when the engines are off: if you are consuming fuel and re-assign the amount, the consumption is actually reduced, and not increased.

Re-assigning the amount is only correct if the leak is the only flow in the tank.

Link to comment
Share on other sites

Question or Idea... if you're simulating a leak in a tank, why wouldn't you want to take fuel from the stack? In real life, if fuel is flowing from one tank to another before being sent to an engine, a leak in the middle tank won't prevent fuel from leaking from the first if it flows through that tank. As long as you're doing the request resource for stuff that is flow type of STACK_PRIORITY_SEARCH, it should only drain from that part or above.

Link to comment
Share on other sites

Question or Idea... if you're simulating a leak in a tank, why wouldn't you want to take fuel from the stack? In real life, if fuel is flowing from one tank to another before being sent to an engine, a leak in the middle tank won't prevent fuel from leaking from the first if it flows through that tank. As long as you're doing the request resource for stuff that is flow type of STACK_PRIORITY_SEARCH, it should only drain from that part or above.

But it FEELS wrong :/

Link to comment
Share on other sites

Hi again, sorry for the spamming.

1) Is it possible to read/write a list in config nodes?

It is, and it's very easy. Assuming that your config file (or config node) looks like this:


MYMODULE
{
mylist = value1
mylist = value2
...
mylist = valueN
}

then you can load all the values like this:


List<string> myList = node.GetValues("mylist").ToList<string>();

2) Is it possible to access the whole persistence file (read-only is fine too)?

Edited by Ippo
Posted the solution if others need it
Link to comment
Share on other sites

Would anyone happen to know how to port

// C#
GameEvents.onVesselWasModified.Add(this.OnVesselWasModified);

to C++/CLI?

I've tried the obvious

// C++/CLI
GameEvents::onVesselWasModified->Add(gcnew EventData<Vessel^>::OnEvent(this, &Events::OnVesselWasModified));

but that results in

error C2664: 'void EventData<Vessel ^>::Add(EventData<Vessel ^>::OnEvent ^)' : cannot convert argument 1 from 'EventData<Vessel ^>::OnEvent ^' to 'EventData<Vessel ^>::OnEvent ^'

I currently work around it by using reflection and calling Delegate::CreateDelegate, but it'd be nice to know if there is a cleaner way of doing it.

Using VS2013 Professional Update 2.

Link to comment
Share on other sites

2) Is it possible to access the whole persistence file (read-only is fine too)?

I believe doing something like this would work:

private string saveFolder
{
get { return System.IO.Path.Combine(KSPUtil.ApplicationRootPath, "saves/" + HighLogic.fetch.GameSaveFolder); }
}

private ConfigNode persistence
{
get
{
string path = System.IO.Path.Combine(saveFolder, "persistent.cfg");
return ConfigNode.Load(path).GetNode("GAME");
}
}

That would return the current persistence ConfigNode I believe.

Link to comment
Share on other sites

'nother quick question: If, hypothetically, I wanted to make my own engine exhaust effect, is there any kind of reference for how to do this? Any existing threads or documentation at all?

Okay scratch that. I managed to dig up some information in the HotRockets thread. But now I have a NEW question: does anyone know if it's possible to make an engine that uses a LineRenderer in addition to or instead of a particle emitter? Because I want to make something like this:

linere10.jpg

Edited by parameciumkid
Link to comment
Share on other sites

Thanks, I'll try ASAP. I thought that System.IO was forbidden though...

Old info, it was allowed again a couple versions back. What are you trying to access in the persistence file? It's better to avoid loading the entire thing whenever possible

Link to comment
Share on other sites

Old info, it was allowed again a couple versions back. What are you trying to access in the persistence file? It's better to avoid loading the entire thing whenever possible

I did notice :P

Anyway, I wanted to read in the full list of hired and applicant kerbals, but that was before I found out the proper way to get them using HighLogic :P

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