Hi,
I have a script that does automatic movement for Birds and Pigeons. Basically the way it works is you name an event either Bird of Pigeon and it changes the movement accordingly (and the graphic for the pigeon). The Bird flys in a straight line in a random direction until it gets to the edge. Then it gets transfered to a random edge in a random position and repeats.
I've already adapted it slightly so instead of putting 'Bird' as the event name I can use 'NPC'. I've also changed it so that the event will only move left or right.
However, I want to adapt the script so that the event will transfer to either the left or right edge when it goes off the map and only horizontally between the coordinates Y15 and Y17 (X doesn't matter if it only transfers to the left or right edge).
That way the event will walk along the street and then walk along it again from either left or right when it gets to the end.
Anyway, the script (with adaptations):
I have a script that does automatic movement for Birds and Pigeons. Basically the way it works is you name an event either Bird of Pigeon and it changes the movement accordingly (and the graphic for the pigeon). The Bird flys in a straight line in a random direction until it gets to the edge. Then it gets transfered to a random edge in a random position and repeats.
I've already adapted it slightly so instead of putting 'Bird' as the event name I can use 'NPC'. I've also changed it so that the event will only move left or right.
However, I want to adapt the script so that the event will transfer to either the left or right edge when it goes off the map and only horizontally between the coordinates Y15 and Y17 (X doesn't matter if it only transfers to the left or right edge).
That way the event will walk along the street and then walk along it again from either left or right when it gets to the end.
Anyway, the script (with adaptations):
#--------------------------------------------------------------------------
# * SDK Log
#--------------------------------------------------------------------------
SDK.log('Birds', 'tibuda', 1.0, '')
#--------------------------------------------------------------------------
# * SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.0, [1, 2])
#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Birds')
#==============================================================================
class Game_Event
#--------------------------------------------------------------------------
def name
return @event.name
end
#--------------------------------------------------------------------------
if SDK.enabled?('AntiLag')
alias_method :tibuda_birds_antilag_gm_event_in_screen?, :in_screen?
def in_screen?
if self.name == 'Pigeon' || self.name == 'NPC'
return true
else
return tibuda_birds_antilag_gm_event_in_screen?
end
end
end
end
class Game_Character
#--------------------------------------------------------------------------
alias_method :tibuda_birds_gm_char_up_movement, :update_movement
def update_movement
if self.is_a?(Game_Event) && self.name == 'Pigeon'
move_type_pigeon
elsif self.is_a?(Game_Event) && self.name == 'NPC'
move_type_bird
else
tibuda_birds_gm_char_up_movement
end
end
#--------------------------------------------------------------------------
def move_type_bird
return if moving?
@bird_dir = @direction unless @bird_dir.is_a?(Numeric)
@move_frequency = 6
@through = false
@always_on_top = false
if !moving? &&
((self.x == 0 && [1,4,7].include?(@bird_dir)) ||
(self.y == 0 && [7,8,9].include?(@bird_dir)) ||
(self.x == $game_map.width-1 && [3,6,9].include?(@bird_dir)) ||
(self.y == $game_map.height-1 && [1,2,3].include?(@bird_dir)))
@bird_dir = rand(8) + 1
@bird_dir += 1 if @bird_dir == 5
case @bird_dir
when 1
pos = rand($game_map.width + $game_map.height - 1)
if pos <= $game_map.width
self.moveto(pos, 0)
else
self.moveto($game_map.width-1, pos - $game_map.width + 1)
end
when 2
self.moveto(rand($game_map.width), 0)
when 3
pos = rand($game_map.width + $game_map.height - 1)
if pos <= $game_map.width
self.moveto(pos, 0)
else
self.moveto(0, pos - $game_map.width + 1)
end
when 4
self.moveto($game_map.width - 1, rand($game_map.height))
when 6
self.moveto(0, rand($game_map.height))
when 7
pos = rand($game_map.width + $game_map.height - 1)
if pos <= $game_map.width
self.moveto(pos, $game_map.height-1)
else
self.moveto($game_map.width-1, pos - $game_map.width + 1)
end
when 8
self.moveto(rand($game_map.width), $game_map.height-1)
when 9
pos = rand($game_map.width + $game_map.height - 1)
if pos <= $game_map.width
self.moveto(pos, $game_map.height - 1)
else
self.moveto(0, pos - $game_map.width + 1)
end
end
end
case @bird_dir
when 1
move_left
when 2
move_left
when 3
move_right
when 4
move_left
when 6
move_right
when 7
move_left
when 8
move_right
when 9
move_right
end
end
#--------------------------------------------------------------------------
def move_type_pigeon
range = ((self.x - $game_player.x)**2 + (self.y - $game_player.y)**2)**0.5
limit = @move_frequency == 3 ? 2 : 5
if range > limit && $game_map.passable?(self.x, self.y, 0)
@character_name = '166-Small08'
@move_frequency = @page.move_frequency
@through = @page.through
@always_on_top = @page.always_on_top
tibuda_birds_gm_char_up_movement
else
@character_name = '165-Small07'
if @move_frequency == 3
turn_away_from_player
@bird_dir = nil
end
move_type_bird
end
end
#--------------------------------------------------------------------------
end
end
#--------------------------------------------------------------------------
# End SDK Enabled Test
#--------------------------------------------------------------------------