查看: 4316|回复: 5

[已经解决] 请问如何事件接触事件来触发动作

[复制链接]
梦石
0
星屑
50
在线时间
137 小时
注册时间
2012-8-27
回帖
86
发表于 2013-6-8 18:00:28 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 liminglun 于 2013-6-8 18:10 编辑

谢谢各位了,在做事健
补充:事件过多,所以用判断x,y会累死的
从某处扒来了个脚本思路
用矩形数组加循环加下标读取所有事件的横,纵坐标。然后编写函数运算x,y的距离值,返回真假
再用一个循环将所有数组带入函数运算一遍,返回真的话就倒出当前数组下标••••然后运行排列为倒出数的时间就行了= =


梦石
1
星屑
23371
在线时间
9572 小时
注册时间
2012-6-19
回帖
7021

开拓者短篇九导演组冠军

发表于 2013-6-9 20:44:07 | 显示全部楼层
回复

使用道具 举报

梦石
0
星屑
50
在线时间
137 小时
注册时间
2012-8-27
回帖
86
 楼主| 发表于 2013-6-10 14:39:30 | 显示全部楼层
喵呜喵5 发表于 2013-6-9 20:44
http://himeworks.wordpress.com/2013/04/05/custom-event-triggers/

(需要翻墙)

能帮忙贴过来吗,实在是懒得弄apn了。。。谢谢大神


回复

使用道具 举报

梦石
1
星屑
23371
在线时间
9572 小时
注册时间
2012-6-19
回帖
7021

开拓者短篇九导演组冠军

发表于 2013-6-10 15:11:48 | 显示全部楼层
liminglun 发表于 2013-6-10 14:39
能帮忙贴过来吗,实在是懒得弄apn了。。。谢谢大神

用法说明:
  1. To specify a custom page trigger, create a comment of the form

  2. <page trigger: trigger_name>
  3. Where `trigger_name` is one of the available custom event triggers. The reference section lists all of the available custom triggers.

  4. Extended Trigger Data

  5. This script adds “extended data” to the trigger.
  6. Certain triggers may use this data to determine how to run.

  7. The general format for extended trigger data is

  8. <page trigger: trigger_name ext_data>
  9. Where ext_data is any string. Check the reference to see what kinds of
  10. extended data may be required for each trigger.

  11. Parallel Triggers

  12. A custom trigger can be used as a condition for starting a parallel process. If the activation condition is met, then the event will begin running as a parallel process. This will not stop until the page changes.



  13. Reference

  14. Here is a list of available triggers and a description about them.

  15. Player_Leave

  16. Triggered when the player steps off an event. Note that this means the
  17. event must have below-character priority.



  18. Timer Expire

  19. Triggered when the game timer counts down to zero. The timer must be counting down in order for these events to trigger.

  20. Event_On_Event

  21. Triggered when an event comes into contact with another event (using the
  22. “event touch” rules).  Takes a list of event ID’s for extended data. Only the specified event ID’s can trigger this event. When no ext data is specified, then any event can trigger this event. Use -1 if you want the player to trigger it as well



  23. Region_Enter

  24. Triggered when the player enters a region. This is not checked if you are already in the region. It takes a list of region ID’s as extended data.



  25. Region_Leave

  26. Triggered when the player leaves a region. It takes a list of region ID’s as extended data.
复制代码


脚本:
  1. =begin
  2. #===============================================================================
  3. Title: Custom Event Triggers
  4. Author: Tsukihime
  5. Date: Apr 9, 2013
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. Apr 9
  9.    - implemented parallel processing for all custom triggers
  10. Apr 8
  11.    - added "region enter" trigger
  12.    - added "region leave" trigger
  13. Apr 5
  14.    - added "event_to_event" trigger
  15. Apr 4, 2013
  16.    - added "timer_expire" trigger
  17.    - Initial release
  18. --------------------------------------------------------------------------------   
  19. ** Terms of Use
  20. * Free to use in commercial/non-commercial projects
  21. * No real support. The script is provided as-is
  22. * Will do bug fixes, but no compatibility patches
  23. * Features may be requested but no guarantees, especially if it is non-trivial
  24. * Credits to Tsukihime in your project
  25. * Preserve this header
  26. --------------------------------------------------------------------------------
  27. ** Description

  28. This script provides additional event triggers.
  29. The built-in event triggers include

  30.    Action Trigger
  31.    Player Touch
  32.    Event Touch
  33.    Autorun
  34.    Parallel Process
  35.    
  36. This script provides additional triggers.
  37.    
  38. --------------------------------------------------------------------------------
  39. ** Installation

  40. Place this below Materials and above Main

  41. --------------------------------------------------------------------------------
  42. ** Usage

  43. To specify a custom page trigger, create a comment of the form

  44.    <page trigger: trigger_name>
  45.    
  46. Where `trigger_name` is one of the available custom event triggers.

  47. -- Extended trigger data --

  48. This script adds "extended data" to the trigger.
  49. Certain triggers may use this data to determine how to run.

  50. The general format for extended trigger data is

  51.    <page trigger: trigger_name ext_data>
  52.    
  53. Where ext_data is any string. Check the reference to see what kinds of
  54. extended data may be required for each trigger.

  55. -- Parallel Triggers --

  56. All event pages using custom triggers can be set as parallel processes if
  57. you set the trigger to Parallel Process. However, the difference is that
  58. rather than running constantly, they will begin to run only when their
  59. activation condition is met. However, after they begin running they will
  60. continue to run until the page is changed.

  61. --------------------------------------------------------------------------------
  62. ** Reference

  63. Here is a list of available triggers and their trigger timing. The timing
  64. indicates when the page will be checked.

  65. Name: Player_Leave
  66. Time: Triggered when the player steps off an event. Note that this means the
  67.        event must have below-character priority.
  68.   Ext: None
  69.    
  70. Name: Timer_Expire
  71. Time: Triggered when the game timer expires (eg: it goes to zero)
  72.   Ext: None

  73. Name: Event_To_Event
  74. Time: Triggered when an event comes into contact with another event (using the
  75.        "event touch" rules)
  76.   Ext: Takes a list of event ID's. Only the specified event ID's can trigger
  77.        this event. When no ext data is specified, then any event can
  78.        trigger this event. Use -1 if you want the player to trigger it as well
  79.      
  80. Name: Region_Enter
  81. Time: Triggered when a player enters a particular region. Does not check if
  82.        the player is already in the region
  83.   Ext: Takes a list of region ID's
  84.   
  85. Name: Region_Leave
  86. Time: Triggered when a player leaves a particular region
  87.   Ext: Takes a list of region ID's
  88.    
  89. #===============================================================================
  90. =end
  91. $imported = {} if $imported.nil?
  92. $imported["TH_CustomEventTriggers"] = true
  93. #===============================================================================
  94. # ** Configuration
  95. #===============================================================================
  96. module TH
  97.   module Custom_Event_Triggers
  98.    
  99. #===============================================================================
  100. # ** Rest of script
  101. #===============================================================================
  102.     Trigger_Table = {
  103.       # default triggers
  104.       :action_trigger    => 0,
  105.       :player_touch      => 1,
  106.       :event_touch       => 2,
  107.       :autorun           => 3,
  108.       :parallel_process  => 4,
  109.       
  110.       # custom triggers
  111.       :player_leave      => 5,
  112.       :timer_expire      => 6,
  113.       :event_to_event    => 7,
  114.       :region_enter      => 8,
  115.       :region_leave      => 9
  116.     }
  117.    
  118.     Regex = /<page trigger:\s*(\w+)\s*(.*)>/i
  119.   end
  120. end

  121. #-------------------------------------------------------------------------------
  122. #
  123. #-------------------------------------------------------------------------------
  124. module RPG
  125.   class Event::Page
  126.    
  127.     def parallel_process?
  128.       return @old_trigger == 4
  129.     end
  130.    
  131.     #---------------------------------------------------------------------------
  132.     # Load any custom triggers, if necessary
  133.     #---------------------------------------------------------------------------
  134.     alias :th_custom_event_triggers_trigger :trigger
  135.     def trigger
  136.       parse_event_triggers unless @custom_event_triggers_checked
  137.       th_custom_event_triggers_trigger
  138.     end
  139.    
  140.     #---------------------------------------------------------------------------
  141.     # Extended trigger data. Use depends on the trigger type
  142.     #---------------------------------------------------------------------------
  143.     def trigger_ext
  144.       return @trigger_ext unless @trigger_ext.nil?
  145.       parse_event_triggers unless @custom_event_triggers_checked
  146.       return @trigger_ext
  147.     end
  148.    
  149.     #---------------------------------------------------------------------------
  150.     # Returns a symbol representing the trigger type. These are the keys in
  151.     # the trigger table above
  152.     #---------------------------------------------------------------------------
  153.     def trigger_type
  154.       return @trigger_type unless @trigger_type.nil?
  155.       parse_event_triggers unless @custom_event_triggers_checked
  156.       return @trigger_type
  157.     end
  158.    
  159.     #---------------------------------------------------------------------------
  160.     # Search for a page trigger comment
  161.     #---------------------------------------------------------------------------
  162.     def parse_event_triggers
  163.       @old_trigger = @trigger
  164.       @trigger_ext = ""
  165.       @list.each do |cmd|
  166.         if cmd.code == 108 && cmd.parameters[0] =~ TH::Custom_Event_Triggers::Regex
  167.           @trigger_type = $1.downcase.to_sym
  168.           @trigger = TH::Custom_Event_Triggers::Trigger_Table[@trigger_type]
  169.           @trigger_ext = parse_extended_trigger($2)
  170.         end
  171.       end
  172.       @custom_event_triggers_checked = true
  173.     end
  174.    
  175.     #---------------------------------------------------------------------------
  176.     # Parse the extended data according to the trigger type. Different triggers
  177.     # may expect different input
  178.     #---------------------------------------------------------------------------
  179.     def parse_extended_trigger(data)
  180.       case @trigger_type
  181.       when :event_to_event, :region_enter, :region_leave
  182.         @trigger_ext = data.split.map{|val| val.to_i}
  183.       else
  184.         @trigger_ext = data
  185.       end
  186.     end
  187.   end
  188. end

  189. #-------------------------------------------------------------------------------
  190. #
  191. #-------------------------------------------------------------------------------
  192. class Game_Timer
  193.   
  194.   #-----------------------------------------------------------------------------
  195.   # Check map events for any events that trigger on time expiry
  196.   #-----------------------------------------------------------------------------
  197.   alias :th_custom_event_triggers_on_expire :on_expire
  198.   def on_expire
  199.     th_custom_event_triggers_on_expire
  200.     $game_map.events.each_value do |event|
  201.       event.check_event_trigger_on_timer_expire([6])
  202.     end
  203.   end
  204. end

  205. #-------------------------------------------------------------------------------
  206. #
  207. #-------------------------------------------------------------------------------
  208. class Game_Player < Game_Character
  209.   
  210.   attr_reader :last_region_id
  211.   attr_reader :last_x
  212.   attr_reader :last_y
  213.   
  214.   alias :th_custom_event_triggers_update :update
  215.   def update
  216.     store_previous_position unless moving?
  217.     th_custom_event_triggers_update
  218.   end
  219.   
  220.   alias :th_custom_event_triggers_update_nonmoving :update_nonmoving
  221.   def update_nonmoving(last_moving)
  222.     th_custom_event_triggers_update_nonmoving(last_moving)
  223.     return if $game_map.interpreter.running?
  224.     if last_moving
  225.       check_player_leave_event
  226.       if @last_region_id != self.region_id
  227.         check_player_region_enter_events
  228.         check_player_region_leave_events
  229.       end
  230.     end
  231.   end
  232.   
  233.   #-----------------------------------------------------------------------------
  234.   # Check for events with event-to-event trigger as well, in case the player
  235.   # also triggers it
  236.   #-----------------------------------------------------------------------------
  237.   alias :th_custom_event_triggers_check_event_trigger_touch :check_event_trigger_touch
  238.   def check_event_trigger_touch(x, y)
  239.     th_custom_event_triggers_check_event_trigger_touch(x, y)
  240.     return if $game_map.interpreter.running?
  241.     start_map_event(x, y, [7], true)
  242.   end
  243.   
  244.   #-----------------------------------------------------------------------------
  245.   # New. Keep track of most recent position
  246.   #-----------------------------------------------------------------------------
  247.   def store_previous_position
  248.     @last_real_x = @real_x
  249.     @last_real_y = @real_y
  250.     @last_x = @x
  251.     @last_y = @y
  252.     @last_region_id = self.region_id
  253.   end
  254.   
  255.   #-----------------------------------------------------------------------------
  256.   # New. Determines if any events at the player's previous position should be
  257.   # triggered
  258.   #-----------------------------------------------------------------------------
  259.   def check_player_leave_event
  260.     check_event_trigger_before([5])
  261.   end
  262.   
  263.   #-----------------------------------------------------------------------------
  264.   # New. Check any events in the player's previous position
  265.   #-----------------------------------------------------------------------------
  266.   def check_event_trigger_before(triggers)
  267.     start_map_event(@last_x, @last_y, triggers, false)
  268.   end
  269.   
  270.   #-----------------------------------------------------------------------------
  271.   # New. Check any events in the player's previous position
  272.   #-----------------------------------------------------------------------------
  273.   def check_player_region_enter_events
  274.     $game_map.events.each_value do |event|
  275.       event.check_event_trigger_on_region_enter
  276.     end
  277.   end
  278.   
  279.   def check_player_region_leave_events
  280.     $game_map.events.each_value do |event|
  281.       event.check_event_trigger_on_region_leave
  282.     end
  283.   end
  284. end

  285. class Game_Event < Game_Character
  286.   
  287.   alias :th_custom_event_triggers_start :start
  288.   def start
  289.     return if empty?
  290.     p 'here'
  291.     if @page.parallel_process?
  292.       @interpreter = Game_Interpreter.new
  293.     else
  294.       th_custom_event_triggers_start
  295.     end
  296.   end
  297.   
  298.   #-----------------------------------------------------------------------------
  299.   # New. Returns the extended trigger data
  300.   #-----------------------------------------------------------------------------
  301.   def trigger_ext
  302.     @page.nil? ? [] : @page.trigger_ext
  303.   end
  304.   
  305.   #-----------------------------------------------------------------------------
  306.   # Start an event if timer expires
  307.   #-----------------------------------------------------------------------------
  308.   def check_event_trigger_on_timer_expire(triggers)
  309.     start if trigger_in?(triggers)
  310.   end
  311.   
  312.   #-----------------------------------------------------------------------------
  313.   # First check event touch with player, then event touch with event
  314.   #-----------------------------------------------------------------------------
  315.   alias :th_custom_event_triggers_check_event_trigger_touch :check_event_trigger_touch
  316.   def check_event_trigger_touch(x, y)
  317.     th_custom_event_triggers_check_event_trigger_touch(x, y)
  318.     return if $game_map.interpreter.running?
  319.     check_event_to_event_touch(x, y, [7])
  320.   end
  321.   
  322.   #-----------------------------------------------------------------------------
  323.   # Check whether events coming into contact should trigger
  324.   #-----------------------------------------------------------------------------
  325.   def check_event_to_event_touch(x, y, triggers)
  326.     $game_map.events_xy(x, y).each do |event|
  327.       next unless event.trigger_in?(triggers)
  328.       event.start if event.trigger_ext.empty? || event.trigger_ext.include?(@id)
  329.     end
  330.   end
  331.   
  332.   #-----------------------------------------------------------------------------
  333.   # Check whether events should run due to player entering a region
  334.   #-----------------------------------------------------------------------------
  335.   def check_event_trigger_on_region_enter
  336.     start if @trigger == 8 && trigger_ext.include?($game_player.region_id)
  337.   end
  338.   
  339.   #-----------------------------------------------------------------------------
  340.   # Check whether events should run due to player leaving a region
  341.   #-----------------------------------------------------------------------------
  342.   def check_event_trigger_on_region_leave
  343.     start if @trigger == 9 && trigger_ext.include?($game_player.last_region_id)
  344.   end
  345. end
复制代码

点评

谢谢。。不过英文说明研究了半天。。。。。。  发表于 2013-6-11 10:19
回复

使用道具 举报

梦石
0
星屑
50
在线时间
137 小时
注册时间
2012-8-27
回帖
86
 楼主| 发表于 2013-6-11 10:40:21 | 显示全部楼层
喵呜喵5 发表于 2013-6-10 15:11
用法说明:
To specify a custom page trigger, create a comment of the form

大神啊,某无赖想要一个范例=、=。。。研究很久不明白怎么用A!。。。


回复

使用道具 举报

梦石
1
星屑
23371
在线时间
9572 小时
注册时间
2012-6-19
回帖
7021

开拓者短篇九导演组冠军

发表于 2013-6-11 12:03:12 | 显示全部楼层
liminglun 发表于 2013-6-11 10:40
大神啊,某无赖想要一个范例=、=。。。研究很久不明白怎么用A!。。。

Data.zip (211.39 KB, 下载次数: 198)

新建一个工程,替换掉那个工程的data文件夹

点评

感谢您耐心的回答! 认可答案  发表于 2013-6-11 12:30

评分

参与人数 1梦石 +1 收起 理由
Sion + 1 认可答案

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部