Modifying Params

● ARCHIVED · READ-ONLY
Started by Engr. Adiktuzmiko 1 posts View original ↗
  1. Overview

    This tutorial will teach about how to modify params via script calls

    The problem

    I've seen quite a number of people wanting to modify params via script calls,

    using a logical method, which doesn't work.

    Look at this

    $game_actors[1].mhp += 100If you just look at it, it looks logical right? You're adding 100 to .mhpBut if you test that out, you'll realize that it doesn't work.

    Why? Well because you could only do that if mhp was an attribute of the Game_BattlerBase

    class which has writers or accessors attached to it. Sadly, it isn't.

    So what is mhp? It's actually just a wrapper for the params method of Game_BattlerBase

    All the "normal" param calls (.mhp,.mmp,.atk and so on) are wrappers. Look at this

    def mhp; param(0); end # MHP Maximum Hit Points def mmp; param(1); end # MMP Maximum Magic Points def atk; param(2); end # ATK ATtacK power def def; param(3); end # DEF DEFense power def mat; param(4); end # MAT Magic ATtack power def mdf; param(5); end # MDF Magic DeFense power def agi; param(6); end # AGI AGIlity def luk; param(7); end # LUK LUcKSee? It simply calls another method. Now let's look at that method and further understandwhy the somehow logical code above doesn't work.

    def param(param_id) value = param_base(param_id) + param_plus(param_id) value *= param_rate(param_id) * param_buff_rate(param_id) [[value, param_max(param_id)].min, param_min(param_id)].max.to_i endNow you'll see that it simply returns a value based from several calculations. It doesn't returnany actual param object so in turn, we cannot modify that param. Technically the param object

    doesn't exist.

    The question now is, how do we modify params using script calls?

    Solution

    To solve the issue, I looked upon how Event Commands do it. Yes, event commands holds the answer

    to this troubling problem.

    Event commands for modifying params work by using this simple method inside Game_BattlerBase

    def add_param(param_id, value) @param_plus[param_id] += value refresh endIt modifies the @param_plus array which is the array that is looked upon by the param_plus line on the param method.And this is exactly the method that we will need to call if we want to modify the params using script calls. The param_id is the same as the parameter passed by each wrapper listed above.

    Example

    So now, to make our max hp modification work, we simply use

    $game_actors[1].add_param(0,100)Ending NotesI hope you learn something from this tutorial which could be helpful to your future endeavors.