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.

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

8wkuuh.jpg
213onwk.jpg
axh05y.jpg
2oylw.jpg

Script
Code:
 

#============================================================================

# Tax Script 2.0 (VX)

#----------------------------------------------------------------------------

# Originally made by Falcon for RMXP (see further info at bottom of this part)

# Edited by Delyemerald2 to fit the RMVX

#----------------------------------------------------------------------------

# This system adds something to shop status, but in the same process, copies

# Everything normally there.

# With this script, you can add taxes or discounts.

# In order to do so, 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)

#----------------------------------------------------------------------------

# Credits to:

# Falcon for the original script

# Blizard for the idea that triggered version 2.0 (Falcon's Credits)

# You, becuase you eat a cookie in your life =D

#----------------------------------------------------------------------------

# ORIGINAL INFO (RMXP Version)

#----------------------------------------------------------------------------

# By Falcon

# Thanks to Blizzard for the idea that triggered version 2.0

#----------------------------------------------------------------------------

# This system should be compatible with all shop systems, but the

# Shop Status window will only show the tax/discount rate for the default

#============================================================================

 

# setup the variable that will hold the tax rate

class Game_System

  attr_accessor :taxrate

  attr_accessor :taxamount

  alias declaration initialize

  def initialize

    declaration

    @taxrate = 0

    @taxamount = 0

  end

end

 

# increase the price of the following items by the tax rate

class RPG::Item

  def price

    return Integer(@price + $game_system.taxamount + @price * $game_system.taxrate / 100)

  end

end

 

class RPG::Weapon

  def price

    return Integer(@price + $game_system.taxamount + @price * $game_system.taxrate / 100)

  end

end

 

class RPG::Armor

  def price

    return Integer(@price + $game_system.taxamount + @price * $game_system.taxrate / 100)

  end

end

 

class Window_ShopStatus < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     x : window X coordinate

  #     y : window Y coordinate

  #--------------------------------------------------------------------------

  def initialize(x, y)

    super(x, y, 240, 304)

    @item = nil

    refresh

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    self.contents.clear

    if @item != nil

      number = $game_party.item_number(@item)

      self.contents.font.color = system_color

      self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)

      self.contents.font.color = normal_color

      self.contents.draw_text(4, 0, 200, WLH, number, 2)

# Here you can customize what there will stand when there's a tax. You can also

# edit the heights of the words and numbers. One warning: Don't make it to long

# or it will overlap the percentages.

      if $game_system.taxrate > 0 # If there is tax

       self.contents.draw_text(4, 16, 200, WLH, "Current Tax")

       self.contents.font.color = normal_color

       self.contents.draw_text(100, 16, 104, WLH, $game_system.taxrate.to_s + "%", 2)

     elsif 0 > $game_system.taxrate # If there is a discount rate

       self.contents.draw_text(4, 16, 200, WLH, "Discount")

       self.contents.font.color = normal_color

       self.contents.draw_text(100, 16, 104, WLH, $game_system.taxrate.to_s + "%", 2)

     end

      if $game_system.taxamount > 0 # If there is tax

       self.contents.draw_text(4, 32, 200, WLH, "Tax (A)")

       self.contents.font.color = normal_color

       self.contents.draw_text(100, 32, 104, WLH, $game_system.taxamount.to_s , 2)

     elsif 0 > $game_system.taxamount # If there is a discount rate

       self.contents.draw_text(4, 32, 200, WLH, "Discount (A)")

       self.contents.font.color = normal_color

       self.contents.draw_text(100, 32, 104, WLH, $game_system.taxamount.to_s , 2)

     end

      for actor in $game_party.members

        x = 4

        y = WLH * (2 + actor.index * 2)

        draw_actor_parameter_change(actor, x, y)

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Draw Actor's Current Equipment and Parameters

  #     actor : actor

  #     x     : draw spot x-coordinate

  #     y     : draw spot y-coordinate

  #--------------------------------------------------------------------------

  def draw_actor_parameter_change(actor, x, y)

    return if @item.is_a?(RPG::Item)

    enabled = actor.equippable?(@item)

    self.contents.font.color = normal_color

    self.contents.font.color.alpha = enabled ? 255 : 128

    self.contents.draw_text(x, y, 200, WLH, actor.name)

    if @item.is_a?(RPG::Weapon)

      item1 = weaker_weapon(actor)

    elsif actor.two_swords_style and @item.kind == 0

      item1 = nil

    else

      item1 = actor.equips[1 + @item.kind]

    end

    if enabled

      if @item.is_a?(RPG::Weapon)

        atk1 = item1 == nil ? 0 : item1.atk

        atk2 = @item == nil ? 0 : @item.atk

        change = atk2 - atk1

      else

        def1 = item1 == nil ? 0 : item1.def

        def2 = @item == nil ? 0 : @item.def

        change = def2 - def1

      end

      self.contents.draw_text(x, y, 200, WLH, sprintf("%+d", change), 2)

    end

    draw_item_name(item1, x, y + WLH, enabled)

  end

  #--------------------------------------------------------------------------

  # * Get Weaker Weapon Equipped by the Actor (for dual wielding)

  #     actor : actor

  #--------------------------------------------------------------------------

  def weaker_weapon(actor)

    if actor.two_swords_style

      weapon1 = actor.weapons[0]

      weapon2 = actor.weapons[1]

      if weapon1 == nil or weapon2 == nil

        return nil

      elsif weapon1.atk < weapon2.atk

        return weapon1

      else

        return weapon2

      end

    else

      return actor.weapons[0]

    end

  end

  #--------------------------------------------------------------------------

  # * Set Item

  #     item : new item

  #--------------------------------------------------------------------------

  def item=(item)

    if @item != item

      @item = item

      refresh

    end

  end

end

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:
Code:
 

class Game_System::Tax

  Direct_First = true

  attr_accessor :percent

  attr_accessor :direct

  def initialize

    @percent = 100

    @direct = 0

  end

  def modify(n)

    if Direct_First

      n += @direct

      n = Integer(n * (@percent / 100.0))

    else

      n = Integer(n * (@percent / 100.0))

      n += @direct

    end

    return n

  end

end

 

class Game_System

  attr_reader :tax

  alias_method :delyemerald2_tax_init, :initialize

  def initialize

    delyemerald2_tax_init

    @tax = Tax.new

  end

end

 

class RPG::Item

  def price

    return $game_system.modify(@price)

  end

end

 

#...

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:
Code:
$game_system.tax.direct =

- or -

$game_system.tax.percent =

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:
Code:
n = Integer(n * (@percent / 100.0))

- to -

n = Integer(n * ((100 + @percent) / 100.0))

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

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