Refreshing original skills names
#1
Hey everyone!
I'm using Skills That Consume Items Ver 1.00a by Cogwheel modified to use skill ID rather that its name. Also, I have script that lets me put item amount in almost every place with command \It[#] (it also produces stack level too deep error with game resetting as side effect, but it's ok for now). So I have that skill e.g., "Poisonous Slash [Icon] 0/1", and its works, but only once... so its actually doesn't. Name of the skill is adjusted just once, when I will see it in any window for the first time. If I will currently have 6 poisons it will be "Poisonous Slash [Icon] 6/1" and it won't change even if poisons amount will. So original name of the skill is "Poisonous Slash [Icon] \It[#]/1", but after first look it permanently replaces \It[#] with number and command can't be used again. So I figured out that there should be the way to remember original name of the skill and "refresh" it after each attack/item use. This way skill name would always adjust to the current item amount in possession. I tried to script it by myself, but my scripting skills are close to 0. I'm becoming better in modifying scripts but I don't really have skills to write them. Can someone help me with that? Or maybe someone have different idea to solve the problem with item name adjustment?

So here you have scripts:
Code:
# Skills That Consume Items Ver 1.00a
# Distribution original support URL
# http://members.jcom.home.ne.jp/cogwheel/

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Set Skill Medium (Item(s) used by Skill)
  #--------------------------------------------------------------------------
  def medium(skill_id)
    case $data_skills[skill_id].id
    when 119
      return [["Jad", 1]]
    when 123
      return [["Jad", 1]]
    when 124
      return [["Jad", 2]]
    when 287
      return [["Okruch Duszy", 10]]
    when 288
      return [["Okruch Duszy", 1]]
    end
    return false
  end
  
  #--------------------------------------------------------------------------
  # * Get Item Name
  #--------------------------------------------------------------------------
  def item_name(name)
    for item in $data_items
      if item != nil and name == item.name
        return item.id
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Determine if Skill can be Used
  #     skill_id : skill ID
  #--------------------------------------------------------------------------
  def skill_can_use?(skill_id)
    items = medium(skill_id)
    if items
      for item in items
        id = item_name(item[0])
        if $game_party.item_number(id) < (item[1] == nil ? 1 : item[1])
          return false
        end
      end
    end
    return super
  end
end

#==============================================================================
# ** Scene_Battle (part 4)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Make Skill Action Results
  #--------------------------------------------------------------------------
  def make_skill_action_result(battler)
    # Get skill
    @skill = $data_skills[battler.current_action.skill_id]
    # Verification whether or not it is cooperation skill
    speller = synthe?(battler)
    # If not a forcing action
    unless battler.current_action.forcing
      # When with SP and so on is cut off and it becomes not be able to use
      if speller == nil
        unless battler.skill_can_use?(@skill.id)
          # Shift to step 6
          battler.phase = 6
         return
        end
      end
    end
    # SP consumption
    temp = false
    if speller != nil
      for spell in speller
        if spell.current_action.spell_id == 0
          spell.sp -= @skill.sp_cost
        else
          spell.sp -= $data_skills[spell.current_action.spell_id].sp_cost
        end
      # Refreshing the status window
        status_refresh(spell)
      end
    else
      battler.sp -= @skill.sp_cost
      # Refreshing the status window
      status_refresh(battler)
    end
    # Setting animation ID
    battler.anime1 = @skill.animation1_id
    battler.anime2 = @skill.animation2_id
    # Setting common event ID
    battler.event = @skill.common_event_id
    # Setting the object side battler
    set_target_battlers(@skill.scope, battler)
    # Applying the effect of skill
    for target in battler.target
      if speller != nil
        damage = 0
        effective = false
        state_p = []
        state_m = []
        for spell in speller
          if spell.current_action.spell_id != 0
            @skill = $data_skills[spell.current_action.spell_id]
          end
          effective |= target.skill_effect(spell, @skill)
          if target.damage[spell].class != String
            damage += target.damage[spell]
          elsif effective == true
            effect = target.damage[spell]
          end
          state_p += target.state_p[spell]
          state_m += target.state_m[spell]
          target.damage.delete(spell)
          target.state_p.delete(spell)
          target.state_m.delete(spell)
        end
        if damage != 0
          target.damage[battler] = damage
        elsif effective = true
          target.damage[battler] = effect
        end
        target.state_p[battler] = state_p
        target.state_m[battler] = state_m
      else
        target.skill_effect(battler, @skill)
      end
    end
    # If item(s) are used
    if battler.is_a?(Game_Actor)
      items = battler.medium(@skill.id)
      if items
        for item in items
          id = battler.item_name(item[0])
          num = item[1] == nil ? 1 : item[1]
          # Check if consumable              
          if $data_items[id].consumable
            $game_party.gain_item(id, -num)
          end
        end
      end
    end
  end
end

#==============================================================================
# ** Scene_Skill
#------------------------------------------------------------------------------
#  This class performs skill screen processing.
#==============================================================================

class Scene_Skill
  #--------------------------------------------------------------------------
  # * Frame Update (when target window is active)
  #--------------------------------------------------------------------------
  def update_target
    # If B button was pressed
    
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Erase target window
      @skill_window.active = true
      @target_window.visible = false
      @target_window.active = false
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # If unable to use because SP ran out
      unless @actor.skill_can_use?(@skill.id)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # If target is all
      if @target_window.index == -1
        # Apply skill use effects to entire party
        used = false
        for i in $game_party.actors
          used |= i.skill_effect(@actor, @skill)
        end
      end
      # If target is user
      if @target_window.index <= -2
        # Apply skill use effects to target actor
        target = $game_party.actors[@target_window.index + 10]
        used = target.skill_effect(@actor, @skill)
      end
      # If single target
      if @target_window.index >= 0
        # Apply skill use effects to target actor
        target = $game_party.actors[@target_window.index]
        used = target.skill_effect(@actor, @skill)
      end
      # If skill was used
      if used
        # If item(s) are used
        if @actor.is_a?(Game_Actor)
          items = @actor.medium(@skill.id)
          if items
            for item in items
              id = @actor.item_name(item[0])
              num = item[1] == nil ? 1 : item[1]
              # Check if consumable              
              if $data_items[id].consumable
                $game_party.gain_item(id, -num)
              end
            end
          end
        end
        # Play skill use SE
        $game_system.se_play(@skill.menu_se)
        # Use up SP
        @actor.sp -= @skill.sp_cost
        # Remake each window content
        @status_window.refresh
        @skill_window.refresh
        @target_window.refresh
        # If entire party is dead
        if $game_party.all_dead?
          # Switch to game over screen
          $scene = Scene_Gameover.new
          return
        end
        # If command event ID is valid
        if @skill.common_event_id > 0
          # Command event call reservation
          $game_temp.common_event_id = @skill.common_event_id
          # Switch to map screen
          $scene = Scene_Map.new
          return
        end
      end
      # If skill wasn't used
      unless used
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
      end
      return
    end
  end
end

This is the modification that I use to put item amount in skill name
Code:
class Bitmap
alias variable_sub draw_text
  def draw_text(*args)
   index = args[0].is_a?(Rect) ? 1 : 4
   args[index].gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
   args[index].gsub!(/\\[Ii]t\[([0-9]+)\]/) { $game_party.item_number($1.to_i) }
   variable_sub(*args)
end
end

This is how it looks during battle.
[Image: LJNzcVt.png]

BTW — I promise that I will watch RGSS programming Course before posting any other thread Winking
Reply }
#2
The problem seems to be you're permanently modifying the text with gsub! instead of gsub. Of course, gsub doesn't modify the string permanently so you gotta assign it to the args array manually. Since it would be treated as a new string, the tags you've been using would not disappear, and they would be parsed every single time that comment is read by the game engine.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }
#3
(05-31-2020, 02:31 AM)kyonides Wrote: The problem seems to be you're permanently modifying the text with gsub! instead of gsub. Of course, gsub doesn't modify the string permanently so you gotta assign it to the args array manually. Since it would be treated as a new string, the tags you've been using would not disappear, and they would be parsed every single time that comment is read by the game engine.

I still didn't know what to do. The script I was using isn't mine, I found it as no copyrighted advice for someone's else request (as far as I remember), but its not important anymore, since I'm not using it now. I have tried to adjust this script with my close-to-zero programming skills but it was futile, so I tried to find the author of the script I've used to credit him. I couldn't find it, but I've found different script instead, and this one works for me Very happy + Tongue sticking out

http://www.hbgames.org/forums/viewtopic....11&t=74073

Thank you, kyonides. I found that thanks to you Winking
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Handling very long Item Names Mel 4 8,380 09-24-2018, 06:37 PM
Last Post: Mel
   Actor names in Quest Script jreagan406 5 8,835 03-07-2017, 08:06 AM
Last Post: JayRay
   Showing only specific skills in a window Mel 2 5,991 01-12-2016, 01:34 PM
Last Post: Mel
   Syvakal's Conditional Skills And Equipment Crashes Samven 0 3,992 08-02-2011, 01:58 PM
Last Post: Samven
   Help with using KGC's delayed skills prioran 0 3,675 05-07-2010, 11:46 PM
Last Post: prioran
   Skills that restore SP and reactive skills. Admetrynne 5 8,218 03-29-2010, 05:49 PM
Last Post: Admetrynne
   Element transmited to skills by weapons mageone 27 33,231 11-20-2009, 07:44 PM
Last Post: mageone



Users browsing this thread: 1 Guest(s)