じ☆ve冰风 发表于 2026-8-2 19:37:27

FG7 - Easy Item Charges

Easy Item Charges
By: FamilyGamer7

Introduction
                        This script was designed to imitate an item charge effect on consumable items. I had this script created within my own project/game and I thought someone could find it useful. Easy and efficient.               
Click to expand...


Features
                        The ability to have an item charge count on a consumable item for multiple uses. By default the game engine works similar in this way without the concept of non-stacks. The script is designed/intended to be used with Hime - Instance Items and is also a requirement for this script run and work.
Click to expand...


Screenshots
                        - Not Needed -               
Click to expand...


Script
Spoiler: FG7 - Easy Item Charges                Ruby:       
#==============================================================================
# Title: Easy Item Charges
# Author: FamilyGamer7 (FG7)
# Version: 1.3
# Engine: RPG Maker VX Ace
#==============================================================================
# ** Description |
# ----------------
# The "easiest" way to implement an Item Charge type effect on items.
#==============================================================================
# ** Change Log |
# ---------------
# 1.0 => Created Script
# 1.1 => Removed "Alias" method as it caused issues with the project
# 1.2 => Removed item charge limit (Flexible for any game/project)
# 1.3 => Added Item Charges switch for ON/OFF functionality
#==============================================================================
# ** Terms of Use |
# -----------------
# * Free to use in non-commercial projects and commercial projects
# * Feel free to modify and improve the script. Credit is still required.
# * Credit FamilyGamer7
#==============================================================================
# ** Script(s) Required |
# -----------------------
# Hime - Instance Items:
# (http://himeworks.com/redirect.php?type=script&name=Instance_Items)
#
# Place this script below "Hime - Instance Items" script.
#==============================================================================
# ** Usage |
# ----------
# * Plug & Play (See notes below for more information)
#==============================================================================
# ** Notes |
# ----------
# Just need to add "ANY" number value on the end of your item name.
#
# Ex: "Potion 3"
# Ex: "Antidote 76"
# Ex: "Elixir 6"
#
# -----------------
# | Script calls: |
# -----------------

# - To turn script off:
#   $game_system.item_charges_switch_off(true)
#
# - To turn script on:
#   $game_system.item_charges_switch_off(false)
#
# * This script is ON by default, so the turn script on call is not needed
#   unless you used the turn off script.
#==============================================================================

#==============================================================================
# ** Required Script Checker
#------------------------------------------------------------------------------
# Ensures Required Script is in place. If not, Game will close down.
#==============================================================================

$imported = {} if $imported.nil?
unless $imported["TH_InstanceItems"]
    msgbox("Required 'Hime - Instance Items' is not detected - Closing Game")
exit
end

#==============================================================================
# ** Module: FG7::Easy_Item_Charges
#------------------------------------------------------------------------------
#This modules creates a static variable to be used within the script.
#==============================================================================

module FG7
module Easy_Item_Charges
   
#==============================================================================
# -------------------- ALLOWED TO EDIT BELOW THIS LINE ---------------------- #
#==============================================================================

# Sets the switch number used for the Item Charges script
# (Feel free to change switch number for your project)
Item_Charge_Switch = 1001

#==============================================================================
# ---------- DO NOT EDIT BELOW THIS LINE (FOR ADVANCED USERS) --------------- #
#==============================================================================

end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#This class handles system data. It saves the disable state of saving and
# menus. Instances of this class are referenced by $game_system.
#==============================================================================

class Game_System
#--------------------------------------------------------------------------
# * New Method: Item Charges Switch - To turn OFF/ON
# (By default the switch is off = the script is turned "ON" working)
#--------------------------------------------------------------------------
def item_charges_switch_off(string)
    $game_switches = string
end
end

#==============================================================================
# ** Scene_ItemBase
#------------------------------------------------------------------------------
#This class performs common processing for the item screen and skill screen.
#==============================================================================

class Scene_ItemBase < Scene_MenuBase
#--------------------------------------------------------------------------
# * Alias Method: Use Item (Modified to simulate "Item Charges" on items)
#--------------------------------------------------------------------------
alias :fg7_easy_item_charges_use_item :use_item
def use_item
    # Checks if switch is turned on to use item charges for items
    if $game_switches == false
      play_se_for_item
      # Checks if a number is in the items name
      if item.name =~ /\d/
      # Separates the number from item.name and subtracts to equal new number
      $item_name = item.name
      $original_charge = $item_name.gsub(/[^0-9]/, '')
      $reduced_charge = $original_charge.to_i - 1
      $item_name = $item_name.gsub!(/\d+/,"") + $reduced_charge.to_s
      # If item charge equals 1 - remove the "1" number value on item name
      if $reduced_charge.to_s == "1"
          $item_name = $item_name.gsub!(/\d+/,"")
      end
      # Places item variable back into "item.name"
      item.name = $item_name
      @category_window.activate
      # When no number in item name - treat item as normal usage
      else
      user.use_item(item)
      # If consuming last item in list, move cursor to top of list
      @item_window.select(0) if item == nil
      end
      use_item_to_actors
      check_common_event
      check_gameover
      @actor_window.refresh
      # Added to provide a true item charge usage feel
      @actor_window.deactivate.unselect
    else
      # If switch is turned off - perform original use_item call
      fg7_easy_item_charges_use_item
    end
end
end


How to Use
                        Add this script in the script editor under in the "Materials" section and above "Main Process".
The instructions and setup for the script are held within the script header itself. No need to repeat here.               
Click to expand...


Terms of Use
                        - Free to use in non-commercial projects and commercial projects
- Feel free to modify and improve the script. Credit is still required.
- Credit FamilyGamer7               
Click to expand...




本贴来自国际rpgmaker官方论坛作者:FG7处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/fg7-easy-item-charges.143823/
页: [1]
查看完整版本: FG7 - Easy Item Charges