질문과 답변

Extra Form

아래 스크립트 보시면 아시겠지만 돈으로 스킬을 구매합니다

그런데 전 따로 스킬 포인트를 만들어서 구매할 수 있도록 하고 싶은데요,

가령 스킬 포인트 변수를 만들어서 처리한다든가.. 하고 싶은데 어떻게 손봐야할까요?

 

 

UseClasses = true # if false anyone can learn any skill
                     # if true only classes can learn the defined skills
end
module RPG
  class Skill
    def price
      case id
      #==========================
      # CONFIG PRICE
      #==========================
      # use
      # when skill_id then return price
      when 1 then return 50
      when 2 then return 75
      end
      return 10
    end
    def llevel
      case id
      #==========================
      # CONFIG LEVEL
      #==========================
      # use
      # when skill_id then return level
      when 1 then return 1
      end
      return 1
    end
  end
  class Class
    def learnskills
      case id
      #==========================
      # CONFIG CLASS SKILLS
      #==========================
      # use
      # when class_id then return [skill id's here]
      when 1 then return []
      when 2 then return []
      when 3 then return []
      when 4 then return []
      end
      return []
    end
  #==========================
  # END CONFIG
  #==========================
  end
end
 
class Window_SkillCommand < Window_Selectable
  def initialize
    super(0, 64, 480, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 2
    @column_max = 2
    @commands = ["배우기", "나가기"]
    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_SkillBuy < Window_Selectable
  def initialize(shop_goods)
    super(0, 128, 368, 352)
    @skill_shop_goods = shop_goods
    self.active = false
    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
    @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]
    price = skill.price
    enabled = (price <= $game_party.gold)
    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_SkillStatus2 < Window_Selectable
  def initialize
    super(368, 128, 272, 352)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.z = 200
    self.active = false
    self.index = -1
  end
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
    for i in 0...$game_party.actors.size
      x = 64
      y = i * 80
      actor = $game_party.actors[i]
      classs = $data_classes[$game_actors[actor.id].class_id]
      draw_actor_graphic(actor, x - 40, y + 60)
      draw_actor_name(actor, x - 13, y + 10)
      if actor.skill_learn?($thing.id)
        self.contents.font.color = crisis_color
        $text = "습득함"
      elsif GameGuy::UseClasses
        if classs.learnskills.include?($thing.id) && $thing.llevel <= actor.level
          self.contents.font.color = normal_color
          $text = "배울 수 있음"
        elsif classs.learnskills.include?($thing.id) && $thing.llevel > actor.level
          self.contents.font.color = disabled_color
          $text = "레벨 요구 Lv " + $thing.llevel.to_s
        else
          self.contents.font.color = disabled_color
          $text = "배울 수 없음"
        end
      else
        if actor.level >= $thing.llevel
          self.contents.font.color = normal_color
          $text = "배울 수 있음"
        else
          self.contents.font.color = disabled_color
          $text = "레벨 요구 Lv " + $thing.llevel.to_s
        end
      end
      self.contents.draw_text(x - 13, y + 40, 200, 32, $text)
    end
  end
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(0, @index * 80, self.width - 32, 80)
    end
  end
end
 
class SkillShop
  def initialize(skills)
    @skills = skills
  end
  def main
    @command = Window_SkillCommand.new
    @help_window = Window_Help.new
    @skillbuy = Window_SkillBuy.new(@skills)
    @skillbuy.active = false
    @skillbuy.help_window = @help_window
    $thing = @skillbuy.skill
    @status = Window_SkillStatus2.new
    #@status.visible = false
    @gold = Window_Gold.new
    @gold.x = 480
    @gold.y = 64
   
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @gold.dispose
    @skillbuy.dispose
    @help_window.dispose
    @command.dispose
    @status.dispose
  end
  def update
    @gold.update
    @status.update
    @gold.refresh
    @command.update
    @skillbuy.update
    @help_window.update
    $thing = @skillbuy.skill
    @status.refresh
    if @command.active
      update_command
      return
    end
   
    if @status.active
      update_status
      return
    end
   
    if @skillbuy.active
      update_buy
      return
    end
  end
 
  def update_buy
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @skillbuy.active = false
      @command.active = true
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @skillbuy.active = false
      @status.active = true
      @status.visible = true
      @status.index = 0 if @status.index == -1
    end
  end
 
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      case @command.index
      when 0
        @command.active = false
        @skillbuy.active = true
      when 1
        $game_system.se_play($data_system.cancel_se)
        $scene = Scene_Map.new
      end
      return
    end
  end
 
  def update_status
    if Input.trigger?(Input::B)
      @status.active = false
      @skillbuy.active = true
      return
    end
    if Input.trigger?(Input::C)
      price = @skillbuy.skill.price
      @actort = $game_party.actors[@status.index]
      enabled = (price <= $game_party.gold)
     
      if enabled
        if @actort.skill_learn?(@skillbuy.skill.id)
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        if GameGuy::UseClasses
          if $data_classes[@actort.class_id].learnskills.include?(@skillbuy.skill.id) && @actort.level >= @skillbuy.skill.llevel
            @actort.learn_skill(@skillbuy.skill.id)
            $game_party.lose_gold(@skillbuy.skill.price)
            $game_system.se_play($data_system.decision_se)
            @skillbuy.active = true
            @status.active = false
            @status.refresh
            return
          else
            $game_system.se_play($data_system.buzzer_se)
            return
          end
        else
          if @actort.level >= @skillbuy.skill.llevel
            @actort.learn_skill(@skillbuy.skill.id)
            $game_party.lose_gold(@skillbuy.skill.price)
            $game_system.se_play($data_system.decision_se)
            @skillbuy.active = true
            @status.active = false
            @status.refresh
          else
            $game_system.se_play($data_system.buzzer_se)
            return
          end
          return
        end
       
      else
        $game_system.se_play($data_system.buzzer_se)
        return
      end
    end
  end
end

Comment '5'
  • ?
    허걱 2011.06.13 23:12

    $game_party.gold 비교하는 부분과 $game_party.lose_gold 지불하는 부분을 원하는 변수로 바꾸시면 될듯 합니다;

    참고로 게임 내에서의 변수는 $game_variables[n] 으로 사용할 수 있습니다. (n = 변수 번호)

  • ?
    허걱 2011.06.16 20:22

    그건 사용할 변수를 몰라서 대답할 수 없습니다;;

  • ?
    허걱 2011.06.16 20:24

    참고로 일반 게임변수로 사용하고 싶다면.. .예를들어 1번 변수가 포인트라면

    $game_party.lose_gold(@skillbuy.skill.price)
    부분을

    $game_variables[1] -= @skillbuy.skill.price 등으로 해주시면 해당 변수에서 @skillbuy.skill.price 만큼을 빼주게 됩니다.

  • profile
    KG05 2011.06.16 20:45

    감사합니다. 덕분에 많이 알아갑니다 ^^

  • profile
    KG05 2011.06.16 18:06

    그런데 $game_party.lose_gold  부분은 어떻게 바꿔야 구문오류가 안 나오나요?


List of Articles
종류 분류 제목 글쓴이 날짜 조회 수
공지 묻고 답하기 가이드 습작 2014.06.14 12456
RMXP 캐릭터가 통행설정을 무시하고 벽위를 걸어다녀요 file 아이비 2018.01.12 162
이벤트 작성 RMVXA 캐릭터가................안 자요................... 2 file nucnuc 2019.12.17 170
RMVXA 캐릭터가...사라졌습니다... 2 보드카짱 2017.04.26 87
RMVX 캐릭터간 대화 질문 7 흐므 2013.02.13 626
RMXP 캐릭터그래픽 만드는법 2 작은오타쿠 2011.09.10 1745
RMVXA 캐릭터나 애니메이션에 잔상효과넣는법? 1 아라비카100 2013.09.27 1052
RMVXA 캐릭터나 이벤트가 자꾸 가만히 있어도 걷습니다.. 3 123qweefadf 2016.10.16 115
RMXP 캐릭터뒤에칼착용하는법좀요; 2 라이토스 2011.12.06 1591
RMVXA 캐릭터들 스토리 만들기 3 Mr멜론 2013.10.25 1005
사이트 이용 캐릭터들은 어디서다운받는건가요??? 2 류넷 2018.05.25 200
RMMV 캐릭터랑 오브젝트를 직접 만들고싶은데 어떻게 하나요? 2 개발자포도 2016.06.05 123
RMVXA 캐릭터를 3등신 정도로 만들고싶은데... 도통모르겠습니다ㅠ 2 Lamiassss3 2018.08.29 627
RMVXA 캐릭터를 따라가는 화면 이동.. 1 file yellowcat 2013.04.03 1147
RMMV 캐릭터를 만드는 데 스크립트좀 주시면 안될까요? 4 하민짱 2017.04.25 143
RMVX 캐릭터를 만들때 색이 깨져서 초록색이 남네요. 10 file rpg덕후 2013.10.08 2122
RM2k3 캐릭터를 만들수 있었던 사이트가 어디 있나요? 1 아브렐라 2014.02.21 1336
RMMV 캐릭터를 만들어서 넣었는데 적용이 안되네요ㅠ 3 file 푸른랩소디 2018.07.21 151
RMXP 캐릭터를 만들었는데요.. 1 깡패토끼0401 2010.09.30 776
기타 캐릭터를 제작할 때 크기문의 vadadad23 2014.11.26 414
플러그인 추천 RMMV 캐릭터를 커지게 해주는 플러그인 없나요? 2 JDG 2020.05.22 159
Board Pagination Prev 1 ... 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 ... 516 Next
/ 516