Jump to content

How to get fuel count for active vessel ?


creekorful

Recommended Posts

Hello everyone, i have a little question,

How to get fuel count for the active vessel ? (The fuel in all parts in mean, for the entire vessel),

I want to get it to check if fuel level is low.

Also if there is a way to check is fuel level is low directly, tell me about it

Thank you in advance.

Creekorful

(By getting fuel level i mean wich function or method i had to use with my plugin using VS13 and C#)

Edited by creekorful
Link to comment
Share on other sites

Thank you, but not like this, i mean with my plugin, in C#

I want to know wich function i hade to use to get fuel level in active vesssel.

You have to summorise the amount of resource for each part in a vessel filtered on resourcetype

[COLOR=blue]
public double getTotalResourceCapacity(Part my_part, string resource_name)
{
return my_part.GetConnectedResources(resource_name).ToList().Sum(partresource => partresource.maxAmount);
}

public static class PartExtensions
{
public static IEnumerable<PartResource> GetConnectedResources(this Part part, String resourcename)
{
PartResourceDefinition definition = PartResourceLibrary.Instance.GetDefinition(resourcename);
return GetConnectedResources(part, definition);
}

public static IEnumerable<PartResource> GetConnectedResources(this Part part, PartResourceDefinition definition)
{
List<PartResource> resources = new List<PartResource>();
part.GetConnectedResources(definition.id, definition.resourceFlowMode, resources);
return resources;
}
}
[/COLOR]

Edited by FreeThinker
Link to comment
Share on other sites

Vessel.getActiveResources()

also works to return a list of resources on the vessel.

If you then want to consume a resource then

part.requestResource()

To get the active vessel

FlightGlobals.activeVessel

Although you'll just want to get the vessel through the module's part

this.part.vessel

So that your mod can still process resources if it's loaded but not being actively driven.

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