Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Error in "Learning Skills Through Items" SephTestBedv3

About that other request ( Crafting System ) I already found out what the problem was.:D

I think I found an error in the "Learning Skills through items" script.

When this certain actor gets knocked out in a battle and you use an item (to revive her) on her, it would say that in Line 87, `has_key?' is undefined method.

Here's the Line (87)

Code:
    @skill_item_use[item.id] = 0 unless @skill_item_use.has_key?(item.id)

I just dont get it.. Can anybody help me out? a new script isn't really needed much. I just need instructions on how to fix this problem. Thank you :thumb:
 
Try this. I made an updated version.

Code:
#==============================================================================
# ** Learn Skills from Items (Usage)
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1.1
# 2007-02-20
# SDK : Version 2.0, Part 1
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (2006-08-23)
#    Version 1.1 ------------------------------------------------- (2007-02-20)
#     - Update : Updated code & updated to SDK 2.0
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to allow your characters to learn skills from
#   using items. You are allowed to set different skills, from different items
#   for different times being used.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#   To Customize your skill settings, refer to the customization instructions.
#------------------------------------------------------------------------------
# * Customization :
#
#   Setting Up Items For Skills
#    - Item_Use_To_Skills = { actor_id => {item_id => times_to_use, ...}, ... }
#
#   Default for all non-defined actors
#    - Item_Use_To_Skills.default = { item_id => times_to_se, ... }
#------------------------------------------------------------------------------
# * Syntax :
#
#   Retrieving Item Use Counter
#    - <game_actor>.skill_item_use_count(item_id)
#
#   Retrieving Item Use Skills
#    - <game_actor>.item_use_skills
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Learn Skills from Items (Usage)', 'SephirothSpawn', 1, '2006-08-23')
SDK.check_requirements(2, [1])

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Learn Skills from Items (Usage)')
  
#==============================================================================
# ** Game_Actor
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Item Use For Skills
  #
  #  ~ actor_id => {skill_id => {item_id => times, ...}, ...}
  #--------------------------------------------------------------------------
  Item_Use_To_Skills = {}
  # Default for all non-defined actors
  Item_Use_To_Skills.default ={}
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_useitems4skills_gmactr_setup,  :setup
  alias_method :seph_useitems4skills_gmactr_sl?,    :skill_learn?
  alias_method :seph_useitems4skills_gmactr_skills, :skills
  alias_method :seph_useitems4skills_gmactr_ie,     :item_effect
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  def setup(actor_id)
    # Sets Up Item Use Counter
    @skill_item_use = {}
    @skill_item_use.default = 0
    # Original Setup
    seph_useitems4skills_gmactr_setup(actor_id)
  end
  #--------------------------------------------------------------------------
  # * Determine if Finished Learning Skill
  #--------------------------------------------------------------------------
  def skill_learn?(skill_id)
    # Return Original Test or Item Use Skills Learned
    return seph_useitems4skills_gmactr_sl?(skill_id) || 
           self.item_use_skills.include?(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Skill Item Use Count
  #--------------------------------------------------------------------------
  def skill_item_use_count(item_id)
    return @skill_item_use[item_id]
  end
  #--------------------------------------------------------------------------
  # * Skills
  #--------------------------------------------------------------------------
  def skills
    # Gets Original Skill List
    skills = seph_useitems4skills_gmactr_skills.dup
    # Adds Item Use Skills
    skills << self.item_use_skills.dup
    # Return Modified Skills
    return skills.flatten.uniq.sort
  end
  #--------------------------------------------------------------------------
  # * Item Use Skills
  #--------------------------------------------------------------------------
  def item_use_skills
    # Start Skill Data Array
    skills = []
    # Get Skill Cost
    skill_use_cost = Item_Use_To_Skills[@actor_id]
    # Pass through all skills
    for i in 1...$data_skills.size
      # Skip if No Skill Cost
      next unless skill_use_cost.has_key?(i)
      # Sets Learn Flag On
      learn_skill = true
      # Checks All Item Use Requirements
      skill_use_cost[i].each do |item_id, n|
        # Turn Learn Flag off if Requirement Not Met
        learn_skill = false if n > skill_item_use_count(item_id)
      end
      # Add skill if item cost all met
      skills << i if learn_skill
    end
    # Return Skills
    return skills
  end
  #--------------------------------------------------------------------------
  # * Item Effect
  #--------------------------------------------------------------------------
  def item_effect(item)
    # Get Original Item Effectiveness
    effective = seph_useitems4skills_gmactr_ie(item)
    # If Skill Learn Display Found
    if SDK.enabled?('Skill Learn Display')
      # Gets Item Skill List
      l = self.item_use_skills
    end
    # Add to Item Use Counter
    self.skill_item_use[item.id] += 1
    # If Skill Learn Display Found
    if SDK.enabled?('Skill Learn Display')
      # Gets New Item Skill List
      nl = self.item_use_skills
      # If Different List
      unless l == nl
        # Delete Old List From New List
        l.each {|n| nl.delete(n)}
        # If Non-Empty List
        unless nl.empty?
          @learn_skills_pop = true
          nl.each { |id| @learning_skills << id }
        end
      end
    end
    # Return Effectiveness
    return effective
  end
end  
  
#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top