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.

Adding Variables to Weapons

Hello,

I started playing around with RGSS just recently and I'm still trying to figure a lot of it out. I added my own custom stats and got them all working how I want them to, however I'm trying to add code in to increase these stats on certain weapons. For example, I have "Mind" which increases the magic attack of the actor. I want certain weapons and pieces of armor to have different values of "Mind" on them.

Right now I have:

Code:
 

def base_mind

    # use this array as multipliers

    mval = [0, 1.2, 1.1, 0.25, 2.4]

        weapon_mod = { 31 => 30, 45 => 10 }

    # mulitply current level * array element for this actor

    mvalue = @level * mval[@actor_id]

    # give weapons mind attribute here

        if weapon_mod.has_key?(@weapon_id)

            mvalue += weapon_mod(@weapon_id)

        end

    return [mvalue, 999].min

  end

 

Am I doing something wrong here? It's saying undefined method for weapon_mod...

Thanks for your time!
 

Atoa

Member

Code:
class RPG::Weapon

 

  Weapon_Mind = { 31 => 30, 45 => 10 }

 

  def mind

    value = Weapon_Mind[@id].nil? ? 0 : Weapon_Mind[@id] #this check is done so you dont need to add equips with an 0 bonus.

    return value

  end

end

Do the same With RPG::Armor

Then, go to the Game_Actor and add the equip stat.

Code:
  def base_mind

    mval = [0, 1.2, 1.1, 0.25, 2.4]

    mvalue = @level * mval[@actor_id]

    weapon_mod = @weapon_id == 0 ? 0 : $data_weapons[@weapon_id].mind

    armor1_mod = @armor1_id == 0 ? 0 : $data_armors[@armor1_id].mind

    armor2_mod = @armor2_id == 0 ? 0 : $data_armors[@armor2_id].mind

    armor3_mod = @armor3_id == 0 ? 0 : $data_armors[@armor3_id].mind

    armor4_mod = @armor4_id == 0 ? 0 : $data_armors[@armor4_id].mind

    return mvalue +  weapon_mod + armor1_mod + armor2_mod + armor3_mod + armor4_mod 

  end
 
Another way you could go about this if you're using VX is using something like my Data Flag Reader snippet, which you can find in my signature. It works over the regular database, as you're working with notes, and will give you lots of possibilities without having you to do the dirty work you're trying to do now... with the additional benefit of being more lightweight on the script library, which adds to general overview :p
Obviously, you still have to include your methods that access the values you create via the flags. Your advantage here is that you can access the flags the (almost) 'regular' way.
 

Atoa

Member

@slayne61
It was probably an infinite loop caused by multiples methods, it return an error on an random like after sometime looping.

something like

Code:
def method_a

  method_b

end

 

def method_b

  method_c

end

 

def method_c

  method_a

end
It won't return an error direct on the methods that caused the error.
 

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