幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1891|回复: 3

超!遇敵系統!測試版 歡迎抓Bug!

[复制链接]

3

主题

20

帖子

222

积分

③业余

积分
222
发表于 2007-4-4 04:49:51 | 显示全部楼层 |阅读模式
這個系統,是模擬 仙劍奇俠傳的地圖遇敵模式。
基本上怪物會在地圖上出現,當玩家處碰/或是被處碰到才會進入戰鬥
(目前戰鬥系統還是以RMXP預設為主)
可能有人會認為,這個功能用事件內建功能就可以達成。在此是利用腳本整合,並且有些
特殊的地方。
1.比如1號地圖上有 史萊姆、蜘蛛、蛇 三類的敵人。
如果運用事件來作,可能事件的圖案就很難達到完善
(地圖上事件是史萊姆,結果一開打竟然是蛇。)
這個腳本他可以把你再[地圖設定]內所加入的怪物,直接轉換到地圖上直接顯示
你的地圖設定有三類的怪,那地圖上絕對不會顯示出第四類...
並且,地圖上顯示史萊姆,進入戰鬥就是跟史萊姆作戰,不會打錯敵人.

2.大幅簡化開發者的怪物設定上的困難度。
如果以事件內建功能來製作,不同的怪物你必許指定不同的圖案外,進入戰鬥這指令
還得再另外的去設定。
這個腳本很簡單,只要在事件名稱上輸入[敵人]。其他欄位都不用管
(你也可以設定他的移動速度/頻率)
系統自動會幫你轉換地圖上因該出現的敵人。開發者只要把這敵人事件放到想要放的位置即可。

目前唯一的BUG無法克服:
設計時地圖上所有[事件ID]必須[連號]
也就是有5個事件,那麼這事件ID必須為1.2.3.4.5
不可以為 1.2.3.4.6 會出現異常錯誤。

目前這系統有修改到 Scene_Battler 4 這腳本些許功能(主要是判斷戰鬥勝利的模組)
因此可能會與部分戰鬥腳本衝突。但是..要修改非常簡單...
因為只是在 Scene_Battler 4 內增加幾個變數而已。

OK!以下就是腳本內容,歡迎測試:

   本帖相关代码如下:
  1. #-------------------------------------------------------------------------------------
  2. #超!遇敵系統
  3. #coding by Kevin Chang
  4. #==============================================================================
  5. # ■ Game_Event
  6. #------------------------------------------------------------------------------
  7. #  處理事件的程式。條件判斷、事件頁的切換、並行處理、執行事件功能
  8. #     在 Game_Map 的內部使用。
  9. #==============================================================================
  10. module RPG #新增name定義,作用於抓取事件名稱欄位值
  11. class Event
  12.    def initialize(x, y)
  13.      @id = 0
  14.      @name = ""
  15.      @x = x
  16.      @y = y
  17.      @pages = [RPG::Event::Page.new]
  18.    end
  19.    attr_accessor :id
  20.    attr_accessor :name
  21.    attr_accessor :x
  22.    attr_accessor :y
  23.    attr_accessor :pages
  24. end
  25. end
  26. class Game_Event < Game_Character
  27. #--------------------------------------------------------------------------
  28. # ● 定義實例變量
  29. #--------------------------------------------------------------------------
  30. attr_accessor   :trigger                  # 目標(改為可讀寫)
  31. attr_reader   :list                     # 執行內容
  32. attr_reader   :starting                 # 啟動中標誌
  33. attr_accessor :name                  #取得事件名稱
  34. attr_accessor :character_name #改變事件圖形為可讀寫
  35. attr_accessor :auto_fight   #敵人事件處碰啟動戰鬥設定
  36. attr_accessor :move_type          #移動方式讓 $game_map.events[event_id].move_type = ? 來設定
  37. #--------------------------------------------------------------------------
  38. # ● 初始化對像
  39. #     map_id : 地圖 ID
  40. #     event  : 事件 (RPG::Event)
  41. #--------------------------------------------------------------------------
  42. def initialize(map_id, event)
  43.    super()
  44.    @map_id = map_id
  45.    @event = event
  46.    @id = @event.id
  47.    @erased = false
  48.    @starting = false
  49.    @through = true
  50.    @name = @event.name #取得事件名稱
  51.    @character_name =""#改變事件圖形為可讀寫
  52.    @auto_fight = false #敵人事件接觸自動戰鬥
  53.    @move_type = 0 #移動方式 讓 $game_map.events[event_id].move_type = ? 來設定
  54.    #改變敵人事件的移動方法 0.不動 1.隨機 2.接近 4.自訂AI
  55.    # 初期位置的移動
  56.    moveto(@event.x, @event.y)
  57.    refresh
  58. end
  59.    #--------------------------------------------------------------------------
  60. # ● 接觸事件啟動判定
  61. #--------------------------------------------------------------------------
  62. def check_event_trigger_touch(x, y)
  63.    # 事件執行中的情況下
  64.    if $game_system.map_interpreter.running?
  65.      return
  66.    end
  67.    # 目標為 [與事件接觸] 以及和主角坐標一致的情況下
  68.    if @trigger == 2 and x == $game_player.x and y == $game_player.y
  69.      # 除跳躍中以外的情況、啟動判定就是正面的事件
  70.      if not jumping? and not over_trigger?
  71.        @auto_fight = true
  72.             start
  73.       else
  74.        @auto_fight = false
  75.      end
  76.    end
  77. end
  78. #--------------------------------------------------------------------------
  79. # ● 自動事件啟動判定
  80. #--------------------------------------------------------------------------
  81. def check_event_trigger_auto
  82.    # 目標為 [與事件接觸] 以及和主角坐標一致的情況下
  83.    if @trigger == 2 and @x == $game_player.x and @y == $game_player.y
  84.      # 除跳躍中以外的情況、啟動判定就是同位置的事件
  85.      if not jumping? and over_trigger?
  86.        @auto_fight = true
  87.        start
  88.      else
  89.        @auto_fight = false
  90.      end
  91.    end
  92.    # 目標是 [自動執行] 的情況下
  93.    if @trigger == 3
  94.      start
  95.    end
  96. end
  97. end
  98. #==============================================================================
  99. # ■ Game_Character (分割定義 2)
  100. #------------------------------------------------------------------------------
  101. #  處理角色的程式。本程式作為 Game_Player 與 Game_Event
  102. #     的超級程式使用。
  103. #==============================================================================
  104. class Game_Character
  105. #--------------------------------------------------------------------------
  106. # ● 移動類型 : 接近
  107. #--------------------------------------------------------------------------
  108. def move_type_toward_player
  109.    # 求得與主角坐標的差
  110.    sx = @x - $game_player.x
  111.    sy = @y - $game_player.y
  112.    # 求得差的絕對值
  113.    abs_sx = sx > 0 ? sx : -sx
  114.    abs_sy = sy > 0 ? sy : -sy
  115.    # 如果縱橫共計離開 20 個元件
  116.    if sx + sy >= 5#修正敵人警戒距離
  117.      # 隨機
  118.      move_random
  119.      return
  120.    end
  121.    # 隨機 0~5 的分支
  122.    case rand(6)
  123.    when 0..3  # 接近主角
  124.      move_toward_player
  125.    when 4  # 隨機
  126.      move_random
  127.    when 5  # 前進一步
  128.      move_forward
  129.    end
  130. end
  131. end
  132. #===========================================================
  133. #==============================================================================
  134. # ■ Scene_Map
  135. #------------------------------------------------------------------------------
  136. #  處理地圖畫面的程式。
  137. #==============================================================================
  138. class Scene_Map
  139. #--------------------------------------------------------------------------
  140. # ● 主處理
  141. #--------------------------------------------------------------------------
  142. $enemy_event_arry = [] #存放敵人事件的事件編號對應的敵人隊伍id(troop_id)
  143. $e_event_id = []#存放屬於敵人事件的事件id
  144. def main  
  145. @a = 0
  146.    # 生成活動塊
  147.    @spriteset = Spriteset_Map.new
  148.    # 生成訊息窗口
  149.    @message_window = Window_Message.new
  150.    # 執行過渡
  151.    Graphics.transition
  152.    # 主循環
  153.    loop do   
  154.      new_battle_module #呼叫新版遇敵系統
  155.      # 刷新遊戲畫面
  156.      Graphics.update
  157.      # 刷新輸入訊息
  158.      Input.update
  159.      # 刷新畫面
  160.      update
  161.      # 如果畫面切換的話就中斷循環
  162.      if $scene != self
  163.        break
  164.      end
  165.    end
  166.    # 準備過渡
  167.    Graphics.freeze
  168.    # 釋放活動塊
  169.    @spriteset.dispose
  170.    # 釋放訊息窗口
  171.    @message_window.dispose
  172.    # 標題畫面切換中的情況下
  173.    if $scene.is_a?(Scene_Title)
  174.      # 淡入淡出畫面
  175.      Graphics.transition
  176.      Graphics.freeze
  177.    end
  178. end
  179. #------------------------------------------------------------------
  180. #●怪物事件隨機圖示變化設計模組-主要控制
  181. #--------------------------------------------------------------------
  182. def new_battle_module
  183.    # 遇敵列表不為空的情況下
  184.    if $game_map.encounter_list != []
  185.      # 不是在事件執行中或者禁止遇敵中
  186.      unless $game_system.map_interpreter.running? or
  187.             $game_system.encounter_disabled
  188.        # 確定隊伍
  189.         for i in 1 .. $game_map.events.size
  190.           if $game_map.events[i].name == "敵人"
  191.             if $game_map.events[i].character_name == ""#避免怪物持續刷新,設置一個break的條件
  192.             $game_map.events[i].character_name = rand_enemies_character_name#改變敵人事件的圖片
  193.             $enemy_event_arry[i] = $enemy_event_id#將獲取的troop_id 存放到敵人事件陣列內
  194.             $e_event_id[@a] = i
  195.            @a += 1
  196.             $game_map.events[i].trigger = 2 #自動改為接觸啟動事件
  197.             $game_map.events[i].move_type = 2
  198.             #改變敵人事件的移動方法 0.不動 1.隨機 2.接近
  199.             # 隊伍有效的話
  200.             else
  201.               break
  202.             end#if 避免怪物持續刷新,設置一個break的條件
  203.           end
  204.       end#end for
  205.    end #unless
  206. end#if 遇敵列表不為空的情況下
  207. end#module   
  208. #--------------------------------------------------------------------
  209. #●怪物事件隨機圖示變化設計模組-戰鬥圖獲取
  210. #--------------------------------------------------------------------
  211. def rand_enemies_character_name
  212.         n = rand($game_map.encounter_list.size)#亂數取得地圖敵人列表數量
  213.         troop_id = $game_map.encounter_list[n]#亂數帶入敵人隊伍ID內,由敵人列表隨機取出一隊伍
  214.         troop = $data_troops[troop_id]#將隨機敵人隊伍資料存放到 troop 變數內
  215.         $enemy_event_id = troop_id
  216.         i =  rand(troop.members.size) #由troop隊伍資料內 隨機抽出一個敵人隊員
  217.         enemy_character_name = $data_enemies[troop.members[i].enemy_id].battler_name
  218.         #抽出的隨機敵人隊員,與data_enemies去比對出對應的怪物戰鬥圖,把戰鬥圖名稱取出
  219.          return enemy_character_name #回傳戰鬥圖名稱
  220. end
  221. #--------------------------------------------------------------------------
  222. # ● 刷新畫面
  223. #--------------------------------------------------------------------------
  224. def update
  225.    # 循環
  226.    loop do
  227.      # 按照地圖、實例、主角的順序刷新
  228.      # (本更新順序不會在的滿足事件的執行條件下成為給予角色瞬間移動
  229.      #  的機會的重要原素)
  230.      $game_map.update
  231.      $game_system.map_interpreter.update
  232.      $game_player.update
  233.      # 系統 (計時器)、畫面刷新
  234.      $game_system.update
  235.      $game_screen.update
  236.      # 如果主角在場所移動中就中斷循環
  237.      unless $game_temp.player_transferring
  238.        break
  239.      end
  240.      # 執行場所移動
  241.      transfer_player
  242.      # 處理過渡中的情況下、中斷循環
  243.      if $game_temp.transition_processing
  244.        break
  245.      end
  246.    end
  247.    # 刷新活動塊
  248.    @spriteset.update
  249.    # 刷新訊息窗口
  250.    @message_window.update
  251.    # 遊戲結束的情況下
  252.    if $game_temp.gameover
  253.      # 切換的遊戲結束畫面
  254.      $scene = Scene_Gameover.new
  255.      return
  256.    end
  257.    # 返回標題畫面的情況下
  258.    if $game_temp.to_title
  259.      # 切換到標題畫面
  260.      $scene = Scene_Title.new
  261.      return
  262.    end
  263.    # 處理過渡中的情況下
  264.    if $game_temp.transition_processing
  265.      # 清除過渡處理中標誌
  266.      $game_temp.transition_processing = false
  267.      # 執行過渡
  268.      if $game_temp.transition_name == ""
  269.        Graphics.transition(20)
  270.      else
  271.        Graphics.transition(40, "Graphics/Transitions/" +
  272.          $game_temp.transition_name)
  273.      end
  274.    end
  275.    # 顯示訊息窗口中的情況下
  276.    if $game_temp.message_window_showing
  277.      return
  278.    end
  279.    # 遇敵列表不為空的情況下且敵人事件 auto_fight 為true
  280.    for i in $e_event_id
  281.    if $game_map.encounter_list != [] and $game_map.events[i].auto_fight == true
  282.      $event_id_on_time = i #把正在進行戰鬥的 event_id 取出,以便後面呼叫使用
  283.      # 不是在事件執行中或者禁止遇敵中
  284.      unless $game_system.map_interpreter.running? or
  285.             $game_system.encounter_disabled
  286.        # 確定隊伍
  287.        troop_id = $enemy_event_arry[i]
  288.        # 隊伍有效的話
  289.        if $data_troops[troop_id] != nil
  290.          # 設置調用戰鬥標誌
  291.          $game_temp.battle_calling = true
  292.          $game_temp.battle_troop_id = troop_id
  293.          $game_temp.battle_can_escape = true
  294.          $game_temp.battle_can_lose = false
  295.          $game_temp.battle_proc = nil
  296.        end
  297.      end
  298.    end
  299.    end #for
  300.    # 按下 B 鍵的情況下
  301.    if Input.trigger?(Input::B)
  302.      # 不是在事件執行中或菜單禁止中
  303.      unless $game_system.map_interpreter.running? or
  304.             $game_system.menu_disabled
  305.        # 設置菜單調用標誌以及 SE 演奏
  306.        $game_temp.menu_calling = true
  307.        $game_temp.menu_beep = true
  308.      end
  309.    end
  310.    # 調試模式為 ON 並且按下 F9 鍵的情況下
  311.    if $DEBUG and Input.press?(Input::F9)
  312.      # 設置調用調試標誌
  313.      $game_temp.debug_calling = true
  314.    end
  315.    # 不在主角移動中的情況下
  316.    unless $game_player.moving?
  317.      # 執行各種畫面的調用
  318.      if $game_temp.battle_calling
  319.        call_battle
  320.      elsif $game_temp.shop_calling
  321.        call_shop
  322.      elsif $game_temp.name_calling
  323.        call_name
  324.      elsif $game_temp.menu_calling
  325.        call_menu
  326.      elsif $game_temp.save_calling
  327.        call_save
  328.      elsif $game_temp.debug_calling
  329.        call_debug
  330.      end
  331.    end
  332. end
  333. end
  334. #==============================================================================
  335. # ■ Scene_Battle (分割定義 2)
  336. #------------------------------------------------------------------------------
  337. #  處理戰鬥畫面的程式。
  338. #==============================================================================
  339. class Scene_Battle
  340. #--------------------------------------------------------------------------
  341. # ● 畫面更新 (結束戰鬥回合)
  342. #--------------------------------------------------------------------------
  343. def update_phase5
  344.    # 等待計數大于 0 的情況下
  345.    if @phase5_wait_count > 0
  346.      # 減少等待計數
  347.      @phase5_wait_count -= 1
  348.      # 等待計數為 0 的情況下
  349.      if @phase5_wait_count == 0
  350.        # 顯示結果窗口
  351.        @result_window.visible = true
  352.        # 清除主回合標誌
  353.        $game_temp.battle_main_phase = false
  354.        # 刷新狀態窗口
  355.        @status_window.refresh
  356.      end
  357.      return
  358.    end
  359.    # 按下 C 鍵的情況下
  360.    if Input.trigger?(Input::C)
  361.      # 戰鬥結束
  362.      $game_map.events[$event_id_on_time].name = "死亡"
  363.      $game_map.events[$event_id_on_time].auto_fight = false
  364.      $game_map.events[$event_id_on_time].trigger = 0
  365.      $game_map.events[$event_id_on_time].erase
  366.      battle_end(0)
  367.    end
  368. end
  369. end
复制代码
回复

使用道具 举报

3

主题

20

帖子

222

积分

③业余

积分
222
 楼主| 发表于 2007-4-4 04:52:50 | 显示全部楼层
補充,因為使用繁體,所以可能再事件名稱的判斷上會出現問題。
可以看到整個程式碼後找到下面這段修改。
  1. #------------------------------------------------------------------
  2. #●怪物事件隨機圖示變化設計模組-主要控制
  3. #--------------------------------------------------------------------
  4. def new_battle_module
  5.   # 遇敵列表不為空的情況下
  6.   if $game_map.encounter_list != []
  7.     # 不是在事件執行中或者禁止遇敵中
  8.     unless $game_system.map_interpreter.running? or
  9.            $game_system.encounter_disabled
  10.       # 確定隊伍
  11.        for i in 1 .. $game_map.events.size
  12.          if $game_map.events[i].name == "敵人"
  13.            if $game_map.events[i].character_name == ""#避免怪物持續刷新,設置一個break的條件
复制代码
  1. 找到這行:
  2. if $game_map.events[i].name == "敵人"
  3. 這敵人請改為簡體,事件名稱使用簡體的[敵人]即可。
复制代码
回复 支持 反对

使用道具 举报

88

主题

5419

帖子

214748万

积分

版主

S素世上最伟大最华丽

Rank: 7Rank: 7Rank: 7

积分
2147483647
QQ
发表于 2007-4-4 09:56:04 | 显示全部楼层
事件做一般用COPYCOPYCOPY,感觉不会麻烦~~
不过,还是支持哈~~
回复 支持 反对

使用道具 举报

38

主题

3468

帖子

1

积分

超级版主

传说中的Bunny火神~!

Rank: 8Rank: 8

积分
1
发表于 2007-4-5 01:07:22 | 显示全部楼层
看起来蛮方便的,不过还是比较习惯以前的复制事件方法…… [s:5]
我突然发现,我是一个很幸运的好人。老婆真好~ 点我进入JQ(激情)教程范例收集!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2025-6-24 05:05 , Processed in 0.014187 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表