查看: 2654|回复: 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]對調
所以我這樣寫
[pre lang="ruby"]$game_party.actors[1] =  $game_party.actors[0]
$game_party.actors[0] = $game_actors[5]
$game_player.refresh[/pre]
但當我要開系統選單或者按A鍵時,遊戲就會出現錯誤訊息然後我就只好關掉了。


我認為是第一行這樣寫有問題,所以還嘗試過把它換成
($game_variables[52] 存放了A的id)
[pre lang="ruby"]$game_party.actors[1] = $game_actors[$game_variables[52]][/pre]
結果還是會出現


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

這是在Game_Player最下面加了更換領隊腳本的整個腳本[pre lang="ruby"]#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles the player. Its functions include event starting
#  determinants and map scrolling. Refer to "$game_player" for the one
#  instance of this class.
#==============================================================================

class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # * Invariables
  #--------------------------------------------------------------------------
  CENTER_X = (320 - 16) * 4   # Center screen x-coordinate * 4
  CENTER_Y = (240 - 16) * 4   # Center screen y-coordinate * 4
  #--------------------------------------------------------------------------
  # * Passable Determinants
  #     x : x-coordinate
  #     y : y-coordinate
  #     d : direction (0,2,4,6,8)
  #         * 0 = Determines if all directions are impassable (for jumping)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    # Get new coordinates
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # If coordinates are outside of map
    unless $game_map.valid?(new_x, new_y)
      # Impassable
      return false
    end
    # If debug mode is ON and ctrl key was pressed
    if $DEBUG and Input.press?(Input::CTRL)
      # Passable
      return true
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Set Map Display Position to Center of Screen
  #--------------------------------------------------------------------------
  def center(x, y)
    max_x = ($game_map.width - 20) * 128
    max_y = ($game_map.height - 15) * 128
    $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
    $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  end
  #--------------------------------------------------------------------------
  # * Move to Designated Position
  #     x : x-coordinate
  #     y : y-coordinate
  #--------------------------------------------------------------------------
  def moveto(x, y)
    super
    # Centering
    center(x, y)
    # Make encounter count
    make_encounter_count
  end
  #--------------------------------------------------------------------------
  # * Increaase Steps
  #--------------------------------------------------------------------------
  def increase_steps
    super
    # If move route is not forcing
    unless @move_route_forcing
      # Increase steps
      $game_party.increase_steps
      # Number of steps are an even number
      if $game_party.steps % 2 == 0
        # Slip damage check
        $game_party.check_map_slip_damage
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Get Encounter Count
  #--------------------------------------------------------------------------
  def encounter_count
    return @encounter_count
  end
  #--------------------------------------------------------------------------
  # * Make Encounter Count
  #--------------------------------------------------------------------------
  def make_encounter_count
    # Image of two dice rolling
    if $game_map.map_id != 0
      n = $game_map.encounter_step
      @encounter_count = rand(n) + rand(n) + 1
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # If party members = 0
    if $game_party.actors.size == 0
      # Clear character file name and hue
      @character_name = ""
      @character_hue = 0
      # End method
      return
    end
    # Get lead actor
    actor = $game_party.actors[0]
    # Set character file name and hue
    @character_name = actor.character_name
    @character_hue = actor.character_hue
    # Initialize opacity level and blending method
    @opacity = 255
    @blend_type = 0
  end
  #--------------------------------------------------------------------------
  # * Same Position Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == @x and event.y == @y and triggers.include?(event.trigger)
        # If starting determinant is same position event (other than jumping)
        if not event.jumping? and event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Front Envent Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # Calculate front event coordinates
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == new_x and event.y == new_y and
         triggers.include?(event.trigger)
        # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # If fitting event is not found
    if result == false
      # If front tile is a counter
      if $game_map.counter?(new_x, new_y)
        # Calculate 1 tile inside coordinates
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        # All event loops
        for event in $game_map.events.values
          # If event coordinates and triggers are consistent
          if event.x == new_x and event.y == new_y and
             triggers.include?(event.trigger)
            # If starting determinant is front event (other than jumping)
            if not event.jumping? and not event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == x and event.y == y and [1,2].include?(event.trigger)
        # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Remember whether or not moving in local variables
    last_moving = moving?
    # If moving, event running, move route forcing, and message window
    # display are all not occurring
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      # Move player in the direction the directional button is being pressed
      case Input.dir4
      when 2
        move_down
      when 4
        move_left
      when 6
        move_right
      when 8
        move_up
      end
    end
    # Remember coordinates in local variables
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # If character moves down and is positioned lower than the center
    # of the screen
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # Scroll map down
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # If character moves left and is positioned more let on-screen than
    # center
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # Scroll map left
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # If character moves right and is positioned more right on-screen than
    # center
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # Scroll map right
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # If character moves up and is positioned higher than the center
    # of the screen
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # Scroll map up
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # If not moving
    unless moving?
      # If player was moving last time
      if last_moving
        # Event determinant is via touch of same position event
        result = check_event_trigger_here([1,2])
        # If event which started does not exist
        if result == false
          # Disregard if debug mode is ON and ctrl key was pressed
          unless $DEBUG and Input.press?(Input::CTRL)
            # Encounter countdown
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # If C button was pressed
      if Input.trigger?(Input::C)
        # Same position and front event determinant
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end

#==========更換領隊==============

class Game_Player < Game_Character
  alias sny46_160407_update update
  def update
    update_change_leader
    sny46_160407_update
  end
  def update_change_leader
    unless ($game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing)
      if Input.trigger?(Input::X)
        $game_system.se_play($data_system.cursor_se)
        $game_party.actors.push($game_party.actors.shift)
        $game_variables[23] = $game_party.actors[0].id  # 把领队人物的ID代入23号变量,自己可以更改变量号。
        refresh
        return
      end
    end
  end
end[/pre]

评分

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

查看全部评分

梦石
0
星屑
9716
在线时间
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
星屑
9716
在线时间
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
星屑
9716
在线时间
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.

在本版发帖返回顶部