질문과 답변

Extra Form

 

 스크립트는 전혀 다룰줄 몰라서 다른분의 스크립트를 챁아보아도 적당한것이 보이지 않아

내구도를 탄약대신 사용해보자 하는 생각이 들어서 츠키히메 님의 인스턴스아이템이랑 무기내구도 스크립트를 다져다 붙여서

글록(15/15)란 아이템을 만들었습니다.뒤에 붙은 15는 실은 무기내구도입니다. 전투중 한번 사용할때마다 1씩 줄어들어서 0이되면 원래는 부서진 아이템으로

바뀌게 되는데 이러게 바뀐 글록(재장전)에 재장전을 구현하기 위해 커먼이벤트로 9미리 탄창이라는 아이템을 하나 사용해서 다시 글록(15/15)로 바꾸는데까지는 성공했습니다.문제는 위의 내구도스크립트인데 무기가 깨지면 자동으로 장비를 해제하고 없앤다음에 부서진무기를 인벤에 하나 추가하게 되어있습니다.

이부분을 자동으로 장착이 되게 혹은 장착되어있던 글록(0/15)가 그냥 글록(재장전)이 되게 할수는 없을까 해서 질문을 드립니다.

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

# Script: Basic Instance Weapon Durability Ver. 1.07

# Author: Selchar

# Credit: Tsukihime

# Required: Tsukihime's Item Instance

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

=begin

이 스크립트는 무기에 대한 내구도를 구현한다.With each use for an attack or

skill, a weapon's durability wil decrease by the amount you specify in the

customization area.  You can that by how much as well via a notetag for skills.

Only weapons with the <use durability> notetag will use this script's function.

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

# Weapon Notetag

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

<set durability>

Sets up the weapon to use durability.  See Default Setting down beow.


<max durability: x>

Where x is the starting durability of a weapon, defaults to the setting beow.


<broken weapon change: x>

Where x is the id of the new "weapon" you obtain when the one you are using

breaks.  Like say you wanted a "broken sword" instead of a "Sword 0/100".  This

only works if Destroy_Broken_Weapon down below is set to false.


<skill durability mod x: y>

Where x is the id of the skill who's durability cost you wish to modify and

y is by how much you wish to modify it by.  y can be either a positive or

a negative number.  Weapon Durability can not be "repaired" through this.

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

# Skill Notetag

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

<durability cost: x>

Where x is how much of a weapon's durability is used, defaults to the constant

Default_Durability_Cost that you set below, default value is 1


=end

module TH_Instance

  module Weapon

    #Set this for weapon durability designation for when the max durability

    #notetag is not present.

    Default_Durability = 100

    

    #Set this to what you want the default cost for successfully using skills

    #while equipped with a durability enabled equip to be.

    Default_Durability_Cost = 1

    

    #When a weapon is destroyed, this determines what will happen to it.  If

    #true, then it disappears from your inventory completely.  If it's false,

    #then either you keep the 0 durability version, or it changes to a new

    #"weapon" that you choose through the broken weapon notetag.

    Destroy_Broken_Weapon = false

    

    #This determines default Behavior of equips, and the behavior of the

    #<set durability> tag which is always the opposite.

    Durability_Setting = false

    

    #Format of durability suffix

    Dur_Suf = ' (%s/%s)'

  end

end

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

# Rest of the script

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

$imported = {} if $imported.nil?

$imported[:Sel_Weapon_Durability] = true

unless $imported["TH_InstanceItems"]

  msgbox("Tsukihime's Instance not detected, exiting")

  exit

end


class Game_Battler < Game_BattlerBase

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

# On Successful Damage

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

  alias :process_weapon_durability_mdv :make_damage_value

  def make_damage_value(user, item)

    process_weapon_durability_mdv(user, item)

    user.process_weapon_durability(item) if user.actor? && @result.hit?

  end

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

# Weapon Durability Methods in Game_Battler

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

  def process_weapon_durability(item)

    return unless item.is_a?(RPG::Skill)

    weapons.each do |i|

      next unless can_process_weapon_durability(i, item)

      process_individual_weapon_durability(i, item)

    end

  end

  

  def can_process_weapon_durability(weapon, skill)

    return false unless weapon

    return false unless weapon.use_durability

    return true

  end

  

  def process_individual_weapon_durability(weapon, skill)

    weapon.durability -= weapon_durability_cost(weapon, skill)

    weapon.durability = 0 if weapon.durability < 0

    weapon.refresh_name

    weapon.refresh_price

    weapon.break_by_durability(self) if weapon.durability.zero?

  end

  

  def weapon_durability_cost(weapon, skill)

    cost = skill.weapon_durability_cost

    cost += weapon.skill_durability_mod(skill.id)

    cost = 0 if cost < 0 #Make sure no negatives

    return cost

  end

end

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

# Can't equip if weapon uses durability and has none left.

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

class Game_Actor < Game_Battler

  alias :zero_durability_wep_equip :equippable?

  def equippable?(item)

    return zero_durability_wep_equip(item) if item.is_a?(RPG::EquipItem) && item.is_template?

    return false if item.is_a?(RPG::Weapon) && item.use_durability && item.durability.zero?

    return zero_durability_wep_equip(item)

  end

end

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

# Extend log_window

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

class Scene_Battle < Scene_Base

  attr_accessor :log_window

end

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

# Weapon Methods

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

class RPG::Weapon

  attr_accessor :durability

  attr_accessor :use_durability

  

  def repair

    @durability = max_durability

    refresh_name

    refresh_price

  end

  

  def can_repair?

    @durability < max_durability

  end

  

  def repair_price

    @durability.zero? ? @non_durability_price : (@non_durability_price - @price)

  end

  

  def broken_weapon_text(actor)

    message = "%s's %s broke!" % [actor.name, @non_durability_name]

    SceneManager.scene.log_window.add_text(message)

  end

  

  def break_by_durability(actor)

    actor.equips.each_index do |i|

      if actor.equips[i] == self

        actor.change_equip(i, nil)

        if TH_Instance::Weapon::Destroy_Broken_Weapon

          $game_party.gain_item(self, -1)

        else

          if broken_weapon_change

            $game_party.gain_item(self, -1)

            broke_version = InstanceManager.get_instance($data_weapons[broken_weapon_change])

            $game_party.gain_item(broke_version, 1) 

          end

        end

        broken_weapon_text(actor)

        break

      end

    end

  end

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

# Renaming/Price Adjusting

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

  def durability_suffix

    return TH_Instance::Weapon::Dur_Suf % [@durability, @max_durability]

  end

  def apply_durability_suffix(name)

    name += durability_suffix

  end

  

  alias :sel_durability_make_name :make_name

  def make_name(name)

    name = sel_durability_make_name(name)

    @non_durability_name = name

    name = apply_durability_suffix(name) if use_durability

    name

  end

  

  def apply_durability_price(price)

    if @durability.zero? && !@non_durability_price.zero?

      price = 2

    else

      price = (price * (@durability.to_f/max_durability)).to_i

    end

    price

  end

  

  alias :sel_durability_make_price :make_price

  def make_price(price)

    price = sel_durability_make_price(price)

    @non_durability_price = price

    price = apply_durability_price(price) if use_durability

    price

  end

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

# Weapon Notetag

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

  def use_durability

    if @use_durability.nil?

      default = TH_Instance::Weapon::Durability_Setting

      @note =~ /<set[-_ ]?durability>/i ? @use_durability = !default : @use_durability = default

    end

    @use_durability

  end

  

  def max_durability

    @note =~ /<max[-_ ]?durability:\s*(.*)\s*>/i ? @max_durability = $1.to_i : @max_durability = TH_Instance::Weapon::Default_Durability if @max_durability.nil?

    @max_durability

  end

  

  def broken_weapon_change

    @note =~ /<broken[-_ ]?weapon[-_ ]?change:\s*(.*)\s*>/i ? @broken_weapon_change = $1.to_i : @broken_weapon_change = false if @broken_weapon_change.nil?

    @broken_weapon_change

  end

  

  def skill_durability_mod(skill_id)

    if @skill_durability_mod.nil?

      @skill_durability_mod = []

      $data_skills.each do |i|

        next unless i

        if @note =~ /<skill[-_ ]?durability[-_ ]?mod[-_ ]?#{i.id.to_s}:\s*(.*)\s*>/i

          @skill_durability_mod[i.id] = $1.to_i

        else

          @skill_durability_mod[i.id] = 0

        end

      end

    end

    @skill_durability_mod[skill_id]

  end

end

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

# Skill Notetag

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

class RPG::Skill

  def weapon_durability_cost

    @note =~ /<durability[-_ ]?cost:\s*(.*)\s*>/i ? @durability_cost = $1.to_i : @durability_cost = TH_Instance::Weapon::Default_Durability_Cost if @durability_cost.nil?

    @durability_cost

  end

end

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

# Instance Manager: setup_instance

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

module InstanceManager

  class << self

    alias :instance_weapon_durability_setup :setup_weapon_instance

  end

  

  def self.setup_weapon_instance(obj)

    instance_weapon_durability_setup(obj)

    obj.repair if obj.use_durability

  end

end

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

# End of File

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

 

 

 

 

 

 

 

■ 질문전 필독!
  • 질문할 내용이 이 게시판이나 강좌에 이미 있는지 확인합니다.
  • 하나의 게시물에는 하나의 질문만 합니다.
  • 제목은 질문의 핵심 내용으로 작성합니다.
  • 질문 내용은 답변자가 쉽게 이해할 수 있도록 최대한 상세하게 작성합니다.
  • 스크립트의 전문이 필요할 경우 txt 파일 등으로 첨부해 주시기 바랍니다.
  • 답변받은 게시물은 삭제하지 않습니다.
  • 답변이 완료된 경우 해당 답변해주신 분들께 감사의 댓글을 달아줍니다.
    • 처음 오신 분들은 공지 게시물을 반드시 읽어주세요!

※ 미준수시 사전경고 없이 게시물을 삭제합니다.

Comment '4'
  • ?
    LuD 2017.08.16 11:52
    weapon.break_by_durability(self) if weapon.durability.zero?
    앞에 # 붙여서 주석처리 해주면 될것 같습니다.

    #weapon.break_by_durability(self) if weapon.durability.zero?
    이렇게..
  • ?
    메카패치 2017.08.16 15:03
    답변주셔서 감사합니다. ^^
    시험해보니 내구도가 없어지면 그냥 장비나 인벤토리에서 사라지는 걸로 구현이 되네요
    def break_by_durability(actor) - 내구도가 없어 짐의 정의
    actor.equips.each_index do |i| - 액터가 그아이템을 착용중일때
    if actor.equips[i] == self - 만약 그아이템이 착용되어있다면
    actor.change_equip(i, nil) -액터의 장비를 해제한다
    if TH_Instance::Weapon::Destroy_Broken_Weapon -만약 부서진장비가 발생하면
    $game_party.gain_item(self, -1) -파티는 그 장비를 제거한다
    else
    if broken_weapon_change -부서진 무기를 바뀐다면
    $game_party.gain_item(self, -1) - 파티에서 그 무기를 제거한다
    broke_version = InstanceManager.get_instance($data_weapons[broken_weapon_change]) -바뀌는 아이템의 정의
    $game_party.gain_item(broke_version, 1) -파티는 부서진 버전의 무기를 얻는다
    end - 끝
    요렇게 해석을 해봤습니다. 그래서 위의 장비를 해제한다 부분도 없애보고 밑에 actor.change_equip(i,broke_version, 1 ) 이렇게도 첨가해보았는데 장렬하게 에러가 발생하여서 도움을 얻고자 하였습니다.
  • ?
    LuD 2017.08.16 19:41
    의미없지만 핑계좀 대보자면.. ㅋ
    질문전 필독 글에도 있긴 한데.. 스크립트 전문은 txt 로....^^;
    아까는 자세히 볼 시간도 없고 본문이 길어서 복붙해서 시험해 볼수도 없어서 대충읽고 답했는데 안됐던거네요..;

    그런데.. 저 줄을 지웠는데 장비가 사라진다는 건가요?
    본문만 가지고는 실행이 안되서 테스트가 안되네요.
    https://open.kakao.com/o/sTBpI7x
    여기 오셔서 작동 안된다는 파일 보내주시면 확인 후 답변드리겠습니다.
  • ?
    메카패치 2017.08.17 10:10
    감사합니다 LuD님 덕분에 문제를 해결하고도 생각도 못했던 것 까지 도움을 받게 되었네요
    행복하셔요 ^^

List of Articles
종류 분류 제목 글쓴이 날짜 조회 수
공지 묻고 답하기 가이드 습작 2014.06.14 12384
기타 RMVXA 타이틀 이스터에그 만드는방법 알려주세요 3 썬키스트1호 2020.11.23 286
기타 RMVXA 아이콘 셋 이미지 이어붙이는법 2 겜만들고싶다앙 2020.11.22 177
플러그인 사용 RMMV 게임 중에 시스템의 효과음을 바꾸고 싶습니다. 2 JDG 2020.11.22 272
기타 RMVXA 아이콘을 직접 만들어 보고싶습니다 겜만들고싶다앙 2020.11.22 66
기타 RMMV 데미지 바닥의 판정을 명확히 하는 법있을까요? 무명시절 2020.11.22 69
기타 RMMV 약간 복잡한 질문 2 레기우스州 2020.11.21 111
게임 배포 RMMV 게임 배포 시 유저가 폰트를 따로 설치하지 않게 하는 방법 깡토 2020.11.20 194
기본툴 사용법 RMMV 대화창을 말풍선 형식으로 띄워지게 어떻게 하나요? 2 file 코볼트코 2020.11.19 562
기본툴 사용법 RMVX 질문합니다. massage back 교체 1 file 효잉 2020.11.18 117
기타 기타 열쇠 안사라짐,추격자 벽에낌 2 RPG메이커초보 2020.11.18 201
기본툴 사용법 RMMV 타이틀구석에 ver1.0.0하고 Author name 2019 어떻게 변경 하거나 제거 못하나요? 4 file hurakan 2020.11.17 141
플러그인 사용 RMMV mv에서는 캐릭터가 말할때 텍스트 음성 어떻게 하나요? 2 코볼트코 2020.11.16 707
이벤트 작성 기타 옷장에 숨는 이벤트 어떻게해요? 5 RPG메이커초보 2020.11.16 225
에러 해결 기타 안녕하세요 rpg메이커 초보입니다(XP) 좀 도와주셨으면 합니다 4 RPG메이커초보 2020.11.16 149
에러 해결 기타 알만툴2003에서 한글 대사를 쓰면 돈2 2020.11.16 111
플러그인 생성 RMMV 철권처럼 게이지바를 만들고 싶습니다 2 abang 2020.11.15 235
기본툴 사용법 RMVXA VXACE 텍스트 소리 어떻게 나게 하나요? rmqqoddl 2020.11.15 151
한글 패치 RMXP RPG XP 스팀 한글패치 최신 버전은 없나요? 1 일리브 2020.11.14 650
기타 RMMV 비트코인을 추가하고 싶습니다... 레기우스州 2020.11.14 125
이벤트 작성 기타 Rpg maker mz 꽃돼지 2020.11.14 155
Board Pagination Prev 1 ... 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 ... 515 Next
/ 515