Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[SOLVED]Changing Atk, Pdef, Mdef....

@nolund: unfortunately only the str, dex, agi, int, maxhp and maxsp can be changed that way. i'm looking to use an item that calls a script to change those values.

@brewmeister: could you explain tht please?
 
Like Brew was saying, you could use a state like this:
Capture-5.png

If you use a state, you could use the event command or use Brew's suggested code. But this depends on your exact needs. You could also do some weapon/armor alterations to achieve the effect. Like equip a character with some armor that reduces/increases the stats (although you'd have to make it fixed to make the player unable to remove the item). If the state and armor ideas won't work, you need to give us more details on what you want like how long it'll last, whether or not it's permanent, etc.
 
yeah that state thing won't work. what i want to do is increase or decrease the atk/pdef/mdef stat by set numbers (+15) the same way you would the other stats(hp, sp, etc). like say if a use an item in battle that increases attack, for example.
 
ATK, MDEF & PDEF are not stored attributes on the character (actor) object, they are calculated values from the weapon, armor(s), & states.

You could create a new state on the fly, and apply it, calculating the correct atk_rate, pdef_rate, mdef_rate percentages based on the character's current values to produce the desired effect.

Or you could apply new attributes to the Game_Actor or Game_Battler class to store a modifier for each attribute, then change them through script commands. e.g.

$game_party.actors[0].atk_mod = -50

You would then need to modify the atk, pdef, & mdef methods of Game_Battler to add the modifier before returning a value.

your call
 
Did I say that? <looks up> :unsure:

No, I would consider adding an attribute 'relatively' easy. It's a matter of understanding how those 3 existing attributes are derived, and finding the other methods that call them. (Cntl-Shift-F is your friend.)

In a new script above Main, below Scene_Debug...

Add the 3 new variables (attributes) to Game_Actor, and initialize them in the setup method...

Code:
class Game_Actor

  

  attr_accessor :atk_mod

  attr_accessor :pdef_mod

  attr_accessor :mdef_mod

  

  alias attr_mods_setup setup

  

  def setup(actor_id)

    attr_mods_setup(actor_id)

    @atk_mod = 0

    @pdef_mod = 0

    @mdef_mod = 0

  end

 

Now, copy the atk, pdef & mdef methods from Game_Battler, and we'll overwrite them for the Game_Actor class only. (Not for the Game_Enemy class.)

Code:
  #--------------------------------------------------------------------------

  # * Get Attack Power

  #--------------------------------------------------------------------------

  def atk

    n = base_atk

    for i in @states

      n *= $data_states[i].atk_rate / 100.0

    end

    n += @atk_mod

    return Integer(n)

  end

  #--------------------------------------------------------------------------

  # * Get Physical Defense Power

  #--------------------------------------------------------------------------

  def pdef

    n = base_pdef

    for i in @states

      n *= $data_states[i].pdef_rate / 100.0

    end

    n += @pdef_mod

    return Integer(n)

  end

  #--------------------------------------------------------------------------

  # * Get Magic Defense Power

  #--------------------------------------------------------------------------

  def mdef

    n = base_mdef

    for i in @states

      n *= $data_states[i].mdef_rate / 100.0

    end

    n += @mdef_mod

    return Integer(n)

  end

end

I added the modifiers AFTER the state calculation. Also take a look at the base_atk, base_pdef & base_mdef methods in Game_Actor. Each attribute is the sum of the attribute for the weapon & armors, * the attribute factor from all active states, + the new modifier.

Get it?
 
$game_party.actors[0].atk_mod = 15

0 is the first actor in the party
you don't need a '+' with a positive number
you do need a '-' for a negative number

$game_party.actors[3].pdef_mod = -50
 
so the entire script should look like this?

Code:
class Game_Actor

 

   attr_accessor :atk_mod

   attr_accessor :pdef_mod

   attr_accessor :mdef_mod

  

   alias attr_mods_setup setup

  

   def setup(actor_id)

     attr_mods_setup(actor_id)

     @atk_mod = 0

     @pdef_mod = 0

     @mdef_mod = 0

   end

   

    #--------------------------------------------------------------------------

#   # * Get Attack Power

#   #--------------------------------------------------------------------------

   def atk

     n = base_atk

     for i in @states

       n *= $data_states[i].atk_rate / 100.0

     end

     n += @atk_mod

     return Integer(n)

   end

   #--------------------------------------------------------------------------

   # * Get Physical Defense Power

   #--------------------------------------------------------------------------

   def pdef

     n = base_pdef

     for i in @states

       n *= $data_states[i].pdef_rate / 100.0

     end

     n += @pdef_mod

     return Integer(n)

   end

   #--------------------------------------------------------------------------

   # * Get Magic Defense Power

   #--------------------------------------------------------------------------

   def mdef

     n = base_mdef

     for i in @states

       n *= $data_states[i].mdef_rate / 100.0

     end

     n += @mdef_mod

     return Integer(n)

   end

 end

if so, i get an error msg like this: line24: TypeError occured. nil can't be coerced into where did i go wrong?
 
i see what the problem is. i'm using a script by leon that aadjust these stats in accordance with the Str, Int and dex stats. i opened up another project and it works fine. anyway to meld these together? i can pm it to you if you want.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top