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.

Having trouble with item using skill script

I've been trying to use SephirothSpawn's 'Skill Use Item' script
http://www.rmxpu.net/staff/sephirothspawn/Script%20Files/Skills%20Use%20Items.txt
to make healing moves which require that an item be consumed to work.
It seems the 1st bit of the script is working since it understands that I need the item to use the skill, but when I use the skill it doesn't consume an item.

Also I was curious if I wanted multiple skills that each needed to consume there own individual item if I'd just add more Item_Cost lines with different skill numbers and item numbers or if I'd have to add a whole new script for each one.

This is what I have:
Code:
#==============================================================================
# ** Skills Use Items
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1
# 2006-10-15
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to make skill using consume items.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#   To customize skill item usage, refer to customization.
#------------------------------------------------------------------------------
# * Customization :
#
#   Settings Skills That Use Items
#    - Item_Cost = { skill_id => <item_cost>, ... }
#
#   Replace <item_cost> with
#    - { item_type => { id => n, ... }, ... }
#
#   Item Types : 0 - Item, 1 - Weapons, 2 - Armors
#==============================================================================

#==============================================================================
# ** RPG::Skill
#==============================================================================
  
class RPG::Skill
  #--------------------------------------------------------------------------
  # * Skills That Use Items
  #
  #  ~ skill_id => { item_type => { id => n, ... }, ...}
  #
  #  Item_Types = 0 : Items, 1 : Weapons, 2 : Armors
  #--------------------------------------------------------------------------
  Item_Cost = {
    84 => { 0 => { 33 => 1 } }
  }
  #--------------------------------------------------------------------------
  # * Item Cost
  #--------------------------------------------------------------------------
  def item_cost
    return ( Item_Cost.has_key?(@id) ? Item_Cost[@id] : {} )
  end
end
  
#==============================================================================
# ** Game_Battler
#==============================================================================

class Game_Battler
  alias seph_skillsuseitems_gmbtlr_skc? skill_can_use?
  alias seph_skillsuseitems_gmbtlr_se skill_effect
  #--------------------------------------------------------------------------
  # * Determine if Skill can be Used
  #--------------------------------------------------------------------------
  def skill_can_use?(skill_id)
    # If Actor
    if self.is_a?(Game_Actor)
      # Checks All Skill Requirements
      $data_skills[skill_id].item_cost.each do |item_type, ids|
        # Items
        if item_type == 0
          ids.each do |id, n|
            return false if $game_party.item_number(id) < n
          end
        # Weapons
        elsif item_type == 1
          ids.each do |id, n|
            return false if $game_party.weapon_number(id) < n
          end
        # Armors
        elsif item_type == 2
          ids.each do |id, n|
            return false if $game_party.armor_number(id) < n
          end
        end
      end
    end
    # Return Original Test
    return seph_skillsuseitems_gmbtlr_skc?(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    # If Original Effect
    if self.seph_skillsuseitems_gmbtlr_se(user, skill)
      # If User is an Actor
      if user.is_a?(Game_Actor)
        # Lose Item Cost
        skill.item_cost.each do |item_type, ids|
          # Items
          if item_type == 0
            ids.each { |id, n| $game_party.lose_item(33, 0) }
          # Weapons
          elsif item_type == 1
            ids.each { |id, n| $game_party.lose_weapon(id, n) }
          # Armors
          elsif item_type == 2
            # Lose All Armors
            ids.each { |id, n| $game_party.lose_armor(id, n) }
          end
        end
      end
    end
  end
end

Thanks
 
*Bump*
Sorry to be a pain with the bump but I'm still having trouble getting this to work.
I've tried adding the SDK script but I had the same problem (and for some odd reason it deleted the fight/escape words when I got into a fight). Though, I have been getting a slight sense of how scripting works by looking up how this script references to other scripts and gives extra conditions and 'equations'. But that pretty much where my scripting knowledge ends for the time being, so I'm having trouble seeing where the small (or large) problem might be thats making it so an item isn't consumed after the skill is used.
 
I think you need post all the script that actually are in your proyect.
___________________________

Now, for the Items, remember this script requires the SDK, because there is a new version of the script:

Code:
#==============================================================================
# ** Skills Use Items
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1.01
# 2007-01-24
# SDK : Version 2.0+, Part I
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (2006-10-15)
#    Version 1.01 ------------------------------------------------ (2007-01-24)
#     - Update : Updated to SDK 2.0
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to make skill using consume items.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#   To customize skill item usage, refer to customization.
#------------------------------------------------------------------------------
# * Customization :
#
#   Settings Skills That Use Items
#    - Item_Cost = { skill_id => <item_cost>, ... }
#
#   Replace <item_cost> with
#    - { item_type => { id => n, ... }, ... }
#
#   Item Types : 0 - Item, 1 - Weapons, 2 - Armors
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Skills Use Items', 'SephirothSpawn', 1.01, '2007-01-24')
SDK.check_requirements(2.0)

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Skills Use Items')

#==============================================================================
# ** RPG::Skill
#==============================================================================
  
class RPG::Skill
  #--------------------------------------------------------------------------
  # * Skills That Use Items
  #
  #  ~ skill_id => { item_type => { id => n, ... }, ...}
  #
  #  Item_Types = 0 : Items, 1 : Weapons, 2 : Armors
  #--------------------------------------------------------------------------
  Item_Cost = {
  }
  Item_Cost.default = {}
  #--------------------------------------------------------------------------
  # * Item Cost
  #--------------------------------------------------------------------------
  def item_cost
    return Item_Cost[@id]
  end
end
  
#==============================================================================
# ** Game_Battler
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_skillsuseitems_scu?, :skill_can_use?
  alias_method :seph_skillsuseitems_se,   :skill_effect
  #--------------------------------------------------------------------------
  # * Determine if Skill can be Used
  #--------------------------------------------------------------------------
  def skill_can_use?(skill_id)
    # If Actor
    if self.is_a?(Game_Actor)
      # Checks All Skill Requirements
      $data_skills[skill_id].item_cost.each do |item_type, ids|
        # Items
        if item_type == 0
          ids.each do |id, n|
            return false if $game_party.item_number(id) < n
          end
        # Weapons
        elsif item_type == 1
          ids.each do |id, n|
            return false if $game_party.weapon_number(id) < n
          end
        # Armors
        elsif item_type == 2
          ids.each do |id, n|
            return false if $game_party.armor_number(id) < n
          end
        end
      end
    end
    # Return Original Test
    return seph_skillsuseitems_scu?(skill_id)
  end
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    # If Original Effect
    if (effective = self.seph_skillsuseitems_se(user, skill))
      # If User is an Actor
      if user.is_a?(Game_Actor)
        # Lose Item Cost
        skill.item_cost.each do |item_type, ids|
          # Items
          if item_type == 0
            ids.each { |id, n| $game_party.lose_item(id, n) }
          # Weapons
          elsif item_type == 1
            ids.each { |id, n| $game_party.lose_weapon(id, n) }
          # Armors
          elsif item_type == 2
            # Lose All Armors
            ids.each { |id, n| $game_party.lose_armor(id, n) }
          end
        end
      end
    end
    # Return Effectiveness
    return effective
  end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end

Now, go to this Line:

Code:
class RPG::Skill
  #--------------------------------------------------------------------------
  # * Skills That Use Items
  #
  #  ~ skill_id => { item_type => { id => n, ... }, ...}
  #
  #  Item_Types = 0 : Items, 1 : Weapons, 2 : Armors
  #--------------------------------------------------------------------------
  Item_Cost = {
  }
  Item_Cost.default = {}

and when says:

Code:
 Item_Cost = {
  }

put your requirements.

- Type of the item: The type, 0 : Items, 1 : Weapons, 2 : Armors.
- ID: The ID of the Item (the ID of the item, that is in the Type Database Item)
- N: The ammount of Item that will be used in the Skill.

For example (By default) to use the Skill ID: 1 (Heal) you need Item ID: 1 (Potion) 2x.

Code:
 Item_Cost = { 1 => { 0 => {1, 2} } }

Now that will work ( I tested it), but if you have another scripts that affect the Skill or something I don't know, so you need the help of another skilled scripter. but if that work for you Good.

Luck!
 
Thanks!!
Both requiring and consuming an item are working now but theres still two littler things that I'm having trouble with.

1) The first is that if I heal a character in battle when their health is full the skill still heals them without consuming the item.
So I was wondering if there was a way to either make it so they can't be healed when they have full life or make the the skill consume an item in this situation as well.

2) The other problem I'm having is making it so that more then one skill can require an item. I tried adding an extra item_cost line but it made it so only the second item_cost worked. So then I tried making a second copy of the script but I get a "System Stack Error - stack level too deep" when I go into skills menu.

Thanks again for the help!
 

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