查看: 2753|回复: 5

[已经解决] 鎖定領隊角色的方式

[复制链接]
梦石
0
星屑
50
在线时间
158 小时
注册时间
2016-1-7
回帖
102
发表于 2016-4-13 03:41:35 | 显示全部楼层 |阅读模式

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

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

×
現在我可以按x換角色(設置為鍵盤A鍵)【曾發過的、已解決覺得問題帖: 用公用事件達成按鍵更換領隊為何無效】,而目前隊裡只有兩個角色A跟B
在某段劇情裡我必須只能控制B,然而A還是在隊裡

請問有什麼方式可以在不梯隊員的情況下,鎖定操縱角色是誰嗎?

目前我可行的方法是

事件設為"並行處理"
然後移除A再讓A入隊,這能保證$game_party.actors[0]絕對不是A
遊戲也能運行,打開選單看AB也確實都在隊伍中。
唯一的小問題就是按下換領隊的A鍵後,A鍵實際上還是有作用所以角色會閃一下+有換角音效,但因為上述移除A再讓A入隊是併行處理,所以還是會回到操控角色為B

我想在事件指令裡用腳本操作,直覺想到的方法是$game_party.actors[0]和$game_party.actors[1]對調
所以我這樣寫
  1. $game_party.actors[1] =  $game_party.actors[0]
  2. $game_party.actors[0] = $game_actors[5]
  3. $game_player.refresh
复制代码

但當我要開系統選單或者按A鍵時,遊戲就會出現錯誤訊息然後我就只好關掉了。


我認為是第一行這樣寫有問題,所以還嘗試過把它換成
($game_variables[52] 存放了A的id)
  1. $game_party.actors[1] = $game_actors[$game_variables[52]]
复制代码

結果還是會出現


我覺得並行處理的不斷移出加入角色作法並不是很好,並且還存在著我上面說的問題
想請問後來用腳本的寫法是不是能銷給哪個地方就可以用,或者有別的方式可以達成鎖定領隊角色的辦法

這是在Game_Player最下面加了更換領隊腳本的整個腳本
  1. #==============================================================================
  2. # ** Game_Player
  3. #------------------------------------------------------------------------------
  4. #  This class handles the player. Its functions include event starting
  5. #  determinants and map scrolling. Refer to "$game_player" for the one
  6. #  instance of this class.
  7. #==============================================================================

  8. class Game_Player < Game_Character
  9.   #--------------------------------------------------------------------------
  10.   # * Invariables
  11.   #--------------------------------------------------------------------------
  12.   CENTER_X = (320 - 16) * 4   # Center screen x-coordinate * 4
  13.   CENTER_Y = (240 - 16) * 4   # Center screen y-coordinate * 4
  14.   #--------------------------------------------------------------------------
  15.   # * Passable Determinants
  16.   #     x : x-coordinate
  17.   #     y : y-coordinate
  18.   #     d : direction (0,2,4,6,8)
  19.   #         * 0 = Determines if all directions are impassable (for jumping)
  20.   #--------------------------------------------------------------------------
  21.   def passable?(x, y, d)
  22.     # Get new coordinates
  23.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  24.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  25.     # If coordinates are outside of map
  26.     unless $game_map.valid?(new_x, new_y)
  27.       # Impassable
  28.       return false
  29.     end
  30.     # If debug mode is ON and ctrl key was pressed
  31.     if $DEBUG and Input.press?(Input::CTRL)
  32.       # Passable
  33.       return true
  34.     end
  35.     super
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # * Set Map Display Position to Center of Screen
  39.   #--------------------------------------------------------------------------
  40.   def center(x, y)
  41.     max_x = ($game_map.width - 20) * 128
  42.     max_y = ($game_map.height - 15) * 128
  43.     $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
  44.     $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # * Move to Designated Position
  48.   #     x : x-coordinate
  49.   #     y : y-coordinate
  50.   #--------------------------------------------------------------------------
  51.   def moveto(x, y)
  52.     super
  53.     # Centering
  54.     center(x, y)
  55.     # Make encounter count
  56.     make_encounter_count
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # * Increaase Steps
  60.   #--------------------------------------------------------------------------
  61.   def increase_steps
  62.     super
  63.     # If move route is not forcing
  64.     unless @move_route_forcing
  65.       # Increase steps
  66.       $game_party.increase_steps
  67.       # Number of steps are an even number
  68.       if $game_party.steps % 2 == 0
  69.         # Slip damage check
  70.         $game_party.check_map_slip_damage
  71.       end
  72.     end
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # * Get Encounter Count
  76.   #--------------------------------------------------------------------------
  77.   def encounter_count
  78.     return @encounter_count
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # * Make Encounter Count
  82.   #--------------------------------------------------------------------------
  83.   def make_encounter_count
  84.     # Image of two dice rolling
  85.     if $game_map.map_id != 0
  86.       n = $game_map.encounter_step
  87.       @encounter_count = rand(n) + rand(n) + 1
  88.     end
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # * Refresh
  92.   #--------------------------------------------------------------------------
  93.   def refresh
  94.     # If party members = 0
  95.     if $game_party.actors.size == 0
  96.       # Clear character file name and hue
  97.       @character_name = ""
  98.       @character_hue = 0
  99.       # End method
  100.       return
  101.     end
  102.     # Get lead actor
  103.     actor = $game_party.actors[0]
  104.     # Set character file name and hue
  105.     @character_name = actor.character_name
  106.     @character_hue = actor.character_hue
  107.     # Initialize opacity level and blending method
  108.     @opacity = 255
  109.     @blend_type = 0
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # * Same Position Starting Determinant
  113.   #--------------------------------------------------------------------------
  114.   def check_event_trigger_here(triggers)
  115.     result = false
  116.     # If event is running
  117.     if $game_system.map_interpreter.running?
  118.       return result
  119.     end
  120.     # All event loops
  121.     for event in $game_map.events.values
  122.       # If event coordinates and triggers are consistent
  123.       if event.x == @x and event.y == @y and triggers.include?(event.trigger)
  124.         # If starting determinant is same position event (other than jumping)
  125.         if not event.jumping? and event.over_trigger?
  126.           event.start
  127.           result = true
  128.         end
  129.       end
  130.     end
  131.     return result
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * Front Envent Starting Determinant
  135.   #--------------------------------------------------------------------------
  136.   def check_event_trigger_there(triggers)
  137.     result = false
  138.     # If event is running
  139.     if $game_system.map_interpreter.running?
  140.       return result
  141.     end
  142.     # Calculate front event coordinates
  143.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  144.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  145.     # All event loops
  146.     for event in $game_map.events.values
  147.       # If event coordinates and triggers are consistent
  148.       if event.x == new_x and event.y == new_y and
  149.          triggers.include?(event.trigger)
  150.         # If starting determinant is front event (other than jumping)
  151.         if not event.jumping? and not event.over_trigger?
  152.           event.start
  153.           result = true
  154.         end
  155.       end
  156.     end
  157.     # If fitting event is not found
  158.     if result == false
  159.       # If front tile is a counter
  160.       if $game_map.counter?(new_x, new_y)
  161.         # Calculate 1 tile inside coordinates
  162.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  163.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  164.         # All event loops
  165.         for event in $game_map.events.values
  166.           # If event coordinates and triggers are consistent
  167.           if event.x == new_x and event.y == new_y and
  168.              triggers.include?(event.trigger)
  169.             # If starting determinant is front event (other than jumping)
  170.             if not event.jumping? and not event.over_trigger?
  171.               event.start
  172.               result = true
  173.             end
  174.           end
  175.         end
  176.       end
  177.     end
  178.     return result
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # * Touch Event Starting Determinant
  182.   #--------------------------------------------------------------------------
  183.   def check_event_trigger_touch(x, y)
  184.     result = false
  185.     # If event is running
  186.     if $game_system.map_interpreter.running?
  187.       return result
  188.     end
  189.     # All event loops
  190.     for event in $game_map.events.values
  191.       # If event coordinates and triggers are consistent
  192.       if event.x == x and event.y == y and [1,2].include?(event.trigger)
  193.         # If starting determinant is front event (other than jumping)
  194.         if not event.jumping? and not event.over_trigger?
  195.           event.start
  196.           result = true
  197.         end
  198.       end
  199.     end
  200.     return result
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # * Frame Update
  204.   #--------------------------------------------------------------------------
  205.   def update
  206.     # Remember whether or not moving in local variables
  207.     last_moving = moving?
  208.     # If moving, event running, move route forcing, and message window
  209.     # display are all not occurring
  210.     unless moving? or $game_system.map_interpreter.running? or
  211.            @move_route_forcing or $game_temp.message_window_showing
  212.       # Move player in the direction the directional button is being pressed
  213.       case Input.dir4
  214.       when 2
  215.         move_down
  216.       when 4
  217.         move_left
  218.       when 6
  219.         move_right
  220.       when 8
  221.         move_up
  222.       end
  223.     end
  224.     # Remember coordinates in local variables
  225.     last_real_x = @real_x
  226.     last_real_y = @real_y
  227.     super
  228.     # If character moves down and is positioned lower than the center
  229.     # of the screen
  230.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  231.       # Scroll map down
  232.       $game_map.scroll_down(@real_y - last_real_y)
  233.     end
  234.     # If character moves left and is positioned more let on-screen than
  235.     # center
  236.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  237.       # Scroll map left
  238.       $game_map.scroll_left(last_real_x - @real_x)
  239.     end
  240.     # If character moves right and is positioned more right on-screen than
  241.     # center
  242.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  243.       # Scroll map right
  244.       $game_map.scroll_right(@real_x - last_real_x)
  245.     end
  246.     # If character moves up and is positioned higher than the center
  247.     # of the screen
  248.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  249.       # Scroll map up
  250.       $game_map.scroll_up(last_real_y - @real_y)
  251.     end
  252.     # If not moving
  253.     unless moving?
  254.       # If player was moving last time
  255.       if last_moving
  256.         # Event determinant is via touch of same position event
  257.         result = check_event_trigger_here([1,2])
  258.         # If event which started does not exist
  259.         if result == false
  260.           # Disregard if debug mode is ON and ctrl key was pressed
  261.           unless $DEBUG and Input.press?(Input::CTRL)
  262.             # Encounter countdown
  263.             if @encounter_count > 0
  264.               @encounter_count -= 1
  265.             end
  266.           end
  267.         end
  268.       end
  269.       # If C button was pressed
  270.       if Input.trigger?(Input::C)
  271.         # Same position and front event determinant
  272.         check_event_trigger_here([0])
  273.         check_event_trigger_there([0,1,2])
  274.       end
  275.     end
  276.   end
  277. end

  278. #==========更換領隊==============

  279. class Game_Player < Game_Character
  280.   alias sny46_160407_update update
  281.   def update
  282.     update_change_leader
  283.     sny46_160407_update
  284.   end
  285.   def update_change_leader
  286.     unless ($game_system.map_interpreter.running? or
  287.            @move_route_forcing or $game_temp.message_window_showing)
  288.       if Input.trigger?(Input::X)
  289.         $game_system.se_play($data_system.cursor_se)
  290.         $game_party.actors.push($game_party.actors.shift)
  291.         $game_variables[23] = $game_party.actors[0].id  # 把领队人物的ID代入23号变量,自己可以更改变量号。
  292.         refresh
  293.         return
  294.       end
  295.     end
  296.   end
  297. end
复制代码

评分

参与人数 1星屑 +35 收起 理由
RyanBern + 35 手动认可奖励

查看全部评分

梦石
0
星屑
9726
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2016-4-13 15:24:06 | 显示全部楼层
本帖最后由 cinderelmini 于 2016-4-14 15:09 编辑

给换领队代码加了个开关…………开关打开将不能更换领队。
此外,如果想要指定领队为数据库指定ID的角色的话,可以试试事件里使用【脚本】:
  1. $game_player.order_leader(指定数据库中的人物ID)
复制代码
指定的任务必须存在队伍中,并且不是现在的领队的时候才会生效。
点击展开/收起
  1. class Game_Player < Game_Character
  2.   alias sny46_160407_update update
  3.   def update
  4.     update_change_leader
  5.     sny46_160407_update
  6.   end
  7.   def order_leader(actor_id)
  8.     order_actor = $game_actors[actor_id]
  9.     return unless ($game_party.actors.include?(order_actor) || $game_party.actors[0] == order_actor)
  10.     $game_party.actors.push($game_party.actors.shift) until $game_party.actors[0] == order_actor
  11.     $game_variables[233] = $game_party.actors[0].id  # 把领队人物的ID代入233号变量,自己可以更改变量号。
  12.     refresh
  13.   end
  14.   def update_change_leader
  15.     unless ($game_system.map_interpreter.running? or $game_switches[233] or # 这里加了个开关,如果这个ID的开关打开的话就不能更换领队。
  16.            @move_route_forcing or $game_temp.message_window_showing)
  17.       if Input.trigger?(Input::X)
  18.         $game_system.se_play($data_system.cursor_se)
  19.         $game_party.actors.push($game_party.actors.shift)
  20.         $game_variables[233] = $game_party.actors[0].id  # 把领队人物的ID代入233号变量,自己可以更改变量号。
  21.         refresh
  22.         return
  23.       end
  24.     end
  25.   end
  26. end
复制代码

点评

2333手抖~那句的意思是如果领队不是指定队员就一直切换领队直到对上号。  发表于 2016-4-14 15:10
謝謝大大!!!然後第10行的最後多了 ")" 會有Syntax Error,拿掉就可以用拉~~ 然後看不懂until,這句是這樣理解嗎? "暫存隊伍角色的改變 直到 領隊==order_actor"   发表于 2016-4-14 03:18
回复

使用道具 举报

梦石
0
星屑
50
在线时间
158 小时
注册时间
2016-1-7
回帖
102
 楼主| 发表于 2016-4-14 03:46:26 | 显示全部楼层
指定领队为数据库指定ID的角色
  1. $game_player.order_leader(指定数据库中的人物ID)
复制代码
作為參數的指定数据库中的人物ID我可以用$game_variables[XX]或者$game_party.actors[X].id帶入使用嗎?
$game_variables[XX]我有設置 = 指定数据库中的人物ID (ex. $game_variables[52] = 1)
$game_party.actors[X].id 照理說也是等於指定数据库中的人物ID
可是我這樣使用會出現如下訊息
錯誤訊息截圖1.$game_variables[XX]

2.$game_party.actors[X].id
回复

使用道具 举报

梦石
0
星屑
9726
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2016-4-14 15:18:25 | 显示全部楼层
燕征 发表于 2016-4-14 03:46
指定领队为数据库指定ID的角色作為參數的指定数据库中的人物ID我可以用$game_variables[XX]或者$game_party ...

这种情况没必要用变量吧?已经是要指定角色了,为什么还用变量呢?
还是说是用在公共事件里?
如果要用变量的话
  1. $game_player.order_leader($game_variables[XX])
复制代码
就可以,ID是从1开始算的,而且数据库中这个ID的位置必须要存在角色。

第二种,各种意义上都不建议使用$game_party.actors[X].id这种格式,
因为领队任何时候都可以变化,$game_party.actors的序列并不是固定不变的,
$game_party.actors[X].id可以是队伍里的任何一个人,代入之后也许根本不是想要的角色ID。
回复

使用道具 举报

梦石
0
星屑
50
在线时间
158 小时
注册时间
2016-1-7
回帖
102
 楼主| 发表于 2016-4-15 01:50:43 | 显示全部楼层
為什麼會覺得是公共事件呢?我很少用公共事件耶,能用地圖事件我就地圖事件搞定了(決定查察資料再看看要不要問這個~
好吧上面那句不是重點。我昨天有試過這個
  1. $game_player.order_leader($game_variables[52])
复制代码
然後會出現截圖1的錯誤訊息,所以覺得困擾

$game_player.order_leader(人物ID)不是得人在隊伍中才行嗎?
而用變數去帶是因為我的主角是用2選1,所以不能直接指定

之前在[已经过期] 立繪顯示的問題(\f[檔名])有放設置了要用的$game_variables的腳本
大意就是我選角的時候順便用了$game_variables[52]記錄了選取角色的ID
把$game_variables[52設置的那部分腳本奔過來,完整的要去看連結的2F了]
  1. # 用來存放角色名字提供對話事件使用,51是日常,52是全名,53存立繪名
  2.       case id
  3.       when 1  #阿萊查
  4.         $game_variables[51] = 3
  5.         $game_variables[52] = 1
  6.         $game_variables[53] = "阿萊查‧尤雅波"
  7.         $game_variables[54] = "立繪_阿萊查"
  8.       when 2  #亞藍娃
  9.         $game_variables[51] = 4
  10.         $game_variables[52] = 2
  11.         $game_variables[53] = "亞藍娃‧尤雅波"
  12.         $game_variables[54] = "立繪_亞藍娃"
  13.       end
复制代码
回复

使用道具 举报

梦石
0
星屑
9726
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2016-4-15 15:30:05 | 显示全部楼层
燕征 发表于 2016-4-15 01:50
為什麼會覺得是公共事件呢?我很少用公共事件耶,能用地圖事件我就地圖事件搞定了(決定查察資料再看看要不要 ...

哦……大概是代码太长了,被换行了的锅……
可以分割来弄:
  1. i = $game_variables[52]
  2. $game_player.order_leader(i)
复制代码
这样应该就没事了。

点评

這鍋;w;總算是翻了 謝謝大大  发表于 2016-4-16 01:58

评分

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

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部