Project1

标题: 有没有装备武器或者防具时自动触发公共事件脚本? [打印本页]

作者: a965645462    时间: 2017-12-23 18:37
标题: 有没有装备武器或者防具时自动触发公共事件脚本?
本帖最后由 a965645462 于 2017-12-23 18:39 编辑

有没有装备武器或者防具时自动触发公共事件脚本?(我知道可以用事件可以做,但是可能做的比较多)
作者: 韩飞广    时间: 2018-1-12 18:17
提示: 作者被禁止或删除 内容自动屏蔽
作者: Nil2018    时间: 2018-1-13 13:38
  1. =begin
  2. #===============================================================================
  3. ** 装备事件
  4. Author: Hime
  5. Date: Feb 26, 2013
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. Feb 26, 2014
  9.    - re-ordered event execution .dequip event is executed before equip event.
  10. Jun 7, 2013
  11.    - updated common event queue for backwards compatibility. common event ID
  12.      returns the first element in the queue list
  13. Jun 6, 2013
  14.    - equip events do not automatically run in scenes now. You will need
  15.      the Scene Interpreter script
  16. May 20, 2013
  17.    - common events now queue up and will be run automatically
  18. Feb 15, 2013
  19.    - added support for dequipping items
  20. Sep 21
  21.    - fixed bug where equipping nothing threw NoMethod error
  22. Sep 6, 2012
  23.    - initial release
  24. --------------------------------------------------------------------------------   
  25. ** Description

  26. 在武器/护甲装备/解除时可以触发一个公共事件.

  27. --------------------------------------------------------------------------------   
  28. ** Installation

  29. Place this below Materials and above Main.

  30. --------------------------------------------------------------------------------   
  31. ** Usage

  32. 武器/护甲备注

  33.     <装备公共事件: x>
  34.     <解除公共事件: x>
  35.    
  36. x为公共事件ID.
  37. #===============================================================================
  38. =end
  39. $imported = {} if $imported.nil?
  40. $imported["Tsuki_EquipEvents"] = true
  41. #===============================================================================
  42. # ** Configuration
  43. #===============================================================================
  44. module Tsuki
  45.   module Equip_Events
  46.    
  47.     Equip_Regex = /<装备公共事件:\s*(\d+)>/i
  48.     Dequip_Regex = /<解除公共事件:\s*(\d+)>/i
  49.   end
  50. end
  51. #===============================================================================
  52. # ** Rest of script
  53. #===============================================================================
  54. module RPG
  55.   class EquipItem
  56.    
  57.     def equip_event_id
  58.       return @equip_event_id unless @equip_event_id.nil?
  59.       res = Tsuki::Equip_Events::Equip_Regex.match(self.note)
  60.       return @equip_event_id = res ? res[1].to_i : 0
  61.     end
  62.    
  63.     def dequip_event_id
  64.       return @dequip_event_id unless @dequip_event_id.nil?
  65.       res = Tsuki::Equip_Events::Dequip_Regex.match(self.note)
  66.       return @dequip_event_id = res ? res[1].to_i : 0
  67.     end
  68.   end
  69. end

  70. class Game_Actor
  71.   
  72.   alias :th_equip_events_change_equip :change_equip
  73.   def change_equip(slot_id, item)
  74.     old_item = @equips[slot_id].object
  75.     th_equip_events_change_equip(slot_id, item)
  76.     if @equips[slot_id].object == item
  77.       $game_temp.reserve_common_event(old_item.dequip_event_id) if old_item
  78.       $game_temp.reserve_common_event(item.equip_event_id) if item
  79.     end
  80.   end
  81. end

  82. unless $imported["TH_CommonEventQueue"]
  83.   class Game_Temp

  84.     attr_reader :reserved_common_events
  85.     alias :th_common_event_queue_init :initialize
  86.     def initialize
  87.       th_common_event_queue_init
  88.       @reserved_common_events = []
  89.     end

  90.     # re-write
  91.     def reserve_common_event(common_event_id)
  92.       @reserved_common_events.push(common_event_id) if common_event_id > 0
  93.     end
  94.    
  95.     def common_event_id
  96.       @reserved_common_events[0]
  97.     end

  98.     # Note that I don't actually need to clear it out. It's done
  99.     # by the queue.

  100.     # true if list is not empty
  101.     def common_event_reserved?
  102.       !@reserved_common_events.empty?
  103.     end

  104.     # Grab the first one, first-in-first-out order
  105.     def reserved_common_event
  106.       $data_common_events[@reserved_common_events.shift]
  107.     end
  108.   end
  109. end
复制代码





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1