Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gold converted to decimals
#1
Gold converted to decimals
by Jadant
Nov 18 2006

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


The basic idea is to convert the monetary values into decimals each time they are displayed on-screen. I also added a dollar sign to the display to make it appear as american currency.

This is my first attempt at making a script, but it's been working without any problems as far as I can tell. I appreciate any suggestions about how I might make it better, cleaner, etc.

Oh, and big thanks to everybody that's taken the time to make a tutorial, I'm really learning a lot.

Edit: Line 22 was changed to correctly log SDK. That's what I get for trying to cut/paste when I'm tired.

Code:
#==============================================================================
# ■ Dollars
#==============================================================================
# Jadant
# Version 1
# 18.11.06
#
#Used to convert gold to dollars and cents.
#The change is purely superficial and only changes the window displays,
#no changes to actual gold calculations.
#==============================================================================


#--------------------------------------------------------------------------
# * SDK Log Script
#--------------------------------------------------------------------------
SDK.log("Dollars", "Jadant", 1, "18.11.06")

#--------------------------------------------------------------------------
# * Begin SDK Enable Test
#--------------------------------------------------------------------------
if SDK.state("Dollars") == true
  
  
  #===================================================
  # ▼ CLASS Window_Gold additional code begins
  #===================================================

  
  class Window_Gold < Window_Base
  
    alias jadant_dollars_window_gold_refresh refresh
  
    def refresh
    
      @totalcents = $game_party.gold          
      dollars = @totalcents / 100 % 100      
      cents = @totalcents % 100              
      money = sprintf("$%s.%02d", dollars.to_s, cents)
    
      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, money.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


  #===================================================
  # ▲ CLASS Window_Gold additional code ends
  #===================================================
  
  
  #===================================================
  # ▼ CLASS Window_ShopBuy additional code begins
  #===================================================

  
  class Window_ShopBuy < Window_Selectable
  
    alias jadant_dollars_window_shopbuy_draw_item draw_item

    def draw_item(index)
      item = @data[index]
      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 item.price <= $game_party.gold 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)
      @totalcents_price = item.price
      dollars_price = @totalcents_price / 100 % 100
      cents_price = @totalcents_price % 100
      item_price = sprintf("$%s.%02d", dollars_price.to_s, cents_price)
      self.contents.draw_text(x + 240, y, 88, 32, item_price, 2)
    end
  end
  
  #===================================================
  # ▲ CLASS Window_ShopBuy additional code ends
  #===================================================
  
  #===================================================
  # ▼ CLASS Window_ShopNumber additional code begins
  #===================================================


  class Window_ShopNumber < Window_Base
    alias jadant_dollars_Window_ShopNumber_refresh refresh

    def refresh
      self.contents.clear
      draw_item_name(@item, 4, 96)
      self.contents.font.color = normal_color
      self.contents.draw_text(272, 96, 32, 32, "×")
      self.contents.draw_text(308, 96, 24, 32, @number.to_s, 2)
      self.cursor_rect.set(304, 96, 32, 32)

      domination = $data_system.words.gold
      cx = contents.text_size(domination).width
      total_price = @price * @number
      dollars = total_price / 100 % 100
      cents = total_price % 100
      money = sprintf("$%s.%02d", dollars.to_s, cents)
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 160, 328-cx-2, 32, money, 2)
      self.contents.font.color = system_color
      self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
    end
  end

  
  #===================================================
  # ▲ CLASS Window_ShopBuy additional code ends
  #===================================================
  
  
  #===================================================
  # ▼ CLASS Window_BattleResult additional code begins
  #===================================================

  
  class Window_BattleResult < Window_Base
  
    alias jadant_dollars_window_battleresult_refresh refresh

    def refresh
      dollars = @gold / 100 % 100
      cents = @gold % 100
      money = sprintf("$%s.%02d", dollars.to_s, cents)
      self.contents.clear
      x = 4
      self.contents.font.color = normal_color
      cx = contents.text_size(@exp.to_s).width
      self.contents.draw_text(x, 0, cx, 32, @exp.to_s)
      x += cx + 4
      self.contents.font.color = system_color
      cx = contents.text_size("Exp").width
      self.contents.draw_text(x, 0, 64, 32, "Exp")
      x += cx + 16
      self.contents.font.color = normal_color
      cx = contents.text_size(money).width
      self.contents.draw_text(x, 0, cx, 32, money)
      x += cx + 4
      self.contents.font.color = system_color
      self.contents.draw_text(x, 0, 128, 32, $data_system.words.gold)
      y = 32
      for item in @treasures
        draw_item_name(item, 4, y)
        y += 32
      end
    end
  end

  #===================================================
  # ▲ CLASS Window_BattleResult additional code ends
  #===================================================


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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Gold Display Add-Ons Mister C Major 0 2,018 04-30-2007, 01:00 PM
Last Post: Mister C Major
  Gained item/gold window. Jimmie 0 2,147 08-28-2005, 01:00 PM
Last Post: Jimmie



Users browsing this thread: