Jump to content

Needing help with adding resorces


Recommended Posts

I struggling to find out how to add a resource to ship or part (doesn't really matter) while the ship is traveling.

To be clear I don't mean adding more of a resource like fuel to a ship, I mean adding a brand new resource like "stellar dust" to a ship and giving this new resource a max and an amount.

I pretty sure I need to add a new resource node or something to the ship but I can't get the syntax right or something. I wouldn't ask but this has me literally stuck for about 4 hours and I have written and remed out about 20 lines of code.

I can think of a work around but it is messy and will look bad.

Link to comment
Share on other sites

They way I've added new resources to the game is modify the "Resource" file in the Game data files (I'm currently at work, but I'll be able to give you the specific location when I get home). You need to define the resource name, density, a few transfer rules... and I think that's about it.

To add storage for the new resources, you need to add bit of code to the specific parts you want to use as a container. Each part in the game has it's own directory with a part config file in it. At the bottom of the config file for each part that can hold a resource, there's a section that defines resources they can hold, the amount they launch with, and the max amount they can store.

So, you don't need to add the resource node to the ship, you just need to add it the ship's parts.

I hope that helps. I'm still figuring out how to use the resources in new part modules.

Link to comment
Share on other sites

Like LethalDose said, you need to add it to the GameData/Squad/Resources/ResourcesGeneric.cfg file. Here's the format:

RESOURCE_DEFINITION

{

name = Stellar Dust

density = 0.005

flowMode = ALL_VESSEL

transfer = PUMP

isTweakable = true

}

Now you have some dust, that weighs 0.005 tons per unit, and can be moved between any parts of the vessel. Now, you need some parts to do something with it. A simple dust bin might look like this (modified from the FL-T500 fuel tank:

PART

{

name = dustBin

module = Part

author = Clockwork_werewolf

// --- asset parameters ---

mesh = model.mu

scale = 0.1

// --- node definitions ---

node_stack_top = 0.0, 7.72552, 0.0, 0.0, 1.0, 0.0

node_stack_bottom = 0.0, -7.3, 0.0, 0.0, 1.0, 0.0

node_attach = 5.01, 0.0, 0.0, 1.0, 0.0, 0.0, 1

// --- editor parameters ---

TechRequired = basicRocketry

entryCost = 1600

cost = 850

category = Science

subcategory = 0

title = Stellar Dust Bin

manufacturer = KerMart

description = Holds stellar dust!

// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision

attachRules = 1,1,1,1,0

// --- standard part parameters ---

mass = 0.25

dragModelType = default

maximum_drag = 0.2

minimum_drag = 0.3

angularDrag = 2

crashTolerance = 6

breakingForce = 50

breakingTorque = 50

maxTemp = 2900

RESOURCE

{

name = Stellar Dust

amount = 0

maxAmount = 180

}

}

And if you want to collect some dust you can either write your own plugin code of some sort, or use something like this (modified from the circular intake):

PART

{

// --- general parameters ---

name = DustScook

module = Part

author = Clockwork_werewolf

// --- asset parameters ---

mesh = model.mu

scale = 0.1

// --- node definitions ---

// definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z

node_stack_bottom01 = 0.0, 0.0, 0.0, 0.0, 1.0, 0.0

// --- FX definitions ---

// --- editor parameters ---

TechRequired = supersonicFlight

entryCost = 8800

cost = 680

category = Aero

subcategory = 0

title = Dust Scoop

manufacturer = KerMart

description = Scoops up stellar dust from SPACE!

// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision

attachRules = 1,0,1,0,0

stackSymmetry = 2

// --- standard part parameters ---

mass = 0.01

dragModelType = default

maximum_drag = 0.3

minimum_drag = 0.3

angularDrag = 1

crashTolerance = 20

maxTemp = 3400

fuelCrossFeed = True

MODULE

{

name = ModuleResourceIntake

resourceName = Stellar Dust

checkForOxygen = false

area = 0.008

intakeSpeed = 10

intakeTransformName = Intake

}

RESOURCE

{

name = Stellar Dust

amount = 0.2

maxAmount = 0.2

}

}

I don't actually know if ModuleResourceIntake will work in space like that, but hey, that's why you write your own module to do it for you! Hope that helps a bit...

Link to comment
Share on other sites

I'm afraid this really doesn't help. I have already added custom resources to ships and added and taken resources from the ship in flight using my own C# code.

What I what is to be able to assign a brand new resource to the ship after it has taken off. I could make the empty space in the ship before hand and then assign it more resources under a condition in space but this is the ugly way of doing it I said above. What I want to be able to do is create a new resource using C# code. The reason for this is I want to be able to add a specific resource on launch for each Kerbal aboard but not for empty seats. I could use a part module and then part.protoModuleCrew.Count per module to fill the resource but there is nothing stopping another ship form docking and transferring over more resources then the Kerbals had at the start. This is why I wish to manipulate the MAX amount of resources available in flight.

Link to comment
Share on other sites

I'm afraid this really doesn't help. I have already added custom resources to ships and added and taken resources from the ship in flight using my own C# code.

What I what is to be able to assign a brand new resource to the ship after it has taken off. I could make the empty space in the ship before hand and then assign it more resources under a condition in space but this is the ugly way of doing it I said above. What I want to be able to do is create a new resource using C# code. The reason for this is I want to be able to add a specific resource on launch for each Kerbal aboard but not for empty seats. I could use a part module and then part.protoModuleCrew.Count per module to fill the resource but there is nothing stopping another ship form docking and transferring over more resources then the Kerbals had at the start. This is why I wish to manipulate the MAX amount of resources available in flight.

I'm afraid you can't do that. Resources are defined in the part config, and our saved using the said config in the persistence file. If the resource is not originally present in the part, you will not be able to add, remove, and save it.

The only workaround I see is for you to redefine resource storage.

Link to comment
Share on other sites

Could the persistence file be modified? Would there be a way to add a savable variable to the game save to act as a virtual maximum? Actualy I might be able to use the crewnumbers as that without the need to save. I know that the ModuleManager mod is able to set new resources on load but is this then fixed after config loading?

Thank you for your help Chris what ever the answer.

Link to comment
Share on other sites

Oh Also I know that TAC Life support is able to add its resources to an EVA Kerbal and then take them away again when he boards. This is so that kerbals on EVA can die of lock of oxygen too. I just don't really understand how. I'm at the Better_Than_Starting_Manned stage of understanding Kerbal codeing. I can get my Kerbals to die and use resources but they do not use resources on EVA or when not in focus. I've been poring over TAC code for days now (literally, well not poring but literally days) but I'm not able to use or reverse engineer it yet.

Link to comment
Share on other sites

It is most likely possible with some ugly hacks (since PartResourceList can be messed with) that might break other stuff. It doesn't look like there is any proven solution for this so you might want to skip this specific feature for now and continue to complete the mod nonetheless. Otherwise you will spend more days to find a working solution and many more weeks fixing/handling all the stuff your "hack" breaks. Please don't, unless everything else is done or you mod can't exist without it.

Link to comment
Share on other sites

hmm I'm not sure, I know that TAC life support gets along without crashes and is very popular so it must be possible to do it without crashes.

The basic idea behind the mod is this: It's a life support mod (yea another I know) with only 4 or 5 resources. Breathable_air, Food, Sanity and Radiation_level. The optional resource is lithium hydroxide which is a basic carbon dioxide remover.

Breathable_air is made of oxygen sourced from Oxidizer (2.376 oxidizer per Kerbal per day based on human oxygen usage) and Carbon dioxide removal using Lithium hydroxide (1.866 per Kerbal per day), or a renewable system that uses energy or hydroponics.

Food which is light but only make-able using hydroponics for which you need 10 tons per Kerbal (heavy but it also makes breathable air so its for infinite supply's).

Sanity is the first new style resource and one of the reason to make a new mod and not just modify someone else's mod. It is based on the number of Kerbals and their available space. One Kerbal cooped up in a tiny capsule will go mad after about 20 days (based on solitary confinement research and astronaut and cosmonaut testimony). One Kerbal with two seats has more space so goes mad slower. To set up a permanent colony you would need about 10 Kerbals and 20 seats.

For this resource I need to be able to on launch set the maximum sanity to 100 (100%) for each Kerbal but not 100 for each available seat in the craft. If a new craft were to dock they could transfer over sanity to the craft and you could end up with one Kerbal having 2000 sanity all to himself (2000% sanity?!). This is why I need to be able to modify the sanity max.

Radiation_level is just that a safe radiation level. Radiation is added based on the atmosphere density so that Kerbals on Kerbin get none but Kerbals in space and on the mun get irradiated. There is radiation plating though so they can be shielded. This doesn't matter as much if it has higher maxes or radiation levels are transferred as this could be thought of as higher natural shielding on an object or adding new scrubbed objects or food to a station. I would prefer it not to be transferred and stay with a Kerbal like the sanity but its not so important.

There are bugs with the present code and system but I would rather be able to build it using good techniques rather than have to go back in a week or a month and rewrite half the code.

Link to comment
Share on other sites

Okay, sanity. You want Kerbal-specific resources. Afaik sth like that was never done before. Kerbals on EVA are ships with a special KerbalEVA part. MM can modify this part to have resources. This is most likely what TAC does. There are no such objects for Kerbals that are in Vessels. I see two possibilities:

- Give crew capsules sanity storage (0 to seats*100), threat them like a group & make sanity a non-transferable resource (PartResourceDefinition has both flowMode & transferMode, though i never tried them)

- Store sanity manually and add visualization wherever possible (right click on the capsule, portrait, low-warnings, whatever)

In either case you have to add kerbal transfer logic, though the first one would be more complicated to never "loose" a kerbals data. For that first solution you might also add some "advanced" transfer logic to prevent abuse, like always taking mostly the more worse values when someone joins a group.

Link to comment
Share on other sites

Thanks for the input. I think I might go with option one even with the chance of loss. I want players to be able to see it as a resource. Going to have to go with a transfer logic. I put this up about a day and a half ago and in that time I understand better what I am dealing with, with the resources as classes not just variables.

Adding sanity might seem strange but I want people to not be able to just send one Kerbal to Eeloo and back in a tiny capsule, it didn't seem realistic and as far as I could tell astronauts going mad was the reason why. Also it gives players a reason to build large bases and space stations.

Link to comment
Share on other sites

It looks like TrueBorn beat me to it, sorry I wasn't able to get it posted last night.

In reading this now, I'm confused: Why do you need to add the capacity for a resource mid-flight? I'm pretty sure that TAC doesn't do this, i.e. TAC mods the kerbal EVA part to have all of those resources. I don't know how they get moved between the two craft (e.g. O2 deducted from the source ship and placed into the new EVA), but kerbals have that maximum now hardcoded into them.

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