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.

Money as an item...

Heya.

I need a simple script that does this:

Any time money changing is called, it instead removes/adds a certain item called "Gold".

So basically, if you are in a shop and it removes 50 gold, it instead removes 50 of this item. If you gain gold through an event process, it instead gives you the item.

The item also needs to be unlimited (but not other items). Or a limit of say... 999,999.

Thanks if you can do this, if not then thanks for looking.

Cheers,
~Wyatt
 

poccil

Sponsor

Here are the changes to make in the Game_Party class (change 200 to the appropriate item ID for gold):

Code:
class Game_Party
  MONEY_ITEM = 200 # Set this to the item ID for gold
  def gain_gold(n)
     gain_item(MONEY_ITEM, n)
  end
  def lose_gold(n)
     lose_item(MONEY_ITEM, n)
  end
  def gain_item(item_id,n)
     # define maximum
     maxcount=(item_id==MONEY_ITEM) ? 999999 : 99
     if item_id > 0
       @items[item_id] = [[item_number(item_id) + n, 0].max, maxcount].min
     end
  end
  def lose_item(item_id, n)
    gain_item(item_id, -n)
  end
end
 
I had this made a long time ago, and I'm still using it, only thing is now, I've made a bunch of edits to it, I'll have to find an old version of it that didn't have any of my personal edits.

Found it.
Code:
#===============================================================================
# ** Currency as Item
#-------------------------------------------------------------------------------
# Author    Icedmetal57
# Version   1.0
# Date      November 2nd, 2006
#===============================================================================
#
# Description
#-------------------
# Changes your currency into an item, instead of just a regular scripted
# variable. Great for games that have an item amount limit, based on weight.
# This was originally made for that purpose, along with making it possible to
# trade money in a Netplay Plusâ„¢ game client.
#
# Instructions
#-------------------
# Scroll down a bit to the Item_Id, and change it to the id of the item,
# representing your currency.
#
# Compatability
#-------------------
# Compatible with SDK.
# To make it compatible with non-SDK, just delete the SDK lines.
# Uncompatible with most custom shop scripts, and uncompatible with all
# multi-currency scripts. Can be compatible with custom shop scripts, but
# will require some extra work to do so.
#
#-------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Currency as Item', 'Icedmetal57', '1.0', 'Nov - 2 - 2006')

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state('Currency as Item') == true

module Currency
  #--------------------------------------------------------------------------
  # * Variable Setup
  #--------------------------------------------------------------------------
  Item_Id = 1 # id number of the item you wish to represent your currency
end

#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold 
#  and items. Refer to "$game_party" for the instance of this class.
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Gain Items (or lose)
  #     item_id : item ID
  #     n       : quantity
  #--------------------------------------------------------------------------
  def gain_item(item_id, n)
    # Update quantity data in the hash.
    if item_id > 0
      case item_id
      when Currency::Item_Id.to_i
        @items[item_id] = [[item_number(item_id) + n, 0].max, 9999999].min
      else
        @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Gain Gold (or lose)
  #     n : amount of gold
  #--------------------------------------------------------------------------    
  def gain_gold(n)
    @items[Currency::Item_Id.to_i] = [[item_number(Currency::Item_Id.to_i) + n, 0].max, 9999999].min
  end
end


#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays amount of gold.
#==============================================================================

class Window_Gold < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    cx = contents.text_size($data_system.words.gold).width
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.item_number(Currency::Item_Id.to_i).to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
  end
end


#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
#  This window displays items in possession on the item and battle screens.
#==============================================================================

class Window_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(32, 96, 576, 352)
    @column_max = 2
    refresh
    self.index = 0
    # If in battle, move window to center of screen
    # and make it semi-transparent
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    self.contents.font.size = 14
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      if item.id == Currency::Item_Id.to_i
        @gold_item = 240 - (contents.text_size($game_party.item_number(Currency::Item_Id.to_i).to_s).width)
        @gold_item2 = 204
        @gold_item3 = 72
      else
        @gold_item = 240
        @gold_item2 = 256
        @gold_item3 = 24
      end
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      @gold_item = 240
      @gold_item2 = 256
      @gold_item3 = 24
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      @gold_item = 240
      @gold_item2 = 256
      @gold_item3 = 24
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288)# + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + @gold_item.to_i - 32, y, 16, 32, ":", 1)
    self.contents.draw_text(x + @gold_item2.to_i - 32, y, @gold_item3.to_i, 32, number.to_s, 2)
  end
end


#==============================================================================
# ** Window_ShopBuy
#------------------------------------------------------------------------------
#  This window displays buyable goods on the shop screen.
#==============================================================================

class Window_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    # Get items in possession
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    # If price is less than money in possession, and amount in possession is
    # not 99, then set to normal text color. Otherwise set to disabled color
    if item.price <= $game_party.item_number(Currency::Item_Id.to_i) and number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 88, 32, item.price.to_s, 2)
  end
end


#==============================================================================
# ** Scene_Shop
#------------------------------------------------------------------------------
#  This class performs shop screen processing.
#==============================================================================

class Scene_Shop
  #--------------------------------------------------------------------------
  # * Frame Update (when buy window is active)
  #--------------------------------------------------------------------------
  def update_buy
    # Set status window item
    @status_window.item = @buy_window.item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Change windows to initial mode
      @command_window.active = true
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      # Erase help text
      @help_window.set_text("")
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get item
      @item = @buy_window.item
      # If item is invalid, or price is higher than money possessed
      if @item == nil or @item.price > $game_party.item_number(Currency::Item_Id.to_i)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Get items in possession count
      case @item
      when RPG::Item
        number = $game_party.item_number(@item.id)
      when RPG::Weapon
        number = $game_party.weapon_number(@item.id)
      when RPG::Armor
        number = $game_party.armor_number(@item.id)
      end
      # If 99 items are already in possession
      if number == 99
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Calculate maximum amount possible to buy
      max = @item.price == 0 ? 99 : $game_party.item_number(Currency::Item_Id.to_i) / @item.price
      max = [max, 99 - number].min
      # Change windows to quantity input mode
      @buy_window.active = false
      @buy_window.visible = false
      @number_window.set(@item, max, @item.price)
      @number_window.active = true
      @number_window.visible = true
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when quantity input window is active)
  #--------------------------------------------------------------------------
  def update_number
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Set quantity input window to inactive / invisible
      @number_window.active = false
      @number_window.visible = false
      # Branch by command window cursor position
      case @command_window.index
      when 0  # buy
        # Change windows to buy mode
        @buy_window.active = true
        @buy_window.visible = true
      when 1  # sell
        # Change windows to sell mode
        @sell_window.active = true
        @sell_window.visible = true
        @status_window.visible = false
      end
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play shop SE
      $game_system.se_play($data_system.shop_se)
      # Set quantity input window to inactive / invisible
      @number_window.active = false
      @number_window.visible = false
      # Branch by command window cursor position
      case @command_window.index
      when 0  # buy
        # Buy process
        $game_party.lose_item(1,@number_window.number * @item.price)
        case @item
        when RPG::Item
          $game_party.gain_item(@item.id, @number_window.number)
        when RPG::Weapon
          $game_party.gain_weapon(@item.id, @number_window.number)
        when RPG::Armor
          $game_party.gain_armor(@item.id, @number_window.number)
        end
        # Refresh each window
        @gold_window.refresh
        @buy_window.refresh
        @status_window.refresh
        # Change windows to buy mode
        @buy_window.active = true
        @buy_window.visible = true
      when 1  # sell
        # Sell process
        $game_party.gain_item(Currency::Item_Id.to_i,@number_window.number * (@item.price / 2))
        case @item
        when RPG::Item
          $game_party.lose_item(@item.id, @number_window.number)
        when RPG::Weapon
          $game_party.lose_weapon(@item.id, @number_window.number)
        when RPG::Armor
          $game_party.lose_armor(@item.id, @number_window.number)
        end
        # Refresh each window
        @gold_window.refresh
        @sell_window.refresh
        @status_window.refresh
        # Change windows to sell mode
        @sell_window.active = true
        @sell_window.visible = true
        @status_window.visible = false
      end
      return
    end
  end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end
 
O.o..Now i know this can be done with events...Do you want that?-already made it-

EDIT: Too bad-Imma give it to you anyway.
Step 1:Make a variable called gold and then go to the very bottom where it says other and click on that then click "Gold".

Step 2: Go to Change Items and Make an item called "Gold" and select that on the first drag down and then on the second one click variable and drag down to the variable "Gold"

Ta-Da!
 
iCheeze... again with the events.

Please explain to me how in any way that will help for:

So basically, if you are in a shop and it removes 50 gold, it instead removes 50 of this item. If you gain gold through an event process, it instead gives you the item.
Shop system is in scripting, not event coding.

The item also needs to be unlimited (but not other items). Or a limit of say... 999,999.
You can't set items to be unlimited by default, without scripting.


Any time money changing is called, it instead removes/adds a certain item called "Gold".
So basically I'd have to make the event every time money si changed. I have an ABS, I have shop systems, I have countless events changing gold. I just want a system that'll see when it's changing the gold value and change the item instead.



Thanks everyone else, I'll try them all out.
 
Thats way wrong since events depend on scripts. Events < Scripts considering events require scripts to work.

Code:
class Events < Scripts
  def function_name(horrible_arguments)
    result = horrible_over_execution
    return result + lag
  end
end
 
I was like you iCheeze. But now I know there is no why for being like that. Scripts are a very way to save time, and simplify things.
By the way, the system he wants cannot be programmed, as soon as you can't change an item limit's by events.

But... What a strange ask. ._.
Why would someone want gold to be item? :|
 

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