Diminishing Mana Return

Discussion in 'RPG Maker MV' started by D-D-D-Dan, Dec 5, 2019.

Thread Status:
Not open for further replies.
  1. D-D-D-Dan

    D-D-D-Dan Veteran Veteran

    Messages:
    42
    Likes Received:
    4
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey there, I have a issue setting something up.
    I have my combat system setup that you start every encounter with 0 mana.
    Basic skills generate mana and abilites spend it.
    Maximum Mana is capped at 150. The regen part all works perfectly fine.

    Now I would like to add Diminishing Return to my mana generation.
    something like ( (max_mana - current_mana) / x) * variable
    What I want to achieve is if Actor A has over X amount of mana generated the next basic skill will generate less mana
    and if Actor A drops below X amount of mana generation is back to base value.

    I figured i could do this via damage formula but i think thats a bust.
    So i thought I would do it via common event.
    But i cant seem to get it working.
    Anyone have a Idea?
     
    #1
  2. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,521
    Likes Received:
    3,774
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    I've done a lot of diminishing returns stuff, but I'm unclear about what kind of curve you are trying to implement. Could you give several examples (the more the better) of how much mana a character has, how much base mana a skill should regen, and what the final value should be based on the combination of the two? If I can understand exactly what you want to do, I'm confident I can give you either a formula or a common event that would accomplish it.
     
    #2
  3. D-D-D-Dan

    D-D-D-Dan Veteran Veteran

    Messages:
    42
    Likes Received:
    4
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    Awesome!
    At the start of combat all actors have 0 mana.
    All classes have a set of several basic attacks that generate 4 mana each while guard generates 12 (This is all working).

    I want there to be deminishing return on generation once a actor reaches 16 mana.

    I hope you understand what i mean :kaoswt:
     
    Last edited: Dec 5, 2019
    #3
  4. Tiamat-86

    Tiamat-86 old jrpg gamer Veteran

    Messages:
    300
    Likes Received:
    119
    First Language:
    english
    Primarily Uses:
    RMMV
    ive seen this done easy with passive states and TP Charge Rate.
    but not with MP because only has MP Cost reduction.
    there a reason you cant swap the 2?
     
    #4
  5. D-D-D-Dan

    D-D-D-Dan Veteran Veteran

    Messages:
    42
    Likes Received:
    4
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    I use TP for a kind of FF styled desperation/trance system
     
    #5
  6. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,521
    Likes Received:
    3,774
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    I was hoping you would give me a flow of the mana curve (e.g. how sharply it should fall off at certain levels beyond 16), but I can make a curve for you that may work. Beyond 16 mana, you'd want the mana gain to fall off, but without ever reaching zero, so the idea is to divide the threshold (16 mana) by the amount of mana the character has, and a constant (like 20) can be added to both sides to make the effect less punishing if desired.

    I would suggest the formula:
    • If Mana <= 16: Base Value
    • If Mana > 16: Base Value * ((16 + 20) / (Mana + 20))
    In a skill formula, I believe that would be: BASEMANAGAIN * (16 + 20) / (Math.max(16, a.mp) + 20)
    (Replace BASEMANAGAIN with the base value that the actor would gain when below 16 mana)

    To create an entire formula, you would use: c = BASEMANAGAIN * (16 + 20) / (Math.max(16, a.mp) + 20); a.gainMp(Math.ceil(c)); DAMAGEFORMULA

    You can increase or decrease the "20" values to your liking - just make sure that you change both 20's to the same number, or the elegance of the curve will be lost.

    (Edited this post to reflect the correct use of the gainMp function, and also to round up in order to avoid decimal MP gains. The formula given here should work now.)
     
    Last edited: Dec 5, 2019
    #6
  7. D-D-D-Dan

    D-D-D-Dan Veteran Veteran

    Messages:
    42
    Likes Received:
    4
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    alright ill give it a go and report back.
    Thanks!

    Edit: So I gave it a try and it doesnt seem to do anything.
    Maybe you can give the formula a look to see if i made a oopsie?
    a.gainMp(Math.floor(a.mmp * 0.03)); c = 4 * (16 + 20) / (Math.max(16, a.mp) + 20); a.mp += c; 4 + (a.atk * 0.5) - (b.def * 0.25)

    I tried with and without var i tried moving the first 2 parts around and for good measure i changed a.mp to a.mmp but the output never changed always got dmg + 4 mana gain
     
    Last edited: Dec 5, 2019
    #7
  8. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,521
    Likes Received:
    3,774
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    Get rid of a.gainMp(Math.floor(a.mmp * 0.03)); and if that also doesn't work then try adding var before the first c. If that also doesn't work, let me know and I'll play around with it in-engine tomorrow.
     
    Last edited: Dec 5, 2019
    #8
  9. D-D-D-Dan

    D-D-D-Dan Veteran Veteran

    Messages:
    42
    Likes Received:
    4
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    ah i hate to do this to you :kaocry:
    var c = 4 * (16 + 20) / (Math.max(16, a.mp) + 20); a.mp += c; 4 + (a.atk * 0.5) - (b.def * 0.25)
    is the formula i now put in and it does not generate or deduct any mana
    tried it with and without the var
     
    #9
  10. Tiamat-86

    Tiamat-86 old jrpg gamer Veteran

    Messages:
    300
    Likes Received:
    119
    First Language:
    english
    Primarily Uses:
    RMMV
    you could try
    a.gainMP(Math.ceil((a.mmp-a.mp)/45)); formula
     
    #10
  11. D-D-D-Dan

    D-D-D-Dan Veteran Veteran

    Messages:
    42
    Likes Received:
    4
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    throws out the error that a.gainMP is not a function

    But thanks for helping :D

    I also tried (Math.floor(a.mmp - a.mp) /4) * 0.12;
    which doesnt crash the game but it also does nothing

    wait why does it throw out that one as error but my other one works?
    time to investigate

    Edit:
    Found the culprit it was the capital P causing the issue!
    It works (to a extent). The first reduction starts at 16 reducing from 4 to 3
    next reduction kicks in at 60 reducing it to 2

    Edit 2: how would this work with guard though?
     
    Last edited: Dec 5, 2019
    #11
  12. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,521
    Likes Received:
    3,774
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    I went ahead and tried my formula in MV and got the same thing you're seeing - no MP gain at all. Playing around with things a little, I realized my mistake was the use of directly setting a.mp using the += operator (an approach that would work in Ace and most libraries thanks to setter methods). Instead, it's apparently necessary to use the gainMp function.

    After testing using that function, everything works as I'd want it to, except that you can gain a decimal amount of MP - obviously we don't want that, so I added the Math.ceil function to round up (allowing the skill to always gain at least 1 MP).

    As such, I've edited my original post to include a formula that should definitely work for you in-game. Let me know if it still doesn't!

    Example of a damage formula that will work in-game:
    c = 4 * (16 + 20) / (Math.max(16, a.mp) + 20); a.gainMp(Math.ceil(c)); 100 + a.mat * 2 - b.mdf * 2
     
    Last edited: Dec 5, 2019
    #12
    caethyril likes this.
  13. D-D-D-Dan

    D-D-D-Dan Veteran Veteran

    Messages:
    42
    Likes Received:
    4
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    It works! But the diminishing return doesnt start until 30 what value do i have to change? (sorry havent slept yet...)

    and any idea how i can add this or something like this to guard?
    either im missing something or you cant add a formula to guard without it
    crashing. I assume ill have to do this via js or event somehow?

    oh and thanks a ton!
     
    Last edited: Dec 5, 2019
    #13
  14. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,521
    Likes Received:
    3,774
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    Change both instances of the number 16.

    I would think you could just change the Guard skill in your database. You can make it an "MP Recover" (instead of "None") type skill and simply type the formula into the formula box; for example:
    12 * (30 + 20) / (Math.max(30, a.mp) + 20)

    Admittedly I've never tried adding a formula to Guard in MV, so there may be some kind of hard-coded behavior that causes issues when you try this, but I wouldn't expect that to be the case. (If it is, though, what I'd probably do is look into a plugin that removes the Guard command, and make its functionality into an ordinary free Skill instead, increasing MP and applying the Guard state.)

    You're very welcome!
     
    #14
    caethyril likes this.
  15. D-D-D-Dan

    D-D-D-Dan Veteran Veteran

    Messages:
    42
    Likes Received:
    4
    Location:
    Germany
    First Language:
    English
    Primarily Uses:
    RMMV
    Cut them all down to 6 and it Works fantastic! Your the best!
     
    Last edited: Dec 6, 2019
    #15
  16. Tiamat-86

    Tiamat-86 old jrpg gamer Veteran

    Messages:
    300
    Likes Received:
    119
    First Language:
    english
    Primarily Uses:
    RMMV
    have guard skill use a MP recovery damage formula using
    Math.ceil((a.mmp-a.mp)/12.5)
     
    #16
  17. Kes

    Kes Global Moderators Global Mod

    Messages:
    21,116
    Likes Received:
    10,722
    First Language:
    English
    Primarily Uses:
    RMVXA

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

     
    #17
Thread Status:
Not open for further replies.

Share This Page