[XP] Hex's Token Shop

Started by (Hexamin), March 26, 2010, 07:29:27 am

Previous topic - Next topic

(Hexamin)

March 26, 2010, 07:29:27 am Last Edit: March 26, 2010, 01:53:49 pm by (Hexamin)
Hex's Token Shop
Authors: (Hexamin)
Version: 1.1
Type: Custom Token Shop
Key Term: Misc. Add-on



Introduction

Updated:  Now allows for the buying of items, weapons, and armors.

So, some cat asked about a system like this, and since I've begun scripting now, it seemed like something I could take on.  It seems as if I've been successful, and here you have it folks, Hex's first submitted script!  It's pretty simple, and I made it in less than a day.  I may or may not tweak it later.  I guess that'll depend on if anyone wants me to or finds errors.  Well, I know its simple, but hope you enjoy!


Features


  • Use tokens to buy items!
  • Define what your tokens are called!
  • Define how much each item costs easily in the configuration!
  • Simple and easy to use!
  • Can be used for prize tokens, war trophies, or whatever you can imagine!
  • That's all the excitement I can handle!



Screenshots

Screen 1: ShowHide



Screen 2: ShowHide






Demo

~None~


Script

Place Script Below Scene_Debug
Spoiler: ShowHide
#------------------------------------------------------------------------------#
#-----Hex's Custom Prize Shop--------------------------------------------------#
# With this, you can have a token you can collect in your game, and exchange   #
# the token for items.                                                         #
#-----Instructions-------------------------------------------------------------#
# Create a new event, and use this in a call script:                           #
#  $scene = Prize_Shop(x1, x2, x3)                                             #
# Where x1, x2, etc., are the items' Database IDs you want in the shop.  You   #
# can have up to 10 items per shop.                                            #
# EXAMPLE:                                                                     #
#  $scene = Prize_Shop(1, 5, 8, 3, 41)                                         #
# In the above example, the shop would sell items with Database IDs 1, 5, 8, 3 #
# and 41.                                                                      #
#                                                                              #
# In the configuration below:                                                  #
#    PRIZE = [singular, plural]                                                #
# singular = Singular name of your token                                       #
# plural = Plural name of your token                                           #
#                                                                              #
#    GVAR = number                                                             #
# number = game_variable used for your party's tokens                          #
#                                                                              #
#    when X: return C                                                          #
# X = item, weapon, armor ID                                                                  #
# C = the price in tokens                                                      #
#------------------------------------------------------------------------------#
#-----Begin Configuration------------------------------------------------------#
#------------------------------------------------------------------------------#
module Prize
 PRIZE = ["Token", "Tokens"]
 
 GVAR = 777
#------------------------------------------------------------------------------#
#-----Item Prices--------------------------------------------------------------#
#------------------------------------------------------------------------------#
 def self.item_price(id)
   case id
   when 1: return 5
   when 2: return 1
   when 4: return 11
   when 5: return 3
   when 9: return 32
   when 10: return 641
   end
   return 10
 end
#------------------------------------------------------------------------------#
#-----Weapon Prices------------------------------------------------------------#
#------------------------------------------------------------------------------#
 def self.weapon_price(id)
   case id
   when 1: return 68
   end
   return 75
 end
#------------------------------------------------------------------------------#
#-----Armor Prices-------------------------------------------------------------#
#------------------------------------------------------------------------------#
 def self.armor_price(id)
   case id
   when 1: return 49
   end
   return 60
 end
 
 
end
#------------------------------------------------------------------------------#
#-----End Configuration--------------------------------------------------------#
#------------------------------------------------------------------------------#
class Prize_Shop
 def initialize(items=[], weapons=[], armors=[], menu_index=0)
   @menu_index=menu_index
   @commands = []
   @data = []
   @type = []
   for i in 0..items.size
     if items[i] != 0 && items[i] != nil
       @data.push($data_items[items[i]])
       @type.push(0)
     end
   end
   for i in 0..weapons.size
     if weapons[i] != 0 && weapons[i] != nil
       @data.push($data_weapons[weapons[i]])
       @type.push(1)
     end
   end
   for i in 0..armors.size
     if armors[i] != 0 && armors[i] != nil
       @data.push($data_armors[armors[i]])
       @type.push(2)
     end
   end
   for i in 0..(@data.size - 1)
     @commands.push(@data[i].name)
   end
 end
 
 def main
   @map = Spriteset_Map.new
   @options = Window_Command.new(200, @commands)
   @options.y = 128
   @buy = Window_Command.new(90, ["Yes", "No"])
   @buy.x = 550
   @buy.y = 192
   @buy.active = false
   @buy.visible = false
   @help = Prize_Help.new
   @cost = Prize_Cost.new
   @trophy = Trophies_Avail.new
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   @help.dispose
   @options.dispose
   @cost.dispose
   @trophy.dispose
   @map.dispose
 end
 
 def update
   if @options.active
     index = @options.index
     @options.update
     @help.update(@data[index])
     @cost.update(@type[index], @data[index])
     @trophy.update
     update_options
     return
   end
   if @buy.active
     @buy.update
     update_buy
     return
   end
 end
 
 def update_options
   @index = @options.index
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     $scene = Scene_Map.new
     return
   end
   if Input.trigger?(Input::C)
     case @type[@index]
       when 0
         if Prize.item_price(@data[@index].id) > $game_variables[Prize::GVAR]
           $game_system.se_play($data_system.buzzer_se)
           return
         end
       when 1
         if Prize.weapon_price(@data[@index].id) > $game_variables[Prize::GVAR]
           $game_system.se_play($data_system.buzzer_se)
           return
         end
       when 2
         if Prize.armor_price(@data[@index].id) > $game_variables[Prize::GVAR]
           $game_system.se_play($data_system.buzzer_se)
           return
         end
     end
     $game_system.se_play($data_system.decision_se)
     @options.active = false
     @purchase = Prize_Purchase.new
     @buy.active = true
     @buy.visible = true
     @buy.index = 0
   end
 end
 
 def update_buy
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     @buy.active = false
     @buy.visible = false
     @buy.index = -1
     @options.active = true
     @purchase.dispose
   end
   if Input.trigger?(Input::C)
     case @buy.index
       when 0
         $game_system.se_play($data_system.shop_se)
         case @type[@index]
           when 0
             $game_variables[Prize::GVAR] -= Prize.item_price(@data[@index].id)
             $game_party.gain_item(@data[@index].id, 1)
           when 1
             $game_variables[Prize::GVAR] -= Prize.weapon_price(@data[@index].id)
             $game_party.gain_weapon(@data[@index].id, 1)
           when 2
             $game_variables[Prize::GVAR] -= Prize.armor_price(@data[@index].id)
             $game_party.gain_armor(@data[@index].id, 1)
         end
         @trophy.update
         @buy.active = false
         @buy.visible = false
         @buy.index = -1
         @options.active = true
         @purchase.dispose
       when 1
         $game_system.se_play($data_system.cancel_se)
         @buy.active = false
         @buy.visible = false
         @buy.index = -1
         @options.active = true
         @purchase.dispose
     end
   end
 end
end

#------------------------------------------------------------------------------#
#-----Prize Help Window--------------------------------------------------------#
#------------------------------------------------------------------------------#
class Prize_Help < Window_Base
 def initialize
   super(0, 0, 640, 64)
   self.contents = Bitmap.new(width-32, height-32)
   self.contents.font.name = "Arial"  
   self.contents.font.size = 24
 end
 
 def update(x)
   self.contents.clear
   if x != 0
   self.contents.draw_text(0, 0, 608, 32, x.description)
   end
 end
 
end

#------------------------------------------------------------------------------#
#-----Prize Cost Window--------------------------------------------------------#
#------------------------------------------------------------------------------#
class Prize_Cost < Window_Base
 def initialize
   super(0, 64, 240, 64)
   self.contents = Bitmap.new(width-32, height-32)
   self.contents.font.name = "Arial"  
   self.contents.font.size = 24
 end
 
 def update(y, x)
   self.contents.clear
   case y
   when 0
     if Prize.item_price(x.id) == 1
       str = Prize::PRIZE[0]
     else
       str = Prize::PRIZE[1]
     end
   prc = Prize.item_price(x.id).to_s
   when 1
     if Prize.weapon_price(x.id) == 1
       str = Prize::PRIZE[0]
     else
       str = Prize::PRIZE[1]
     end
   prc = Prize.weapon_price(x.id).to_s
   when 2
     if Prize.armor_price(x.id) == 1
       str = Prize::PRIZE[0]
     else
       str = Prize::PRIZE[1]
     end
   prc = Prize.armor_price(x.id).to_s
   end
   cx = contents.text_size(str).width
   self.contents.font.color = system_color
   self.contents.draw_text(0, 0, 64, 32, "Cost:")
   self.contents.font.color = normal_color
   self.contents.draw_text(200-cx-64, 0, 64, 32, prc, align=2)
   self.contents.draw_text(208-cx, 0, cx, 32, str)
 end
 
end

#------------------------------------------------------------------------------#
#-----Trophies Available Window------------------------------------------------#
#------------------------------------------------------------------------------#
class Trophies_Avail < Window_Base
 def initialize
   super(400, 64, 240, 64)
   self.contents = Bitmap.new(width-32, height-32)
   self.contents.font.name = "Arial"  
   self.contents.font.size = 24
   update
 end
 
 def update
   self.contents.clear
   x = $game_variables[Prize::GVAR]
     str = Prize::PRIZE[1]
   self.contents.font.color = system_color
   self.contents.draw_text(0, 0, 160, 32, "Available" + " " + str + ":")
   self.contents.font.color = normal_color
   self.contents.draw_text(160, 0, 48, 32, x.to_s, align = 2)
 end
 
end

#------------------------------------------------------------------------------#
#-----Purchase Window----------------------------------------------------------#
#------------------------------------------------------------------------------#
class Prize_Purchase < Window_Base
 def initialize
   super(486, 128, 154, 64)
   self.contents = Bitmap.new(width-32, height-32)
   self.contents.font.name = "Arial"
   self.contents.font.size = 24
   self.contents.draw_text(0, 0, 128, 32, "Purchase?", align = 1)
 end
end





Instructions

Instructions located in script!
Setting up the Event: ShowHide

Simply follow the guidelines in the picture, that's an easy way to do it.  Just remember, this script can just handle 10 items per shop right now, so keep that in mind.




Compatibility

Haven't found any issues, please lemme know if you find any ^_^


Credits and Thanks


  • (Hexamin) @ Chaos-Project
  • Nope, just Hex!



Author's Notes

Hope someone finds this useful!  Just lemme know if you wanna see something else, I'll see what I can do to tweak it.  Keep in mind this is my first submitted script.  I'm quite the noob when it comes to scripting, so I'm sure there are lots of shortcuts that probably could've been used that weren't, better coding possible, la dee da.  Bottom line, its a working system, and that's what I was going for.  Enjoy! ^_^

Edit 1: Updated where the purchase window popped up.
Max 1111101000; characters remaining: 1110111000

G_G

March 26, 2010, 07:51:45 am #1 Last Edit: March 26, 2010, 07:57:35 am by Hellfire's G_G
Theres a bug. You can have 0 Coins and still buy something.

EDIT: You can only buy items. What about weapons and stuff? Also there's an easier way then having all those arguments.
for initialize
def initialize(goods = [])
  goods.each{|i| 
  case i[0]
  when 0
  @data.push($data_items[i[1]])
  when 1
  @data.push($data_weapons[i[1]])
  when 2
  @data.push($data_armors[i[1]])
  end
  }
  #other stuff here
end


Then to call the script use you would make an array of arrays.
 $scene = Scene_Prize.new([
[0, 1], [0, 2], [0, 3], [1, 1], [2, 1]
]

The 0 would be for items, 1 is for weapons and 2 is for armors. The 2nd number in the arrays are the item id.
[x, y]
x = 0 - items, 1 - weapons, 2 - armors
y = item id

(Hexamin)

March 26, 2010, 08:37:54 am #2 Last Edit: March 26, 2010, 08:41:45 am by (Hexamin)
I'm not getting the 0 token bug.

What instance are you getting that in?  And... I think I will take your advice and expand it to include weapons and armor, although I really just did this on a whim.  Thanks for the criticism though, I really appreciate it seeing as I am very new to scripting.  ^_^

Edit 1:  I'll update this in a bit.  i realized I need to go into module and fix the prices, and fix some other code if i'm going to implement weapons and armor.

I wasn't sure how {} works, but... this is getting me a little more familiar with it.  I know its a loop-type code...  Anyway.  Update to come.
Max 1111101000; characters remaining: 1110111000

Trainer Zydragon

I think this would be good for buying skills too :P

Like an AP system, battles get you AP per monster, and you buy skill levels and stuff... Might be a good idea if it isnt already done XD

(Hexamin)

i've already got a skill buying system for ~DB~

maybe i'll change it from using gold to using some other currency  o.O
Max 1111101000; characters remaining: 1110111000

Trainer Zydragon

Yeah, make it optional?

Cos I would personally prefer spending AP on skills :)

Makes killing things more worth it :P
Could use it to level up too? like go from Soldier to Paladin for a certain amount of AP

(Hexamin)

Updated to allow for buying of armor and weapons as well.

^_^

although i couldn't do it in a cool way like G_G was talkin' about...
Max 1111101000; characters remaining: 1110111000

RogerSmith

How do you give tokens to players? Is there a call script for that?

Aqua

They're just a game variable.

G_G

Its controlled by a variable. Just add a number to the variable.

RogerSmith

Got it. I never was one for variables, but after using Tidloc's Dynamic Shop script and Hex'sscript, it's getting easier to grasp.