Exp based skill shop(one actor only)

This is a modified version of the gameguys skill shop. It lets use exp rather than gold for buying, but only for one actor.

  1. #===============================================================================
  2. # Skill Shop
  3. # Author: Game_guy, gerkt(exp based addition), mast3rshake2049(idea)
  4. # Date: June 7th, 2009
  5. # Version: 2.2z
  6. # VERY IMPORTANT ADDITION: Edited to use exp and not gold. Only works with one actor in the
  7. # party. The actor have to be the actor with the ID=1 of the database.
  8. #===============================================================================
  9. #
  10. # Intro:
  11. # What this script does is act as a shop but sells skills instead.
  12. #
  13. # Instructions:
  14. # 1: First how do you want it setup? Theres two ways
  15. #   1: -Any person can learn any skill
  16. #   or
  17. #   2: -Classes learn different skills then other classes
  18. #
  19. #   Go down to UseClasses and set it to false for 1: or true for 2:
  20. #
  21. # 2: Ok now that thats over lets move onto price. Go down to CONFIG PRICE and
  22. #   follow the instructions there.
  23. #  
  24. # 3: Skip this step if you set UseClasses to false.
  25. #   Go to CONFIG CLASS SKILLS and follow the instructions there.
  26. #   
  27. # 4: Ok so everythings setup now. Time to actually find out how to open the
  28. #   skillshop right? You use this line
  29. #   $scene = SkillShop.new([skill id's go here])
  30. #   example
  31. #   $scene = SkillShop.new([1, 2]) will make a shop with the skills
  32. #   Heal and Great Heal
  33. #
  34. # 5: Ok the script now is able to make it where only skills are learnable at
  35. #   certain levels. Go to CONFIG LEVEL and follow instructions there.
  36. #
  37. # 6: Ok so now there's a new option that sorts the skills in the following.
  38. #   Alphabetical
  39. #   Reverse Alphabetical
  40. #   Numeric (Sorts it by Id)
  41. #   Reverse Numberic
  42. #   Price
  43. #   Reverse price
  44. #   At default its at numeric but to change it use this,
  45. #   $game_system.ssort = 0,1,2, or 3.
  46. #   0 = Numeric, 1 = Reverse Numeric, 2 = Alphabetical,
  47. #   3 = Reverse Alphabetical, 4 = Price, 5 = Reverse Price.
  48. #===============================================================================
  49. module GameGuy
  50.   #==========================
  51.   # BEGIN CONFIG
  52.   #==========================
  53.   UseClasses = true # if false anyone can learn any skill
  54.                      # if true only classes can learn the defined skills
  55. end
  56. module RPG
  57.   class Skill
  58.     def price
  59.       case id
  60.       #==========================
  61.       # CONFIG PRICE
  62.       #==========================
  63.       # use
  64.       # when skill_id then return price
  65.       when 1 then return 50
  66.       when 57 then return 75
  67.       end
  68.       return 10
  69.     end
  70.     def llevel
  71.       case id
  72.       #==========================
  73.       # CONFIG LEVEL
  74.       #==========================
  75.       # use
  76.       # when skill_id then return level
  77.       when 57 then return 2
  78.       end
  79.       return 1
  80.     end
  81.   end
  82.   class Class
  83.     def learnskills
  84.       case id
  85.       #==========================
  86.       # CONFIG CLASS SKILLS
  87.       #==========================
  88.       # use
  89.       # when class_id then return [skill id's here]
  90.       when 1 then return [1, 2, 57, 58, 59, 60]
  91.       when 2 then return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 81]
  92.       when 7 then return [69, 70, 71, 72, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80]
  93.       when 8 then return [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56]
  94.       end
  95.       return []
  96.     end
  97.   #==========================
  98.   # END CONFIG
  99.   #==========================
  100.   end
  101. end
  102. class Game_System
  103.   attr_accessor :ssort
  104.   alias sort_me_skillz initialize
  105.   def initialize
  106.     @ssort = 0
  107.     sort_me_skillz
  108.   end
  109. end
  110. class Window_SkillCommand < Window_Selectable
  111.   def initialize
  112.     super(0, 64, 480, 64)
  113.     self.contents = Bitmap.new(width - 32, height - 32)
  114.     @item_max = 2
  115.     @column_max = 2
  116.     @commands = ["Learn", "Exit"]
  117.     refresh
  118.     self.index = 0
  119.   end
  120.   def refresh
  121.     self.contents.clear
  122.     for i in 0...@item_max
  123.       draw_item(i)
  124.     end
  125.   end
  126.   def draw_item(index)
  127.     x = 4 + index * 240
  128.     self.contents.draw_text(x, 0, 128, 32, @commands[index])
  129.   end
  130. end
  131.  
  132. class Window_SkillBuy < Window_Selectable
  133.   def initialize(shop_goods)
  134.     super(0, 128, 368, 352)
  135.     @skill_shop_goods = shop_goods
  136.     self.active = false
  137.     refresh
  138.     self.index = 0
  139.   end
  140.   def skill
  141.     return @data[self.index]
  142.   end
  143.   def refresh
  144.     if self.contents != nil
  145.       self.contents.dispose
  146.       self.contents = nil
  147.     end
  148.     @data = []
  149.     for i in 0...@skill_shop_goods.size
  150.       skill = $data_skills[@skill_shop_goods[i]]
  151.       if skill != nil
  152.         @data.push(skill)
  153.       end
  154.     end
  155.     case $game_system.ssort
  156.     when 0
  157.       [@data].each {|ary| ary.sort! {|a, b| a.id <=> b.id}}
  158.     when 1
  159.       [@data].each {|ary| ary.sort! {|a, b| a.id <=> b.id}}
  160.       [@data].each {|ary| ary.reverse!}
  161.     when 2
  162.       [@data].each {|ary| ary.sort! {|a, b| a.name <=> b.name}}
  163.     when 3
  164.       [@data].each {|ary| ary.sort! {|a, b| a.name <=> b.name}}
  165.       [@data].each {|ary| ary.reverse!}
  166.     when 4
  167.       [@data].each {|ary| ary.sort! {|a, b| a.price <=> b.price}}
  168.     when 5
  169.       [@data].each {|ary| ary.sort! {|a, b| a.price <=> b.price}}
  170.       [@data].each {|ary| ary.reverse!}
  171.     else
  172.       [@data].each {|ary| ary.sort! {|a, b| a.id <=> b.id}}
  173.     end
  174.     @item_max = @data.size
  175.     if @item_max > 0
  176.       self.contents = Bitmap.new(width - 32, row_max * 32)
  177.       for i in 0...@item_max
  178.         draw_item(i)
  179.       end
  180.     end
  181.   end
  182.   def draw_item(index)
  183.     skill = @data[index]
  184.     price = skill.price
  185.     enabled = (price <= $game_actors[1].exp)
  186.     if enabled
  187.       self.contents.font.color = normal_color
  188.     else
  189.       self.contents.font.color = disabled_color
  190.     end
  191.     x = 4
  192.     y = index * 32
  193.     rect = Rect.new(x, y, self.width - 32, 32)
  194.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  195.     bitmap = RPG::Cache.icon(skill.icon_name)
  196.     opacity = self.contents.font.color == normal_color ? 255 : 128
  197.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  198.     self.contents.draw_text(x + 28, y, 212, 32, skill.name, 0)
  199.     self.contents.draw_text(x + 240, y, 88, 32, price.to_s, 2)
  200.   end
  201.   def update_help
  202.     @help_window.set_text(skill == nil ? "" : skill.description)
  203.   end
  204. end
  205.  
  206. class Window_SkillStatus2 < Window_Selectable
  207.   def initialize
  208.     super(368, 128, 272, 352)
  209.     self.contents = Bitmap.new(width - 32, height - 32)
  210.     refresh
  211.     self.z = 200
  212.     self.active = false
  213.     self.index = -1
  214.   end
  215.   def refresh
  216.     self.contents.clear
  217.     @item_max = $game_party.actors.size
  218.     for i in 0...$game_party.actors.size
  219.       x = 64
  220.       y = i * 80
  221.       actor = $game_party.actors[i]
  222.       classs = $data_classes[$game_actors[actor.id].class_id]
  223.       draw_actor_graphic(actor, x - 40, y + 60)
  224.       draw_actor_name(actor, x - 13, y + 10)
  225.       if actor.skill_learn?($thing.id)
  226.         self.contents.font.color = crisis_color
  227.         $text = "Aquired"
  228.       elsif GameGuy::UseClasses
  229.         if classs.learnskills.include?($thing.id) && $thing.llevel <= actor.level
  230.           self.contents.font.color = normal_color
  231.           $text = "Can Learn"
  232.         elsif classs.learnskills.include?($thing.id) && $thing.llevel > actor.level
  233.           self.contents.font.color = disabled_color
  234.           $text = "Can Learn At Level " + $thing.llevel.to_s
  235.         else
  236.           self.contents.font.color = disabled_color
  237.           $text = "Can't Learn"
  238.         end
  239.       else
  240.         if actor.level >= $thing.llevel
  241.           self.contents.font.color = normal_color
  242.           $text = "Can Learn"
  243.         else
  244.           self.contents.font.color = disabled_color
  245.           $text = "Can Learn At Level " + $thing.llevel.to_s
  246.         end
  247.       end
  248.       self.contents.draw_text(x - 13, y + 40, 200, 32, $text)
  249.     end
  250.   end
  251.   def update_cursor_rect
  252.     if @index < 0
  253.       self.cursor_rect.empty
  254.     else
  255.       self.cursor_rect.set(0, @index * 80, self.width - 32, 80)
  256.     end
  257.   end
  258. end
  259.  
  260. class SkillShop
  261.   def initialize(skills)
  262.     @skills = skills
  263.   end
  264.   def main
  265.     @command = Window_SkillCommand.new
  266.     @help_window = Window_Help.new
  267.     @skillbuy = Window_SkillBuy.new(@skills)
  268.     @skillbuy.active = false
  269.     @skillbuy.help_window = @help_window
  270.     $thing = @skillbuy.skill
  271.     @status = Window_SkillStatus2.new
  272.     #@status.visible = false
  273.     @gold = Window_Exp.new
  274.     @gold.x = 480
  275.     @gold.y = 64
  276.    
  277.     Graphics.transition
  278.     loop do
  279.       Graphics.update
  280.       Input.update
  281.       update
  282.       if $scene != self
  283.         break
  284.       end
  285.     end
  286.     Graphics.freeze
  287.     @gold.dispose
  288.     @skillbuy.dispose
  289.     @help_window.dispose
  290.     @command.dispose
  291.     @status.dispose
  292.   end
  293.   def update
  294.     @gold.update
  295.     @status.update
  296.     @gold.refresh
  297.     @command.update
  298.     @skillbuy.update
  299.     @help_window.update
  300.     $thing = @skillbuy.skill
  301.     @status.refresh
  302.     if @command.active
  303.       update_command
  304.       return
  305.     end
  306.    
  307.     if @status.active
  308.       update_status
  309.       return
  310.     end
  311.    
  312.     if @skillbuy.active
  313.       update_buy
  314.       return
  315.     end
  316.   end
  317.  
  318.   def update_buy
  319.     if Input.trigger?(Input::B)
  320.       $game_system.se_play($data_system.cancel_se)
  321.       @skillbuy.active = false
  322.       @skillbuy.index = -1
  323.       @command.active = true
  324.       @command.index = 0
  325.       return
  326.     end
  327.     if Input.trigger?(Input::C)
  328.       $game_system.se_play($data_system.decision_se)
  329.       @skillbuy.active = false
  330.       @status.active = true
  331.       @status.visible = true
  332.       @status.index = 0 if @status.index == -1
  333.     end
  334.   end
  335.  
  336.   def update_command
  337.     if Input.trigger?(Input::B)
  338.       $game_system.se_play($data_system.cancel_se)
  339.       $scene = Scene_Map.new
  340.       return
  341.     end
  342.     if Input.trigger?(Input::C)
  343.       $game_system.se_play($data_system.decision_se)
  344.       case @command.index
  345.       when 0
  346.         @command.active = false
  347.         @command.index = -1
  348.         @skillbuy.active = true
  349.         @skillbuy.index = 0
  350.       when 1
  351.         $game_system.se_play($data_system.cancel_se)
  352.         $scene = Scene_Map.new
  353.       end
  354.       return
  355.     end
  356.   end
  357.  
  358.   def update_status
  359.     if Input.trigger?(Input::B)
  360.       @status.active = false
  361.       @status.index = -1
  362.       @skillbuy.active = true
  363.       return
  364.     end
  365.     if Input.trigger?(Input::C)
  366.       price = @skillbuy.skill.price
  367.       @actort = $game_party.actors[@status.index]
  368.       enabled = (price <= $game_actors[1].exp)
  369.      
  370.       if enabled
  371.         if @actort.skill_learn?(@skillbuy.skill.id)
  372.           $game_system.se_play($data_system.buzzer_se)
  373.           return
  374.         end
  375.         if GameGuy::UseClasses
  376.           if $data_classes[@actort.class_id].learnskills.include?(@skillbuy.skill.id) && @actort.level >= @skillbuy.skill.llevel
  377.             @actort.learn_skill(@skillbuy.skill.id)
  378.             $game_actors[1].exp -= (@skillbuy.skill.price)
  379.             $game_system.se_play($data_system.decision_se)
  380.             @status.refresh
  381.             @skillbuy.refresh
  382.             return
  383.           else
  384.             $game_system.se_play($data_system.buzzer_se)
  385.             return
  386.           end
  387.         else
  388.           if @actort.level >= @skillbuy.skill.llevel
  389.             @actort.learn_skill(@skillbuy.skill.id)
  390.             $game_actors[1].exp -= (@skillbuy.skill.price)
  391.             $game_system.se_play($data_system.decision_se)
  392.             @status.refresh
  393.             @skillbuy.refresh
  394.           else
  395.             $game_system.se_play($data_system.buzzer_se)
  396.             return
  397.           end
  398.           return
  399.         end
  400.        
  401.       else
  402.         $game_system.se_play($data_system.buzzer_se)
  403.         return
  404.       end
  405.     end
  406.   end
  407.  
  408. end
  409.  
  410. #==============================================================================
  411. # ** Window_Exp
  412. #------------------------------------------------------------------------------
  413. #  This window displays amount of gold.
  414. #==============================================================================
  415.  
  416. class Window_Exp < Window_Base
  417.   #--------------------------------------------------------------------------
  418.   # * Object Initialization
  419.   #--------------------------------------------------------------------------
  420.   def initialize
  421.     super(0, 0, 160, 64)
  422.     self.contents = Bitmap.new(width - 32, height - 32)
  423.     refresh
  424.   end
  425.   #--------------------------------------------------------------------------
  426.   # * Refresh
  427.   #--------------------------------------------------------------------------
  428.   def refresh
  429.     self.contents.clear
  430.     cx = contents.text_size('Exp').width
  431.     self.contents.font.color = normal_color
  432.     self.contents.draw_text(4, 0, 120-cx-2, 32, $game_actors[1].exp.to_s, 2)
  433.     self.contents.font.color = system_color
  434.     self.contents.draw_text(124-cx, 0, cx, 32, 'Exp', 2)
  435.    
  436.   end
  437. end
Expand to see the code.
Thanks!
Pretty nifty script. I didn't try it out, but maybe you should add a bit more documentation in the topic, like where to exactly put it, and how to use it.
He just modified my skill shop. Here's the original script.
viewtopic.php?f=11&t=65534

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