This question is for me and I still haven't gotten a good grasp of a solution. I'm wringing my head with confusion as I type this. I'm trying to come up with a work around as well, but I can't seem to find a sasifactory way to make this work.
Basically let me tell you what I'm doing. I'm making a script that makes events run toward a target. As of right now it works perfectly if I use one event. Now if I add another event the slowest one will just line up behind the target.
[ - ] [ 1 ] [ - ]
[ 2 ] [ T ] [ 3 ]
[ - ] [ 4 ] [ - ]
T is the target, Events run to 1, 2, 3 or 4 based on a large script determining where on the map the active event is. If there is a map obstacle in 1, 2, 3, or 4 they will pick a different node. If their is already an event or a player there with no map impassability it will line up behind it and wait instead of picking a different node.
if $game_map.passable?(target_x, node_negativey, 0)
noodlenode = 1
elsif $game_map.passable?(node_negativex, target_y, 0)
noodlenode = 2
elsif $game_map.passable?(node_positivex, target_y, 0)
noodlenode = 3
elsif $game_map.passable?(target_x, node_positivey, 0)
noodlenode = 4
else
noodlenode = 5 # which means don't do anything till there's an opening
end
@ Zeriab - Hey! Thanks for the response and the question for my question. D; Umm. Err.. I tried all of those and got the same results if not worse. I've already wide searched xp for "passable?" and scanned those scripts for any solution.
def passable?(x, y, d, self_event = nil)
# If coordinates given are outside of the map
unless valid?(x, y)
# impassable
return false
end
# Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)
bit = (1 << (d / 2 - 1)) & 0x0f
# Loop in all events
for event in events.values
# If tiles other than self are consistent with coordinates
if event.tile_id >= 0 and event != self_event and
event.x == x and event.y == y and not event.through
# If obstacle bit is set
if @passages[event.tile_id] & bit != 0
# impassable
return false
# If obstacle bit is set in all directions
elsif @passages[event.tile_id] & 0x0f == 0x0f
# impassable
return false
# If priorities other than that are 0
elsif @priorities[event.tile_id] == 0
# passable
return true
end
end
end
This line under game_map seems to be the most fitting for what I'm trying to achieve.
@ shaz I tried event.passable?(x,y,d) like you said and got the same results as $game_map.passable?(x,y,d)
Spoiler
Code:
# *****************************************************************************# * Star Enemy Detection# * v1.0# * by Star (StarGGundam2)# *****************************************************************************SIGHT_RANGE = 4ENEMY_RANGE = 1ENEMY_DETECTION_SWITCH = 51class Game_Event attr_accessor :move_type attr_accessor :move_speed attr_accessor :old_speed attr_accessor :exclamation attr_accessor :old_type attr_accessor :old_y_position attr_accessor :old_x_position attr_accessor :stop_trigger attr_reader :f_route def initialize(map_id, event) super() @map_id = map_id @event = event @id = @event.id @erased = false @starting = false @through = true @name = @event.name @old_x_position = 0 @old_y_position = 0 # Move to starting position moveto(@event.x, @event.y) refresh end def name return @name end end class Game_Map def update if $game_map.need_refresh refresh end # If scrolling if @scroll_rest > 0 # Change from scroll speed to distance in map coordinates distance = 2 ** @scroll_speed # Execute scrolling case @scroll_direction when 2 # Down scroll_down(distance) when 4 # Left scroll_left(distance) when 6 # Right scroll_right(distance) when 8 # Up scroll_up(distance) end # Subtract distance scrolled @scroll_rest -= distance end for event in @events.values event.update key001 = [$game_map.map_id, event.id, "A"] key002 = [$game_map.map_id, event.id, "B"] key003 = [$game_map.map_id, event.id, "C"] key004 = [$game_map.map_id, event.id, "D"] if event.name.include?("Battle")# and $game_switches[216 + event.id] != true # Looks like the start of the CP Modifer for the event if $cp_mod[event.id] == nil $cp_mod[event.id] = 0 end # end CP mod starter # Start of the CP Modfier for Allies if event.id <= 3 and $game_party.actors[event.id + -1].cp != $game_party.actors[event.id + -1].maxcp $cp_mod[event.id] += $game_party.actors[event.id + -1].maxcp end # Restore CP for Allies if $cp_mod[event.id] >= 200 and event.id <= 3 $game_party.actors[event.id + -1].cp += 1 $game_player.wref = true $cp_mod[event.id] = 0 end # Some method I need to research event.character_movement_please # Cross block range identifier enemy_negativex = event.x - ENEMY_RANGE enemy_positivex = event.x + ENEMY_RANGE enemy_negativey = event.y - ENEMY_RANGE enemy_positivey = event.y + ENEMY_RANGE if event.name.include?("Ally") enemy_target = $game_variables[205 + event.id] + 3 else enemy_target = $game_variables[205 + event.id] end ### Set Ally_x and Ally_y for the map locations if enemy_target == 1 # if the target is the player ally_x = $game_player.x $game_variables[1] = ally_x ally_y = $game_player.y $game_variables[2] = ally_y elsif enemy_target >= 2 # if the target is an event ally_x = $game_map.events[enemy_target].x ally_y = $game_map.events[enemy_target].y end unless ally_x == nil or ally_y == nil if ally_x >= enemy_negativex and ally_x <= enemy_positivex and ally_y >= enemy_negativey and ally_y <= enemy_positivey range = 1 if ally_x == enemy_negativex and ally_y == enemy_negativey range = 0 # Sitting in the corner doesn't mean you're adjacent end if ally_x == enemy_negativex and ally_y == enemy_positivey range = 0 # Another one of the four corners end if ally_x == enemy_positivex and ally_y == enemy_negativey range = 0 # Have to be right next to the enemy end if ally_x == enemy_positivex and ally_y == enemy_positivey range = 0 # ditto end else range = 0 # else you're not in range end# Range 1 means within range, Range 0 means not in range need to get closer. if range == 1 and $game_switches[331 + event.id] != true $game_switches[331 + event.id] = true # sets within range switch to ON $game_map.need_refresh = true elsif range == 0 and $game_switches[331 + event.id] != false $game_switches[331 + event.id] = false # sets within range switch to OFF $game_map.need_refresh = true end end if $game_switches[331 + event.id] == false and $game_switches[1] == true if enemy_target != 0 # setting up the cross for range node_negativex = ally_x - ENEMY_RANGE node_positivex = ally_x + ENEMY_RANGE node_negativey = ally_y - ENEMY_RANGE node_positivey = ally_y + ENEMY_RANGE end # a primitive method for enemy's to move towards the player or party # if enemy_target <= 3 # if enemy_target == 1 # event.move_toward_player unless event.moving? # else # event.move_toward_event(enemy_target)unless event.moving? # end if enemy_target >= 1 #checkplace if ally_y < event.y and ally_x < event.x # coordinate 4 noodle_x = event.x - ally_x noodle_y = event.y - ally_y if noodle_x == noodle_y # incase diagonally from target case rand(2) when 0 noodle = 3 noodle2 = 4 when 1 noodle = 4 noodle2 = 3 end end if noodle_x > noodle_y noodle = 3 noodle2 = 4 else noodle = 4 noodle2 = 3 end end if ally_y < event.y and ally_x > event.x # Coordinate 3 noodle_x = event.x - ally_x noodle_y = ally_y - event.y if noodle_x == noodle_y # incase diagonally from target case rand(2) when 0 noodle = 2 noodle2 = 4 when 1 noodle = 4 noodle2 = 2 end end if noodle_x > noodle_y noodle = 2 noodle2 = 4 else noodle = 4 noodle2 = 2 end end if ally_y > event.y and ally_x < event.x # Coordinate 2 noodle_x = ally_x - event.x noodle_y = event.y - ally_y if noodle_x == noodle_y # incase diagonally from target case rand(2) when 0 noodle = 3 noodle2 = 1 when 1 noodle = 1 noodle2 = 3 end end if noodle_x > noodle_y noodle = 3 noodle2 = 1 else noodle = 1 noodle2 = 3 end end if ally_y > event.y and ally_x > event.x # Coordinate 1 noodle_x = ally_x - event.x noodle_y = ally_y - event.y if noodle_x == noodle_y # incase diagonally from target case rand(2) when 0 noodle = 2 noodle2 = 1 when 1 noodle = 1 noodle2 = 2 end end if noodle_x > noodle_y noodle = 2 noodle2 = 1 else noodle = 1 noodle = 2 end end #checkend #noode begin if noodle == 1 if $game_map.passable?(ally_x, node_negativey, 0) noodlenode = 1 elsif $game_map.passable?(node_negativex, ally_y, 0) noodlenode = 2 elsif $game_map.passable?(node_positivex, ally_y, 0) noodlenode = 3 elsif $game_map.passable?(ally_x, node_positivey, 0) noodlenode = 4 else noodlenode = 5 end end if noodle == 2 if $game_map.passable?(node_negativex, ally_y, 0) noodlenode = 2 elsif $game_map.passable?(ally_x, node_negativey, 0) noodlenode = 1 elsif $game_map.passable?(ally_x, node_positivey, 0) noodlenode = 4 elsif $game_map.passable?(node_positivex, ally_y, 0) noodlenode = 3 else noodlenode = 5 end end if noodle == 3 if $game_map.passable?(node_positivex, ally_y, 0) noodlenode = 3 elsif $game_map.passable?(ally_x, node_negativey, 0) noodlenode = 1 elsif $game_map.passable?(ally_x, node_positivey, 0) noodlenode = 4 elsif $game_map.passable?(node_negativex, ally_y, 0) noodlenode = 2 else noodlenode = 5 end end if noodle == 4 if $game_map.passable?(ally_x, node_positivey, 0) noodlenode = 4 elsif $game_map.passable?(node_negativex, ally_y, 0) noodlenode = 2 elsif $game_map.passable?(node_positivex, ally_y, 0) noodlenode = 3 elsif $game_map.passable?(ally_x, node_negativey, 0) noodlenode = 1 else noodlenode = 5 end end if noodlenode == 1 event.force_path (ally_x, node_negativey, true, 20) noodlereach_x = ally_x noodlereach_y = node_negativey elsif noodlenode == 2 event.force_path (node_negativex, ally_y, true, 20) noodlereach_x = ally_x noodlereach_y = node_negativey elsif noodlenode == 3 event.force_path (node_positivex, ally_y, true, 20) noodlereach_x = node_positivex noodlereach_y = ally_y elsif noodlenode == 4 event.force_path (ally_x, node_positivey, true, 20) noodlereach_x = ally_x noodlereach_y = node_positivey else noodlereach_x = event.x noodlereach_y = event.y end # What to do when the event reached the target if noodlereach_x == event.x and noodlereach_y == event.y event.turn_toward_event(enemy_target) unless event.moving? end end # target end end # switch end end # if Battle name event # Most likely a long winded enemy detection system used for on the field map # # # Nothing to do with the battle system at all. # if event.name.include?("Enemy") and $game_switches[ENEMY_DETECTION_SWITCH] == false and $game_self_switches[key004] != true if event.old_x_position == 0 event.old_x_position = event.x event.old_y_position = event.y end eventnegativex = event.x - SIGHT_RANGE eventpositivex = event.x + SIGHT_RANGE eventnegativey = event.y - SIGHT_RANGE eventpositivey = event.y + SIGHT_RANGE if $game_player.x >= eventnegativex and $game_player.x <= eventpositivex and $game_player.y >= eventnegativey and $game_player.y <= eventpositivey if event.direction == 2 and $game_player.y > event.y eye_distance = $game_player.y - event.y distance_neg = event.x - eye_distance distance_pos = event.x + eye_distance if $game_player.x >= distance_neg and $game_player.x <= distance_pos switch_a = 1 end # end distance end # end direction if event.direction == 4 and $game_player.x < event.x eye_distance = event.x - $game_player.x distance_neg = event.y - eye_distance distance_pos = event.y + eye_distance if $game_player.y >= distance_neg and $game_player.y <= distance_pos switch_a = 1 end # end distance end # end direction if event.direction == 8 and $game_player.y < event.y eye_distance = event.y - $game_player.y distance_neg = event.x - eye_distance distance_pos = event.x + eye_distance if $game_player.x >= distance_neg and $game_player.x <= distance_pos switch_a = 1 end # end distance end # end direction if event.direction == 6 and $game_player.x > event.x eye_distance = $game_player.x - event.x distance_neg = event.y - eye_distance distance_pos = event.y + eye_distance if $game_player.y >= distance_neg and $game_player.y <= distance_pos switch_a = 1 end # end distance end # end direction else switch_a = 0 if $game_self_switches[key001] != false and $game_self_switches[key004] != true $game_self_switches[key001] = false $game_self_switches[key002] = true event.animation_id = 97 $game_map.need_refresh = true end end # end gameplayerloc if switch_a == 1 and $game_self_switches[key004] != true if $game_self_switches[key001] != true $game_self_switches[key001] = true event.animation_id = 98 $game_map.need_refresh = true end end if $game_self_switches[key001] == true event.move_toward_player unless event.moving? == true end if $game_self_switches[key002] == true #and $game_self_switches[key004] != true # x = event.old_x_position # y = event.old_y_position # e = Node.new(x, y) # ch = event.id # $path = A_Star_Pathfinder.new # $path.setup(e, ch, 0, true) # $path.character.stop_all_paths # $path.calculate_path # $path.generate_path if event.x == event.old_x_position and event.y == event.old_y_position $game_self_switches[key002] = false $game_map.need_refresh = true end end end # end include eventname end # end for event in values # Update common event for common_event in @common_events.values common_event.update end # Manage fog scrolling @fog_ox -= @fog_sx / 8.0 @fog_oy -= @fog_sy / 8.0 # Manage change in fog color tone if @fog_tone_duration >= 1 d = @fog_tone_duration target = @fog_tone_target @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d @fog_tone_duration -= 1 end # Manage change in fog opacity level if @fog_opacity_duration >= 1 d = @fog_opacity_duration @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d @fog_opacity_duration -= 1 end # # # End long winded outside field map detection system # # end # definitionend #class# A script used to change the character graphic when movingclass Game_Character def character_movement_please if @event.id == event.id and @event.id <= 3 if moving? == true and @game_character_wait_frame = 0 character_event_number = event.id if @character_name != $game_party.actors[character_event_number + -1].name + "_Battle" @character_name = $game_party.actors[character_event_number + -1].name + "_Battle" @step_anime = false $game_map.need_refresh = true end else @game_character_wait_frame += 1 if @game_character_wait_frame == 4 character_event_number = event.id if @character_name != $game_party.actors[character_event_number + -1].name + "_Battle_ANI" @character_name = $game_party.actors[character_event_number + -1].name + "_Battle_ANI" @step_anime = true $game_map.need_refresh = true end end end end end end