Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Class Dependent Stat Bonuses On Level Up, Be a slave to the parameter curve no more!
BigEd781
post Sep 20 2008, 07:48 PM
Post #1


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




Class Dependent Stat Bonuses On Level Up
Version: 1.0
Author: BigEd781
Release Date



Introduction
This script allows you to define parameter bonuses for an actor based on the their class when they gain a level.
You can choose to use constants that are predefined, or you can write your own algorithms if you know some ruby.

Configuration / Use
The script uses constant values for stat bonuses by default. This can be changed by editing the first line of code in the script:
CODE
USE_CONSTANT_MODIFIERS = true

Setting that to false will change tell the script to use custom made algorithms to determine each stat bonus. That is for people who know ruby and will be discussed later.

Using Constant Values
[Show/Hide] directions

If the first line of code is set to true, a hash will be used to determine the stat bonuses for each class. For example:
CODE
#======================================================================
    # * Class ID 1  
    #----------------------------------------------------------------------
    #   default : Paladin Stat Modifiers
    #======================================================================    
    1  =>  {"maxhp" => 20,
            "maxmp" =>  0,
            "atk"   =>  2,
            "def"   =>  3,
            "spi"   =>  3,
            "agi"   =>  0},


This piece of code holds the stat values for Class ID 1, Paladin by default. All you will be interested in editing are the numbers after the "=>" symbols. That is the bonus that will be given to the stat on the left when a player of Paladin class (Class ID 1) gains a level. There is a chink like that for each of the 8 default classes. If/when you need to add another class, you will need to copy one of these code chunks and paste in into the hash. You want to paste it here:
CODE
#======================================================================
    # * Class ID 8 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : Thief
    #======================================================================                              
    8  =>  {"maxhp" => 12,
            "maxmp" =>  0,
            "atk"   =>  2,
            "def"   =>  2,
            "spi"   =>  0,
            "agi"   => 11}
    #<--- RIGHT HERE!        
    } #End


I know that's not the greatest, I may try and make that easier soon.


Using Your Own Algorithms
[Show/Hide] directions

If you know some ruby and would like to do more than use simple constant bonus values, you can accomplish this. I did not write any algorithms, but I set up the framework for you, you just need to fill in the logic. Begin by setting the constant "USE_CONSTANT_MODIFIERS" to false at the top of the script. Now you can look at sub-section 2 in the script, about half way down. Here you will find a class named "BonusManager". This class has five methods:

CODE
alter_maxhp(actor)
alter_maxmp(actor)
alter_atk(actor)
alter_def(actor)
alter_spi(actor)
alter_agi(actor)

All of those take an actor object as an argument, but you don't need to call it, just know that you have it available to you. In these methods are empty "case" statments, like this one:

CODE
case actor.class_id
        when @PALADIN
          
        when @WARRIOR
          
        when @PRIEST
          
        when @MAGICIAN
          
        when @KNIGHT
          
        when @DARK_KNIGHT
          
        when @GRAPPLER
          
        when @THIEF
          
      end


Insert your code in here and define the behavior for each class. You will be doing most of the work, but everything else is done for you.




Script

You can download this as text here. Attached File  class_stats.txt ( 11.78K ) Number of downloads: 103


CODE
#==========================================================================
#                 BigEd781's Class Dependant Stat Bonuses
#--------------------------------------------------------------------------
#     The prupose of this script is to allow one to set stat
#     bonuses upon level up depending on the player's class.
#==========================================================================
# * When the below value is set to "true", the table of constant values
#   below it are used to determine what the level bonuses are, depending
#   on the class.  If you would like to define your own algorithms to
#   determine stat bonuses, set this to false and scroll to sub-section 2.
#==========================================================================
USE_CONSTANT_MODIFIERS = true
#==========================================================================
# * Sub-section 1
#--------------------------------------------------------------------------
#   This is the section of code that is used if
#   USE_CONSTANT_MODIFIERS == false.
#==========================================================================
if USE_CONSTANT_MODIFIERS
  #========================================================================
  # * Configuration module
  #------------------------------------------------------------------------
  #   Only used when USE_CONSTANT_MODIFIERS above is set to "true"
  #
  #========================================================================  
  module ClassStatBonusConfig  
    
    STAT_MODIFIERS = {
    #======================================================================
    # * Class ID 1  
    #----------------------------------------------------------------------
    #   default : Paladin Stat Modifiers
    #======================================================================    
    1  =>  {"maxhp" => 20,
            "maxmp" =>  0,
            "atk"   =>  2,
            "def"   =>  3,
            "spi"   =>  3,
            "agi"   =>  0},
    #======================================================================
    # * Class ID 2 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : Warrior
    #======================================================================                              
    2  =>  {"maxhp" => 29,
            "maxmp" =>  0,
            "atk"   =>  4,
            "def"   =>  5,
            "spi"   =>  0,
            "agi"   =>  2},      
    #======================================================================
    # * Class ID 3 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : Priest
    #======================================================================                              
    3  =>  {"maxhp" =>  0,
            "maxmp" => 19,
            "atk"   =>  0,
            "def"   =>  0,
            "spi"   =>  6,
            "agi"   =>  0},
    #======================================================================
    # * Class ID 4 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : Magician
    #======================================================================                              
    4  =>  {"maxhp" =>  0,
            "maxmp" => 26,
            "atk"   =>  0,
            "def"   =>  0,
            "spi"   => 11,
            "agi"   =>  0},  
    #======================================================================
    # * Class ID 5 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : Knight
    #======================================================================                              
    5  =>  {"maxhp" => 26,
            "maxmp" =>  0,
            "atk"   =>  8,
            "def"   =>  6,
            "spi"   =>  1,
            "agi"   =>  2},  
    #======================================================================
    # * Class ID 6 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : DarkKnight
    #======================================================================                              
    6  =>  {"maxhp" => 32,
            "maxmp" =>  3,
            "atk"   =>  7,
            "def"   =>  6,
            "spi"   =>  4,
            "agi"   =>  2},    
    #======================================================================
    # * Class ID 7 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : Grappler
    #======================================================================                              
    7  =>  {"maxhp" => 34,
            "maxmp" =>  0,
            "atk"   => 11,
            "def"   =>  2,
            "spi"   =>  0,
            "agi"   =>  3},  
    #======================================================================
    # * Class ID 8 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : Thief
    #======================================================================                              
    8  =>  {"maxhp" => 12,
            "maxmp" =>  0,
            "atk"   =>  2,
            "def"   =>  2,
            "spi"   =>  0,
            "agi"   => 11}
            
    } #End
                                            
  end
  #==========================================================================
  # * Game_Actor
  #--------------------------------------------------------------------------
  #   aliased the "change_exp" method
  #==========================================================================  
  class Game_Actor < Game_Battler
    
    include ClassStatBonusConfig    
    alias :eds_old_pre_stat_mod_change_exp :change_exp  
    def change_exp(exp, show)  
          last_level = self.level
          eds_old_pre_stat_mod_change_exp(exp, show)
          if self.level > last_level      
            (0...(self.level - last_level)).each {
              self.maxhp += STAT_MODIFIERS[class_id]["maxhp"]
              self.maxmp += STAT_MODIFIERS[class_id]["maxmp"]          
              self.atk += STAT_MODIFIERS[class_id]["atk"]              
              self.def += STAT_MODIFIERS[class_id]["def"]      
              self.spi += STAT_MODIFIERS[class_id]["spi"]
              self.agi += STAT_MODIFIERS[class_id]["agi"]
            }        
          end
        end
        
  end

else  #USE_CONSTANT_MODIFIERS == false
#==========================================================================
# * Sub-section 2
#--------------------------------------------------------------------------
#   This is the section of code that is used if
#   USE_CONSTANT_MODIFIERS == True.
#==========================================================================  
#--------------------------------------------------------------------------
#==========================================================================
# * BonusManager Class Implementation
#--------------------------------------------------------------------------
#   This class holds all of the logic that is used to determine
#   and award stat bonuses if you are using your own algorithms.
#
#   To define your algorithms, simply fill in the "case" statement
#   blocks below.  
#==========================================================================
  class BonusManager

    def initialize
      @PALADIN     = 1
      @WARRIOR     = 2
      @PRIEST      = 3
      @MAGICIAN    = 4
      @KNIGHT      = 5
      @DARK_KNIGHT = 6
      @GRAPPLER    = 7
      @THIEF       = 8
    end    
    #----------------------------------------------------------------------
    # * Functions to change Max HP
    #----------------------------------------------------------------------
    def alter_maxhp(actor)
      case actor.class_id
        when @PALADIN
          
        when @WARRIOR
          
        when @PRIEST
          
        when @MAGICIAN
          
        when @KNIGHT
          
        when @DARK_KNIGHT
          
        when @GRAPPLER
          
        when @THIEF
          
      end
    end
    #----------------------------------------------------------------------
    # * Functions to change Max MP
    #----------------------------------------------------------------------
    def alter_maxmp(actor)
      case actor.class_id
        when @PALADIN
          
        when @WARRIOR
          
        when @PRIEST
          
        when @MAGICIAN
          
        when @KNIGHT
          
        when @DARK_KNIGHT
          
        when @GRAPPLER
          
        when @THIEF
          
      end
    end
    #----------------------------------------------------------------------
    # * Functions to change ATK
    #----------------------------------------------------------------------
    def alter_atk(actor)
      case actor.class_id
        when @PALADIN
          
        when @WARRIOR
          
        when @PRIEST
          
        when @MAGICIAN
          
        when @KNIGHT
          
        when @DARK_KNIGHT
          
        when @GRAPPLER
          
        when @THIEF
          
      end
    end
    #----------------------------------------------------------------------
    # * Functions to change DEF
    #----------------------------------------------------------------------
    def alter_def(actor)
      case actor.class_id
        when @PALADIN
          
        when @WARRIOR
          
        when @PRIEST
          
        when @MAGICIAN
          
        when @KNIGHT
          
        when @DARK_KNIGHT
          
        when @GRAPPLER
          
        when @THIEF
          
      end
    end
    #----------------------------------------------------------------------
    # * Functions to change SPI
    #----------------------------------------------------------------------
    def alter_spi(actor)
      case actor.class_id
        when @PALADIN
          
        when @WARRIOR
          
        when @PRIEST
          
        when @MAGICIAN
          
        when @KNIGHT
          
        when @DARK_KNIGHT
          
        when @GRAPPLER
          
        when @THIEF
          
      end
    end
    #----------------------------------------------------------------------
    # * Functions to change AGI
    #----------------------------------------------------------------------
    def alter_agi(actor)
      case actor.class_id
        when @PALADIN
          
        when @WARRIOR
          
        when @PRIEST
          
        when @MAGICIAN
          
        when @KNIGHT
          
        when @DARK_KNIGHT
          
        when @GRAPPLER
          
        when @THIEF
          
      end
    end
      
  end
  #==========================================================================
  # * Game_Actor
  #--------------------------------------------------------------------------
  #   aliased the "change_exp" method
  #==========================================================================  
  class Game_Actor < Game_Battler
    
    alias :eds_old_pre_stat_mod_change_exp :change_exp  
    def change_exp(exp, show)  
      last_level = self.level
      eds_old_pre_stat_mod_change_exp(exp, show)
      if self.level > last_level
        bonus_manager = BonusManager.new
        bonus_manager.alter_maxhp(self)
        bonus_manager.alter_maxmp(self)
        bonus_manager.alter_atk(self)
        bonus_manager.alter_def(self)
        bonus_manager.alter_spi(self)
        bonus_manager.alter_agi(self)
      end
    end
    
  end

end  #end USE_CONSTANT_MODIFIERS check



Compatibility
You will need to make some additions if you are using a script which gives you more than the six default stats. You will need to add a new row to each of the hashes if you are using constant bonuses, like this:

CODE

#======================================================================
    # * Class ID 6 Stat Modifiers
    #----------------------------------------------------------------------
    #   default : DarkKnight
    #======================================================================                              
    6  =>  {"maxhp" => 32,
            "maxmp" =>  3,
            "atk"   =>  7,
            "def"   =>  6,
            "spi"   =>  4,
            "agi"   =>  2
            "newstat"   => 3},


Now you need to add a line to the function change_exp. Add something like this at line 120:
Beside that I do not see any potential problems, but if you find one be sure to let me know.

CODE
self.newstat += STAT_MODIFIERS[class_id]["newstat"]


Installation
Just place it above main in the materials section.

Terms and Conditions
None. Do what you like.[attachment=1679:delete.txt]


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Shadonn
post Sep 20 2008, 07:56 PM
Post #2


Level 6
Group Icon

Group: Member
Posts: 81
Type: Writer
RM Skill: Undisclosed




So will each class have it's own stats. Example: Warrior has no MP and gets up 9999 Hp but when they switch to White Mage they have up to 9999 Mp but only 5067 Hp. Am I right?


__________________________
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 20 2008, 08:00 PM
Post #3


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




No. That is a good point though, because that is exactly what would happen if you directly changed their parameter curves. All this does is add to their respective values every time a level is gained. When they switch class they will get a different set of bonuses.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Shadonn
post Sep 20 2008, 08:11 PM
Post #4


Level 6
Group Icon

Group: Member
Posts: 81
Type: Writer
RM Skill: Undisclosed




Example: Warrior levels up and hp goes up by 50, however when White Mage when he levels up he gets 34 Hp. Is that right?


__________________________
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 20 2008, 08:14 PM
Post #5


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




OK, all this does is give a bonus to a stat. The actor still uses their base stat curve values, but these are an added bonus. If the actor was a Magician and would normally have 20 spirit on lv 2, they would now have 31 because they got a +11 bonus to spirit when they gained a level. If they switch class nothing will change, only the bonuses that they receive from now on.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Shadonn
post Sep 20 2008, 08:22 PM
Post #6


Level 6
Group Icon

Group: Member
Posts: 81
Type: Writer
RM Skill: Undisclosed




Ahh ok. Sorry it's like 12 o' clock where I am. Great script btw. You always do make good ones and you've always helped me. Thanks smile.gif


__________________________
Go to the top of the page
 
+Quote Post
   
NOWAYLARRY
post Sep 21 2008, 07:56 AM
Post #7


Level 5
Group Icon

Group: Member
Posts: 61
Type: Developer
RM Skill: Intermediate




This may just be a dumb question but, how would you go about making a stat. increase of let's say +6 STR each level to a number like 5,6 or 7. One of the three selected at random each time you level up.
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 21 2008, 12:46 PM
Post #8


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




Glad you asked NOWAYLARRY. I have provided two ways of awarding bonuses; constants (the default), or through a function. I explain all of this in the Configuration / Use section. Basically, you set the first line of code to "false", and then scroll to section two and write your own algorithms. It is not the most user friendly, but if you know even a little ruby it is not difficult.

To get a random number, you can write a line like this in one of the switch statements for "attack" (alter_atk):

CODE
return 5 + rand(2)


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Rukaroa
post Sep 28 2008, 08:25 PM
Post #9


Level 4
Group Icon

Group: Member
Posts: 52
Type: Event Designer
RM Skill: Beginner




I just tried this script today and I'm getting a couple of problems.

When USE_CONSTANT_MODIFIERS = true, this error shows up:
Attached File  Untitled_1.png ( 10.29K ) Number of downloads: 15


When USE_CONSTANT_MODIFIERS = false, returning any value doesn't add to the stats. In fact, it doesn't seem to run at all.

Other info:
Using KGC scripts in the order that My. Anonymous has it.
Putting the script just below KGC_PassiveSkills.


__________________________
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 28 2008, 08:42 PM
Post #10


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




Can you tell me what is on line 134 of my script in your game? That error could not have been thrown right there, so perhaps some of he script did not get copied. I tested this in the KGC demo. If you do have the correct script I can try a few more things.

Also, if USE_CONSTANT_MODIFIERS is set to false, you need to program each of the routines yourself. As they are by default they do nothing.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Rukaroa
post Sep 28 2008, 08:51 PM
Post #11


Level 4
Group Icon

Group: Member
Posts: 52
Type: Event Designer
RM Skill: Beginner




QUOTE (BigEd781 @ Sep 28 2008, 11:04 PM) *
Can you tell me what is on line 134 of my script in your game? That error could not have been thrown right there, so perhaps some of he script did not get copied. I tested this in the KGC demo. If you do have the correct script I can try a few more things.

Also, if USE_CONSTANT_MODIFIERS is set to false, you need to program each of the routines yourself. As they are by default they do nothing.


It'd be this line:

self.maxhp += STAT_MODIFIERS[class_id]["maxhp"]

I downloaded it straight from the link in the first post.

I'm also using some of stars scripts, but I don't see how that would throw off anything.

This post has been edited by Rukaroa: Sep 28 2008, 08:53 PM


__________________________
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 28 2008, 08:52 PM
Post #12


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




*embarrassed * I had an old version. I'll fix it, let me take a look.

EDIT: I just tried it again and it works fine with all of the KGC scripts and it worked fine. I put it right after PassiveSkills and it still worked. The only ting that I can think of is that you modified the config portion and removed the "maxhp" key. Did you remove the "maxhp" key from any of the class hash tables? If not, could you post your entire script for me (assuming that you made a modification. if you didn't, I could use your project because I can't seem to replicate the problem).


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Rukaroa
post Sep 28 2008, 09:05 PM
Post #13


Level 4
Group Icon

Group: Member
Posts: 52
Type: Event Designer
RM Skill: Beginner




I left it alone as it was. I'm not exactly sure what's going on myself since I didn't see anything wrong with the coding.

I should've added that it only happens during level up either by battle, exp event, or level up event.

If the result can't still be replicated, I'll may give you a copy of my project.


__________________________
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 28 2008, 09:09 PM
Post #14


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




It's weird, because it is saying that there is no object being returned when using a key of "maxhp", and that is defined in a module and should never have compatibility problems. If you want to get me your project I would be happy to look at it.

Actually, it may be better for you to just post your script, I don't think this is a compatibility issue.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Rukaroa
post Sep 28 2008, 09:23 PM
Post #15


Level 4
Group Icon

Group: Member
Posts: 52
Type: Event Designer
RM Skill: Beginner




Sent. I had to trim some stuff in there (private scripts, images, etc), but as far as I know, the error still shows after the trimming.


__________________________
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 28 2008, 09:45 PM
Post #16


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




OK, so I know why this is happening. There is unfortunately an aspect of this script that is not user friendly. By default, it has constant values defined for the 7 default class. When you add a class, you need to add a map from the class id to the stats. If you look at the Configuration/Use section above and expand the "Using Constant Values" part, it explains how to do this.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Rukaroa
post Sep 28 2008, 09:52 PM
Post #17


Level 4
Group Icon

Group: Member
Posts: 52
Type: Event Designer
RM Skill: Beginner




How about for algorithms? It doesn't seem like you need to add character classes into the script, but the values returned from the algorithms don't seem to add into the actors. At least when a value is supposed to be returned anyway.

Say I enter this for the algorithm:

QUOTE
def alter_maxhp(actor)
case actor.class_id
when @PALADIN
return 50

end
end


That 50 HP is never added to the maxhp on level up for whoever has class_id number 1.

This post has been edited by Rukaroa: Sep 28 2008, 09:59 PM


__________________________
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 28 2008, 10:09 PM
Post #18


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




Because you don't specify a return value, you modify it directly in the when statement. perhaps this is a bit confusing, it would be easy to change. In your example, you would want this:

CODE
def alter_maxhp(actor)
  case actor.class_id
    when @PALADIN
      actor.maxhp += 50
    when @Warrior
      ...


I think that it would be better to simply specify a return value, because then you don't need to know how to alter the attributes directly. I will change it to work that way when I get time.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   
Rukaroa
post Sep 28 2008, 10:14 PM
Post #19


Level 4
Group Icon

Group: Member
Posts: 52
Type: Event Designer
RM Skill: Beginner




Thanks for the trouble. Honestly though, it would've helped to have some concrete examples for both parts in the script so that it would've been easier to follow.


__________________________
Go to the top of the page
 
+Quote Post
   
BigEd781
post Sep 28 2008, 10:19 PM
Post #20


No method: 'stupid_title' found for `nil:NilClass'
Group Icon

Group: Revolutionary
Posts: 1,829
Type: Scripter
RM Skill: Undisclosed




well, the first part was clearly explained in the configuration/Use portion and there is nothing more to be added. I will admit that the second part is lacking a bit, but I only expected scripters to mess around with that and they would realize that they were passed an actor object. They may want to use actor parameters in their calculations.

I admit that it's not the most user friendly script out there, but it's tough because I have no way of knowing what stat bonuses you want to give to what class, so some editing is required.


__________________________
`
Give me teh codez!!!


I am the master debator!
Go to the top of the page
 
+Quote Post
   

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 20th May 2013 - 07:12 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker