The Default Scripts include buttons to make an Event both Turn and Move Toward or Away From the Player, but lacked the ability to have Events have the same level of interactivity with each other. This script will allow you to do these things without the need for complex eventing to accomplish the same thing.
# ---------------------------------------------
# ---- ----
# ---- Heretics Movement Enhancements ----
# ---- Version 1.0 ----
# ---- Release Date: August 22nd, 2012 ----
# ---- ----
# ------------------------------------------------
# --- Purpose ---
#
# This script will allow you to have either the Player or an Event to interact
# with other Events. The Default Scripts were only set up to have Events
# react to the Player, which is somewhat limiting.
#
# This script will be most useful during Cutscenes. It is intended to help
# save you a lot of time from the complexity of trying to accomplish the same
# effects by using Events and Conditional Branches.
#
# The usefulness of this script becomes apparent if you have a Dynamic Cutscene
# where the Direction and Position of the Player and / or Events has not been
# predetermined.
#
#
# --- Installation ----
#
# Put it anywhere in between Main and Scene_Debug
#
#
# --- Compatability ----
# This script should be 100% with every script out there. If you do run into
# a situation that this script isnt compatible, you probably dont even need it.
#
# Note: Heretic's Caterpillar already has these features included.
#
#
# --- Usage ---
#
# To use this script, you'll need to call the commands from the Correct Window.
# There are a couple of places in the Event Editor where you can call one of
# the Script Commands from. The Script Commands need to be called from the
# Event Editor -> Set Move Route -> Scripts window. The other Script Windows
# execute differently, so it needs to be done in a Move Route Script.
#
# - turn_toward_event(event_target_id)
# - turn_away_from_event(event_target_id)
# - move_toward_event(event_target_id)
# - move_away_from_event(event_target_id)
#
# The 'event_target_id' should be the Number of the Event that you are using
# the script to Turn or Move Toward or Away From. You can use 0 to target
# the Player, but there is already a Button for that. Examine the Events
# in the Demo for Examples.
class Game_Character
#--------------------------------------------------------------------------
# * Turn Towards Event (Player or Event)
#--------------------------------------------------------------------------
def turn_toward_event(event_target_id)
# Check if the Event ID is requesting Player
if event_target_id == 0
# Target is the Game Player - Do anyway even though there is a Button for it...
event_target = $game_player
# Make sure that event_target_id is Numeric
elsif event_target_id.is_a?(Integer)
# Set Variable to the corresponding Event
event_target = $game_map.events[event_target_id]
elsif not event_target_id.is_a?(Integer)
if $DEBUG
print "Warning: Problem in turn_toward_event(", event_target_id, ")\n",
"\"", event_target_id, "\" should be an Event ID\n",
"which is a Number!"
end
return
else
# Set to Nil to prevent further processing
event_target = nil
end
# Arg isnt usable or Event doesnt exist, return to stop processing
if event_target.nil?
if $DEBUG
print "Warning: Problem in turn_toward_event(", event_target_id, ")\n",
"The Event \"", event_target_id, "\" does not exist!"
end
# event_target_id isnt usable or Event doesnt exist, return if it is to
# stop processing and prevent Game Crash
return
end
# Get difference in Self and Target coordinates
sx = @x - event_target.x
sy = @y - event_target.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# If horizontal distance is longer
if sx.abs > sy.abs
# Turn to the right or left towards target event
sx > 0 ? self.turn_left : self.turn_right
# If vertical distance is longer
else
# Turn up or down towards target event
sy > 0 ? self.turn_up : self.turn_down
end
end
#--------------------------------------------------------------------------
# * Turn Away From Event (Player or Event)
#--------------------------------------------------------------------------
def turn_away_from_event(event_target_id)
# Check if the Event ID is requesting Player
if event_target_id == 0
# Target is the Game Player - Do anyway even though there is a Button for it...
event_target = $game_player
# Make sure that event_target_id is Numeric
elsif event_target_id.is_a?(Integer)
# Set Variable to the corresponding Event
event_target = $game_map.events[event_target_id]
elsif not event_target_id.is_a?(Integer)
if $DEBUG
print "Warning: ",
"Problem in turn_away_from_event(", event_target_id, ")\n",
"\"", event_target_id, "\" should be an Event ID\n",
"which is a Number!"
end
return
else
# Set to Nil to prevent further processing
event_target = nil
end
# Arg isnt usable or Event doesnt exist, return to stop processing
if event_target.nil?
if $DEBUG
print "Warning: ",
"Problem in turn_away_from_event(", event_target_id, ")\n",
"The Event \"", event_target_id, "\" does not exist!"
end
# event_target_id isnt usable or Event doesnt exist, return if it is to
# stop processing and prevent Game Crash
return
end
# Get difference in Self and Target coordinates
sx = @x - event_target.x
sy = @y - event_target.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# If horizontal distance is longer
if sx.abs > sy.abs
# Turn to the right or left towards target event
sx > 0 ? self.turn_right : self.turn_left
# If vertical distance is longer
else
# Turn up or down towards target event
sy > 0 ? self.turn_down : self.turn_up
end
end
#--------------------------------------------------------------------------
# * Move toward Event
#--------------------------------------------------------------------------
def move_toward_event(event_target_id)
# Check if the Event ID is requesting Player, pointless but just in case...
if event_target_id == 0
# Target is the Game Player - Do anyway even though there is a Button for it...
event_target = $game_player
# Make sure that event_target_id is Numeric
elsif event_target_id.is_a?(Integer)
# Set Variable to the corresponding Event
event_target = $game_map.events[event_target_id]
elsif not event_target_id.is_a?(Integer)
if $DEBUG
print "Warning: Problem in move_toward_event(", event_target_id, ")\n",
"\"", event_target_id, "\" should be an Event ID\n",
"which is a Number!"
end
return
else
# Set to Nil to prevent further processing
event_target = nil
end
# Arg isnt usable or Event doesnt exist, return to stop processing
if event_target.nil?
if $DEBUG
print "Warning: ",
"Problem in move_toward_event(", event_target_id, ")\n",
"The Event \"", event_target_id, "\" does not exist!"
end
# event_target_id isnt usable or Event doesnt exist, return if it is to
# stop processing and prevent Game Crash
return
end
# Get difference in Self and Target coordinates
sx = @x - event_target.x
sy = @y - event_target.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Move towards player, prioritize left and right directions
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# If vertical distance is longer
else
# Move towards player, prioritize up and down directions
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
#--------------------------------------------------------------------------
# * Move away from Event
#--------------------------------------------------------------------------
def move_away_from_event(event_target_id)
# Check if the Event ID is requesting Player, pointless but just in case...
if event_target_id == 0
# Target is the Game Player - Do anyway even though there is a Button for it...
event_target = $game_player
# Make sure that event_target_id is Numeric
elsif event_target_id.is_a?(Integer)
# Set Variable to the corresponding Event
event_target = $game_map.events[event_target_id]
elsif not event_target_id.is_a?(Integer)
if $DEBUG
print "Warning: ",
"Problem in move_away_from_event(", event_target_id, ")\n",
"\"", event_target_id, "\" should be an Event ID\n",
"which is a Number!"
end
return
else
# Set to Nil to prevent further processing
event_target = nil
end
# Arg isnt usable or Event doesnt exist, return to stop processing
if event_target.nil?
if $DEBUG
print "Warning: ",
"Problem in move_away_from_event(", event_target_id, ")\n",
"The Event \"", event_target_id, "\" does not exist!"
end
# event_target_id isnt usable or Event doesnt exist, return if it is to
# stop processing and prevent Game Crash
return
end
# Get difference in Self and Target coordinates
sx = @x - event_target.x
sy = @y - event_target.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Move away from event or player, prioritize left and right directions
sx > 0 ? move_right : move_left
if not moving? and sy != 0
sy > 0 ? move_down : move_up
end
# If vertical distance is longer
else
# Move away from player, prioritize up and down directions
sy > 0 ? move_down : move_up
if not moving? and sx != 0
sx > 0 ? move_right : move_left
end
end
end
end
# This section isnt necessary, but it is useful for someone that doesn't call
# the script from the right window. The other problem is that using something
# like $game_map.events[@event_id].turn_toward_event(event_target_id) from the
# Interpreter class will cause the event to return to its @original_direction
# at the end of script execution, so the direction is not maintained, hence
# the need of a Move Route to run the script. That and I am just too lazy
# to write in anything to change @original_direction
class Interpreter
# Allows an Event to TURN Toward another Event, like Move Toward Player, just with events
# DEBUG Msg here indicates Mapper needs to call from the right window, however...
def turn_toward_event(*args)
if $DEBUG
print "Please call \"turn_toward_event(event_id)\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
# Allows an Event to TURN Away From another Event, like Move Away From Player, just with events
# DEBUG Msg here indicates Mapper needs to call from the right window, however...
def turn_away_from_event(*args)
if $DEBUG
print "Please call \"turn_away_from_event(event_id)\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
# Allows an Event to MOVE Toward another Event, like Move Toward Player, just with events
# DEBUG Msg here indicates Mapper needs to call from the right window, however...
def move_toward_event(*args)
if $DEBUG
print "Please call \"move_toward_event(event_id)\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
# Allows an Event to MOVE Away From another Event, like Move Away From Player, just with events
# DEBUG Msg here indicates Mapper needs to call from the right window, however...
def move_away_from_event(*args)
if $DEBUG
print "Please call \"move_away_from_event(event_id)\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
end
Put anywhere in between Scene_Debug and Main.
If you use Heretic's Caterpillar, these features are already built in. Other than that, this script should be 100% compatible with every script out there.
Legalese: This software may not, in whole or in any part, be copied, reproduced, transmitted, translated (into any language, natural or computer), stored in a retrieval system, reduced to any electronic medium or machine readable format, or by any other form or means without prior consent, in writing, from, oh who am I kidding? Besides, these legal threats are empty. You can do what ever you want to with this script.
I dont have a copy of VX or VXA to test this script out on, but I believe it will run on those as well. If someone wouldnt mind letting me know if they work or not, it would be appreciated.