Project1

标题: 【VA】脚本Spawn Event [打印本页]

作者: 杂兵天下    时间: 2012-3-13 17:36
标题: 【VA】脚本Spawn Event
本帖最后由 无双sxa 于 2012-3-13 18:54 编辑

YF的脚本真如“大音希声扫阴翳”,犹如“拨开云雾见青天”,使我等网民看到了希望,看到了未来!晴天霹雳、醍醐灌顶或许不足以形容大师脚本的万一;巫山行云、长江流水更难以比拟大师的才气!黄钟大吕,振聋发聩!你烛照天下,明见万里;雨露苍生,泽被万方!透过你深邃的脚本,我仿佛看到了你鹰视狼顾、龙行虎步的伟岸英姿;仿佛看到了你手执如椽大笔、写天下脚本的智慧神态;仿佛看见了你按剑四顾、指点江山的英武气概!

我在R界打滚这么多年,所谓阅人无数,就算没有见过猪走路,也总明白猪肉是啥味道的。一看到YF的气势,我就觉得YF同在6R里灌水的那帮小混混有着本质的差别!那神奇的脚本功效,那熟悉的脚本格式,还有字里行间高屋建瓴的辞藻。没用的,YF,就算你怎么换马甲都是没有用的,你的亿万拥戴者早已经把你认出来了,你一定就是传说中的Yanfly大神。自从6R复活之后,我就已经心灰意冷,对R界也没抱什么希望了,传说已经幻灭,神话已经终结,留在R界还有什么意思?没想到,没想到,今天可以再睹YF的风范,我激动得忍不住就在屏幕前流下了眼泪。是啊,只要在YF的带领下,R界就有希望了。我的内心再一次沸腾了,我胸腔里的血再一次燃烧了。YF的几句话虽然简单,却概括扼要,一语道出了我们苦想多年仍不可解的几个重大问题的根本。YF就好比R界的明灯,YF就好比R界的方向,YF就好比R界的栋梁。有YF在,R界的明天必将更好!

YF的脚本实在是写得太好了。文笔流畅,修辞得体,深得柳柳九夜遗风,更将VictorYami之风格发扬得入木三分,能在有生之年看见YF的这个脚本。实在是我三生之幸啊。看完YF的这个脚本之后,我竟产生出一种无以名之的悲痛感——啊,这么好的脚本,如果将来我再也看不到了,那我该怎么办?那我该怎么办?直到我毫不犹豫地把YF的这个脚本收藏了,我内心的那种激动才逐渐平静下来。可是我立刻想到,这么好的脚本,倘若别人看不到,那么不是浪费YF的心血吗?经过痛苦的思想斗争,我终于下定决心,牺牲小我,奉献大我。我要拿出这帖子奉献给6R各位水客赏阅,我要把这个帖子一直往上顶,往上顶!顶到所有人都看到为止!
http://yanflychannel.wordpress.c ... cripts/spawn-event/
RUBY 代码复制
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Spawn Event v1.00
  4. # -- Last Updated: 2012.02.08
  5. # -- Level: Normal, Hard
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-SpawnEvent"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.02.08 - Started Script and Finished.
  17. #
  18. #==============================================================================
  19. # ▼ Introduction
  20. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. # For those who would like to spawn pre-made events from the current map or
  22. # even other maps, this script allows you to do so. With the option of spawning
  23. # the events at specific locations or a random spot marked by a certain region,
  24. # you can have events spawn using simple script calls. The events remain until
  25. # a map change.
  26. #
  27. #==============================================================================
  28. # ▼ Instructions
  29. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  30. # To install this script, open up your script editor and copy/paste this script
  31. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  32. #
  33. # -----------------------------------------------------------------------------
  34. # Script Calls - These commands are used with script calls.
  35. # -----------------------------------------------------------------------------
  36. # spawn_event_location(x, y, event_id)
  37. # spawn_event_location(x, y, event_id, map_id)
  38. # This causes a new event to be created at location x and y on the current map.
  39. # The event to be created will use the event data from event_id. If no map_id
  40. # is used, then the current map's event will be used to spawn the new event.
  41. # The event cannot spawn on top of another event or vehicle. If there is an
  42. # event or vehicle in place, then no event will be spawned at all.
  43. #
  44. # spawn_event_region(region_id, event_id)
  45. # spawn_event_region(region_id, event_id, map_id)
  46. # This causes a new event to be created at a random location with a matching
  47. # region_id. The event to be created will use the event data from event_id. If
  48. # no map_id is used, then the current map's event will be used to spawn the
  49. # new event. If the region_id does not exist on the current map, then no event
  50. # will be spawned. The event will not spawn on top of another event nor on top
  51. # of a vehicle. If there is not enough room to spawn an event, then no event
  52. # will be spawned at all. This process takes slightly longer on larger maps.
  53. #
  54. #==============================================================================
  55. # ▼ Compatibility
  56. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  57. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  58. # it will run with RPG Maker VX without adjusting.
  59. #
  60. #==============================================================================
  61.  
  62. #==============================================================================
  63. # ■ Game_Map
  64. #==============================================================================
  65.  
  66. class Game_Map
  67.  
  68.   #--------------------------------------------------------------------------
  69.   # new method: spawn_event
  70.   #--------------------------------------------------------------------------
  71.   def spawn_event(dx, dy, event_id, map_id)
  72.     return if $game_player.collide_with_characters?(dx, dy)
  73.     return if dx == $game_player.x && dy == $game_player.y
  74.     map_id = @map_id if map_id == 0
  75.     map = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
  76.     event = generated_event(map, event_id)
  77.     return if event.nil?
  78.     key_id = @events.keys.max + 1
  79.     @events[key_id] = Game_Event.new(@map_id, event)
  80.     @events[key_id].moveto(dx, dy)
  81.     SceneManager.scene.spriteset.refresh_characters
  82.   end
  83.  
  84.   #--------------------------------------------------------------------------
  85.   # new method: generated_event
  86.   #--------------------------------------------------------------------------
  87.   def generated_event(map, event_id)
  88.     for key in map.events
  89.       event = key[1]
  90.       next if event.nil?
  91.       return event if event.id == event_id
  92.     end
  93.     return nil
  94.   end
  95.  
  96.   #--------------------------------------------------------------------------
  97.   # new method: spawn_event_region
  98.   #--------------------------------------------------------------------------
  99.   def spawn_event_region(reg_id, event_id, map_id)
  100.     tile = get_random_region_tile(reg_id)
  101.     return if tile.nil?
  102.     spawn_event(tile[0], tile[1], event_id, map_id)
  103.   end
  104.  
  105.   #--------------------------------------------------------------------------
  106.   # new method: get_random_region_tile
  107.   #--------------------------------------------------------------------------
  108.   def get_random_region_tile(reg_id)
  109.     tiles = []
  110.     for i in 0...width
  111.       for j in 0...height
  112.         next unless (region_id(i, j) == reg_id) or (reg_id == 0)
  113.         next if $game_player.collide_with_characters?(i, j)
  114.         next if i == $game_player.x && j == $game_player.y
  115.         tiles.push([i, j])
  116.       end
  117.     end
  118.     return tiles.sample
  119.   end
  120.  
  121. end # Game_Map
  122.  
  123. #==============================================================================
  124. # ■ Game_Interpreter
  125. #==============================================================================
  126.  
  127. class Game_Interpreter
  128.  
  129.   #--------------------------------------------------------------------------
  130.   # new method: spawn_event_location
  131.   #--------------------------------------------------------------------------
  132.   def spawn_event_location(dx, dy, event_id, map_id = 0)
  133.     return unless SceneManager.scene_is?(Scene_Map)
  134.     $game_map.spawn_event(dx, dy, event_id, map_id)
  135.   end
  136.  
  137.   #--------------------------------------------------------------------------
  138.   # new method: spawn_event_region
  139.   #--------------------------------------------------------------------------
  140.   def spawn_event_region(region_id, event_id, map_id = 0)
  141.     return unless SceneManager.scene_is?(Scene_Map)
  142.     $game_map.spawn_event_region(region_id, event_id, map_id)
  143.   end
  144.  
  145. end # Game_Interpreter
  146.  
  147. #==============================================================================
  148. # ■ Scene_Map
  149. #==============================================================================
  150.  
  151. class Scene_Map < Scene_Base
  152.  
  153.   #--------------------------------------------------------------------------
  154.   # public instance variables
  155.   #--------------------------------------------------------------------------
  156.   attr_accessor :spriteset
  157.  
  158. end # Scene_Map
  159.  
  160. #==============================================================================
  161. #
  162. # ▼ End of File
  163. #
  164. #==============================================================================

spawn_event_location(x, y, event_id, map_id)表示从仓库地图map_id中提取编号为event_id的事件到当前地图的x,y位置上。
spawn_event_region(0, event_id, map_id)表示从仓库地图map_id中提取编号为event_id的事件到当前地图随机位置上。
spawn_event_region(region_id, event_id, map_id)表示从仓库地图map_id中提取编号为event_id的事件到当前地图的区域region_id中的随机位置上。
作者: www.μ.com    时间: 2012-3-13 17:46
前辈过谦了,这么好的脚本..把新任版主叫回来吧,加分。
@无双sxa
作者: 杂兵天下    时间: 2012-3-13 17:52
本帖最后由 杂兵天下 于 2012-3-13 22:00 编辑

下面我稍微将将此脚本的重大作用。
首先,可以随机生成敌人,免去费劲地到处复制明雷。
其次,可以随机生成宝箱,让开到宝箱真的变成运气的体现了。
第三,可以用作极多小游戏的框架(比如说,打地鼠?)
第四,可以用此系统快速的排布战棋,ZTBS杂兵战也能变得策略化。
第五,可以方便的制作出带有大量陷阱的迷宫。
第六,可以让不同区域的明雷不同,方便制作鱼、鸟等怪物。
第七,可以制作出随机的魔法阵,产生像仙三问路篇(囧)一样的复杂迷宫。
第八,可以制作出空中飞舞的火球,产生魔幻世界大战的辉煌效果。
第九,可以制作出ARPG中的随机放置敌人效果。
第十,如果运用得好,可以制造出大量效果,请大家仔细思考。
作者: 无双sxa    时间: 2012-3-13 17:54
本帖最后由 无双sxa 于 2012-3-13 18:55 编辑

楼主的确是很棒的,也不要看低自己什么的。谁说没有希望啥的,有信念支撑谁都能有希望的,会不会都是种潜力,实干才知道能不能做到。
另外,没有神,因此没有神作,没有神脚本。
作者: 杂兵天下    时间: 2012-3-13 20:55
标题: 【补丁】Spawn Event与雪流星即时遇敌的共存补丁(更新)
本帖最后由 杂兵天下 于 2012-3-14 15:59 编辑

  1. #==============================================================================
  2. # ■ Patch Of 雪流星即时遇敌 and Yanfly Engine Ace - Spawn Event v1.00
  3. #==============================================================================
  4. $imported = {} if $imported.nil?
  5. if $imported["YEA-SpawnEvent"]
  6.   #============================================================================
  7.   # ■ Game_Event Patch Of 雪流星即时遇敌
  8.   #============================================================================
  9.   class Game_Event < Game_Character
  10.     attr_accessor :id #create a attr_accessor of event id
  11.   end
  12.   
  13.   #============================================================================
  14.   # ■ Game_Map Patch Of 雪流星即时遇敌
  15.   #============================================================================

  16.   class Game_Map

  17.     #------------------------------------------------------------------------
  18.     # alias method: spawn_event
  19.     #------------------------------------------------------------------------
  20.     alias spawn_event_before_patch_of_xlx_instantcounter spawn_event
  21.     def spawn_event(dx, dy, event_id, map_id)
  22.       spawn_event_before_patch_of_xlx_instantcounter(dx, dy, event_id, map_id)
  23.       key_id = @events.keys.max#get the key id of the new event
  24.       @events[key_id].id = key_id#edit the event store id to the real id
  25.     end
  26.   end
  27. end

  28. class Game_Player < Game_Character
  29.   #--------------------------------------------------------------------------
  30.   # ● 执行遇敌处理
  31.   #--------------------------------------------------------------------------
  32.   def encounter
  33.     return false if $game_map.interpreter.running?
  34.     return false if $game_system.encounter_disabled
  35.     return false if @encounter_count > 0
  36.     make_encounter_count
  37.     troop_id = make_encounter_troop_id
  38.     return false unless $data_troops[troop_id]
  39.     if $game_map.anlei
  40.       BattleManager.setup(troop_id)
  41.       BattleManager.on_encounter
  42.       SceneManager.goto(Scene_Battle)
  43.     else
  44.       spawn_event_region(0, troop_id, 11, true, $game_map.daditu)#请把11改为仓库地图的ID
  45.     end
  46.     return true
  47.   end
  48. end
  49. class Scene_Map < Scene_Base
  50.   #--------------------------------------------------------------------------
  51.   # ● 监听遇敌事件
  52.   #--------------------------------------------------------------------------
  53.   def update_encounter
  54.     $game_player.encounter
  55.   end
  56. end
  57. def spawn_event_region(region_id, event_id, map_id = 0, pas = false, pangbian = false)
  58.   return unless SceneManager.scene_is?(Scene_Map)
  59.   $game_map.spawn_event_region(region_id, event_id, map_id, pas, pangbian)
  60. end
  61. module RPG
  62.   class Map
  63.     def daditu
  64.       self.note.split(/[\r\n]+/).each { |line|
  65.         return true if line == "<大地图>"
  66.       }
  67.       return false
  68.     end
  69.     def anlei
  70.       self.note.split(/[\r\n]+/).each { |line|
  71.         return true if line == "<暗雷>"
  72.       }
  73.       return false
  74.     end
  75.   end
  76. end
  77. class Game_Map
  78.   def daditu
  79.     return @map.daditu
  80.   end
  81.   def anlei
  82.     return @map.anlei
  83.   end
  84.   alias spawn_event_region_beforepatch_jatc spawn_event_region
  85.   def spawn_event_region(reg_id, event_id, map_id, pas = false, pangbian = false)
  86.     if pas or pangbian
  87.       tile = get_random_region_tile(reg_id,pas,pangbian)
  88.       return if tile.nil?
  89.       spawn_event(tile[0], tile[1], event_id, map_id)
  90.     else
  91.       spawn_event_region_beforepatch_jatc(reg_id, event_id, map_id)
  92.     end
  93.   end
  94.   def get_random_region_tile(reg_id,pas = false,pangbian = false)
  95.     if pangbian
  96.       a = $game_player.x - [18,encounter_step].max
  97.       b = $game_player.x + [18,encounter_step].max
  98.       c = $game_player.y - [13,encounter_step].max
  99.       d = $game_player.y + [13,encounter_step].max
  100.     else
  101.       a = 0
  102.       b = width
  103.       c = 0
  104.       d = width
  105.     end
  106.     tiles = []
  107.     for i in a...b
  108.       for j in c...d
  109.         next unless (region_id(i, j) == reg_id) or (reg_id == 0)
  110.         next if $game_player.collide_with_characters?(i, j)
  111.         next if i == $game_player.x && j == $game_player.y
  112.         unless $game_map.passable?(i,j,2)
  113.           unless $game_map.passable?(i,j,4)
  114.             unless $game_map.passable?(i,j,6)
  115.               unless $game_map.passable?(i,j,8)
  116.                 next if pas
  117.               end
  118.             end
  119.           end
  120.         end
  121.         tiles.push([i, j])
  122.       end
  123.     end
  124.     return tiles.sample
  125.   end
  126. end
复制代码
打补丁后,用spawn event生成的敌人也可以即时遇敌了!
一定要把补丁放在spawn event的后面!!!
在Kimu的地盘发补丁感觉不放心,所以还是发到这里了
在脚本中把11改为仓库地图ID。然后把此仓库地图中事件ID与敌人ID对应,做一些明雷事件。
然后在地图属性里设置遇敌。
会自动改暗雷为明雷。
如果要暗雷,请在地图备注里写<暗雷>
如果明雷遇敌的地图太大了,备注里写<大地图>
会自动优化处理,只在角色身边生成明雷。
但这样的效果其实不如全局生成好,所以地图不是太大(根据测试时卡的程度决定)还是不要用此选项。
作者: 姬文翔    时间: 2012-3-14 19:20
话说我看到Yanfly这个名字时误以为是yangff很长时间……
作者: 精灵使者    时间: 2012-3-14 22:43
其实美兽以前有一个“爱护环境人人有责”的帖子,就是说生成事件的。
作者: ArcDriver    时间: 2012-3-19 19:43
好东西收下了,多谢楼主亲分享XD

P.S.其实总觉得楼主亲就是Yami大神,是错觉么XD
作者: ohyee    时间: 2012-5-1 19:29
哇嘎嘎嘎嘎 ,见到宝贝了……

好好研究研究,可能我之前做的会因为这个脚本改完…………(泪奔
为什么没有再点遇到你啊,我亲爱的楼主……
作者: 夜飞尔-流星    时间: 2013-7-23 19:36
能告诉我们一下怎么用吗?
工程里有这个脚本但是不会用.




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