Skill Shop

Started by Jackolas, January 13, 2009, 10:29:40 am

Previous topic - Next topic

Jackolas

i been looking for a nice script for a skill shop and i could only find 2... (and 1 working on SDK left me with 1 good script)

This is a Skill shop system made by Nechigawara (all credits go to him)
now the problem: its based on hero id, while I want one that works on class id

I already tried to change the system so it would use class id instead of hero id to see if u can buy a skill.
but the problem seems greater than I thought.
my last option now is to ask one of you guys knows a nice solution to fix this. ore maybe have a better system of there own.


#==============================================================================
# Skill Shop for RMXP
#==============================================================================
# By Nechigawara Sanzenin
# WARNING!! : This script can use on RPG Maker XP Only!! (VX Not Support)
#==============================================================================
# Buy Skill Option For RMXP
#==============================================================================
=begin

How to Use:

You will add "$skill_shop =[Id of Skill]" 
To Call Script to set id of skill for sell.
You will add "$scene = Scene_Skill_Shop.new" 
To Call Skill Shop Windows.

Example:
$skill_shop = [1,2,3,6,7]
$scene = Scene_Skill_Shop.new

You can set text to use in Skill Shop under "# Learn Text".
You can set Skill Price under "# Price Data".
You can set Skill that the fighter each person can study under "# Hero Data".

You will setting look like this in Hero Data
[ID of skill, Level requirement for learn]

=end
#==============================================================================
#module SKILL_SHOP
#==============================================================================
module SKILL_SHOP
  # Learn Text
  How_Learn = "What 's hero can learn?"
  Can_Learn = "Can Learn"
  Can_Learn_Lv = "On Lv"
  Cant_Learn = "Can't Learn"
  Learnt = "Learnt"
  Teach = "Teach"
  Cancel = "Cancel"
  # Price Data
  PRICE = {
  # for No Set Price
  0 => 100,
  # Add Price Here
  1 => 150,
  2 => 550,
  3 => 450,
  # End
  }
  # Hero Data
  SKILL_BUY = {
  # Add what skill can hero buy Here
  # [ID of skill,Level]
 
  1 => [
 
  [1,4],[2,3],[3,1],[7,1],
 
  ],
 
  2 => [
 
  [1,4],[2,3],[3,1],[7,5],
 
  ],
 
  # End
  }
  # Add Price
  def self.skill_price(id)
    if PRICE.include?(id)
      return PRICE[id]
    else
      return PRICE[0]
    end
  end
  # Add Hero id
  def self.skill_buy(id)
    if SKILL_BUY.include?(id)
      return SKILL_BUY[id]
    else
      return []
    end
  end
end
#==============================================================================
#class Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  def learn?(skill)
    learn = skill_learn?(skill.id)
    if learn
      return false
    else
      return true
    end
  end
end
#==============================================================================
#class Window_Skill_ShopCommand
#==============================================================================
class Window_Skill_ShopCommand < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 480, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 2
    @column_max = 2
    s1 = SKILL_SHOP::Teach
    s2 = SKILL_SHOP::Cancel
    @commands = [s1, s2]
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    x = 4 + index * 240
    self.contents.draw_text(x, 0, 128, 32, @commands[index])
  end
end
#==============================================================================
#class Window_Skill_ShopBuy
#==============================================================================
class Window_Skill_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize(shop_goods)
    super(0, 128, 368, 352)
    @skill_shop_goods = $skill_shop
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def skill
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 0...@skill_shop_goods.size
      skill = $data_skills[@skill_shop_goods[i]]
      if skill != nil
        @data.push(skill)
      end
    end
    # If the number of items is not 0, it draws up bit map, drawing all item
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    skill = @data[index]
    # Acquiring the frequency of possession of the item
    price = SKILL_SHOP.skill_price(skill.id)
    enabled = (price <= $game_party.gold)
    # If price is not below the money in hand, at the same time the frequency of possession 99, usually in letter color
    # So if is not, it sets to invalid letter color
    if enabled
      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(skill.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, skill.name, 0)
    self.contents.draw_text(x + 240, y, 88, 32, price.to_s, 2)
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(skill == nil ? "" : skill.description)
  end
end
#==============================================================================
#class Window_Skill_ShopStatus
#==============================================================================
class Window_Skill_ShopStatus < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
    super(368, 128, 272, 352)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item = nil
    refresh
    self.active = false
    self.index = -1
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    if @item == nil
      return
    end
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, self.width - 32, 32, SKILL_SHOP::How_Learn)
    self.contents.font.color = normal_color
    # Equipment supplementary information
    for i in 0...$game_party.actors.size
      # Acquiring the actor
      can = false
      lv = false
      ac_lv = 0
      actor = $game_party.actors[i]
      can_learn = SKILL_SHOP.skill_buy(actor.id)
      id = @item.id
      for e in 0...can_learn.size
        if can_learn[e][0] == id
          can = true
          if can_learn[e][1] <= actor.level
            lv = true
          else
            lv = false
            ac_lv = can_learn[e][1]
          end
          break
        else
          can = false
        end
      end
      enabled = (can and lv and actor.learn?(@item))
      # If equipment possibility if usually in letter color, the impossibility, it sets to invalid letter color
      if enabled
        self.contents.font.color = normal_color
      else
        self.contents.font.color = disabled_color
      end
      #Draw Cha Pic
      bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
      cw = bitmap.rect.width / 4
      ch = bitmap.rect.height / 4
      src_rect = Rect.new(0, 0, cw, ch)
      cx = contents.text_size(actor.name).width
      self.contents.blt(cx, 64 + 64 * i, bitmap, src_rect)
      # Drawing the name of the actor
      self.contents.draw_text(4, 64 + 64 * i, 120, 32, actor.name)
      # Check Skill
      if can == false
        text = SKILL_SHOP::Cant_Learn
      elsif can == true and lv == false
        ac = ac_lv.to_s
        text = SKILL_SHOP::Can_Learn_Lv + " " + ac + "+"
      elsif actor.learn?(@item) == false
        text = SKILL_SHOP::Learnt
      else
        text = SKILL_SHOP::Can_Learn
      end
      # Drawing the item
      self.contents.draw_text(124, 64 + 64 * i, 112, 32, text, 2)
    end
  end
  #--------------------------------------------------------------------------
  def item=(item)
    if @item != item
      @item = item
      refresh
    end
  end
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # Cursor position as for -1 all selection, -2 below independence selection (user himself)
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(0, 62 + @index * 64, self.width - 32, 50)
    end
  end
end
#==============================================================================
#class Scene_Skill_Shop
#==============================================================================
class Scene_Skill_Shop
  #--------------------------------------------------------------------------
  def main
    # Drawing up the help window
    @help_window = Window_Help.new
    # Drawing up the command window
    @command_window = Window_Skill_ShopCommand.new
    # Drawing up the Goldwyn dough
    @gold_window = Window_Gold.new
    @gold_window.x = 480
    @gold_window.y = 64
    # Drawing up the dummy window
    @dummy_window = Window_Base.new(0, 128, 640, 352)
    # Drawing up the purchase window
    @buy_window = Window_Skill_ShopBuy.new($game_temp.shop_goods)
    @buy_window.active = false
    @buy_window.visible = false
    @buy_window.help_window = @help_window
    # Drawing up the status window
    @status_window = Window_Skill_ShopStatus.new
    @status_window.visible = false
    @status_window.active
    # Transition execution
    Graphics.transition
    # Main loop
    loop do
      # Renewing the game picture
      Graphics.update
      # Updating the information of input
      Input.update
      # Frame renewal
      update
      # When the picture changes, discontinuing the loop
      if $scene != self
        break
      end
    end
    # Transition preparation
    Graphics.freeze
    # Releasing the window
    @help_window.dispose
    @command_window.dispose
    @gold_window.dispose
    @dummy_window.dispose
    @buy_window.dispose
    @status_window.dispose
  end
  #--------------------------------------------------------------------------
  def update
    # Renewing the window
    @help_window.update
    @command_window.update
    @gold_window.update
    @dummy_window.update
    @buy_window.update
    @status_window.update
    # When the command window is active,: Update_command is called
    if @command_window.active
      update_command
      return
    end
    # When the purchase window is active,: Update_buy is called
    if @buy_window.active
      update_buy
      return
    end
    # When the target window is active,: Update_target is called
    if @status_window.active
      update_target
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_command
    # The B when button is pushed
    if Input.trigger?(Input::B)
      # Performing cancellation SE
      $game_system.se_play($data_system.cancel_se)
      # Change to map picture
      $scene = Scene_Map.new
      return
    end
    # When C button is pushed
    if Input.trigger?(Input::C)
      # Eliminating the help text
      @help_window.set_text("")
      # It diverges at cursor position of the command window
      case @command_window.index
      when 0  # It purchases
        # Performing decision SE
        $game_system.se_play($data_system.decision_se)
        # State of window to purchase mode
        @command_window.active = false
        @dummy_window.visible = false
        @buy_window.active = true
        @buy_window.visible = true
        @buy_window.refresh
        @status_window.visible = true
      when 1  # It stops
        # Performing decision SE
        $game_system.se_play($data_system.decision_se)
        # Change to map picture
        $scene = Scene_Map.new
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_buy
    # Setting the item of the status window
    @status_window.item = @buy_window.skill
    # The B when button is pushed
    if Input.trigger?(Input::B)
      # Performing cancellation SE
      $game_system.se_play($data_system.cancel_se)
      # State of window to early mode
      @command_window.active = true
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      # Eliminating the help text
      @help_window.set_text("")
      return
    end
    # When C button is pushed
    if Input.trigger?(Input::C)
      # Acquiring the item
      @item = @buy_window.skill
      @price = SKILL_SHOP.skill_price(@item.id)
      enabled = (@price <= $game_party.gold)
      # When the item is invalid, or when price it is on from the money in hand
      unless  enabled
        # Performing buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Performing decision SE
      $game_system.se_play($data_system.decision_se)
      @buy_window.active = false
      @status_window.active = true
      @status_window.index = 0
    end
  end
  #--------------------------------------------------------------------------
  def update_target
    # The B when button is pushed
    if Input.trigger?(Input::B)
      # Performing cancellation SE
      $game_system.se_play($data_system.cancel_se)
      # Eliminating the target window
      @buy_window.active = true
      @status_window.index =- 1
      @status_window.active = false
      return
    end
    # When C button is pushed
    if Input.trigger?(Input::C)
      @actor = $game_party.actors[@status_window.index]
      can = false
      lv = false
      can_learn = SKILL_SHOP.skill_buy(@actor.id)
      id = @item.id
      for i in 0...can_learn.size
        if can_learn[i][0] == id
          can = true
          if can_learn[i][1] <= @actor.level
            lv = true
          else
            lv = false
          end
          break
        else
          can = false
        end
      end
      enabled = (can and lv and @actor.learn?(@item))
      # When with SP and so on is cut off and it becomes not be able to use
      unless enabled
        # Performing buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Performing shop SE
      $game_system.se_play($data_system.shop_se)
      @actor.learn_skill(@item.id)
      $game_party.lose_gold(@price)
      @buy_window.refresh
      @gold_window.refresh
      @status_window.refresh
      @buy_window.active = true
      @status_window.index =- 1
      @status_window.active = false
     end
  end
end

Blizzard

Have you tried SephirothSpawn's skill shop? I'm pretty sure that he made one.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Blizzard

I'm not sure if he would approve it, but if you can post his script here, I will remove the SDK dependency.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.