The RPG Maker Resource Kit

RMRK RPG Maker Creation => MV => Topic started by: flapbat on August 01, 2016, 02:04:33 AM

Title: What is the script call for passability of events adjacent to each other?
Post by: flapbat on August 01, 2016, 02:04:33 AM
Hello,

I've asked this question elsewhere to no avail, so here's hoping for a reply!

I'm not sure how to check whether an object is blocking the player's movement route (via an autostart movement call). The code I've been using only checks for map passability, not event passability:

 
Code: [Select]
$gameMap.isPassable($gamePlayer.x+1, $gamePlayer.y, $gamePlayer.directionRight)


Any help is appreciated!
Title: Re: What is the script call for passability of events adjacent to each other?
Post by: Heretic86 on August 01, 2016, 12:53:05 PM
Im not sure in MV but I'll assume it is similar.  Trouble is that it requires Iterating every Event on the Map.

NOTE: This is the RUBY version.

Spoiler for:
    # Loop all events
    for event in $game_map.events.values
      # If event coordinates are consistent with move destination
      if event.x == new_x and event.y == new_y
        # If through is OFF
        unless event.through
          # If self is event not a Player
          if self != $game_player
            # impassable
            return false
          end
          # With self as the player and partner graphic as character
          if event.character_name != ""
            # impassable
            return false
          end
        end
      end
    end

Thing is that there are easier ways to do it.  The section above is only part of the code that checks for passable.  In XP, it can be called as part of the Player, not the Map.  There are usually two parts of the code, one is for the Map, the other is for the Characters.

if $game_player.passable?(x, y, d)
  # Do stuff here
end

As you can see, its part of the Player, not the Map.  The Map part of passable is also checked by the Player for both Tiles and Events.

As far as the MV code you are looking for, I am absolutely no help, I don't have MV, but hopefully, I can get you pointed in the right direction...
Title: Re: What is the script call for passability of events adjacent to each other?
Post by: flapbat on August 04, 2016, 12:15:09 AM
Hello Monsieur86,

Thanks for your reply.  I hadn't thought of issuing a movement command and then checking whether the event's x/y coordinates == the expected x/y.  :)

Quote
if $game_player.passable?(x, y, d)
  # Do stuff here
end

As you can see, its part of the Player, not the Map.  The Map part of passable is also checked by the Player for both Tiles and Events.

How would you set up this example using the Map instead of the Player?  Would this be right?:
Code: [Select]
if $game_map.event().passable?(x,y,d)
Title: Re: What is the script call for passability of events adjacent to each other?
Post by: Heretic86 on August 07, 2016, 09:41:12 PM
Hello Monsieur86,

Thanks for your reply.  I hadn't thought of issuing a movement command and then checking whether the event's x/y coordinates == the expected x/y.  :)

Quote
if $game_player.passable?(x, y, d)
  # Do stuff here
end

As you can see, its part of the Player, not the Map.  The Map part of passable is also checked by the Player for both Tiles and Events.

How would you set up this example using the Map instead of the Player?  Would this be right?:
Code: [Select]
if $game_map.event().passable?(x,y,d)

That looks correct.  Sorry, been busy for a few days so late reply.  Did the code above work for you?  I think it may need an Event ID in the $game_map.event(ID GOES HERE) part...