Class-Actor-Skill Hybrid?

Started by shintashi, October 06, 2011, 09:46:57 pm

Previous topic - Next topic

shintashi

October 06, 2011, 09:46:57 pm Last Edit: October 06, 2011, 09:51:34 pm by shintashi
I'm working on something right now that is a thingamabob that actors can have (and maybe some NPCs or enemies), that is basically a meta skill container that has the following attributes


attr_accessor :id                       # technique ID
 attr_accessor :name                     # e.g. Black Magic, Dodge, Rifles
 attr_accessor :multiplier               # e.g x1, x2, ...x9, etc.
 attr_accessor :exp                      # total exp earned
 attr_accessor :physical                 # true or false
 attr_accessor :magical                  # true or false
 attr_accessor :level                    # level
 attr_accessor :skills                   # skills/options from main
 attr_accessor :description              # help window description
 



Essentially it's a container for multiple "single action" skills (like fire, mass fire, ice, greater ice, etc.), but it also has levels and experience points, allowing players to buy up levels in it. The multiplier is the cost multiplier for buying each level. For example, learning "weapons" might have a much higher cost than "swords", because it includes swords.

The mess I have so far is as follows, and I'm aware it won't work. I'd like some help fixing the most obvious mistakes and get a clunky version working before I mess with it further. One of the problems I'm foreseeing is not knowing how to subordinate it to actors, so that each actor's version is unique to them.




#==============================================================================
# ** Game_Technique
#------------------------------------------------------------------------------
#  This class handles the Techniques. It's used within the Game_Actors class
#  ($game_actors) and refers to the Technique class.
#==============================================================================

class Game_Technique
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :id                       # technique ID
 attr_accessor :name                     # e.g. Black Magic, Dodge, Rifles
 attr_accessor :multiplier               # e.g x1, x2, ...x9, etc.
 attr_accessor :exp                      # total exp earned
 attr_accessor :physical                 # true or false
 attr_accessor :magical                  # true or false
 attr_accessor :level                    # level
 attr_accessor :skills                   # skills, spells, merits, flaws
 attr_accessor :description              # help window description
 
 #--------------------------------------------------------------------------
 # * Object Initialization
 #     tech_id : tech ID
 #--------------------------------------------------------------------------
 def initialize(tech_id)
   super()
   setup(tech_id)
 end
 #--------------------------------------------------------------------------
 # * Setup
 #     tech_id : tech ID
 #--------------------------------------------------------------------------
 def setup(tech_id)
   tech = $game_technique[tech_id] #this isn't going to work - needs actor
   @tech_id = tech_id
   @name = tech.name
   @level = tech.initial_level
   @exp_list = Array.new(101)
   make_exp_list
   @exp = @exp_list[@level]
   @skills = []
 end
 #--------------------------------------------------------------------------
 # * Get Tech ID
 #--------------------------------------------------------------------------
 def id
   return @tech_id
 end
 #--------------------------------------------------------------------------
 # * Get Tech Multiplier # needs revision to 0 + ...0.1+ 0.2 +x9...etc.
 #--------------------------------------------------------------------------
 def multiplier
   return @multiplier
 end
 #--------------------------------------------------------------------------
 # * Get Index
 #--------------------------------------------------------------------------
 def index
   return @data[self.index]
 end
 #--------------------------------------------------------------------------
 # * Calculate EXP
 #--------------------------------------------------------------------------
   def make_exp_list
   tech = $data_technique[@tech_id]
   @exp_list[1] = 0
   for i in 2..100
     if i > tech.final_level
       @exp_list[i] = 0
     else
@exp_list[i] = @tech.multiplier *(i * 0.5) * (i + 1)
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Get EXP String
 #--------------------------------------------------------------------------
 def exp_s
   return @exp_list[@level+1] > 0 ? @exp.to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Get Next Level EXP String
 #--------------------------------------------------------------------------
 def next_exp_s
   return @exp_list[@level+1] > 0 ? @exp_list[@level+1].to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Get Until Next Level EXP String
 #--------------------------------------------------------------------------
 def next_rest_exp_s
   return @exp_list[@level+1] > 0 ?
     (@exp_list[@level+1] - @exp).to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Change EXP
 #     exp : new EXP
 #--------------------------------------------------------------------------
 def exp=(exp)
   @exp = [[exp, 99999].min, 0].max
   # Level up
   while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
     @level += 1
#====================================================================      
# NEEDS HEAVY REVISION CF SKILL WINDOW
     # Learn skill
     for j in $data_classes[@class_id].learnings
       if j.level == @level
         learn_skill(j.skill_id)
       end
     end
   end
#====================================================================    
   # Level down
   while @exp < @exp_list[@level]
     @level -= 1
   end
 end
 #--------------------------------------------------------------------------
 # * Change Level
 #     level : new level
 #--------------------------------------------------------------------------
 def level=(level)
   # Check up and down limits - NEEDS REVISION
   level = [[level, $data_actors[@actor_id].final_level].min, 1].max
   # Change EXP
   self.exp = @exp_list[level]
 end
 #--------------------------------------------------------------------------
 # * Learn Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def learn_skill(skill_id)
   if skill_id > 0 and not skill_learn?(skill_id)
     @skills.push(skill_id)
     @skills.sort!
   end
 end
 #--------------------------------------------------------------------------
 # * Forget Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def forget_skill(skill_id)
   @skills.delete(skill_id)
 end
 #--------------------------------------------------------------------------
 # * Determine if Finished Learning Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def skill_learn?(skill_id)
   return @skills.include?(skill_id)
 end
 #--------------------------------------------------------------------------
 # * Determine if Skill can be Used
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def skill_can_use?(skill_id)
   if not skill_learn?(skill_id)
     return false
   end
   return super
 end
 #--------------------------------------------------------------------------
 # * Change Name #comes in handy when creating custom techniques
 #     name : new name
 #--------------------------------------------------------------------------
 def name=(name)
   @name = name
 end
   #--------------------------------------------------------------------------
 # * Change Description #comes in handy when creating custom techniques
 #     description : new description
 #--------------------------------------------------------------------------
 def description=(description)
   @description = description
 end
end





I envision calling parts of it by saying something like


p $game_actors[11].tech[4].name
p $game_actors[11].tech[4].level


with

p $game_actors[11].tech[4]


looking similar but smaller than what is normally spat out when you type something like


p $game_actors[11]




and have yet to figure out the window interface, since I originally came up with this idea with a mouse in mind and clicking on an expand icon for details in a list, similar to a text based linear skill tree or list. For now, I just want the thing to exist, and worry about interfacing and windows later.


shintashi

October 07, 2011, 12:08:44 am #1 Last Edit: October 07, 2011, 12:50:10 am by shintashi
I've revised some stuff as seen below, it still doesn't work, but I've been thinking of it sort of like a hash. I wanted some stock techniques that could be built into the system, but then you would have the option of developing your own. While that's the main point - inventing your own class abilities, the idea that some basic functions exist seems paramount.


#==============================================================================
# ** Game_Technique
#------------------------------------------------------------------------------
#  This class handles the Techniques. It's used within the Game_Actors class
#  ($game_actors) and refers to the Technique class.
#==============================================================================

class Game_Technique
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :id                       # technique ID
 attr_accessor :name                     # e.g. Black Magic, Dodge, Rifles
 attr_accessor :multiplier               # e.g x1, x2, ...x9, etc.
 attr_accessor :exp                      # total exp earned
 attr_accessor :physical                 # true or false
 attr_accessor :magical                  # true or false
 attr_accessor :level                    # level
 attr_accessor :skills                   # skills, spells, merits, flaws
 attr_accessor :description              # help window description
 
 #--------------------------------------------------------------------------
 # * Stock Techniques
 #     tech_id : tech ID
 #--------------------------------------------------------------------------
 $game_technique[0].name = "Endurance" # Hit Points
 $game_technique[1].name = "Dodge"     # Dodge
 $game_technique[2].name = "Melee"     # Attack
 $game_technique[3].name = "Willforce" # Spell Points
 #--------------------------------------------------------------------------
 # * Object Initialization
 #     tech_id : tech ID
 #--------------------------------------------------------------------------
 def initialize(tech_id)
   super()
   setup(tech_id)
 end
 #--------------------------------------------------------------------------
 # * Setup
 #     tech_id : tech ID
 #--------------------------------------------------------------------------
 def setup(tech_id)
   tech = $game_technique[tech_id] #this isn't going to work - needs actor
   @tech_id = tech_id
   @name = tech.name
   @level = 0
   @multiplier = multiplier              
   @physical = false                
   @magical = false
   @description = ""              
   @exp_list = Array.new(101)
   make_exp_list
   @exp = @exp_list[@level]
   @skills = []
 end
 #--------------------------------------------------------------------------
 # * Get Tech ID
 #--------------------------------------------------------------------------
 def id
   return @tech_id
 end
 #--------------------------------------------------------------------------
 # * Get Tech Multiplier # needs revision to 0 + ...0.1+ 0.2 +x9...etc.
 #--------------------------------------------------------------------------
 def multiplier
   #i = self.id
   #n = 0 + (tech[i].skill[1].power + tech[i].skill[2].power * 0.1)
   #n = 0 + skill[1].power + skill[2].power + skill[3].power
   #return n
   return @multiplier
 end
 #--------------------------------------------------------------------------
 # * Get Index
 #--------------------------------------------------------------------------
 def index
   return @data[self.index]
 end
 #--------------------------------------------------------------------------
 # * Calculate EXP
 #--------------------------------------------------------------------------
   def make_exp_list
   tech = $data_technique[@tech_id]
   @exp_list[1] = 0
   for i in 2..100
     if i > tech.final_level
       @exp_list[i] = 0
     else
@exp_list[i] = @tech.multiplier *(i * 0.5) * (i + 1)
     end
   end
 end
 #--------------------------------------------------------------------------
 # * Get EXP String
 #--------------------------------------------------------------------------
 def exp_s
   return @exp_list[@level+1] > 0 ? @exp.to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Get Next Level EXP String
 #--------------------------------------------------------------------------
 def next_exp_s
   return @exp_list[@level+1] > 0 ? @exp_list[@level+1].to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Get Until Next Level EXP String
 #--------------------------------------------------------------------------
 def next_rest_exp_s
   return @exp_list[@level+1] > 0 ?
     (@exp_list[@level+1] - @exp).to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Change EXP
 #     exp : new EXP
 #--------------------------------------------------------------------------
 def exp=(exp)
   @exp = [[exp, 99999].min, 0].max
   # Level up
   while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
     @level += 1
#====================================================================      
# NEEDS HEAVY REVISION CF SKILL WINDOW
     # Learn skill
     for j in $data_classes[@class_id].learnings
       if j.level == @level
         learn_skill(j.skill_id)
       end
     end
   end
#====================================================================    
   # Level down
   while @exp < @exp_list[@level]
     @level -= 1
   end
 end
 #--------------------------------------------------------------------------
 # * Change Level
 #     level : new level
 #--------------------------------------------------------------------------
 def level=(level)
   # Check up and down limits - NEEDS REVISION
   level = [[level, $data_actors[@actor_id].final_level].min, 1].max
   # Change EXP
   self.exp = @exp_list[level]
 end
 #--------------------------------------------------------------------------
 # * Learn Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def learn_skill(skill_id)
   if skill_id > 0 and not skill_learn?(skill_id)
     @skills.push(skill_id)
     @skills.sort!
   end
 end
 #--------------------------------------------------------------------------
 # * Forget Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def forget_skill(skill_id)
   @skills.delete(skill_id)
 end
 #--------------------------------------------------------------------------
 # * Determine if Finished Learning Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def skill_learn?(skill_id)
   return @skills.include?(skill_id)
 end
 #--------------------------------------------------------------------------
 # * Determine if Skill can be Used
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def skill_can_use?(skill_id)
   if not skill_learn?(skill_id)
     return false
   end
   return super
 end
 #--------------------------------------------------------------------------
 # * Change Name #comes in handy when creating custom techniques
 #     name : new name
 #--------------------------------------------------------------------------
 def name=(name)
   @name = name
 end
   #--------------------------------------------------------------------------
 # * Change Description #comes in handy when creating custom techniques
 #     description : new description
 #--------------------------------------------------------------------------
 def description=(description)
   @description = description
 end
end




Well, I did some testing, and ended up testing it with a hash in the script editor...

$game_technique = {}
$game_technique[0] = ["Endurance", 1, 0, true, false, 0, [1, 2], "Hit Point Bonus"]


and was able to use an event to produce answers to all parts of my hash.

p $game_technique[0][0]
p $game_technique[0][1]
p $game_technique[0][2]
p $game_technique[0][3]
p $game_technique[0][4]
p $game_technique[0][5]
p $game_technique[0][6][0]
p $game_technique[0][6][1]
p $game_technique[0][7]


My concern is 1. getting the info inside the game actors, and 2. doing this all preferably without a hash (which I don't currently know how to do).

KK20

If you want to get these stored into the actors, you obviously are going to have to edit class Actor. Make an array that stores the ID numbers. If you're going to define every skill at each ID value, use 'case'.

Of course, I can't think like you so I'm just throwing out ideas.

-waits for someone to start bashing about your programming-

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

shintashi

October 07, 2011, 09:57:44 am #3 Last Edit: October 07, 2011, 09:59:03 am by shintashi
I was beginning to think id have to stick it in actor about 2-3am this morning, while mulling over this message to myself in my scrap notes:


$game_actor[n].tech[m][a][b][c]

n = actor number
m = technique number
a = technique attribute
b = skill number (assumes a = technique's "skill list")
c = skill attribute (assumes b = skill number)

I'm thinking skill list should probably be either the 1st, the second, or the last number, to avoid confusion. If it's the first, it will be zero, $game_actor[n].tech[m][0][skill_id][skill_attribute], but as a matter of form, perhaps name should come first.

if I prided myself in my programming skills I don't think I would be so quick to ask for help on this part of the project. Actually, statements like that are why I post so seldom in this forum.

Twb6543

This is similar to the goal I have for my script (VX), I currently haven't updated the topic recently but I have made progress on fulfilling the ultimate goal for it. You may wish to take a look at the non-updated script it might give you a few ideas on how to manage skills.

Script
If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.
The rest of them will write Perl programs.

shintashi

Quote from: Twb6543 on October 07, 2011, 10:45:52 am
This is similar to the goal I have for my script (VX), I currently haven't updated the topic recently but I have made progress on fulfilling the ultimate goal for it. You may wish to take a look at the non-updated script it might give you a few ideas on how to manage skills.

Script


while the script structures are different in VX, I did see some similarities for sure. We both have level at around 100 and have experience ranges and options. Right now I'm trying to figure out how to create both standardized "stock" techniques plus open, editable techniques. While I only envisioned each actor having between 2 and 4 main techniques with a lot of overlap (e.g. dodge) bringing each to about 5-10, the total number of techniques in the game was probably under 20.

I'm pretty certain now I should make the the techniques a part of the actor class, in some shape or form, rather than creating a new $data_techniques file.

ForeverZer0

class Game_Actor

  attr_accessor :techniques

  alias tech_init initialize(id)
  def initialize(id)
    @techniques = Game_Technique.new
    tech_init(id)
  end
end


I can't remember the exact args that go with Game_Actor, but you get the idea.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

KK20

I've played around with your script a bit. I did have to make a few edits to "Game_Techniques" because of the errors in initializing.
Spoiler: ShowHide
#==============================================================================
# ** Game_Technique
#------------------------------------------------------------------------------
#  This class handles the Techniques. It's used within the Game_Actors class
#  ($game_actors) and refers to the Technique class.
#==============================================================================

class Game_Technique
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :id                       # technique ID
  attr_accessor :name                     # e.g. Black Magic, Dodge, Rifles
  attr_accessor :multiplier               # e.g x1, x2, ...x9, etc.
  attr_accessor :exp                      # total exp earned
  attr_accessor :physical                 # true or false
  attr_accessor :magical                  # true or false
  attr_accessor :level                    # level
  attr_accessor :skills                   # skills, spells, merits, flaws
  attr_accessor :description              # help window description
 
  #--------------------------------------------------------------------------
  # * Stock Techniques
  #     tech_id : tech ID
  #--------------------------------------------------------------------------
  def techniques_data(id)
    # return [name, mult, exp, physical?, magical?, level, skills, desc]
    case id
    when 0 then return ["Endurance", 1, 0, true, false, 0, [1, 2], "Hit Point Bonus"]
    end
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     tech_id : tech ID
  #--------------------------------------------------------------------------
  def initialize(tech_id)
    tech = techniques_data(tech_id)
    @tech_id = tech_id
    @name = tech[0]
    @level = tech[5]
    @multiplier = tech[1]               
    @physical = tech[3]                 
    @magical = tech[4]
    @description = tech[7]             
    @exp_list = Array.new(101)
    make_exp_list
    @exp = tech[2]
    @skills = []
    tech[6].each{|id|
      @skills.push(id)
    }
    @skills.sort!
  end
  #--------------------------------------------------------------------------
  # * Get Tech ID
  #--------------------------------------------------------------------------
  def id
    return @tech_id
  end
  #--------------------------------------------------------------------------
  # * Get Tech Multiplier # needs revision to 0 + ...0.1+ 0.2 +x9...etc.
  #--------------------------------------------------------------------------
  def multiplier
    #i = self.id
    #n = 0 + (tech[i].skill[1].power + tech[i].skill[2].power * 0.1)
    #n = 0 + skill[1].power + skill[2].power + skill[3].power
    #return n
    return @multiplier
  end
  #--------------------------------------------------------------------------
  # * Get Index
  #--------------------------------------------------------------------------
  def index
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Calculate EXP
  #--------------------------------------------------------------------------
    def make_exp_list
    @exp_list[1] = 0
    for i in 2..100
      @exp_list[i] = @exp_list[i-1] + (@multiplier * (i / 2) * (i + 1))
    end
  end
  #--------------------------------------------------------------------------
  # * Get EXP String
  #--------------------------------------------------------------------------
  def exp_s
    return @exp_list[@level+1] > 0 ? @exp.to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Next Level EXP String
  #--------------------------------------------------------------------------
  def next_exp_s
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1].to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Until Next Level EXP String
  #--------------------------------------------------------------------------
  def next_rest_exp_s
    return @exp_list[@level+1] > 0 ?
      (@exp_list[@level+1] - @exp).to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Change EXP
  #     exp : new EXP
  #--------------------------------------------------------------------------
  def exp=(exp)
    @exp = [[exp, 99999].min, 0].max
    # Level up
    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
      @level += 1
#====================================================================     
# NEEDS HEAVY REVISION CF SKILL WINDOW
      # Learn skill
      for j in $data_classes[@class_id].learnings
        if j.level == @level
          learn_skill(j.skill_id)
        end
      end
    end
#====================================================================   
    # Level down
    while @exp < @exp_list[@level]
      @level -= 1
    end
  end
  #--------------------------------------------------------------------------
  # * Change Level
  #     level : new level
  #--------------------------------------------------------------------------
  def level=(level)
    # Check up and down limits - NEEDS REVISION
    level = [[level, $data_actors[@actor_id].final_level].min, 1].max
    # Change EXP
    self.exp = @exp_list[level]
  end
  #--------------------------------------------------------------------------
  # * Learn Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def learn_skill(skill_id)
    if skill_id > 0 and not skill_learn?(skill_id)
      @skills.push(skill_id)
      @skills.sort!
    end
  end
  #--------------------------------------------------------------------------
  # * Forget Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def forget_skill(skill_id)
    @skills.delete(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Finished Learning Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_learn?(skill_id)
    return @skills.include?(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Skill can be Used
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_can_use?(skill_id)
    if not skill_learn?(skill_id)
      return false
    end
    return super
  end
end
#===============================================================================
# Class Game_Actor
#===============================================================================
class Game_Actor < Game_Battler
  attr_accessor :techniques
 
  alias initialize_techniques initialize
  def initialize(actor_id)
    @techniques = []
    initialize_techniques(actor_id)
  end
 
  alias setup_techniques setup
  def setup(actor_id)
    setup_techniques(actor_id)
    # How will you determine what techniques the character starts with?
  end
 
  # Adds the specified technique to the @techniques array
  def add_tech(tech_id)
    return if @techniques[tech_id] != nil # stops if tech is already possessed
    @techniques[tech_id] = Game_Technique.new(tech_id)
  end

end
Keep me updated on what you want fixed.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

shintashi

Quote from: KK20 on October 07, 2011, 03:15:54 pm
I've played around with your script a bit. I did have to make a few edits to "Game_Techniques" because of the errors in initializing.
Spoiler: ShowHide
#==============================================================================
# ** Game_Technique
#------------------------------------------------------------------------------
#  This class handles the Techniques. It's used within the Game_Actors class
#  ($game_actors) and refers to the Technique class.
#==============================================================================

class Game_Technique
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :id                       # technique ID
  attr_accessor :name                     # e.g. Black Magic, Dodge, Rifles
  attr_accessor :multiplier               # e.g x1, x2, ...x9, etc.
  attr_accessor :exp                      # total exp earned
  attr_accessor :physical                 # true or false
  attr_accessor :magical                  # true or false
  attr_accessor :level                    # level
  attr_accessor :skills                   # skills, spells, merits, flaws
  attr_accessor :description              # help window description
 
  #--------------------------------------------------------------------------
  # * Stock Techniques
  #     tech_id : tech ID
  #--------------------------------------------------------------------------
  def techniques_data(id)
    # return [name, mult, exp, physical?, magical?, level, skills, desc]
    case id
    when 0 then return ["Endurance", 1, 0, true, false, 0, [1, 2], "Hit Point Bonus"]
    end
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     tech_id : tech ID
  #--------------------------------------------------------------------------
  def initialize(tech_id)
    tech = techniques_data(tech_id)
    @tech_id = tech_id
    @name = tech[0]
    @level = tech[5]
    @multiplier = tech[1]               
    @physical = tech[3]                 
    @magical = tech[4]
    @description = tech[7]             
    @exp_list = Array.new(101)
    make_exp_list
    @exp = tech[2]
    @skills = []
    tech[6].each{|id|
      @skills.push(id)
    }
    @skills.sort!
  end
  #--------------------------------------------------------------------------
  # * Get Tech ID
  #--------------------------------------------------------------------------
  def id
    return @tech_id
  end
  #--------------------------------------------------------------------------
  # * Get Tech Multiplier # needs revision to 0 + ...0.1+ 0.2 +x9...etc.
  #--------------------------------------------------------------------------
  def multiplier
    #i = self.id
    #n = 0 + (tech[i].skill[1].power + tech[i].skill[2].power * 0.1)
    #n = 0 + skill[1].power + skill[2].power + skill[3].power
    #return n
    return @multiplier
  end
  #--------------------------------------------------------------------------
  # * Get Index
  #--------------------------------------------------------------------------
  def index
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Calculate EXP
  #--------------------------------------------------------------------------
    def make_exp_list
    @exp_list[1] = 0
    for i in 2..100
      @exp_list[i] = @exp_list[i-1] + (@multiplier * (i / 2) * (i + 1))
    end
  end
  #--------------------------------------------------------------------------
  # * Get EXP String
  #--------------------------------------------------------------------------
  def exp_s
    return @exp_list[@level+1] > 0 ? @exp.to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Next Level EXP String
  #--------------------------------------------------------------------------
  def next_exp_s
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1].to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Until Next Level EXP String
  #--------------------------------------------------------------------------
  def next_rest_exp_s
    return @exp_list[@level+1] > 0 ?
      (@exp_list[@level+1] - @exp).to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Change EXP
  #     exp : new EXP
  #--------------------------------------------------------------------------
  def exp=(exp)
    @exp = [[exp, 99999].min, 0].max
    # Level up
    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
      @level += 1
#====================================================================     
# NEEDS HEAVY REVISION CF SKILL WINDOW
      # Learn skill
      for j in $data_classes[@class_id].learnings
        if j.level == @level
          learn_skill(j.skill_id)
        end
      end
    end
#====================================================================   
    # Level down
    while @exp < @exp_list[@level]
      @level -= 1
    end
  end
  #--------------------------------------------------------------------------
  # * Change Level
  #     level : new level
  #--------------------------------------------------------------------------
  def level=(level)
    # Check up and down limits - NEEDS REVISION
    level = [[level, $data_actors[@actor_id].final_level].min, 1].max
    # Change EXP
    self.exp = @exp_list[level]
  end
  #--------------------------------------------------------------------------
  # * Learn Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def learn_skill(skill_id)
    if skill_id > 0 and not skill_learn?(skill_id)
      @skills.push(skill_id)
      @skills.sort!
    end
  end
  #--------------------------------------------------------------------------
  # * Forget Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def forget_skill(skill_id)
    @skills.delete(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Finished Learning Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_learn?(skill_id)
    return @skills.include?(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Skill can be Used
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_can_use?(skill_id)
    if not skill_learn?(skill_id)
      return false
    end
    return super
  end
end
#===============================================================================
# Class Game_Actor
#===============================================================================
class Game_Actor < Game_Battler
  attr_accessor :techniques
 
  alias initialize_techniques initialize
  def initialize(actor_id)
    @techniques = []
    initialize_techniques(actor_id)
  end
 
  alias setup_techniques setup
  def setup(actor_id)
    setup_techniques(actor_id)
    # How will you determine what techniques the character starts with?
  end
 
  # Adds the specified technique to the @techniques array
  def add_tech(tech_id)
    return if @techniques[tech_id] != nil # stops if tech is already possessed
    @techniques[tech_id] = Game_Technique.new(tech_id)
  end

end
Keep me updated on what you want fixed.


That's F*ing brilliant actually. My main concern is whether the skill list should be id=1 or id=some other number. In your version, likely based on my hash, you have it as 6, with description as 7. I guess 0 should be name because that makes the most sense, but I'm beginning to think skills should be "1", because there's a lot of derived values after that.

in order, its basically skills.power added together = multiplier, then multiplier determines experience chart, then experience chart determines level. the other attributes - magic/physical/description are useful but not critical. I don't think the computer cares which order they appear in, but if sorted by a number, I'm guessing

?: ID Number
0: name
1: skills []
2: multiplier
3: experience total
4: level
5/6/7: magic/physical/description

KK20

When calling back the data for your techniques (name, skills, level, exp, etc), it doesn't have to be values in an array. What I mean is, taking the edit I made, you don't have to go $game_actors[1].techniques[0][0] to get the name (actually that'd cause an error). You just use $game_actors[1].techniques[0].name and "Endurance" should be the result.

Because of that, it doesn't matter how you set up your technique data. Granted, it is preferable to order your values based on importance, but it's not necessary.

Also, I added in class "Game_Actors" a method called 'add_tech(tech_id)'. If you do a script call like $game_actors[1].add_tech(0), it will add the technique with the ID value of 0 (Endurance in this case). @tech_id will equal parameter tech_id, and does not need to be part of your setup array. It can be called the same way as I stated at the top of this post.

What's next? :naughty:

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

shintashi

October 08, 2011, 12:28:49 pm #10 Last Edit: October 08, 2011, 12:32:39 pm by shintashi
Quote from: KK20 on October 08, 2011, 12:51:57 am
When calling back the data for your techniques (name, skills, level, exp, etc), it doesn't have to be values in an array. What I mean is, taking the edit I made, you don't have to go $game_actors[1].techniques[0][0] to get the name (actually that'd cause an error). You just use $game_actors[1].techniques[0].name and "Endurance" should be the result.

Because of that, it doesn't matter how you set up your technique data. Granted, it is preferable to order your values based on importance, but it's not necessary.

Also, I added in class "Game_Actors" a method called 'add_tech(tech_id)'. If you do a script call like $game_actors[1].add_tech(0), it will add the technique with the ID value of 0 (Endurance in this case). @tech_id will equal parameter tech_id, and does not need to be part of your setup array. It can be called the same way as I stated at the top of this post.

What's next? :naughty:


this:


 #--------------------------------------------------------------------------
 # * Get Tech Multiplier # needs revision to 0 + ...0.1+ 0.2 +x9...etc.
 #--------------------------------------------------------------------------
 def multiplier
   for i in 0..tech.skills.length
   n = 0 + (tech.skills[i].power * 0.1)
   end
   return n
 end


clearly doesn't work but I hope it illustrates enough to be fixed. Basically add up all the technique's skills' power values together and divide by 10. I basically suck at for loops with gaps. like if I had an array that pulled from a list of 26 variables (a..z), and the list was called my_variables, and my array was something like my_array = [a,m,x], I don't know how to add a + m + x , without adding the rest of the alphabet, or literally typing my_array[a] + my_array[m] + my_array
  • ... which means if I wanted to add b, or n, or get rid of x, I would be screwed.

KK20

Spoiler: ShowHide
#==============================================================================
# ** Game_Technique
#------------------------------------------------------------------------------
#  This class handles the Techniques. It's used within the Game_Actors class
#  ($game_actors) and refers to the Technique class.
#==============================================================================

class Game_Technique
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :id                       # technique ID
  attr_accessor :name                     # e.g. Black Magic, Dodge, Rifles
  attr_accessor :multiplier               # e.g x1, x2, ...x9, etc.
  attr_accessor :exp                      # total exp earned
  attr_accessor :physical                 # true or false
  attr_accessor :magical                  # true or false
  attr_accessor :level                    # level
  attr_accessor :skills                   # skills, spells, merits, flaws
  attr_accessor :description              # help window description
 
  #--------------------------------------------------------------------------
  # * Stock Techniques
  #     tech_id : tech ID
  #--------------------------------------------------------------------------
  def techniques_data(id)
    # return [name, mult, exp, physical?, magical?, level, skills, desc]
    case id
    when 0 then return ["Endurance", 1, 0, true, false, 0, [1, 2], "Hit Point Bonus"]
    end
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     tech_id : tech ID
  #--------------------------------------------------------------------------
  def initialize(tech_id)
    tech = techniques_data(tech_id)
    @tech_id = tech_id
    @name = tech[0]
    @level = tech[5]               
    @physical = tech[3]                 
    @magical = tech[4]
    @description = tech[7]             
    @skills = []
    tech[6].each{|id|
      @skills.push(id)
    }
    @skills.sort!
    @multiplier = get_multi
    @exp_list = Array.new(101)
    make_exp_list
    @exp = tech[2]
  end
  #--------------------------------------------------------------------------
  # * Get Tech ID
  #--------------------------------------------------------------------------
  def id
    return @tech_id
  end
  #--------------------------------------------------------------------------
  # * Get Tech Multiplier # needs revision to 0 + ...0.1+ 0.2 +x9...etc.
  #--------------------------------------------------------------------------
  def get_multi
    m = 0
    @skills.each{|i|
      m += $data_skills[i].power.abs
    }
    return m/10
  end
  #--------------------------------------------------------------------------
  # * Get Index
  #--------------------------------------------------------------------------
  def index
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Calculate EXP
  #--------------------------------------------------------------------------
    def make_exp_list
    @exp_list[1] = 0
    for i in 2..100
      @exp_list[i] = @exp_list[i-1] + (@multiplier * (i / 2) * (i + 1))
    end
  end
  #--------------------------------------------------------------------------
  # * Get EXP String
  #--------------------------------------------------------------------------
  def exp_s
    return @exp_list[@level+1] > 0 ? @exp.to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Next Level EXP String
  #--------------------------------------------------------------------------
  def next_exp_s
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1].to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Until Next Level EXP String
  #--------------------------------------------------------------------------
  def next_rest_exp_s
    return @exp_list[@level+1] > 0 ?
      (@exp_list[@level+1] - @exp).to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Change EXP
  #     exp : new EXP
  #--------------------------------------------------------------------------
  def exp=(exp)
    @exp = [[exp, 99999].min, 0].max
    # Level up
    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
      @level += 1
#====================================================================     
# NEEDS HEAVY REVISION CF SKILL WINDOW
      # Learn skill
      for j in $data_classes[@class_id].learnings
        if j.level == @level
          learn_skill(j.skill_id)
        end
      end
    end
#====================================================================   
    # Level down
    while @exp < @exp_list[@level]
      @level -= 1
    end
  end
  #--------------------------------------------------------------------------
  # * Change Level
  #     level : new level
  #--------------------------------------------------------------------------
  def level=(level)
    # Check up and down limits - NEEDS REVISION
    level = [[level, $data_actors[@actor_id].final_level].min, 1].max
    # Change EXP
    self.exp = @exp_list[level]
  end
  #--------------------------------------------------------------------------
  # * Learn Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def learn_skill(skill_id)
    if skill_id > 0 and not skill_learn?(skill_id)
      @skills.push(skill_id)
      @skills.sort!
    end
  end
  #--------------------------------------------------------------------------
  # * Forget Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def forget_skill(skill_id)
    @skills.delete(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Finished Learning Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_learn?(skill_id)
    return @skills.include?(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Skill can be Used
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_can_use?(skill_id)
    if not skill_learn?(skill_id)
      return false
    end
    return super
  end
end
#===============================================================================
# class Game_Actor
#===============================================================================
class Game_Actor < Game_Battler
  attr_accessor :techniques
 
  alias initialize_techniques initialize
  def initialize(actor_id)
    @techniques = []
    initialize_techniques(actor_id)
  end
 
  alias setup_techniques setup
  def setup(actor_id)
    setup_techniques(actor_id)
    # How will you determine what techniques the character starts with?
  end
 
  # Adds the specified technique to the @techniques array
  def add_tech(tech_id)
    return if @techniques[tech_id] != nil # stops if tech is already possessed
    @techniques[tech_id] = Game_Technique.new(tech_id)
  end

end
I had to change the method name 'def multiplier' to 'def get_multi'. It is entirely possible to just move the contents of that method and put it into 'def initialize' but I wasn't sure if you wanted to, say, add more skills into the technique later on. Tested with Heal and Greater Heal (powers of 150 and 300) and it returned 45.

Also had to shift things around a bit in 'def initialize'.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

shintashi

October 08, 2011, 09:13:44 pm #12 Last Edit: October 08, 2011, 09:33:53 pm by shintashi
Here's a happy screenshot showing pretty much what I hoped would happen if the script started working
Spoiler: ShowHide


I'm especially impressed that the experience table exists. I haven't tested leveling the technique yet, or seeing if two characters can have the same technique, but so far, it looks great.



Quote from: KK20 on October 08, 2011, 02:10:28 pm
Spoiler: ShowHide
#==============================================================================
# ** Game_Technique
#------------------------------------------------------------------------------
#  This class handles the Techniques. It's used within the Game_Actors class
#  ($game_actors) and refers to the Technique class.
#==============================================================================

class Game_Technique
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :id                       # technique ID
 attr_accessor :name                     # e.g. Black Magic, Dodge, Rifles
 attr_accessor :multiplier               # e.g x1, x2, ...x9, etc.
 attr_accessor :exp                      # total exp earned
 attr_accessor :physical                 # true or false
 attr_accessor :magical                  # true or false
 attr_accessor :level                    # level
 attr_accessor :skills                   # skills, spells, merits, flaws
 attr_accessor :description              # help window description
 
 #--------------------------------------------------------------------------
 # * Stock Techniques
 #     tech_id : tech ID
 #--------------------------------------------------------------------------
 def techniques_data(id)
   # return [name, mult, exp, physical?, magical?, level, skills, desc]
   case id
   when 0 then return ["Endurance", 1, 0, true, false, 0, [1, 2], "Hit Point Bonus"]
   end
 end
 #--------------------------------------------------------------------------
 # * Object Initialization
 #     tech_id : tech ID
 #--------------------------------------------------------------------------
 def initialize(tech_id)
   tech = techniques_data(tech_id)
   @tech_id = tech_id
   @name = tech[0]
   @level = tech[5]              
   @physical = tech[3]                
   @magical = tech[4]
   @description = tech[7]            
   @skills = []
   tech[6].each{|id|
     @skills.push(id)
   }
   @skills.sort!
   @multiplier = get_multi
   @exp_list = Array.new(101)
   make_exp_list
   @exp = tech[2]
 end
 #--------------------------------------------------------------------------
 # * Get Tech ID
 #--------------------------------------------------------------------------
 def id
   return @tech_id
 end
 #--------------------------------------------------------------------------
 # * Get Tech Multiplier # needs revision to 0 + ...0.1+ 0.2 +x9...etc.
 #--------------------------------------------------------------------------
 def get_multi
   m = 0
   @skills.each{|i|
     m += $data_skills[i].power.abs
   }
   return m/10
 end
 #--------------------------------------------------------------------------
 # * Get Index
 #--------------------------------------------------------------------------
 def index
   return @data[self.index]
 end
 #--------------------------------------------------------------------------
 # * Calculate EXP
 #--------------------------------------------------------------------------
   def make_exp_list
   @exp_list[1] = 0
   for i in 2..100
     @exp_list[i] = @exp_list[i-1] + (@multiplier * (i / 2) * (i + 1))
   end
 end
 #--------------------------------------------------------------------------
 # * Get EXP String
 #--------------------------------------------------------------------------
 def exp_s
   return @exp_list[@level+1] > 0 ? @exp.to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Get Next Level EXP String
 #--------------------------------------------------------------------------
 def next_exp_s
   return @exp_list[@level+1] > 0 ? @exp_list[@level+1].to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Get Until Next Level EXP String
 #--------------------------------------------------------------------------
 def next_rest_exp_s
   return @exp_list[@level+1] > 0 ?
     (@exp_list[@level+1] - @exp).to_s : "-------"
 end
 #--------------------------------------------------------------------------
 # * Change EXP
 #     exp : new EXP
 #--------------------------------------------------------------------------
 def exp=(exp)
   @exp = [[exp, 99999].min, 0].max
   # Level up
   while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
     @level += 1
#====================================================================      
# NEEDS HEAVY REVISION CF SKILL WINDOW
     # Learn skill
     for j in $data_classes[@class_id].learnings
       if j.level == @level
         learn_skill(j.skill_id)
       end
     end
   end
#====================================================================    
   # Level down
   while @exp < @exp_list[@level]
     @level -= 1
   end
 end
 #--------------------------------------------------------------------------
 # * Change Level
 #     level : new level
 #--------------------------------------------------------------------------
 def level=(level)
   # Check up and down limits - NEEDS REVISION
   level = [[level, $data_actors[@actor_id].final_level].min, 1].max
   # Change EXP
   self.exp = @exp_list[level]
 end
 #--------------------------------------------------------------------------
 # * Learn Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def learn_skill(skill_id)
   if skill_id > 0 and not skill_learn?(skill_id)
     @skills.push(skill_id)
     @skills.sort!
   end
 end
 #--------------------------------------------------------------------------
 # * Forget Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def forget_skill(skill_id)
   @skills.delete(skill_id)
 end
 #--------------------------------------------------------------------------
 # * Determine if Finished Learning Skill
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def skill_learn?(skill_id)
   return @skills.include?(skill_id)
 end
 #--------------------------------------------------------------------------
 # * Determine if Skill can be Used
 #     skill_id : skill ID
 #--------------------------------------------------------------------------
 def skill_can_use?(skill_id)
   if not skill_learn?(skill_id)
     return false
   end
   return super
 end
end
#===============================================================================
# class Game_Actor
#===============================================================================
class Game_Actor < Game_Battler
 attr_accessor :techniques
 
 alias initialize_techniques initialize
 def initialize(actor_id)
   @techniques = []
   initialize_techniques(actor_id)
 end
 
 alias setup_techniques setup
 def setup(actor_id)
   setup_techniques(actor_id)
   # How will you determine what techniques the character starts with?
 end
 
 # Adds the specified technique to the @techniques array
 def add_tech(tech_id)
   return if @techniques[tech_id] != nil # stops if tech is already possessed
   @techniques[tech_id] = Game_Technique.new(tech_id)
 end

end
I had to change the method name 'def multiplier' to 'def get_multi'. It is entirely possible to just move the contents of that method and put it into 'def initialize' but I wasn't sure if you wanted to, say, add more skills into the technique later on. Tested with Heal and Greater Heal (powers of 150 and 300) and it returned 45.

Also had to shift things around a bit in 'def initialize'.


the stuff labled game actor... can that stuff go into the game actor, or does it have to go above main?

Also, I see you guys use "alias" a lot. What's it for?

in answer to the question "How will you determine what techniques the character starts with?" I planned on using events to grant specific techniques based on player choices during a phase called "character creation". Stock techniques include stuff like black and white magic, melee, dodge, endurance, willpower, and later some thief stuff.

KK20

You can put 'Game_Actor' in its own, separate space, as long as it is below RPG Maker's default 'Game_Actor' and above 'Main'.

There are some guides that explain what alias does, but I'll try to explain it.
class Something
 
  def method_one
    print ("a")
  end
 
  alias copy_of_method_one method_one
  # Essentially means this below:
  # def copy_of_method_one
  #   print("a")
  # end
 
  # You should know that if you define a method that already exists, you are
  # rewriting the method. That's why we made a copy of the original method
  # right before we're about to change it.
  def method_one
    print ("b")
    copy_of_method_one
  end
 
end
If you were to somehow call 'Something.method_one' you would get two pop-up windows, the first saying "b" and the next saying "a". alias means "make an exact copy of the method".

Looking forward to the next reply.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

shintashi

So I made some small modifications, shown below:

Spoiler: ShowHide


#==============================================================================
# ** Game_Technique
#------------------------------------------------------------------------------
#  This class handles the Techniques. It's used within the Game_Actors class
#  ($game_actors) and refers to the Technique class.
#==============================================================================
#==============================================================================
# ** Game_Technique
#------------------------------------------------------------------------------
#  This class handles the Techniques. It's used within the Game_Actors class
#  ($game_actors) and refers to the Technique class.
#==============================================================================

class Game_Technique
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :id                       # technique ID
  attr_accessor :name                     # e.g. Black Magic, Dodge, Rifles
  attr_accessor :multiplier               # e.g x1, x2, ...x9, etc.
  attr_accessor :exp                      # total exp earned
  attr_accessor :physical                 # true or false
  attr_accessor :magical                  # true or false
  attr_accessor :level                    # level
  attr_accessor :skills                   # skills, spells, merits, flaws
  attr_accessor :description              # help window description
 
  #--------------------------------------------------------------------------
  # * Stock Techniques
  #     tech_id : tech ID
  #--------------------------------------------------------------------------
  def techniques_data(id)
    # return [name, mult, exp, physical?, magical?, level, skills, desc]
    case id
    when 0 then return ["Endurance", 1, 0, true, false, 0, [1, 2, 10], "Hit Point Bonus"]
    end
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     tech_id : tech ID
  #--------------------------------------------------------------------------
  def initialize(tech_id)
    tech = techniques_data(tech_id)
    @tech_id = tech_id
    @name = tech[0]
    @level = tech[5]               
    @physical = tech[3]                 
    @magical = tech[4]
    @description = tech[7]             
    @skills = []
    tech[6].each{|id|
      @skills.push(id)
    }
    @skills.sort!
    @multiplier = get_multi
    @exp_list = Array.new(100)
    make_exp_list
    @exp = tech[2]
  end
  #--------------------------------------------------------------------------
  # * Get Tech ID
  #--------------------------------------------------------------------------
  def id
    return @tech_id
  end
  #--------------------------------------------------------------------------
  # * Get Tech Multiplier # needs revision to 0 + ...0.1+ 0.2 +x9...etc.
  #--------------------------------------------------------------------------
  def get_multi
    m = 0
    @skills.each{|i|
      m += $data_skills[i].power
    }
    n = [1, m/10].max
    return n
  end
  #--------------------------------------------------------------------------
  # * Get Index
  #--------------------------------------------------------------------------
  def index
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Calculate EXP
  #--------------------------------------------------------------------------
    def make_exp_list
    @exp_list[0] = 0
    for i in 1..99
      @exp_list[i] = Integer(0 + (@multiplier * ((i / 2.0) * (i + 1))))
    end
  end
  #--------------------------------------------------------------------------
  # * Get EXP String
  #--------------------------------------------------------------------------
  def exp_s
    return @exp_list[@level+1] > 0 ? @exp.to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Next Level EXP String
  #--------------------------------------------------------------------------
  def next_exp_s
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1].to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Get Until Next Level EXP String
  #--------------------------------------------------------------------------
  def next_rest_exp_s
    return @exp_list[@level+1] > 0 ?
      (@exp_list[@level+1] - @exp).to_s : "-------"
  end
  #--------------------------------------------------------------------------
  # * Change EXP
  #     exp : new EXP
  #--------------------------------------------------------------------------
  def exp=(exp)
    @exp = [[exp, 999999].min, 0].max
    # Level up
    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
      @level += 1
#====================================================================     
# NEEDS HEAVY REVISION CF SKILL WINDOW
      # Learn skill
      for j in $data_classes[@class_id].learnings
        if j.level == @level
          learn_skill(j.skill_id)
        end
      end
    end
#====================================================================   
    # Level down
    while @exp < @exp_list[@level]
      @level -= 1
    end
  end
  #--------------------------------------------------------------------------
  # * Change Level
  #     level : new level
  #--------------------------------------------------------------------------
  def level=(level)
    # Check up and down limits - NEEDS REVISION
    level = [[level, $data_actors[@actor_id].final_level].min, 1].max
    # Change EXP
    self.exp = @exp_list[level]
  end
  #--------------------------------------------------------------------------
  # * Learn Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def learn_skill(skill_id)
    if skill_id > 0 and not skill_learn?(skill_id)
      @skills.push(skill_id)
      @skills.sort!
    end
  end
  #--------------------------------------------------------------------------
  # * Forget Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def forget_skill(skill_id)
    @skills.delete(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Finished Learning Skill
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_learn?(skill_id)
    return @skills.include?(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Skill can be Used
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_can_use?(skill_id)
    if not skill_learn?(skill_id)
      return false
    end
    return super
  end
end



mainly in the multiplier and experience point system. I dropped my array from 0-100 to 0-99, and started experience point requirements at level 1. The idea is you can have a technique listed, showing you can 'learn it', but you don't know anything about it.  Also took out the absolute value for skill.power, because I wanted some "skills" to act as placeholders for flaws that reduce costs, like vows of poverty or costs permanent [mana/hp/levels/etc.]. Also set the minimum multiplier at x1, so no amount of flaws could reduce raising levels to 0.

Well it's a bit after midnight, so the alias thing is a bit over my head right now, but im happy to have received some guidance. There's not a lot of books on this programming language in my area.

Twb6543

An alias makes a copy of a definition and changes the name of it, this is so you can rewrite the definition without causing errors or just to add something to it...

QuickExamples: ShowHide


# define the Definition to copy
# This method defines a fruit as an array containing "Apple"
def Fruit
  return ["Apple"]
end

call Fruit # Returns ["Apple"]

alias :oldFruit :Fruit
def Fruit
  return ["Apple","Banana"]
end

call Fruit # Returns ["Apple","Banana"]
call oldFruit # Returns ["Apple"]

# Here I show how you can use aliases to add to a definition
# This adds 1 to cost
def costadd1
  @@cost += 1
end

call costadd1 # @@cost + 1

alias :costadd1old :costadd1
def costadd1
  @@cost += 2
  costadd1old # Calls old method
end

# Same as this
=begin
def costadd1
  @@cost += 2
  @@cost += 1 # Calls old method
end
=end

call costadd1 # @@cost + 2 then @@cost + 1
                   # Same as @@cost + 3

call costadd1old # @@cost + 1

If you put a million monkeys at a million keyboards, one of them will eventually write a Java program.
The rest of them will write Perl programs.

shintashi

October 09, 2011, 03:23:32 pm #16 Last Edit: October 09, 2011, 03:34:11 pm by shintashi
I think I get what an Alias does - it protects the original...

So I began testing the script and made an exp fairy event to level up one of the techniques to see if
#1 would it gain experience points?
#2 would a second technique retain it's separate identity?
#3 would the technique gain a level, given enough experience points?

Well, what happened is #1 and #2 worked, and then #3 crashed on the following lines:


#====================================================================      
# NEEDS HEAVY REVISION CF SKILL WINDOW
     # Learn skill
     for j in $data_classes[@class_id].learnings
       if j.level == @level
         learn_skill(j.skill_id)
       end
     end
   end
#====================================================================  


Which wasn't surprising at all, actually. So I took it out

And this is the resulting success:
Spoiler: ShowHide



Now the idea of having the "for i/j" thing was originally to allow people to have something like "black magic" final fantasy 4. So when you get to a certain technique level, you unlock a new spell, and again at a higher level, and so on, just like the actors do with their skill list. I haven't figured out how to set that up yet, but would presume it's a small table or array, that assigns a "level" to zero or more of your technique's skills.

Originally I thought this would only be useful for spells or "secret ninja techniques" etc., but I realize now throwing in some delayed flaws might also be interesting. For example, having some skills in your list simply act as placeholders for common events that inflict insanity, aging, or whatever, would be great for high powered Black Magic.  

For now, it doesn't matter what the skills do, just that there's an optional "level attainment" list for them. I was thinking of exploiting some existing part of skills, like their element checkbox would be the fastest way to say "this skill/spell can have a level", or slightly more complex,
have three elements, like
.power x2 = level
.power x4 = level
.power x8 = level
or whatever. Then with that mechanism in place, I could actually create a "learn powerful spell early" option that would jack up the total skill multiplier.

So if something had a power of 20, and a multiplier of x2, it might be attainable at level 40, but you could have a "learn[skill_id] early" option that allows you to learn it at 20th level. I think the only problem is the complexity of the array. The simplest way to do it is to apply it to all skills, the second simplest is to have a single "skill", or a small list (like three), that reduce levels by something like 4,8, and 32 levels respectively, for a single chosen skill.

I do like the idea of 3 elements determining level attainment, but I'm pretty intimidated by the mess of being able to choose which skill is getting the discount, because it would look something like

game_actor[i].technique[a].skill[x]
game_actor[i].technique[a].skill[y][z]


Where x is the spell (like Meteo), y is the discount (like "learn 8 levels sooner"), and z refers back to Meteo.
Edit: maybe I can create an 8th category called "addendum" or "auxiliary" that's basically a junk array that after the computer checks existing skills, does additional calculations for certain skills and stores it. like which skills are discounted, what special trainers are needed, etc.

shintashi

Two Questions:

if I didn't want the Game_Actor part of this program to be separated using aliases, What would it look like inside game_actor?

and where you said


  alias setup_techniques setup
  def setup(actor_id)
    setup_techniques(actor_id)
    # How will you determine what techniques the character starts with?
  end


is "setup_techniques(actor_id)" a new method for creating a preexisting list? like


def  setup_techniques(actor_id)
n = $data_actors[@actor_id]
case n
    when 0
       return n.techniques = [0,11,13]
    when 1
       return n.techniques = [1,3]
    when 2
       return n.techniques = [0,5,8]
    when 3
       return n.techniques = [0,2,6]
    #etc.
end

end




KK20

Spoiler: ShowHide
class Game_Actor < Game_Battler
  attr_accessor :techniques
 
  def initialize(actor_id)
    @techniques = []
    super()
    setup(actor_id)
  end
 
  def setup(actor_id)
    actor = $data_actors[actor_id]
    @actor_id = actor_id
    @name = actor.name
    @character_name = actor.character_name
    @character_hue = actor.character_hue
    @battler_name = actor.battler_name
    @battler_hue = actor.battler_hue
    @class_id = actor.class_id
    @weapon_id = actor.weapon_id
    @armor1_id = actor.armor1_id
    @armor2_id = actor.armor2_id
    @armor3_id = actor.armor3_id
    @armor4_id = actor.armor4_id
    @level = actor.initial_level
    @exp_list = Array.new(101)
    make_exp_list
    @exp = @exp_list[@level]
    @skills = []
    @hp = maxhp
    @sp = maxsp
    @states = []
    @states_turn = {}
    @maxhp_plus = 0
    @maxsp_plus = 0
    @str_plus = 0
    @dex_plus = 0
    @agi_plus = 0
    @int_plus = 0
    # Learn skill
    for i in 1..@level
      for j in $data_classes[@class_id].learnings
        if j.level == i
          learn_skill(j.skill_id)
        end
      end
    end
    # Update auto state
    update_auto_state(nil, $data_armors[@armor1_id])
    update_auto_state(nil, $data_armors[@armor2_id])
    update_auto_state(nil, $data_armors[@armor3_id])
    update_auto_state(nil, $data_armors[@armor4_id])
  end
end
That 'setup_techniques' was a placeholder. In all actuality, you can delete the 'alias' and 'def setup' and nothing would change. I just wasn't sure how you would initialize what techniques your actors started out with--hence, I put that there for a later time to edit.

Think of alias as the process of mitosis in biology: you start with one cell which becomes two, identical cells. Both of these cells, however, cannot have the same name, so you name one cell Bob and the other Bill. Now translate that metaphor into programming.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

shintashi

October 11, 2011, 05:23:54 pm #19 Last Edit: October 11, 2011, 05:30:44 pm by shintashi
Quote from: KK20 on October 11, 2011, 01:04:06 pm
Spoiler: ShowHide
class Game_Actor < Game_Battler
 attr_accessor :techniques
 
 def initialize(actor_id)
   @techniques = []
   super()
   setup(actor_id)
 end
 
 def setup(actor_id)
   actor = $data_actors[actor_id]
   @actor_id = actor_id
   @name = actor.name
   @character_name = actor.character_name
   @character_hue = actor.character_hue
   @battler_name = actor.battler_name
   @battler_hue = actor.battler_hue
   @class_id = actor.class_id
   @weapon_id = actor.weapon_id
   @armor1_id = actor.armor1_id
   @armor2_id = actor.armor2_id
   @armor3_id = actor.armor3_id
   @armor4_id = actor.armor4_id
   @level = actor.initial_level
   @exp_list = Array.new(101)
   make_exp_list
   @exp = @exp_list[@level]
   @skills = []
   @hp = maxhp
   @sp = maxsp
   @states = []
   @states_turn = {}
   @maxhp_plus = 0
   @maxsp_plus = 0
   @str_plus = 0
   @dex_plus = 0
   @agi_plus = 0
   @int_plus = 0
   # Learn skill
   for i in 1..@level
     for j in $data_classes[@class_id].learnings
       if j.level == i
         learn_skill(j.skill_id)
       end
     end
   end
   # Update auto state
   update_auto_state(nil, $data_armors[@armor1_id])
   update_auto_state(nil, $data_armors[@armor2_id])
   update_auto_state(nil, $data_armors[@armor3_id])
   update_auto_state(nil, $data_armors[@armor4_id])
 end
end
That 'setup_techniques' was a placeholder. In all actuality, you can delete the 'alias' and 'def setup' and nothing would change. I just wasn't sure how you would initialize what techniques your actors started out with--hence, I put that there for a later time to edit.

Think of alias as the process of mitosis in biology: you start with one cell which becomes two, identical cells. Both of these cells, however, cannot have the same name, so you name one cell Bob and the other Bill. Now translate that metaphor into programming.


Ok, I think I got it to transfer without crashing. I made a dummy holder for


 #--------------------------------------------------------------------------
 # * Setup Techniques for Stock Classes
 #--------------------------------------------------------------------------
 def setup_techniques(actor_id)
 # do nothing for now
 end




And now I'm going to test having the techniques actually do something to the actor, for the first time.

I've chosen "Swords" as my first target, the idea is if your actor gains this technique, they should gain access to the sword list of usable weapons.

If that works, I'm going to see if I can create a thing that depending on my 'swords' level, determines how many on the sword list I've learned. If it works, I can use similar ideas for knives, guns, and possibly spells.