Jump to content

Resource Decay


Recommended Posts

Hello there!

I am making a mod that adds a new resource to the game. And while I have successfully implemented that - I have a desire to complicate matters further.

I would like the resource to 'decay' after a while.

Now, this can easily be faked by having the parts that generate it, also have an always-on generator set to a negative value (thus always consuming it)...

However, that's too easy to eject or otherwise render moot.

What I would really want is to have this resource decay on its own, without the need for parts to fake it.

Any advice?

Thank you much

- A

Link to comment
Share on other sites

Actually, if I'm not mistaken, a generator with a negative value will create the resource. If you can code in C#, it would be pretty easy actually. I just did something like that for my submarine. If they have the neutral buoyancy toggled on, every 10 seconds it consumes an electrical charge.

Link to comment
Share on other sites

Fengist is right. Using Resource.Request() with a negative value will add to the resource, while a positive value will decrease it.

However, a ModuleGenerator *already* uses a negative sign in code (since the rate is positive), so a ModuleGenerator entry with a negative rate could work as a decay method.

If you want to do it in code, put a statement in PartModule.OnFixedUpdate() which decays the resource. You *will* need to write your own code if you don't want to keep a possibility of sabotaging it through hacking the part config or ModuleManager.

Link to comment
Share on other sites

Fengist is right. Using Resource.Request() with a negative value will add to the resource, while a positive value will decrease it.

However, a ModuleGenerator *already* uses a negative sign in code (since the rate is positive), so a ModuleGenerator entry with a negative rate could work as a decay method.

If you want to do it in code, put a statement in PartModule.OnFixedUpdate() which decays the resource. You *will* need to write your own code if you don't want to keep a possibility of sabotaging it through hacking the part config or ModuleManager.

Ill be happy if it cant be sabotaged though parts ejection, lol.

Link to comment
Share on other sites

Ill be happy if it cant be sabotaged though parts ejection, lol.

In that case, ModuleManager the PartModule into any of the command pods. Those can't be ejected without rendering the entire ship useless. ;)

Out of curiosity, what kind of resource are you looking into here? Life support? Coolant? Ship wear?

Link to comment
Share on other sites

In that case, ModuleManager the PartModule into any of the command pods. Those can't be ejected without rendering the entire ship useless. ;)

Out of curiosity, what kind of resource are you looking into here? Life support? Coolant? Ship wear?

I'm working on an anti-mass set of parts, and the idea is that without maintainance (the generator being 'on') the artificial particles decay.

Link to comment
Share on other sites

I'm working on an anti-mass set of parts, and the idea is that without maintainance (the generator being 'on') the artificial particles decay.

That should be no problem to integrate into your PartModule as it is.

If you jettison the generator which has the decay logic, the logic will keep running even though the part is not on the active vessel. Your "Antimatter" resource will drop to zero if you have no separate storage part for it. (PartModules will run on any vessel or debris within physics range, not just the active)

Conversely, if you *have* a separate storage part (containment field generator of some sorts) you could put the decay logic in there. Dump the container and your resource is gone anyway, and if you somehow re-attach it or on ship startup, you can hook to the PartModule.OnAwake() method to re-set your resource count to zero.

Simply put, a user can ditch their containment tank but it would do them no good because all of the antimatter will be gone once they re-attach it.

As a good side-objective, gameplay wise, you could have the generator put out some heat and explode it when the containment field is full and the power is suddenly lost for too long. If a player doesn't attach enough radiators or kills the power, you have the chance of everything blowing up.

Basically, add enough radiators and the particles will decay naturally without any ill side effects, but not enough radiators and your power drops... boom.

Link to comment
Share on other sites

It's a plugin. You have to copy it to your gamedata diretory. Look in the .zip. Then, you have to add the partmodule to something on your ship. Read the docs I on the webpage. You don't load a .dll into visual studio.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...