Tax System

Tax System VX Version: 2.0
By: Delyemerald2 (Original XP version by Falcon)

Introduction

With this script you can add taxes to shops, or even add discounts. Depending on the item's price, you can make taxes or discounts everywhere. You can even create shops which will give you money when you buy an item if you overdo the discounts.

Features
  • Taxes (in percentage)
  • Taxes (in amounts)
  • Discounts (in percentage)
  • Discounts (in amounts)
  • Free items (which aren't free normally)
  • Items (that are free normally) with a price
  • Free items with money

Screenshots

Normally Spoiler
Image

With Tax Spoiler
Image

With Discount Spoiler
Image

Overdid it a little =P Spoiler
Image


Script
  1.  
  2. #============================================================================
  3. # Tax Script 2.0 (VX)
  4. #----------------------------------------------------------------------------
  5. # Originally made by Falcon for RMXP (see further info at bottom of this part)
  6. # Edited by Delyemerald2 to fit the RMVX
  7. #----------------------------------------------------------------------------
  8. # This system adds something to shop status, but in the same process, copies
  9. # Everything normally there.
  10. # With this script, you can add taxes or discounts.
  11. # In order to do so, use the command Script in an event and enter this:
  12. # (For Taxes)
  13. # $game_system.taxrate = x
  14. # Where x is a value above 0 (will be counted in percentages)
  15. # $game_system.taxamount = y
  16. # Where y is a value above 0 (this will be added to the base prices)
  17. # (For Discounts)
  18. # $game_system.taxrate = x
  19. # Where x is a value below 0 (will be counted in percentages)
  20. # $game_system.taxamount = y
  21. # Where y is a value below 0 (this will be added to the base prices)
  22. #----------------------------------------------------------------------------
  23. # Credits to:
  24. # Falcon for the original script
  25. # Blizard for the idea that triggered version 2.0 (Falcon's Credits)
  26. # You, becuase you eat a cookie in your life =D
  27. #----------------------------------------------------------------------------
  28. # ORIGINAL INFO (RMXP Version)
  29. #----------------------------------------------------------------------------
  30. # By Falcon
  31. # Thanks to Blizzard for the idea that triggered version 2.0
  32. #----------------------------------------------------------------------------
  33. # This system should be compatible with all shop systems, but the
  34. # Shop Status window will only show the tax/discount rate for the default
  35. #============================================================================
  36.  
  37. # setup the variable that will hold the tax rate
  38. class Game_System
  39.   attr_accessor :taxrate
  40.   attr_accessor :taxamount
  41.   alias declaration initialize
  42.   def initialize
  43.     declaration
  44.     @taxrate = 0
  45.     @taxamount = 0
  46.   end
  47. end
  48.  
  49. # increase the price of the following items by the tax rate
  50. class RPG::Item
  51.   def price
  52.     return Integer(@price + $game_system.taxamount + @price * $game_system.taxrate / 100)
  53.   end
  54. end
  55.  
  56. class RPG::Weapon
  57.   def price
  58.     return Integer(@price + $game_system.taxamount + @price * $game_system.taxrate / 100)
  59.   end
  60. end
  61.  
  62. class RPG::Armor
  63.   def price
  64.     return Integer(@price + $game_system.taxamount + @price * $game_system.taxrate / 100)
  65.   end
  66. end
  67.  
  68. class Window_ShopStatus < Window_Base
  69.   #--------------------------------------------------------------------------
  70.   # * Object Initialization
  71.   #     x : window X coordinate
  72.   #     y : window Y coordinate
  73.   #--------------------------------------------------------------------------
  74.   def initialize(x, y)
  75.     super(x, y, 240, 304)
  76.     @item = nil
  77.     refresh
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Refresh
  81.   #--------------------------------------------------------------------------
  82.   def refresh
  83.     self.contents.clear
  84.     if @item != nil
  85.       number = $game_party.item_number(@item)
  86.       self.contents.font.color = system_color
  87.       self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
  88.       self.contents.font.color = normal_color
  89.       self.contents.draw_text(4, 0, 200, WLH, number, 2)
  90. # Here you can customize what there will stand when there's a tax. You can also
  91. # edit the heights of the words and numbers. One warning: Don't make it to long
  92. # or it will overlap the percentages.
  93.       if $game_system.taxrate > 0 # If there is tax
  94.        self.contents.draw_text(4, 16, 200, WLH, "Current Tax")
  95.        self.contents.font.color = normal_color
  96.        self.contents.draw_text(100, 16, 104, WLH, $game_system.taxrate.to_s + "%", 2)
  97.      elsif 0 > $game_system.taxrate # If there is a discount rate
  98.        self.contents.draw_text(4, 16, 200, WLH, "Discount")
  99.        self.contents.font.color = normal_color
  100.        self.contents.draw_text(100, 16, 104, WLH, $game_system.taxrate.to_s + "%", 2)
  101.      end
  102.       if $game_system.taxamount > 0 # If there is tax
  103.        self.contents.draw_text(4, 32, 200, WLH, "Tax (A)")
  104.        self.contents.font.color = normal_color
  105.        self.contents.draw_text(100, 32, 104, WLH, $game_system.taxamount.to_s , 2)
  106.      elsif 0 > $game_system.taxamount # If there is a discount rate
  107.        self.contents.draw_text(4, 32, 200, WLH, "Discount (A)")
  108.        self.contents.font.color = normal_color
  109.        self.contents.draw_text(100, 32, 104, WLH, $game_system.taxamount.to_s , 2)
  110.      end
  111.       for actor in $game_party.members
  112.         x = 4
  113.         y = WLH * (2 + actor.index * 2)
  114.         draw_actor_parameter_change(actor, x, y)
  115.       end
  116.     end
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Draw Actor's Current Equipment and Parameters
  120.   #     actor : actor
  121.   #     x     : draw spot x-coordinate
  122.   #     y     : draw spot y-coordinate
  123.   #--------------------------------------------------------------------------
  124.   def draw_actor_parameter_change(actor, x, y)
  125.     return if @item.is_a?(RPG::Item)
  126.     enabled = actor.equippable?(@item)
  127.     self.contents.font.color = normal_color
  128.     self.contents.font.color.alpha = enabled ? 255 : 128
  129.     self.contents.draw_text(x, y, 200, WLH, actor.name)
  130.     if @item.is_a?(RPG::Weapon)
  131.       item1 = weaker_weapon(actor)
  132.     elsif actor.two_swords_style and @item.kind == 0
  133.       item1 = nil
  134.     else
  135.       item1 = actor.equips[1 + @item.kind]
  136.     end
  137.     if enabled
  138.       if @item.is_a?(RPG::Weapon)
  139.         atk1 = item1 == nil ? 0 : item1.atk
  140.         atk2 = @item == nil ? 0 : @item.atk
  141.         change = atk2 - atk1
  142.       else
  143.         def1 = item1 == nil ? 0 : item1.def
  144.         def2 = @item == nil ? 0 : @item.def
  145.         change = def2 - def1
  146.       end
  147.       self.contents.draw_text(x, y, 200, WLH, sprintf("%+d", change), 2)
  148.     end
  149.     draw_item_name(item1, x, y + WLH, enabled)
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Get Weaker Weapon Equipped by the Actor (for dual wielding)
  153.   #     actor : actor
  154.   #--------------------------------------------------------------------------
  155.   def weaker_weapon(actor)
  156.     if actor.two_swords_style
  157.       weapon1 = actor.weapons[0]
  158.       weapon2 = actor.weapons[1]
  159.       if weapon1 == nil or weapon2 == nil
  160.         return nil
  161.       elsif weapon1.atk < weapon2.atk
  162.         return weapon1
  163.       else
  164.         return weapon2
  165.       end
  166.     else
  167.       return actor.weapons[0]
  168.     end
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # * Set Item
  172.   #     item : new item
  173.   #--------------------------------------------------------------------------
  174.   def item=(item)
  175.     if @item != item
  176.       @item = item
  177.       refresh
  178.     end
  179.   end
  180. end
Expand to see the code.


Instructions

Paste above main, underneath ALL standard shop scripts.
Use the command Script in an event and enter this:
(For Taxes)
$game_system.taxrate = x
Where x is a value above 0 (will be counted in percentages)
$game_system.taxamount = y
Where y is a value above 0 (this will be added to the base prices)
(For Discounts)
$game_system.taxrate = x
Where x is a value below 0 (will be counted in percentages)
$game_system.taxamount = y
Where y is a value below 0 (this will be added to the base prices)

Compatibility

No compatibility issues are found yet. If any are found, report them please.

Credits and Thanks

Falcon for the original RMXP version

Author's Notes

The original version is on an other site. I've said there that any requests are welcome, and thus this script CAN be updated. If any of you have a request, PM me please.

Terms and Conditions

This script is open for everyone, but be sure to credit Falcon, for the original version, and me for the small edits.
Been awhile since I have done this, but in the interest of getting back into things, a little review of your script:

Very nice and neat script. The only thing I would suggest is would be to make a Game_System::Tax class, to hold your direct and percent rates, as well as a method to convert a price from its base price to modified price (for things more than just Items, Weapons and Armors:
  1.  
  2. class Game_System::Tax
  3.   Direct_First = true
  4.   attr_accessor :percent
  5.   attr_accessor :direct
  6.   def initialize
  7.     @percent = 100
  8.     @direct = 0
  9.   end
  10.   def modify(n)
  11.     if Direct_First
  12.       n += @direct
  13.       n = Integer(n * (@percent / 100.0))
  14.     else
  15.       n = Integer(n * (@percent / 100.0))
  16.       n += @direct
  17.     end
  18.     return n
  19.   end
  20. end
  21.  
  22. class Game_System
  23.   attr_reader :tax
  24.   alias_method :delyemerald2_tax_init, :initialize
  25.   def initialize
  26.     delyemerald2_tax_init
  27.     @tax = Tax.new
  28.   end
  29. end
  30.  
  31. class RPG::Item
  32.   def price
  33.     return $game_system.modify(@price)
  34.   end
  35. end
  36.  
  37. #...
Expand to see the code.


Also your aliasing. It is better to have a very percise name when renaming methods. If that first argument is ever used again in an alias, you'll end up in a stack error. Best format (or most practical) would be yourname_scriptname_methodname. I also threw in an option to perform direct modifications first, or second.

Works the same, but you change your rates with:
  1. $game_system.tax.direct =
  2. - or -
  3. $game_system.tax.percent =
Expand to see the code.


Happy scripting.
Thanks for the tips.
As for that part you gave me, it doens't real work.
First of all, that def modify went wrong. (gonna try to fix it)
Second, you set the tax.percent on 100 but it should be on 0. Else, the game starts of with 100% tax.
100 is a base. You are taking the price * n / 100. If you wanted, you could modify this line:
  1. n = Integer(n * (@percent / 100.0))
  2. - to -
  3. n = Integer(n * ((100 + @percent) / 100.0))
Expand to see the code.


That would work with your setup. I merely work percentages differently than you lol.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=69976