Jump to content

Changing maximum Resource in-flight


Recommended Posts

I'm wondering/hoping someone can point me in the right direction. I'm hoping to find a simple way of changing the maximum amount of Electric Charge a part has after a instantiation. I'll see if i can explain it, the idea is that the part (a cryogenic escape pod) has 3001 EC when it is spawned but as soon as it is reduced down to, say 50, the maximum it can be re-charged to is 50. The rational behind this is that there is sufficient stored charge to do a single freeze and then after that it needs to be recovered before de-frosting can take place.

Is there a way in stock i could configure part as such? If not could new 'RESOURCE' module be written to be single shot?

Link to comment
Share on other sites

Not sure what you mean by "in stock", you'd have to write a plug-in, but changing the max amount is simply changing the Part.Resources.Get("ElectricCharge").maxAmount value.

The only catch is I have done almost nothing with resources and don't know what the persistence of that value is. (If it saves once set, or you'll have to set if every time the part loads.)

D.

Link to comment
Share on other sites

Absolutely no idea if this can work but have you tried to change the part.cfg to something like :

Quote

// stuff

RESOURCE
    {
        name = ElectricCharge
        amount = 3001
        maxAmount = 50
    }

// stuff

 

Link to comment
Share on other sites

4 hours ago, Li0n said:

Absolutely no idea if this can work but have you tried to change the part.cfg to something like :

Yep, that's what I initially tried to get it to do what I wanted. It worked once, but hasn't repeated it since (I'm thinking it;s something to do with the stored configurations on the MM cache). I need something more consistent.

Link to comment
Share on other sites

I don't think MM can do what you want, MM can only edit 'the' part, not 'a' part. By that I mean if you change the max EC on a part, you change it on all parts in-game. This includes the 'unbuilt' parts in the editor and all parts that exist in flight.

First, you are trying to do the following correct?

-Part spawns with 3001 max EC which auto-fills on launch.

-Cryo happens, part max EC drops to 50.

-Some other trigger (Time delay?), the part max EC goes back to 3001.

You can set the original max amount with MM (or just in the part.cfg as you are making this part I assume),  but changing it in game will require a plug-in to detect when the change should happen and then editing the Part.Resources.Get("ElectricCharge").maxAmount value as needed.

As for what @Li0n suggested, I wouldn't recommend it. While it might work, it's not working as intended because a part is not 'supposed' to be able to contain more resources (currentAmount) then it can hold (maxAmount). This sort of thing is what causes mod conflicts as other people (including Squad) will assume a part can't hold more resources then maxValue when they are working on their own stuff.

D.

Edited by Diazo
Link to comment
Share on other sites

53 minutes ago, Diazo said:

First, you are trying to do the following correct?

-Part spawns with 3001 max EC which auto-fills on launch.

-Cryo happens, part max EC drops to 50.

This is the plan, there is no need for the part to have the 3001 EC after it has been used (it would need to go to a ship yard for a re-fit sort of thing).

 

56 minutes ago, Diazo said:

You can set the original max amount with MM (or just in the part.cfg as you are making this part I assume),  but changing it in game will require a plug-in to detect when the change should happen and then editing the Part.Resources.Get("ElectricCharge").maxAmount value as needed.

So would this only affect instantiated parts? not the original part config. Would I be right in assuming that what the plugin would do as alter the EC max on the loaded part?

Link to comment
Share on other sites

Yes, the plug-in would be a partModule that you attach to the parts that can do this via MM (or in it's part.cfg if you're making the part).

How clear are you on how the underlying KSP engine works? I think part of the issue is that MM does not do quite what you think it does. Notably how were you going to do this cryo thing at all without a plug-in?

MM is for changing the default settings of part, it can't change settings of parts in flight. It can appear to change settings in flight as KSP will always use the most recent version of the "default" part, but settings in the save file will override it. (So settings that don't get saved can be modified by MM on parts spawned in flight.)

So once you've spawned a part inflight, the currentAmount of the resource gets saved and it doesn't matter what you do with MM, the currentAmount in the save file will always override your MM changes.

To make changes such as this that happen in flight requires a plug-in.

D.

Edited by Diazo
Link to comment
Share on other sites

2 hours ago, Diazo said:

How clear are you on how the underlying KSP engine works? I think part of the issue is that MM does not do quite what you think it does. Notably how were you going to do this cryo thing at all without a plug-in?

To make changes such as this that happen in flight requires a plug-in.

D.

I knew this wouldn't be something MM could do on it's own (I meant that where I managed to trick Stock KSP by setting the Amount to 3000 and the maximumAmount to 3000 worked only once (firs time), then I think MM caught up an wouldn't allow it to start with 3000 EC again (due to MM inbuilt cache function for mods to facilitate quicker loading).

As to how the Underlying KSP work i have only the most basic understanding of C#. I can happily drive unity and blender to build models but my plugin expertise are very lacking (i can recompile stuff but that's pretty much my limit at the minute). Modelling is more my forte.

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