Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Geust on June 05, 2010, 11:46:52 am

Title: Delete
Post by: Geust on June 05, 2010, 11:46:52 am
Thanks.
Title: Re: [XP] Script needed
Post by: SBR* on June 05, 2010, 12:08:57 pm
Just do it with events. Let the player swap places with the event, change the event's graphic to the player graphic and vice versa and you're done. I don't really get the diagonal thingy? Can you show a screenshot? I will make a demo.
Title: Re: [XP] Script needed
Post by: SBR* on June 05, 2010, 12:25:14 pm
Wait, I think I don't get you right. So you don't want something to swap places with an event?
Title: Re: [XP] Script needed
Post by: SBR* on June 05, 2010, 12:55:02 pm
This?

http://rapidshare.com/files/395612640/Transfer_controls_to_event_and_vice_versa.exe.html

EDIT: Fixed it: http://rapidshare.com/files/395670266/Transfer_controls_to_event_and_vice_versa.exe

EDIT: New version: http://rapidshare.com/files/395894433/Transfer_controls_to_event_and_vice_versa.exe
Title: Re: [XP] Script needed
Post by: Valdred on June 05, 2010, 01:16:12 pm
What SBR first suggested would work as well. Fool the player to believe that the player-character is an event and visa-versa by swapping locations and graphics.
Title: Re: [XP] Script needed
Post by: Valdred on June 05, 2010, 01:35:38 pm
just put the two commands right after each others. Wont be noticed. ;)
Title: Re: [XP] Script needed
Post by: SBR* on June 05, 2010, 01:47:15 pm
So do you want them to be switched, or do you want to switch what character is controlled?
Title: Re: [XP] Script needed
Post by: SBR* on June 05, 2010, 02:53:41 pm
You got to lvl -2. Oh, and tried out my demo? That should do it.
Title: Re: [XP] Script needed
Post by: SBR* on June 05, 2010, 03:48:37 pm
It should work :urgh:! Z is the button to switch btw.
Title: Re: [XP] Script needed
Post by: Valdred on June 05, 2010, 03:49:56 pm
For some reason he made a decrypted project. Upload a new one
Title: Re: [XP] Script needed
Post by: SBR* on June 05, 2010, 03:52:32 pm
Just a nooby question, but what is a decrypted project?

EDIT: Ah, so that's what that button does. I always thought: "Well, why not include those 'encryptions'?"

New link: http://rapidshare.com/files/395670266/Transfer_controls_to_event_and_vice_versa.exe
Title: Re: [XP] Script needed
Post by: Valdred on June 05, 2010, 04:35:21 pm
I ment enchrypted. sorry :D
Title: Re: [XP] Script needed
Post by: SBR* on June 06, 2010, 06:54:38 am
Need graphics switched? Hang on a sec.

EDIT: Made:
http://rapidshare.com/files/395894433/Transfer_controls_to_event_and_vice_versa.exe
Title: Re: [XP] Script needed
Post by: SBR* on June 06, 2010, 02:57:12 pm
First I give you a system that doesn't change graphics, so it really gets switched. Then I give you a system that changes graphics, so it looks like you control the event. WHAT DO YOU WANT?!  >:(
Title: Re: [XP] Script needed
Post by: nathmatt on June 06, 2010, 04:15:00 pm
this should work put this in a parallel process
e = $game_map.events[id]
$game_player.center(e.x, e.y)
change the id to the events id

run this after you turn off the parallel process
p = $game_player
$game_player.center(p.x, p.y)
Title: Re: [XP] Script needed
Post by: nathmatt on June 06, 2010, 06:35:49 pm
edit working on it
Title: Re: [XP] Script needed
Post by: nathmatt on June 06, 2010, 07:47:55 pm
here but im not sure if it is exactly in the center just call $game_map.events[id].follow = true
to turn it on and false to turn it off

Spoiler: ShowHide
class Game_Event < Game_Character
 
 def follow=(condition)
   @follow = condition
   if condition
     $game_player.center(@x, @y)
   else
     p = $game_player
     $game_player.center(p.x, p.y)
   end
 end
 
 alias follow_update update
 def update
   if moving?
     $game_map.display_x = @real_x - 1064
     $game_map.display_y = @real_y - 1064
   end
   follow_update
 end
 
end
Title: Re: [XP] Script needed
Post by: Jragyn on June 06, 2010, 08:35:54 pm
I think it'd just be easier to create a dummy character or something with a spriteset the same as the event you want to take over, then just do a bit of event teleporting or something without fade to move around and voila.

Title: Re: [XP] Script needed
Post by: nathmatt on June 06, 2010, 09:09:11 pm
try this

Spoiler: ShowHide
class Game_Map
 
  attr_accessor :following
 
  def scroll_down(distance)
    return if following
    @display_y = [@display_y + distance, (self.height - 15) * 128].min
  end
 
  def scroll_left(distance)
    return if following
    @display_x = [@display_x - distance, 0].max
  end
 
  def scroll_right(distance)
    return if following
    @display_x = [@display_x + distance, (self.width - 20) * 128].min
  end
 
  def scroll_up(distance)
    return if following
    @display_y = [@display_y - distance, 0].max
  end
 
end

class Game_Event < Game_Character
 
  def follow=(condition)
    @follow = condition
    if condition
      $game_player.center(@x, @y)
      $game_map.following = true
    else
      p = $game_player
      $game_player.center(p.x, p.y)
      $game_map.following = false
    end
  end
 
  alias follow_update update
  def update
    if moving?
      $game_map.display_x = @real_x - 1064
      $game_map.display_y = @real_y - 1064
    end
    follow_update
  end
 
end
Title: Re: [XP] Script needed
Post by: nathmatt on June 06, 2010, 09:30:32 pm
Demo ?
Title: Re: [XP] Script needed
Post by: nathmatt on June 07, 2010, 12:07:49 pm
well im going to need a demo because i just tryed that and the charactors follow me btw blizzards tons of add-ons v3.9b is really out dated updating might fix ur problem
Title: Re: [XP] Script needed
Post by: nathmatt on June 07, 2010, 12:32:16 pm
no http://forum.chaos-project.com/index.php/topic,105.0.html
Title: Re: [XP] Script needed
Post by: nathmatt on June 07, 2010, 12:51:47 pm
i still need the demo if you want me to try and fix it because i made a new project put nothing put the script i gave you and tons turn on the caterpillar script and the characters all followed me not the event
Title: Re: [XP] Script needed
Post by: nathmatt on June 07, 2010, 07:51:04 pm
click file then compress data to do click encrypt and upload the file to sendspace
Title: Re: [XP] Script needed
Post by: nathmatt on June 08, 2010, 12:37:20 am
yea
Title: Re: [XP] Script needed
Post by: nathmatt on June 08, 2010, 12:56:28 pm
i emailed you back with it fixed ant telling you how to use it
Title: Re: [XP] Script needed
Post by: SBR* on June 09, 2010, 03:41:16 pm
Quote from: nathmatt on June 07, 2010, 07:51:04 pm
click file then compress data to do click encrypt and upload the file to sendspace


I thought encrypting meant that you CAN'T view the file?
Title: Re: [XP] Script needed
Post by: nathmatt on June 09, 2010, 03:52:08 pm
it does but he zipped it so it instead so it didn't matter
but i meant to say don't press it
Title: Re: [XP] Script needed
Post by: nathmatt on June 09, 2010, 06:11:36 pm
how are you tracking it ?
Title: Re: [XP] Script needed
Post by: nathmatt on June 09, 2010, 07:37:15 pm
the problem was when i turned it back into an event is was returning to its original location here add this to what ever method ur using to check its location !$game_event.events[id].moving?
Spoiler: ShowHide
class Event
 

 def on(id)
   @id = id
   @map = $game_map.map.events[@id]
   character = @event = $game_map.events[@id]
   $game_map.events[@id] = Game_Event_Player.new(@map)
   $scene.spriteset.character_sprites.each {|sprite|
   # if sprite found
   if sprite.character == character
     # set new character
     sprite.character = $game_map.events[@id]
     # update sprite
     sprite.update
     # event found, stop here
     break
   end}
   $game_player.following = true
   $game_player.center(@event.y,@event.y)
 end
 
 def off
   player = $game_map.events[@id]
   @map.x = player.x
   @map.y = player.y
   character = $game_map.events[@id] = @event
   $game_map.events[@id].moveto(player.x,player.y)
   $game_map.map.events[@id] = @map
   character = $game_map.events[@id] = @event
   $scene.spriteset.character_sprites.each {|sprite|
   # if sprite found
   if sprite.character == character
     # set new character
     sprite.dispose
     sprite.character = player
     # update sprite
     sprite.update
     # event found, stop here
     break
   end}
   $game_player.following = false
   $game_player.center($game_player.y,$game_player.y)
 end
 
end

class Scene_Map
 def reset
   @spriteset = Spriteset_Map.new
 end
end

$event = Event.new

class Game_Event_Player < Game_Character
 
 attr_accessor :off
 
 def initialize(event)
 super()
   moveto(event.x,event.y)
   $scene.reset
   @last_event = event
   refresh
 end
 #--------------------------------------------------------------------------
 # ● 定数
 #--------------------------------------------------------------------------
 CENTER_X = (320 - 16) * 4   # 画面中央の X 座標 * 4
 CENTER_Y = (240 - 16) * 4   # 画面中央の Y 座標 * 4
 #--------------------------------------------------------------------------
 # ● 通行可能判定
 #     x : X 座標
 #     y : Y 座標
 #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向通行不可の場合を判定 (ジャンプ用)
 #--------------------------------------------------------------------------
 def passable?(x, y, d)
   # 新しい座標を求める
   new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
   new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
   # 座標がマップ外の場合
   unless $game_map.valid?(new_x, new_y)
     # 通行不可
     return false
   end
   # デバッグモードが ON かつ CTRL キーが押されている場合
   if $DEBUG and Input.press?(Input::CTRL)
     # 通行可
     return true
   end
   super
 end
 #--------------------------------------------------------------------------
 # ● 画面中央に来るようにマップの表示位置を設定
 #--------------------------------------------------------------------------
 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
 def starting
   return false
 end
 def need_update?
   return false
 end
 #--------------------------------------------------------------------------
 # ● 指定位置に移動
 #     x : X 座標
 #     y : Y 座標
 #--------------------------------------------------------------------------
 def moveto(x, y)
   super
   # センタリング
   center(x, y)
   # エンカウント カウントを作成
   make_encounter_count
 end
 #--------------------------------------------------------------------------
 # ● 歩数増加
 #--------------------------------------------------------------------------
 def increase_steps
   super
   # 移動ルート強制中ではない場合
   unless @move_route_forcing
     # 歩数増加
     $game_party.increase_steps
     # 歩数が偶数の場合
     if $game_party.steps % 2 == 0
       # スリップダメージチェック
       $game_party.check_map_slip_damage
     end
   end
 end
 #--------------------------------------------------------------------------
 # ● エンカウント カウント取得
 #--------------------------------------------------------------------------
 def encounter_count
   return @encounter_count
 end
 #--------------------------------------------------------------------------
 # ● エンカウント カウント作成
 #--------------------------------------------------------------------------
 def make_encounter_count
   # サイコロを 2 個振るイメージ
   if $game_map.map_id != 0
     n = $game_map.encounter_step
     @encounter_count = rand(n) + rand(n) + 1
   end
 end
 #--------------------------------------------------------------------------
 # ● リフレッシュ
 #--------------------------------------------------------------------------
 def refresh
   @character_name = @last_event.pages[0].graphic.character_name
   @character_hue  = @last_event.pages[0].graphic.character_hue
   # 不透明度と合成方法を初期化
   @opacity = 255
   @blend_type = 0
 end
 #--------------------------------------------------------------------------
 # ● 同位置のイベント起動判定
 #--------------------------------------------------------------------------
 def check_event_trigger_here(triggers)
   result = false
   # イベント実行中の場合
   if $game_system.map_interpreter.running?
     return result
   end
   # 全イベントのループ
   return result
 end
 #--------------------------------------------------------------------------
 # ● 正面のイベント起動判定
 #--------------------------------------------------------------------------
 def check_event_trigger_there(triggers)
   result = false
   # イベント実行中の場合
   if $game_system.map_interpreter.running?
     return result
   end
   # 正面の座標を計算
   new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
   new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
   # 全イベントのループ
   for event in $game_map.events.values
     # イベントの座標とトリガーが一致した場合
     if event.x == new_x and event.y == new_y and
        triggers.include?(event.trigger)
       # ジャンプ中以外で、起動判定が正面のイベントなら
       if not event.jumping? and not event.over_trigger?
         event.start
         result = true
       end
     end
   end
   # 該当するイベントが見つからなかった場合
   if result == false
     # 正面のタイルがカウンターなら
     if $game_map.counter?(new_x, new_y)
       # 1 タイル奥の座標を計算
       new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
       new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
       # 全イベントのループ
       for event in $game_map.events.values
         # イベントの座標とトリガーが一致した場合
         if event.x == new_x and event.y == new_y and
            triggers.include?(event.trigger)
           # ジャンプ中以外で、起動判定が正面のイベントなら
           if not event.jumping? and not event.over_trigger?
             event.start
             result = true
           end
         end
       end
     end
   end
   return result
 end
 #--------------------------------------------------------------------------
 # ● 接触イベントの起動判定
 #--------------------------------------------------------------------------
 def check_event_trigger_touch(x, y)
   result = false
   # イベント実行中の場合
   if $game_system.map_interpreter.running?
     return result
   end
   # 全イベントのループ
   for event in $game_map.events.values
     # イベントの座標とトリガーが一致した場合
     if event.x == x and event.y == y and [1,2].include?(event.trigger)
       # ジャンプ中以外で、起動判定が正面のイベントなら
       if not event.jumping? and not event.over_trigger?
         event.start
         result = true
       end
     end
   end
   return result
 end
 #--------------------------------------------------------------------------
 # ● フレーム更新
 #--------------------------------------------------------------------------
 def update
   # ローカル変数に移動中かどうかを記憶
   last_moving = moving?
   # 移動中、イベント実行中、移動ルート強制中、
   # メッセージウィンドウ表示中のいずれでもない場合
   unless moving? or $game_system.map_interpreter.running? or
          @move_route_forcing or $game_temp.message_window_showing
     # 方向ボタンが押されていれば、その方向へプレイヤーを移動
     case Input.dir4
     when 2
       move_down
     when 4
       move_left
     when 6
       move_right
     when 8
       move_up
     end
   end
   # ローカル変数に座標を記憶
   last_real_x = @real_x
   last_real_y = @real_y
   super
   # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
   if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
     # マップを下にスクロール
     $game_map.scroll_down(@real_y - last_real_y)
   end
   # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
   if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
     # マップを左にスクロール
     $game_map.scroll_left(last_real_x - @real_x)
   end
   # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
   if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
     # マップを右にスクロール
     $game_map.scroll_right(@real_x - last_real_x)
   end
   # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
   if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
     # マップを上にスクロール
     $game_map.scroll_up(last_real_y - @real_y)
   end
   # 移動中ではない場合
   unless moving?
     # 前回プレイヤーが移動中だった場合
     if last_moving
       # 同位置のイベントとの接触によるイベント起動判定
       result = check_event_trigger_here([1,2])
       # 起動したイベントがない場合
       if result == false
         # デバッグモードが ON かつ CTRL キーが押されている場合を除き
         unless $DEBUG and Input.press?(Input::CTRL)
           # エンカウント カウントダウン
           if @encounter_count > 0
             @encounter_count -= 1
           end
         end
       end
     end
     # C ボタンが押された場合
     if Input.trigger?(Input::C)
       # 同位置および正面のイベント起動判定
       check_event_trigger_here([0])
       check_event_trigger_there([0,1,2])
     end
   end
 end
end


class Game_Player
 attr_accessor :following
 #--------------------------------------------------------------------------
 # ● フレーム更新
 #--------------------------------------------------------------------------
 def update
   # ローカル変数に移動中かどうかを記憶
   last_moving = moving?
   # 移動中、イベント実行中、移動ルート強制中、
   # メッセージウィンドウ表示中のいずれでもない場合
   if !@following
     unless moving? or $game_system.map_interpreter.running? or
            @move_route_forcing or $game_temp.message_window_showing
       # 方向ボタンが押されていれば、その方向へプレイヤーを移動
       case Input.dir4
       when 2
         move_down
       when 4
         move_left
       when 6
         move_right
       when 8
         move_up
       end
     end
     # ローカル変数に座標を記憶
     last_real_x = @real_x
     last_real_y = @real_y
     super
     # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
       # マップを下にスクロール
       $game_map.scroll_down(@real_y - last_real_y)
     end
     # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
       # マップを左にスクロール
       $game_map.scroll_left(last_real_x - @real_x)
     end
     # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
       # マップを右にスクロール
       $game_map.scroll_right(@real_x - last_real_x)
     end
     # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
       # マップを上にスクロール
       $game_map.scroll_up(last_real_y - @real_y)
     end
   else
     super
   end
   # 移動中ではない場合
   unless moving?
     # 前回プレイヤーが移動中だった場合
     if last_moving
       # 同位置のイベントとの接触によるイベント起動判定
       result = check_event_trigger_here([1,2])
       # 起動したイベントがない場合
       if result == false
         # デバッグモードが ON かつ CTRL キーが押されている場合を除き
         unless $DEBUG and Input.press?(Input::CTRL)
           # エンカウント カウントダウン
           if @encounter_count > 0
             @encounter_count -= 1
           end
         end
       end
     end
     # C ボタンが押された場合
     if Input.trigger?(Input::C)
       # 同位置および正面のイベント起動判定
       check_event_trigger_here([0])
       check_event_trigger_there([0,1,2])
     end
   end
 end
end


fixed
to walk through them just click through
Title: Re: [XP] Script needed
Post by: nathmatt on June 10, 2010, 07:33:57 pm
http://yfrog.com/7dhelpqrp
Title: Re: [XP] Script needed
Post by: nathmatt on June 10, 2010, 08:29:04 pm
Spoiler: ShowHide
class Event
 

  def on(id)
    @id = id
    @map = $game_map.map.events[@id]
    character = @event = $game_map.events[@id]
    $game_map.events[@id] = Game_Event_Player.new(@map)
    $scene.spriteset.character_sprites.each {|sprite|
    # if sprite found
    if sprite.character == character
      # set new character
      sprite.character = $game_map.events[@id]
      # update sprite
      sprite.update
      # event found, stop here
      break
    end}
    $game_player.following = true
    $game_player.center(@event.y,@event.y)
  end
 
  def off
    player = $game_map.events[@id]
    @map.x = player.x
    @map.y = player.y
    character = $game_map.events[@id] = @event
    $game_map.events[@id].moveto(player.x,player.y)
    $game_map.map.events[@id] = @map
    character = $game_map.events[@id] = @event
    $scene.spriteset.character_sprites.each {|sprite|
    # if sprite found
    if sprite.character == character
      # set new character
      sprite.dispose
      sprite.character = player
      # update sprite
      sprite.update
      # event found, stop here
      break
    end}
    $game_player.following = false
    $game_player.center($game_player.y,$game_player.y)
  end
 
end

$event = Event.new

class Game_Event_Player < Game_Character
 
  attr_accessor :off
 
  def initialize(event)
  super()
    moveto(event.x,event.y)
    @last_event = event
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 定数
  #--------------------------------------------------------------------------
  CENTER_X = (320 - 16) * 4   # 画面中央の X 座標 * 4
  CENTER_Y = (240 - 16) * 4   # 画面中央の Y 座標 * 4
  #--------------------------------------------------------------------------
  # ● 通行可能判定
  #     x : X 座標
  #     y : Y 座標
  #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向通行不可の場合を判定 (ジャンプ用)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    # 新しい座標を求める
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # 座標がマップ外の場合
    unless $game_map.valid?(new_x, new_y)
      # 通行不可
      return false
    end
    # デバッグモードが ON かつ CTRL キーが押されている場合
    if $DEBUG and Input.press?(Input::CTRL)
      # 通行可
      return true
    end
    super
  end
  #--------------------------------------------------------------------------
  # ● 画面中央に来るようにマップの表示位置を設定
  #--------------------------------------------------------------------------
  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
  def starting
    return false
  end
  def need_update?
    return false
  end
  #--------------------------------------------------------------------------
  # ● 指定位置に移動
  #     x : X 座標
  #     y : Y 座標
  #--------------------------------------------------------------------------
  def moveto(x, y)
    super
    # センタリング
    center(x, y)
    # エンカウント カウントを作成
    make_encounter_count
  end
  #--------------------------------------------------------------------------
  # ● 歩数増加
  #--------------------------------------------------------------------------
  def increase_steps
    super
    # 移動ルート強制中ではない場合
    unless @move_route_forcing
      # 歩数増加
      $game_party.increase_steps
      # 歩数が偶数の場合
      if $game_party.steps % 2 == 0
        # スリップダメージチェック
        $game_party.check_map_slip_damage
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● エンカウント カウント取得
  #--------------------------------------------------------------------------
  def encounter_count
    return @encounter_count
  end
  #--------------------------------------------------------------------------
  # ● エンカウント カウント作成
  #--------------------------------------------------------------------------
  def make_encounter_count
    # サイコロを 2 個振るイメージ
    if $game_map.map_id != 0
      n = $game_map.encounter_step
      @encounter_count = rand(n) + rand(n) + 1
    end
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    @character_name = @last_event.pages[0].graphic.character_name
    @character_hue  = @last_event.pages[0].graphic.character_hue
    # 不透明度と合成方法を初期化
    @opacity = 255
    @blend_type = 0
  end
  #--------------------------------------------------------------------------
  # ● 同位置のイベント起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 全イベントのループ
    return result
  end
  #--------------------------------------------------------------------------
  # ● 正面のイベント起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 正面の座標を計算
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # 全イベントのループ
    for event in $game_map.events.values
      # イベントの座標とトリガーが一致した場合
      if event.x == new_x and event.y == new_y and
         triggers.include?(event.trigger)
        # ジャンプ中以外で、起動判定が正面のイベントなら
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # 該当するイベントが見つからなかった場合
    if result == false
      # 正面のタイルがカウンターなら
      if $game_map.counter?(new_x, new_y)
        # 1 タイル奥の座標を計算
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        # 全イベントのループ
        for event in $game_map.events.values
          # イベントの座標とトリガーが一致した場合
          if event.x == new_x and event.y == new_y and
             triggers.include?(event.trigger)
            # ジャンプ中以外で、起動判定が正面のイベントなら
            if not event.jumping? and not event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● 接触イベントの起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 全イベントのループ
    for event in $game_map.events.values
      # イベントの座標とトリガーが一致した場合
      if event.x == x and event.y == y and [1,2].include?(event.trigger)
        # ジャンプ中以外で、起動判定が正面のイベントなら
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    # ローカル変数に移動中かどうかを記憶
    last_moving = moving?
    # 移動中、イベント実行中、移動ルート強制中、
    # メッセージウィンドウ表示中のいずれでもない場合
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      # 方向ボタンが押されていれば、その方向へプレイヤーを移動
      case Input.dir4
      when 2
        move_down
      when 4
        move_left
      when 6
        move_right
      when 8
        move_up
      end
    end
    # ローカル変数に座標を記憶
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # マップを下にスクロール
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # マップを左にスクロール
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # マップを右にスクロール
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # マップを上にスクロール
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # 移動中ではない場合
    unless moving?
      # 前回プレイヤーが移動中だった場合
      if last_moving
        # 同位置のイベントとの接触によるイベント起動判定
        result = check_event_trigger_here([1,2])
        # 起動したイベントがない場合
        if result == false
          # デバッグモードが ON かつ CTRL キーが押されている場合を除き
          unless $DEBUG and Input.press?(Input::CTRL)
            # エンカウント カウントダウン
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # C ボタンが押された場合
      if Input.trigger?(Input::C)
        # 同位置および正面のイベント起動判定
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end


class Game_Player
  attr_accessor :following
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    # ローカル変数に移動中かどうかを記憶
    last_moving = moving?
    # 移動中、イベント実行中、移動ルート強制中、
    # メッセージウィンドウ表示中のいずれでもない場合
    if !@following
      unless moving? or $game_system.map_interpreter.running? or
             @move_route_forcing or $game_temp.message_window_showing
        # 方向ボタンが押されていれば、その方向へプレイヤーを移動
        case Input.dir4
        when 2
          move_down
        when 4
          move_left
        when 6
          move_right
        when 8
          move_up
        end
      end
      # ローカル変数に座標を記憶
      last_real_x = @real_x
      last_real_y = @real_y
      super
      # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
      if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
        # マップを下にスクロール
        $game_map.scroll_down(@real_y - last_real_y)
      end
      # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
      if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
        # マップを左にスクロール
        $game_map.scroll_left(last_real_x - @real_x)
      end
      # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
      if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
        # マップを右にスクロール
        $game_map.scroll_right(@real_x - last_real_x)
      end
      # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
      if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
        # マップを上にスクロール
        $game_map.scroll_up(last_real_y - @real_y)
      end
    else
      super
    end
    # 移動中ではない場合
    unless moving?
      # 前回プレイヤーが移動中だった場合
      if last_moving
        # 同位置のイベントとの接触によるイベント起動判定
        result = check_event_trigger_here([1,2])
        # 起動したイベントがない場合
        if result == false
          # デバッグモードが ON かつ CTRL キーが押されている場合を除き
          unless $DEBUG and Input.press?(Input::CTRL)
            # エンカウント カウントダウン
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # C ボタンが押された場合
      if Input.trigger?(Input::C)
        # 同位置および正面のイベント起動判定
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end


missed that error fixed note make the other events through not the 1 your controlling
Title: Re: [XP] Script needed
Post by: nathmatt on June 11, 2010, 10:46:14 am
fixed

Spoiler: ShowHide
class Event
  attr_reader   :id

  def on(id)
    @id = id
    @map = $game_map.map.events[@id]
    character = @event = $game_map.events[@id]
    $game_map.events[@id] = Game_Event_Player.new(@map)
    $scene.spriteset.character_sprites.each {|sprite|
    # if sprite found
    if sprite.character == character
      # set new character
      sprite.character = $game_map.events[@id]
      # update sprite
      sprite.update
      # event found, stop here
      break
    end}
    $game_player.following = true
    $game_player.center(@event.y,@event.y)
  end
 
  def off
    player = $game_map.events[@id]
    @map.x = player.x
    @map.y = player.y
    character = $game_map.events[@id] = @event
    $game_map.events[@id].moveto(player.x,player.y)
    $game_map.map.events[@id] = @map
    character = $game_map.events[@id] = @event
    $scene.spriteset.character_sprites.each {|sprite|
    # if sprite found
    if sprite.character == character
      # set new character
      sprite.dispose
      sprite.character = player
      # update sprite
      sprite.update
      # event found, stop here
      break
    end}
    $game_player.following = false
    $game_player.center($game_player.y,$game_player.y)
  end
 
end

$event = Event.new

class Game_Event_Player < Game_Character
 
  attr_accessor :off
 
  def initialize(event)
  super()
    moveto(event.x,event.y)
    @last_event = event
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 定数
  #--------------------------------------------------------------------------
  CENTER_X = (320 - 16) * 4   # 画面中央の X 座標 * 4
  CENTER_Y = (240 - 16) * 4   # 画面中央の Y 座標 * 4
  #--------------------------------------------------------------------------
  # ● 通行可能判定
  #     x : X 座標
  #     y : Y 座標
  #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向通行不可の場合を判定 (ジャンプ用)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    # 新しい座標を求める
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # 座標がマップ外の場合
    unless $game_map.valid?(new_x, new_y)
      # 通行不可
      return false
    end
    # デバッグモードが ON かつ CTRL キーが押されている場合
    if $DEBUG and Input.press?(Input::CTRL)
      # 通行可
      return true
    end
    super
  end
  #--------------------------------------------------------------------------
  # ● 画面中央に来るようにマップの表示位置を設定
  #--------------------------------------------------------------------------
  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
  def starting
    return false
  end
  def need_update?
    return false
  end
  #--------------------------------------------------------------------------
  # ● 指定位置に移動
  #     x : X 座標
  #     y : Y 座標
  #--------------------------------------------------------------------------
  def moveto(x, y)
    super
    # センタリング
    center(x, y)
    # エンカウント カウントを作成
    make_encounter_count
  end
  #--------------------------------------------------------------------------
  # ● 歩数増加
  #--------------------------------------------------------------------------
  def increase_steps
    super
    # 移動ルート強制中ではない場合
    unless @move_route_forcing
      # 歩数増加
      $game_party.increase_steps
      # 歩数が偶数の場合
      if $game_party.steps % 2 == 0
        # スリップダメージチェック
        $game_party.check_map_slip_damage
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● エンカウント カウント取得
  #--------------------------------------------------------------------------
  def encounter_count
    return @encounter_count
  end
  #--------------------------------------------------------------------------
  # ● エンカウント カウント作成
  #--------------------------------------------------------------------------
  def make_encounter_count
    # サイコロを 2 個振るイメージ
    if $game_map.map_id != 0
      n = $game_map.encounter_step
      @encounter_count = rand(n) + rand(n) + 1
    end
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    @character_name = @last_event.pages[0].graphic.character_name
    @character_hue  = @last_event.pages[0].graphic.character_hue
    # 不透明度と合成方法を初期化
    @opacity = 255
    @blend_type = 0
  end
  #--------------------------------------------------------------------------
  # ● 同位置のイベント起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 全イベントのループ
    return result
  end
  #--------------------------------------------------------------------------
  # ● 正面のイベント起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 正面の座標を計算
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # 全イベントのループ
    for event in $game_map.events.values
      # イベントの座標とトリガーが一致した場合
      if event.x == new_x and event.y == new_y and
         triggers.include?(event.trigger)
        # ジャンプ中以外で、起動判定が正面のイベントなら
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # 該当するイベントが見つからなかった場合
    if result == false
      # 正面のタイルがカウンターなら
      if $game_map.counter?(new_x, new_y)
        # 1 タイル奥の座標を計算
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        # 全イベントのループ
        for event in $game_map.events.values
          # イベントの座標とトリガーが一致した場合
          if event.x == new_x and event.y == new_y and
             triggers.include?(event.trigger)
            # ジャンプ中以外で、起動判定が正面のイベントなら
            if not event.jumping? and not event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● 接触イベントの起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 全イベントのループ
    for event in $game_map.events.values
      # イベントの座標とトリガーが一致した場合
      if event.x == x and event.y == y and [1,2].include?(event.trigger)
        # ジャンプ中以外で、起動判定が正面のイベントなら
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    # ローカル変数に移動中かどうかを記憶
    last_moving = moving?
    # 移動中、イベント実行中、移動ルート強制中、
    # メッセージウィンドウ表示中のいずれでもない場合
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      # 方向ボタンが押されていれば、その方向へプレイヤーを移動
      case Input.dir4
      when 2
        move_down
      when 4
        move_left
      when 6
        move_right
      when 8
        move_up
      end
    end
    # ローカル変数に座標を記憶
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # マップを下にスクロール
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # マップを左にスクロール
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # マップを右にスクロール
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # マップを上にスクロール
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # 移動中ではない場合
    unless moving?
      # 前回プレイヤーが移動中だった場合
      if last_moving
        # 同位置のイベントとの接触によるイベント起動判定
        result = check_event_trigger_here([1,2])
        # 起動したイベントがない場合
        if result == false
          # デバッグモードが ON かつ CTRL キーが押されている場合を除き
          unless $DEBUG and Input.press?(Input::CTRL)
            # エンカウント カウントダウン
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # C ボタンが押された場合
      if Input.trigger?(Input::C)
        # 同位置および正面のイベント起動判定
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end


class Game_Player
  attr_accessor :following
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    # ローカル変数に移動中かどうかを記憶
    last_moving = moving?
    # 移動中、イベント実行中、移動ルート強制中、
    # メッセージウィンドウ表示中のいずれでもない場合
    if !@following
      unless moving? or $game_system.map_interpreter.running? or
             @move_route_forcing or $game_temp.message_window_showing
        # 方向ボタンが押されていれば、その方向へプレイヤーを移動
        case Input.dir4
        when 2
          move_down
        when 4
          move_left
        when 6
          move_right
        when 8
          move_up
        end
      end
      # ローカル変数に座標を記憶
      last_real_x = @real_x
      last_real_y = @real_y
      super
      # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
      if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
        # マップを下にスクロール
        $game_map.scroll_down(@real_y - last_real_y)
      end
      # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
      if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
        # マップを左にスクロール
        $game_map.scroll_left(last_real_x - @real_x)
      end
      # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
      if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
        # マップを右にスクロール
        $game_map.scroll_right(@real_x - last_real_x)
      end
      # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
      if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
        # マップを上にスクロール
        $game_map.scroll_up(last_real_y - @real_y)
      end
    else
      super
    end
    # 移動中ではない場合
    unless moving?
      # 前回プレイヤーが移動中だった場合
      if last_moving
        # 同位置のイベントとの接触によるイベント起動判定
        result = check_event_trigger_here([1,2])
        # 起動したイベントがない場合
        if result == false
          # デバッグモードが ON かつ CTRL キーが押されている場合を除き
          unless $DEBUG and Input.press?(Input::CTRL)
            # エンカウント カウントダウン
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # C ボタンが押された場合
      if Input.trigger?(Input::C)
        # 同位置および正面のイベント起動判定
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end

class Game_Character
 
  #--------------------------------------------------------------------------
  # ● プレイヤーの方を向く
  #--------------------------------------------------------------------------
  def turn_toward_player
    t = ($game_player.following ? $game_map.events[$event.id] : $game_player)
    # プレイヤーの座標との差を求める
    sx = @x - t.x
    sy = @y - t.y
    # 座標が等しい場合
    if sx == 0 and sy == 0
      return
    end
    # 横の距離のほうが長い場合
    if sx.abs > sy.abs
      # 左右方向でプレイヤーのいるほうを向く
      sx > 0 ? turn_left : turn_right
    # 縦の距離のほうが長い場合
    else
      # 上下方向でプレイヤーのいるほうを向く
      sy > 0 ? turn_up : turn_down
    end
  end
 
end
Title: Re: [XP] Script needed
Post by: nathmatt on June 17, 2010, 07:17:21 am
fixed

Spoiler: ShowHide
class Event
  attr_reader   :id

  def on(id)
    @id = id
    @map = $game_map.map.events[@id]
    character = @event = $game_map.events[@id]
    $game_map.events[@id] = Game_Event_Player.new(@map)
    $scene.spriteset.character_sprites.each {|sprite|
    # if sprite found
    if sprite.character == character
      # set new character
      sprite.character = $game_map.events[@id]
      # update sprite
      sprite.update
      # event found, stop here
      break
    end}
    $game_player.following = true
  end
 
  def off
    player = $game_map.events[@id]
    @map.x = player.x
    @map.y = player.y
    character = $game_map.events[@id] = @event
    $game_map.events[@id].moveto(player.x,player.y)
    $game_map.map.events[@id] = @map
    character = $game_map.events[@id] = @event
    $scene.spriteset.character_sprites.each {|sprite|
    # if sprite found
    if sprite.character == character
      # set new character
      sprite.dispose
      sprite.character = player
      # update sprite
      sprite.update
      # event found, stop here
      break
    end}
    $game_player.following = false
    $game_player.center($game_player.y,$game_player.y)
  end
 
end

$event = Event.new

class Game_Event_Player < Game_Character
 
  attr_accessor :off
 
  def initialize(event)
  super()
    moveto(event.x,event.y)
    center(event.x,event.y)
    @last_event = event
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 定数
  #--------------------------------------------------------------------------
  CENTER_X = (320 - 16) * 4   # 画面中央の X 座標 * 4
  CENTER_Y = (240 - 16) * 4   # 画面中央の Y 座標 * 4
  #--------------------------------------------------------------------------
  # ● 通行可能判定
  #     x : X 座標
  #     y : Y 座標
  #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向通行不可の場合を判定 (ジャンプ用)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    # 新しい座標を求める
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # 座標がマップ外の場合
    unless $game_map.valid?(new_x, new_y)
      # 通行不可
      return false
    end
    # デバッグモードが ON かつ CTRL キーが押されている場合
    if $DEBUG and Input.press?(Input::CTRL)
      # 通行可
      return true
    end
    super
  end
  #--------------------------------------------------------------------------
  # ● 画面中央に来るようにマップの表示位置を設定
  #--------------------------------------------------------------------------
  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
  def starting
    return false
  end
  def need_update?
    return false
  end
  #--------------------------------------------------------------------------
  # ● 指定位置に移動
  #     x : X 座標
  #     y : Y 座標
  #--------------------------------------------------------------------------
  def moveto(x, y)
    super
    # センタリング
    center(x, y)
    # エンカウント カウントを作成
    make_encounter_count
  end
  #--------------------------------------------------------------------------
  # ● 歩数増加
  #--------------------------------------------------------------------------
  def increase_steps
    super
    # 移動ルート強制中ではない場合
    unless @move_route_forcing
      # 歩数増加
      $game_party.increase_steps
      # 歩数が偶数の場合
      if $game_party.steps % 2 == 0
        # スリップダメージチェック
        $game_party.check_map_slip_damage
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● エンカウント カウント取得
  #--------------------------------------------------------------------------
  def encounter_count
    return @encounter_count
  end
  #--------------------------------------------------------------------------
  # ● エンカウント カウント作成
  #--------------------------------------------------------------------------
  def make_encounter_count
    # サイコロを 2 個振るイメージ
    if $game_map.map_id != 0
      n = $game_map.encounter_step
      @encounter_count = rand(n) + rand(n) + 1
    end
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    @character_name = @last_event.pages[0].graphic.character_name
    @character_hue  = @last_event.pages[0].graphic.character_hue
    # 不透明度と合成方法を初期化
    @opacity = 255
    @blend_type = 0
  end
  #--------------------------------------------------------------------------
  # ● 同位置のイベント起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 全イベントのループ
    return result
  end
  #--------------------------------------------------------------------------
  # ● 正面のイベント起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 正面の座標を計算
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # 全イベントのループ
    for event in $game_map.events.values
      # イベントの座標とトリガーが一致した場合
      if event.x == new_x and event.y == new_y and
         triggers.include?(event.trigger)
        # ジャンプ中以外で、起動判定が正面のイベントなら
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # 該当するイベントが見つからなかった場合
    if result == false
      # 正面のタイルがカウンターなら
      if $game_map.counter?(new_x, new_y)
        # 1 タイル奥の座標を計算
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        # 全イベントのループ
        for event in $game_map.events.values
          # イベントの座標とトリガーが一致した場合
          if event.x == new_x and event.y == new_y and
             triggers.include?(event.trigger)
            # ジャンプ中以外で、起動判定が正面のイベントなら
            if not event.jumping? and not event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● 接触イベントの起動判定
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # イベント実行中の場合
    if $game_system.map_interpreter.running?
      return result
    end
    # 全イベントのループ
    for event in $game_map.events.values
      # イベントの座標とトリガーが一致した場合
      if event.x == x and event.y == y and [1,2].include?(event.trigger)
        # ジャンプ中以外で、起動判定が正面のイベントなら
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    # ローカル変数に移動中かどうかを記憶
    last_moving = moving?
    # 移動中、イベント実行中、移動ルート強制中、
    # メッセージウィンドウ表示中のいずれでもない場合
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      # 方向ボタンが押されていれば、その方向へプレイヤーを移動
      case Input.dir4
      when 2
        move_down
      when 4
        move_left
      when 6
        move_right
      when 8
        move_up
      end
    end
    # ローカル変数に座標を記憶
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # マップを下にスクロール
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # マップを左にスクロール
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # マップを右にスクロール
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # マップを上にスクロール
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # 移動中ではない場合
    unless moving?
      # 前回プレイヤーが移動中だった場合
      if last_moving
        # 同位置のイベントとの接触によるイベント起動判定
        result = check_event_trigger_here([1,2])
        # 起動したイベントがない場合
        if result == false
          # デバッグモードが ON かつ CTRL キーが押されている場合を除き
          unless $DEBUG and Input.press?(Input::CTRL)
            # エンカウント カウントダウン
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # C ボタンが押された場合
      if Input.trigger?(Input::C)
        # 同位置および正面のイベント起動判定
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end


class Game_Player
  attr_accessor :following
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    # ローカル変数に移動中かどうかを記憶
    last_moving = moving?
    # 移動中、イベント実行中、移動ルート強制中、
    # メッセージウィンドウ表示中のいずれでもない場合
    if !@following
      unless moving? or $game_system.map_interpreter.running? or
             @move_route_forcing or $game_temp.message_window_showing
        # 方向ボタンが押されていれば、その方向へプレイヤーを移動
        case Input.dir4
        when 2
          move_down
        when 4
          move_left
        when 6
          move_right
        when 8
          move_up
        end
      end
      # ローカル変数に座標を記憶
      last_real_x = @real_x
      last_real_y = @real_y
      super
      # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
      if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
        # マップを下にスクロール
        $game_map.scroll_down(@real_y - last_real_y)
      end
      # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
      if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
        # マップを左にスクロール
        $game_map.scroll_left(last_real_x - @real_x)
      end
      # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
      if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
        # マップを右にスクロール
        $game_map.scroll_right(@real_x - last_real_x)
      end
      # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
      if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
        # マップを上にスクロール
        $game_map.scroll_up(last_real_y - @real_y)
      end
    else
      super
    end
    # 移動中ではない場合
    unless moving?
      # 前回プレイヤーが移動中だった場合
      if last_moving
        # 同位置のイベントとの接触によるイベント起動判定
        result = check_event_trigger_here([1,2])
        # 起動したイベントがない場合
        if result == false
          # デバッグモードが ON かつ CTRL キーが押されている場合を除き
          unless $DEBUG and Input.press?(Input::CTRL)
            # エンカウント カウントダウン
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # C ボタンが押された場合
      if Input.trigger?(Input::C)
        # 同位置および正面のイベント起動判定
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end

class Game_Character
 
  #--------------------------------------------------------------------------
  # ● プレイヤーの方を向く
  #--------------------------------------------------------------------------
  def turn_toward_player
    t = ($game_player.following ? $game_map.events[$event.id] : $game_player)
    # プレイヤーの座標との差を求める
    sx = @x - t.x
    sy = @y - t.y
    # 座標が等しい場合
    if sx == 0 and sy == 0
      return
    end
    # 横の距離のほうが長い場合
    if sx.abs > sy.abs
      # 左右方向でプレイヤーのいるほうを向く
      sx > 0 ? turn_left : turn_right
    # 縦の距離のほうが長い場合
    else
      # 上下方向でプレイヤーのいるほうを向く
      sy > 0 ? turn_up : turn_down
    end
  end
 
end