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.

[SOLOVED]Changing troop memeber's atk, pdef, mdef, eva

i'm trying to changes the enemy atk, pdef, mdef, and eva through the call script. i know you can do this by using "$data_enemies[1].atk" but i'd rather not have to go thru that with every monster in the troop. brewmeister gave me a fix for the hero party

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

any way this can be done?
 
Ok. Made this real quick (and thank you because this made me finally come up with some multi-dimensional hash method ideas, even though I ended up not using them in this script).

Code:
# Troop Members Stat Mods

# SephirothSpawn

# 1.0

# 2004-04-04

 

module TMSM

  # Mods = { [troop_id, index, stat_name] => value, ... }

  Mods = {}

  def self.stat_mod(troop_id, member_index, stat)

    key = [troop_id, member_index, stat]

    return Mods[key] if Mods.has_key?(key)

    return 0

  end

end

 

class Game_Enemy

  alias_method :seph_tmsm_bmaxhp, :base_maxhp

  def base_maxhp

    return seph_tmsm_bmaxhp + TMSM[@troop_id, @member_index, 'maxhp')

  end

  alias_method :seph_tmsm_bmaxsp, :base_maxsp

  def base_maxsp

    return seph_tmsm_bmaxsp + TMSM[@troop_id, @member_index, 'maxsp')

  end

  alias_method :seph_tmsm_bstr, :base_str

  def base_str

    return seph_tmsm_bstr + TMSM[@troop_id, @member_index, 'str')

  end

  alias_method :seph_tmsm_bdex, :base_dex

  def base_dex

    return seph_tmsm_bdex + TMSM[@troop_id, @member_index, 'dex')

  end

  alias_method :seph_tmsm_bagi, :base_agi

  def base_agi

    return seph_tmsm_bagi + TMSM[@troop_id, @member_index, 'agi')

  end

  alias_method :seph_tmsm_bint, :base_int

  def base_int

    return seph_tmsm_bint + TMSM[@troop_id, @member_index, 'int')

  end

  alias_method :seph_tmsm_batk, :base_atk

  def base_atk

    return seph_tmsm_batk + TMSM[@troop_id, @member_index, 'atk')

  end

  alias_method :seph_tmsm_bpdef, :base_pdef

  def base_pdef

    return seph_tmsm_bpdef + TMSM[@troop_id, @member_index, 'pdef')

  end

  alias_method :seph_tmsm_bmdef, :base_mdef

  def base_mdef

    return seph_tmsm_bmdef + TMSM[@troop_id, @member_index, 'mdef')

  end

  alias_method :seph_tmsm_beva, :base_eva

  def base_eva

    return seph_tmsm_beva + TMSM[@troop_id, @member_index, 'eva')

  end

end

Ok so lets say in troop 2, you want to add 10 to the first enemies atk. Below this line: Mods = {}, you would add:
Mods[2, 0, 'atk'] = 10


Hope it helps and let me know how it works out for you.
 

MicKo

Member

Okay, I tried this based on SephirothSpawn's work. (Just tell me if I'm not allowed to do that SephirothSpawn!)
[ruby]# Troop Members Stat Mods
# SephirothSpawn, modified by MicKo
# 1.0
# 2010-04-05
 
module TMSM
  Mods = {}
  def self.stat_mod(troop_id, member_index, stat, value)
    Mods[[troop_id, member_index, stat]] = value
  end
end
 
class Game_Enemy
  alias_method :seph_tmsm_bmaxhp, :base_maxhp
  def base_maxhp
    return seph_tmsm_bmaxhp + (TMSM::Mods[[@troop_id, @member_index, 'maxhp']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'maxhp']])
  end
  alias_method :seph_tmsm_bmaxsp, :base_maxsp
  def base_maxsp
    return seph_tmsm_bmaxsp + (TMSM::Mods[[@troop_id, @member_index, 'maxsp']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'maxsp']])
  end
  alias_method :seph_tmsm_bstr, :base_str
  def base_str
    return seph_tmsm_bstr + (TMSM::Mods[[@troop_id, @member_index, 'str']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'str']])
  end
  alias_method :seph_tmsm_bdex, :base_dex
  def base_dex
    return seph_tmsm_bdex + (TMSM::Mods[[@troop_id, @member_index, 'dex']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'dex']])
  end
  alias_method :seph_tmsm_bagi, :base_agi
  def base_agi
    return seph_tmsm_bagi + (TMSM::Mods[[@troop_id, @member_index, 'agi']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'agi']])
  end
  alias_method :seph_tmsm_bint, :base_int
  def base_int
    return seph_tmsm_bint + (TMSM::Mods[[@troop_id, @member_index, 'int']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'int']])
  end
  alias_method :seph_tmsm_batk, :base_atk
  def base_atk
    return seph_tmsm_batk + (TMSM::Mods[[@troop_id, @member_index, 'atk']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'atk']])
  end
  alias_method :seph_tmsm_bpdef, :base_pdef
  def base_pdef
    return seph_tmsm_bpdef + (TMSM::Mods[[@troop_id, @member_index, 'pdef']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'pdef']])
  end
  alias_method :seph_tmsm_bmdef, :base_mdef
  def base_mdef
    return seph_tmsm_bmdef + (TMSM::Mods[[@troop_id, @member_index, 'mdef']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'mdef']])
  end
  alias_method :seph_tmsm_beva, :base_eva
  def base_eva
    return seph_tmsm_beva + (TMSM::Mods[[@troop_id, @member_index, 'eva']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'eva']])
  end
end
[/ruby]
With this you simply make a call script with "TMSM.stat_mod(troop_id, member_id, stat, value)".
For example, if I write "TMSM.stat_mod(1, 2, 'str', 99)", it'll take the 3rd enemy (1st = 0) of the troop with ID 1 (1st = 1 here) and change his str (don't forget the ' ') by adding the last argument. So here, it'll just add 99 str to this enemy.
I tried it, it works, but just say it if you see any bug. :p
Again, SephirothSpawn, just tell me if there's a problem with this edit. :wink:
 

MicKo

Member

[ruby]# Troop Members Stat Mods
# SephirothSpawn, modified by MicKo
# 1.0
# 2010-04-05
 
module TMSM
  Mods = {}
  def self.stat_mod(troop_id, member_index, stat, value)
    if member_index == 'all'
      $data_troops[troop_id].members.each_index {|member|
        Mods[[troop_id, member, stat]] = value
      }
    else
      Mods[[troop_id, member_index, stat]] = value
    end
  end
end
 
class Game_Enemy
  alias_method :seph_tmsm_bmaxhp, :base_maxhp
  def base_maxhp
    return seph_tmsm_bmaxhp + (TMSM::Mods[[@troop_id, @member_index, 'maxhp']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'maxhp']])
  end
  alias_method :seph_tmsm_bmaxsp, :base_maxsp
  def base_maxsp
    return seph_tmsm_bmaxsp + (TMSM::Mods[[@troop_id, @member_index, 'maxsp']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'maxsp']])
  end
  alias_method :seph_tmsm_bstr, :base_str
  def base_str
    return seph_tmsm_bstr + (TMSM::Mods[[@troop_id, @member_index, 'str']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'str']])
  end
  alias_method :seph_tmsm_bdex, :base_dex
  def base_dex
    return seph_tmsm_bdex + (TMSM::Mods[[@troop_id, @member_index, 'dex']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'dex']])
  end
  alias_method :seph_tmsm_bagi, :base_agi
  def base_agi
    return seph_tmsm_bagi + (TMSM::Mods[[@troop_id, @member_index, 'agi']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'agi']])
  end
  alias_method :seph_tmsm_bint, :base_int
  def base_int
    return seph_tmsm_bint + (TMSM::Mods[[@troop_id, @member_index, 'int']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'int']])
  end
  alias_method :seph_tmsm_batk, :base_atk
  def base_atk
    return seph_tmsm_batk + (TMSM::Mods[[@troop_id, @member_index, 'atk']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'atk']])
  end
  alias_method :seph_tmsm_bpdef, :base_pdef
  def base_pdef
    return seph_tmsm_bpdef + (TMSM::Mods[[@troop_id, @member_index, 'pdef']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'pdef']])
  end
  alias_method :seph_tmsm_bmdef, :base_mdef
  def base_mdef
    return seph_tmsm_bmdef + (TMSM::Mods[[@troop_id, @member_index, 'mdef']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'mdef']])
  end
  alias_method :seph_tmsm_beva, :base_eva
  def base_eva
    return seph_tmsm_beva + (TMSM::Mods[[@troop_id, @member_index, 'eva']] == nil ? 0 : TMSM::Mods[[@troop_id, @member_index, 'eva']])
  end
end
[/ruby]
Scipt Call -> TMSM.stat_mod(1, 'all', 'str', 99) will increase all troop's members str by 99. Just replace 'all' by the member's ID when you don't want to change the entire troop.
 
okay. thanks guys. works pretty good. i have a question though. is there a way this can be used on a randomly generated troop? or a way without using the troop id thingy?

nvrmind. i made it work. but i'm curious as to how to make it works with this.
Code:
for i in $game_troop.enemies

if i.armor_id == 7

i.atk += 15

i.agi += 10  

i.str += 5  

end

end

how can i apply the mods to this?(i.atk += 15)
 

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