10-09-2006, 01:00 PM (This post was last modified: 11-17-2021, 12:56 AM by DerVVulfman.)
Event dependent Movement Caldaron Version: 1.03
Oct 9 2006
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
Introduction
With this Script, u can simple make events follow events like move_toward_player
Features
move_toward_event
move_away_from_event
turn_toward_event
turn_away_from_event
8-way movement included
Script
Event dependent Movement
Code:
#==============================================================================
# Event dependent Movement Script v. 1.03
# by Caldaron (8.10.2006)
#==============================================================================
SDK.log('Event dependent Movement', 'Caldaron', 1.03, '2006-10-8')
if SDK.state('Event dependent Movement')
#==============================================================================
Eight_Way = true
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
def move_toward_event(id)
turn_toward_event(id)
move_forward
if not moving?
move_random
end
end
#--------------------------------------------------------------------------
def move_away_from_event(id)
turn_away_from_event(id)
move_forward
if not moving?
move_random
end
end
#--------------------------------------------------------------------------
def turn_toward_event(id)
sx = @x - $game_map.events[id].x
sy = @y - $game_map.events[id].y
if sx == 0 and sy == 0
return
end
if sx.abs == sy.abs and Eight_Way
sx > 0 ? sy > 0 ? turn_upper_left : turn_lower_left : sy > 0 ? turn_upper_right : turn_lower_right
elsif sx.abs > sy.abs
sx > 0 ? turn_left : turn_right
else
sy > 0 ? turn_up : turn_down
end
end
#--------------------------------------------------------------------------
def turn_away_from_event(id)
sx = $game_map.events[id].x - @x
sy = $game_map.events[id].y - @y
if sx == 0 and sy == 0
return
end
if sx.abs == sy.abs and Eight_Way
sx > 0 ? sy > 0 ? turn_upper_left : turn_lower_left : sy > 0 ? turn_upper_right : turn_lower_right
elsif sx.abs > sy.abs
sx > 0 ? turn_left : turn_right
else
sy > 0 ? turn_up : turn_down
end
end
#--------------------------------------------------------------------------
def turn_upper_left
unless @direction_fix
@direction = 7
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_lower_left
unless @direction_fix
@direction = 1
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_upper_right
unless @direction_fix
@direction = 9
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def turn_lower_right
unless @direction_fix
@direction = 3
@stop_count = 0
end
end
#--------------------------------------------------------------------------
def move_forward
case @direction
when 1
move_lower_left
when 2
move_down(false)
when 3
move_lower_right
when 4
move_left(false)
when 6
move_right(false)
when 7
move_upper_left
when 8
move_up(false)
when 9
move_upper_right
end
end
#--------------------------------------------------------------------------
def move_random
case rand(8)
when 0
move_lower_left
when 1
move_down(false)
when 2
move_lower_right
when 3
move_left(false)
when 4
move_right(false)
when 5
move_upper_left
when 6
move_up(false)
when 7
move_upper_right
end
end
#--------------------------------------------------------------------------
end
#==============================================================================
end
Instructions
Place this above main.
to let events follow events, choose script in the move route editor and put in: