Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
AgentPaper

(quick) pathing check script

Question

I'm currently putting together a series of simple boulder-pushing puzzles, and I've got the events working pretty well, but I've run into an issue. I can't figure out how to check if the tile in front of the boulder (where it is going to be pushed to) is passable or not. Of course, if the tile isn't movable, then the boulder simply won't move, but the problem is that the sound effect still plays.

 

Is there a simple script I can use to check if a certain X/Y coordinate is pathable? The code I'm imagining is:

 

Switch0001 = isPathable(rock.x, rock.y + 1)

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

i quickly put this together:

class Interpreter
def movable?(event_id, direction)
case direction
when 2 # down
 return true if $game_map.passable?($game_map.events[event_id].x,
						 $game_map.events[event_id].y + 1, 8)
when 4 # left
 return true if $game_map.passable?($game_map.events[event_id].x - 1,
						 $game_map.events[event_id].y, 6)
when 6 # right
 return true if $game_map.passable?($game_map.events[event_id].x + 1,
						 $game_map.events[event_id].y, 4)
when 8 # up
 return true if $game_map.passable?($game_map.events[event_id].x,
						 $game_map.events[event_id].y - 1, 2)
end
return false
end
end

in a script call use this: movable?(EVENT_ID, DIRECTION_ITS_MOVING)

EVENT_ID can be: [@event_id] for the currently running event or an events id

for the direction:

2 = down

4 = left

6 = right

8 = up

hope this helps smile.png

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

That looks perfect. Now, how do I set a switch (ie, switch 0001) to be equal to that result?

 

Edit: Derp, you can put a script directly into a conditional branch, so I don't need to do that. Nevermind.

Edited by AgentPaper

Share this post


Link to post
Share on other sites
  • 0

Ran into a slight issue: This works great if the boulder runs into a wall, but it doesn't detect other boulders. So, if I have two boulders next to each other, then the same issue will occur.

Edited by AgentPaper

Share this post


Link to post
Share on other sites
  • 0

tiles should return unpassable if an event without the through tag is on them, are any of the events set as through? or do you have any other scripts that mess with passable? in Game_Map.

i tested it and i didnt recieve the following error, the structure of my event is like so:

Conditional branch: Player is facind down

Conditional branch: Script: movable?(@event_id, 2)

set move route: this event

: $>move down

play se:

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

The only other script I'm using is Heretic's Catepillar script, and looking through, it does seem to change how moveable? is defined, so I suppose that is what's causing the issue.

 

If I could get the script to be modified so that it also checks if there is an event in the location it's going to, that would solve the problem I think and would also allow me to do something like place invisible, through events in walls to block where the boulder can go, without blocking the player.

 

 

Edit: Ok, I looked through the passable? script, and I think this is close to what I'm looking for:

 

def event_here?(x,y)
for event in $game_map.events.values
 if event.x == $game_map.events[event_id].x and
 event.y == $game_map.events[event_id].y
 return true
 else
 return false
 end
end
end

 

However, this doesn't seem to work. I'm not getting any errors, but it doesn't do anything to prevent the boulder from moving, either. I just added on " and not event_here?(x, y+1)" to your script, after the passable? call.

Edited by AgentPaper

Share this post


Link to post
Share on other sites
  • 0

this should work:

class Interpreter
 def movable?(event_id, direction)
   rock_event = $game_map.events[event_id]
   for event in $game_map.events.values
  case direction
  when 2 # down
    return false if event.y == rock_event.y + 1
    return true if $game_map.passable?(rock_event.x, rock_event.y + 1, 8)
  when 4 # left
    return false if event.x == rock_event.x - 1
    return true if $game_map.passable?(rock_event.x - 1, rock_event.y, 6)
  when 6 # right
    return false if event.x == rock_event.x + 1
    return true if $game_map.passable?(rock_event.x + 1, rock_event.y, 4)
  when 8 # up
    return false if event.y == rock_event.y - 1
    return true if $game_map.passable?(rock_event.x, rock_event.y - 1, 2)
  end
  return false
   end
 end
end

you were corect in the code you had but you didnt add 1 onto the x or y, so really it was checking the event against itself, anyway i easily modified the code i had to include the event check, let me know if it works out :)

Share this post


Link to post
Share on other sites
  • 0

Made a few tweaks to my code, and it's working now. I was adding 1 onto the x/y, that wasn't the problem. The real problem was that my return false clause was put in the wrong spot. If the first event it checked wasn't at the x/y coordinates, then it would return false right after, instead of waiting for it to loop through all of the events.

 

Anyways, it's working like a charm now. Here's the code I ended up with, in case anyone else wants to use it:

 

class Interpreter

# Checks if the event can move in a specified direction
def movable?(event_id, direction)
x = $game_map.events[event_id].x
y = $game_map.events[event_id].y
case direction
when 2 # down
 return true if $game_map.passable?(x, y+1, 8) and not event_here?(x, y+1)
when 4 # left
 return true if $game_map.passable?(x-1, y, 6) and not event_here?(x-1, y)
when 6 # right
 return true if $game_map.passable?(x+1, y, 4) and not event_here?(x+1, y)
when 8 # up
 return true if $game_map.passable?(x, y-1, 2) and not event_here?(x, y-1)
end
return false
end

# Checks if there is an event at a location
def event_here?(x,y)
for some_event in $game_map.events.values
 return true if some_event.x == x and some_event.y == y
end
return false
end
end

Edited by AgentPaper

Share this post


Link to post
Share on other sites
  • 0

Nice work Agent Paper!

 

For future reference, I just wanted to say that Events and Player passability are calculated differently. The player is allowed to move through events, regardless of their passage settings, based on Event Graphics. NPC Events and Events with Non Passable Tile Graphics arent passable unless they have a Through Flag. However, Events calculate their passage differently. Events arent "allowed" to pass through other Events unless one of them has a Through flag.

 

If you want to read more on them, start off with class Game_Character. It defines "passable?", but Game_Character basically redefines it for the Game_Player class to do further checks on Tile Passability.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...