RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[TUTORIAL] How to Make a New Attribute

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
This is a basic tutorial on how to make a new attribute using Script editor and eventing.


1. Choose your Brand
First of all, you need to decide if your attribute is going to be level based, derived, or static. Static means the number doesn't change. Derived means some computation from existing attributes (like strength or intelligence or a combination of multiple attributes) creates the number in the program.

2. Choose a Name
You need a name for your attribute. I've found you want no less than three ways of addressing the attribute, since most attributes have a lot of abbreviations. For example, when I made 'Mind', it was also known as MIND, mnd, and MND in the search features.

Ctrl+SHIFT + F is your friend. This is how you find a string already existing in your script editor, no matter what section it is in.

3. Let's begin.

I. Open your RPGmaker XP project you intend to edit.
II. Hit F11. This should bring up the script editor.
III. Hit CTRL+SHIFT+F. This should bring up the "find in all sections" window.
IV. Type in "str" without the quotes, and hit ENTER.

You should see a list pop up.

V. Double click the one that says "@str_plus = 0"

This should move you to Game Battler 1, possibly somewhere around line 38. You might see something looking like this:

Code: [Select]
    @states_turn = {}
    @maxhp_plus = 0
    @maxsp_plus = 0
    @str_plus = 0
    @dex_plus = 0
    @agi_plus = 0
    @int_plus = 0


VI. Copy paste str_plus = 0 so you have something looking like this


Code: [Select]
    @states_turn = {}
    @maxhp_plus = 0
    @maxsp_plus = 0
    @str_plus = 0
    @str_plus = 0
    @dex_plus = 0
    @agi_plus = 0
    @int_plus = 0


This process is what I'm going to call Cloning. Not that anyone else would call it that, but hey, whatever.

VII. now change the part of your clone that says "str" to some other 3 letter abbreviation for your new wonder stat. I made a stat called "mind", and I chose the abrreviation "mnd". So mine looks something like this.


Code: [Select]
    @states_turn = {}
    @maxhp_plus = 0
    @maxsp_plus = 0
    @str_plus = 0
    @mnd_plus = 0
    @dex_plus = 0
    @agi_plus = 0
    @int_plus = 0


So far So good. Perhaps you will have a Cool stat abbreviated col_plus, or a speed stat abbreviated spd_plus. Whatever you choose, try to stick with three letters to make it easier to find.

VIII. Next, I put in what I call a Tracer, #Edited by shintashi

Code: [Select]
    @states_turn = {}
    @maxhp_plus = 0
    @maxsp_plus = 0
    @str_plus = 0
    @mnd_plus = 0 #Edited by shintashi
    @dex_plus = 0
    @agi_plus = 0
    @int_plus = 0


IX. Next,  CTRL+SHIFT+F again, type in 'str' again, and double click the one that says
"* Get Strength (STR)".

X. Clone the following section.

Code: [Select]
  #--------------------------------------------------------------------------
  # * Get Strength (STR)
  #--------------------------------------------------------------------------
  def str
    n = [[base_str + @str_plus, 1].max, 999].min
    for i in @states
      n *= $data_states[i].str_rate / 100.0
    end
    n = [[Integer(n), 1].max, 999].min
    return n
  end

so it looks like this

Code: [Select]
  #--------------------------------------------------------------------------
  # * Get Strength (STR)
  #--------------------------------------------------------------------------
  def str
    n = [[base_str + @str_plus, 1].max, 999].min
    for i in @states
      n *= $data_states[i].str_rate / 100.0
    end
    n = [[Integer(n), 1].max, 999].min
    return n
  end
  #--------------------------------------------------------------------------
  # * Get Strength (STR)
  #--------------------------------------------------------------------------
  def str
    n = [[base_str + @str_plus, 1].max, 999].min
    for i in @states
      n *= $data_states[i].str_rate / 100.0
    end
    n = [[Integer(n), 1].max, 999].min
    return n
  end

you will be doing your changes to the clone.

XI. Change all the 'str' values to your new abbreviation. In my case, with Mind, I changed all the str values to mind. Then I changed 'Get Strength (STR)' to Get Mind (MND), and added my tracer, as show below.

Code: [Select]
  #--------------------------------------------------------------------------
  # * Get Mind (MND) added by shintashi
  #--------------------------------------------------------------------------
  def mnd
    n = [[base_mnd + @mnd_plus, 1].max, 999].min
    for i in @states
      n *= 100 / 100.0
    end
    n = [[Integer(n), 1].max, 999].min
    return n
  end

Be careful not to miss anything.

XII. Next, you need to CTRL+SHIFT+F str again, and find the "* Set Strength (STR)" line, which should be somewhere in Game Battler 1, around lines 140-170.

Code: [Select]
#--------------------------------------------------------------------------
  # * Set Strength (STR)
  #     str : new Strength (STR)
  #--------------------------------------------------------------------------
  def str=(str)
    @str_plus += str - self.str
    @str_plus = [[@str_plus, -999].max, 999].min
  end

XIII. Clone it, and adjust the str figures again to reflect your new attribute. Here's my modified clone for Mind:

Code: [Select]
  #--------------------------------------------------------------------------
  # * Set Mind (MND)
  #     mnd : new Mind (MND)
  #--------------------------------------------------------------------------
  def mnd=(mnd)
    @mnd_plus += mnd - self.mnd
    @mnd_plus = [[@mnd_plus, -999].max, 999].min
  end   

XIV. Now you want to move out of Game Battler and into Game Actor. CTRL+SHIFT+F str again, and look for the line that says "@str_plus = 0" IN THE GAME ACTOR, NOT THE GAME BATTLER. Again you will want to clone your new stat, which will look virtually identical, except you will see a line that says

" # Learn skill" nearby in the game actor, whereas the game battler talks about "@hidden=false" and "@immortal=false". So if you do it right, yours might look something like this.

Code: [Select]
@maxsp_plus = 0
    @str_plus = 0
    @mnd_plus = 0 #mind attribute added by shintashi
    @dex_plus = 0
    @agi_plus = 0
    @int_plus = 0
    @hidden = false
    @immortal = false

XV. Now comes the tricky part. Scroll Down to the following line in Game Actor "* Get Basic Strength", probably around line 190-200.

You should see something like this.
Code: [Select]
  #--------------------------------------------------------------------------
  # * Get Basic Strength
  #--------------------------------------------------------------------------
  def base_str
    n = $data_actors[@actor_id].parameters[2, @level]
    weapon = $data_weapons[@weapon_id]
    armor1 = $data_armors[@armor1_id]
    armor2 = $data_armors[@armor2_id]
    armor3 = $data_armors[@armor3_id]
    armor4 = $data_armors[@armor4_id]
    n += weapon != nil ? weapon.str_plus : 0
    n += armor1 != nil ? armor1.str_plus : 0
    n += armor2 != nil ? armor2.str_plus : 0
    n += armor3 != nil ? armor3.str_plus : 0
    n += armor4 != nil ? armor4.str_plus : 0
    return [[n, 1].max, 999].min
  end

Now you can clone it, as per usual, but most of that stuff is going to be changed. Here's my version for Mind.

Code: [Select]
  #--------------------------------------------------------------------------
  # * Get Basic Mind by shintashi
  #--------------------------------------------------------------------------
  def base_mnd
    n = 8
    return [[n, 1].max, 999].min
  end


and here's my version for Endurance
Code: [Select]
  #--------------------------------------------------------------------------
  # * Get Basic Endurance by shintashi
  #--------------------------------------------------------------------------
  def base_end
    n = 4 + Integer(base_str/2)
    return [[n, 1].max, 999].min
  end

and my version for Charisma in another game...

Code: [Select]
  #--------------------------------------------------------------------------
  # * Get Basic Faith - Added by shintashi
  #--------------------------------------------------------------------------
  def base_faith
      if $data_actors[@actor_id].class_id == 9 || $data_actors[@actor_id].class_id == 7
      return n = 1
    else
      return n = 0
    # item modifiers for holy symbols may be facilitated through var
    end
  end

So what's going on here? Why so many different versions of this code? Well, the answer is because this is the part where your attribute Brand (from step 1) comes into play. My Mind example is static - it's always '8' unless modified during play. Endurance is derived from strength - so if my actor's strength changes, their endurance also changes. This means i don't have to change the endurance stat directly through programming any more - strength will keep increasing it even if I do nothing else.

The Faith stat has two outcomes here, zero, and one. They are based on character classes - Paladins and Clerics have Faith by default, while the other classes, such as the Gunner or Mage, might not. It is up to you to decide how your attribute will advance, and who will have it, and how high it will start off. If you don't like the value, you can always change it later through events.

XVI. Now you have to define what your attribute is going to do. If it's not going to do anything but look pretty, you can skip this section. Otherwise, stick with me. Here's two examples of random code that have been edited.
Quote from: Mind for mdef
  #--------------------------------------------------------------------------
  # * Get Basic Magic Defense # mind will be used here.
  #--------------------------------------------------------------------------
  def base_mdef
    weapon = $data_weapons[@weapon_id]
    armor1 = $data_armors[@armor1_id]
    armor2 = $data_armors[@armor2_id]
    armor3 = $data_armors[@armor3_id]
    armor4 = $data_armors[@armor4_id]
    mdef1 = weapon != nil ? weapon.mdef : 0
    mdef2 = armor1 != nil ? armor1.mdef : 0
    mdef3 = armor2 != nil ? armor2.mdef : 0
    mdef4 = armor3 != nil ? armor3.mdef : 0
    mdef5 = armor4 != nil ? armor4.mdef : 0
    return mdef1 + mdef2 + mdef3 + mdef4 + mdef5 + base_mnd #by shintashi
  end


Quote from: speed for Eva
  #--------------------------------------------------------------------------
  # * Get Basic Evasion Correction # speed will be used here
  #--------------------------------------------------------------------------
  def base_eva
    armor1 = $data_armors[@armor1_id]
    armor2 = $data_armors[@armor2_id]
    armor3 = $data_armors[@armor3_id]
    armor4 = $data_armors[@armor4_id]
    eva1 = armor1 != nil ? armor1.eva : 0
    eva2 = armor2 != nil ? armor2.eva : 0
    eva3 = armor3 != nil ? armor3.eva : 0
    eva4 = armor4 != nil ? armor4.eva : 0
    return eva1 + eva2 + eva3 + eva4 +base_spd #by shintashi
  end

Clearly, you can do a wide variety of things this way, depending on your programming skill.

XVII. You are almost done. You are now going to add this attribute to your Status menu, so you can prove to yourself and your friends that it actually exists. CTRL+SHIFT+F a phrase called "      parameter_name = $data_system.words.str". It should be located in Window_Base, around lines 270-300. It should look like this.
Code: [Select]
    when 3
      parameter_name = $data_system.words.str
      parameter_value = actor.str

you want to clone the last "when (number)" and change it to that number +1, so you have something like this.

Code: [Select]
    when 6
      parameter_name = $data_system.words.int
      parameter_value = actor.int
    when 7
      parameter_name = $data_system.words.mnd
      parameter_value = actor.mnd

XVIII. Now you want to change your "$data_system.words.(your attribute abbreviation)" to a Quote, and that quote is the full name of your attribute, either Upper or lower case. My mind stat looks like this:

Code: [Select]
    when 6
      parameter_name = $data_system.words.int
      parameter_value = actor.int
    when 7
      parameter_name = "Mind"
      parameter_value = actor.mnd

That's because the names are normally pulled from the Database, but you aren't editing the database and there's no happy name slot waiting for your mysterious new attribute in database/system. Sucks for you, so you have to type in a new word, like       parameter_name = "Speed", or       parameter_name = "Doom Power" etc. The important thing to remember, is the fact that it will take up space on your status menu, so if it's really long, like parameter_name = "Power to destroy all who stand in my way", the words are going to overlap each other in your menu.

XIX. Almost finished, you need to clean up your Status menu so it can display this new "when 7". By the way, you can only get about 20-26 extra attributes this way. After that you need to start adding attribute parameter stuff that's very complex.

CTRL+SHIFT+F for "draw_actor_parameter" and double click on the line that says

"draw_actor_parameter(@actor, 96, ..." in Window_Status, around lines 30-40.

You will want to change what probably looks like this:
Code: [Select]
    draw_actor_parameter(@actor, 96, 192, 0)
    draw_actor_parameter(@actor, 96, 224, 1)
    draw_actor_parameter(@actor, 96, 256, 2)
    draw_actor_parameter(@actor, 96, 304, 3)
    draw_actor_parameter(@actor, 96, 336, 4)
    draw_actor_parameter(@actor, 96, 368, 5)
    draw_actor_parameter(@actor, 96, 400, 6)
   

into something more like this:
Code: [Select]
   draw_actor_parameter(@actor, 96, 192, 0)
    draw_actor_parameter(@actor, 96, 224, 1)
    draw_actor_parameter(@actor, 96, 256, 2)
    draw_actor_parameter(@actor, 96, 320, 3)
    draw_actor_parameter(@actor, 96, 352, 4)
    draw_actor_parameter(@actor, 96, 384, 5)
    draw_actor_parameter(@actor, 96, 416, 6)
    draw_actor_parameter(@actor, 96, 288, 7)

DEFINITELY play with the numbers 96, 192-400, these are X and Y coordinates in pixels of where your text appears in the actor's status menu. There are lots of tutorials explaining how to rearrange these tables, but they are just text, and have no impact on the game other than looks. I recommend messing with other coordinates in Windows_Status in case you want longer names, multiple character classes, more or less equipment, larger icons, etc.

Good Luck !
« Last Edit: November 16, 2010, 02:31:46 AM by shintashi »