Fighting System Script

Discussion in 'RPG Maker MV' started by kR1pt0n1t3, Mar 15, 2019.

  1. kR1pt0n1t3

    kR1pt0n1t3 Veteran Veteran

    Messages:
    43
    Likes Received:
    7
    Location:
    Croatia
    First Language:
    Croatian
    Primarily Uses:
    RMMV
    I want to build a system that powers up character based on the skills they learned and used in fights rather than exp.
    For example, if a character uses magic spells in battle a certain amount of times, I want his mana pool, magic attack, and magic defense increase.

    All the characters at the start of the game will have certain predispositions to a certain type of skills based on their history but as you play the game I want that the development of the characters to depend on the skills the player decided to teach that character and the skills the character used.

    This would allow for a character that was previously good at magic to become somewhat good at melee and vice versa.
    It would also allow negating certain weakness of a character or strengthening even further advantages.

    Except fighting the character will be powered up through training with experienced fighters, mages, thieves the player encounters throughout the world. The player will be able to leave a character for a day to train with them to gain powerful boosts.

    Does a battle script with a system similar to this exist? If yes, please tell me the name, if not, how hard would be to code a script like that?

    I was thinking of just using variables to track how often each actor used certain skills and then make an event whenever the player goes to sleep to check if XY conditions have been fulfilled and readjust each character's stats.

    Example:
    Actor 1 used in battle that day:
    - var 1 = x20 Slash
    - var 2 = x25 Double Slash

    Event 1 is called at night and increases actor 1's: STR + 5, MAT -3. MDF -3 , DEF +2, HP+50, MP-5
    Reset var 1 = 0, var 2 = 0.

    How can I make it so a variable is increased when X actor used Y skill in battle?
     
    #1
  2. NinjaKittyProductions

    NinjaKittyProductions Professional Murder Hobos Veteran

    Messages:
    242
    Likes Received:
    174
    First Language:
    English
    Primarily Uses:
    RMMV
    The closest thing I could find that meets this would be Crystal Noel's plugins... particularly their Final Fantasy II Progression Plugin. It can be found here: https://crystalnoel42.wordpress.com/2015/10/18/crystal-engine-final-fantasy-ii-stat-advancement/
     
    #2
  3. kR1pt0n1t3

    kR1pt0n1t3 Veteran Veteran

    Messages:
    43
    Likes Received:
    7
    Location:
    Croatia
    First Language:
    Croatian
    Primarily Uses:
    RMMV
    @NinjaKittyProductions
    Thanks, I'll look into it.

    A system like that would be pretty easy to make if only I knew how to increase a variable when a skill is used.
    I read you can put a script line inside the damage but for some reason it's not working.

    v[201] += 1; 40 + a.mat * 3 - b.mdf * 2

    v201 isn't increased when that skill is used. I guess something was changed inside the rpg maker mv and this no longer is working.
     
    #3
  4. NinjaKittyProductions

    NinjaKittyProductions Professional Murder Hobos Veteran

    Messages:
    242
    Likes Received:
    174
    First Language:
    English
    Primarily Uses:
    RMMV
    It would be tedious but you could also link a common event with a skill so that when the skill is used, the common event is ran. Just setup the common event to increase variable x by y amount.
     
    #4
  5. kR1pt0n1t3

    kR1pt0n1t3 Veteran Veteran

    Messages:
    43
    Likes Received:
    7
    Location:
    Croatia
    First Language:
    Croatian
    Primarily Uses:
    RMMV
    I could, but I read that the common event inside a skill will be only run once and only after the battle which is not good for what I want.

    I did figure out why the above wasn't working. I noticed that when I set the variable to anything other than zero, the variable is increased with v[201] += 1. I don't know why 0 is the problem tho.
     
    #5
  6. Weremole

    Weremole Veteran Veteran

    Messages:
    224
    Likes Received:
    199
    First Language:
    Swedish
    If the common event is paralell or auto-run. A common event that isn't is run after the skill effect (or called anytime you want to using an action sequence plugin).
     
    #6
  7. Oliin

    Oliin Villager Member

    Messages:
    22
    Likes Received:
    15
    First Language:
    English
    Primarily Uses:
    RMMV
    You should be able to do script calls within Yanfly's action sequences that would allow you to increment variables as well.
     
    #7
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    37,533
    Likes Received:
    11,252
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    v[n] in the damage formula will let you retrieve the value of a variable, but not change it. You would need to use the longhand version:

    Code:
    $gameVariables.setValue(201, $gameVariables.value(201) + 1); 40 + a.mat * 3 - b.mdf * 2
     
    #8
  9. kR1pt0n1t3

    kR1pt0n1t3 Veteran Veteran

    Messages:
    43
    Likes Received:
    7
    Location:
    Croatia
    First Language:
    Croatian
    Primarily Uses:
    RMMV
    That's weird because "v[201] += 1" works as well as long as the value of the variable isn't 0.
    I don't know why zero is the problem.

    Your suggestion works with 0 while "mine" isn't.
     
    #9
  10. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,552
    Likes Received:
    977
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    It's because behind the scenes, if a game variable hasn't been used yet, it's value is actually "undefined", not zero. Say variable #201 hasn't been set yet.
    Code:
    V[201] += 1
    undefined += 1  // if the variable isn't initialized
    It doesn't work to do "undefined += 1" since undefined isn't a number.

    Shaz' solution works because the helper functions already consider this possibility.

    If you want to use the v[201] += 1 style, it's perfectly valid but you need to explicitly set the value to 0 at the start of the game.

    You can also define your own increment function that takes this possibility into account.
    Code:
    Game_Variables.prototype.increse = function(varId, amount = 1) {
        if (!this._data[varId]) {
            this._data[varId] = amount;
        } else {
            this._data[varId] += amount;
        }
    }
    Then you could call that in any formula or script call:
    Code:
    $gameVariables.increase(201)
     
    Last edited: Mar 16, 2019
    #10
  11. kR1pt0n1t3

    kR1pt0n1t3 Veteran Veteran

    Messages:
    43
    Likes Received:
    7
    Location:
    Croatia
    First Language:
    Croatian
    Primarily Uses:
    RMMV
    Thanks so much for that explanation.

    I thought that the default value of a variable is 0.
    It makes sense now why it wasn't working.

    v[201] += 1 is much better than
    $gameVariables.setValue(201, $gameVariables.value(201) + 1) just because of the code size.
     
    #11
  12. Shaz

    Shaz Veteran Veteran

    Messages:
    37,533
    Likes Received:
    11,252
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    If you use the event commands, the default value of a variable is zero because of this:
    Code:
    Game_Variables.prototype.value = function(variableId) {
        return this._data[variableId] || 0;
    };
    So if it detects that it's undefined, it returns 0.

    The length of a line of code isn't really relevant, unless you're really, really lazy and just don't want to type that much (and if that's the case, developing a game is probably not something you'll get very far with).

    Try this, but I don't know if it'll work:
    Code:
    v[201] = v[201] ? v[201] + 1 : 1 ; 40 + a.mat * 3 - b.mdf * 2
    That's saying if it exists, add 1 to it, otherwise set it to 1. But I don't know if an undefined variable is the same as one that doesn't exist.
     
    #12
  13. kR1pt0n1t3

    kR1pt0n1t3 Veteran Veteran

    Messages:
    43
    Likes Received:
    7
    Location:
    Croatia
    First Language:
    Croatian
    Primarily Uses:
    RMMV
    Thank you both.

    I've set all the variables to 0 at the start of the game and now v[201] += 1 is working.

    The length of the code is relevant. To me at least, it is. There's no reason to use the long line for something that v[201] += 1 does also but you only need to pre-set variable in question to 0 at the start of the game.
     
    #13

Share This Page