Guide on how to prevent a player from blocking npc paths

Discussion in 'RMVX Ace Tutorials' started by AwesomeCool, Apr 27, 2015.

  1. AwesomeCool

    AwesomeCool Bratty and spoiled little sister Veteran

    Messages:
    2,877
    Likes Received:
    1,953
    Location:
    Behind you! BOOOO!
    First Language:
    English
    Primarily Uses:
    N/A
    This tutorial is made to help get rid of the problem of players being able to block paths of npcs (which causes npcs to just stand there).

    Note: This guide assumes you have some experience with VX Ace

    For this tutorial you will need two script snippets and one script.

    Put these scripts in the same order as the links are in the script section.

    Step 1:

    Create a npc that will be moving around a map of some kind. It is a good idea to keep track of the event id for this method (it's event id is the events default name).  For this tutorial I made it so I have to talk to him to get him to move on the first event page.

    Here is Bill's (my npc) first page:

    [​IMG]

    Step 2:

    Let's have the npc Bill follow a path after self switch A gets turned on. So lets have the second page have a custom move route using Theo's script.

    [​IMG]

    For this to work we will use find_path(x,y) in the move route dialog window. the x and y coordinates are where you want the npc to move too.

    Should look something like this:

    [​IMG]

    step 3:

    At the spot where you want the npc's trail to come to an end, put a region there (I used region 1).  Then put a second region around the region at the end point (I used region 2).  These two regions will indicate if the player is on top of the ending point of the npc and if the npc is close to getting to the location.

    What my map looked like:

    [​IMG]

    Step 4:

    Now we are going to need another event to control when the player is blocking the end point of the npc. (in parallel process mode) It can be left blank in terms of image

    We are going to need three functions from the first script to make this work:

    • get_region_event_is_in(id) - id is the event id of the event (Bill) that the npc is currently in
    • get_region_player_is_in - what region the player is in
    • get_event_position_relative_to_player(id) - is the event (Bill) to the right, left, above, or behind the player. id will be Bill's event id in this case.
    get_region_event_is_in(id) is going to check if the event is in region 2 (or the region you picked for the region surrounding the ending point). get_region_player_is_in is going to check if the player is in region 1. get_event_position_relative_to_player(id) is going to be used to see what direction to move the player if he is in the ending sport (to allow the npc to move there).

    To do this, in the new event's page make a condition branch that checks if Bill (event id 1) is in region 2 (ex: get_region_event_is_in(1) == 2 ). Make sure to use script option on page 4 of the conditional branch pop-up window to get this check to work.  Within this condition branch another condition branch should be added that checks what region the player is in (ex: get_region_player_is_in == 1).  

    In this condition branch, add four more conditional branches that check if the event is to the left, right, above, or below the player (ex: get_event_position_relative_to_player(1) == "right"). Note that right needs to be in-between "" marks. within each of these branches make the player move in the opposite direction of the check for the branch (ex: if you check to see if the event is to the right of the player, then move the player to the left).

    This will cause the player to move out of the way of the npc when he gets close to his destination.

    (optional) Step 5:

    Make it so the second event stops checking if the player is in the way when the destination is reached.

    like this (this switch will make the event go to the next page):

    [​IMG]

    Demo:

    Here is a link to the demo of the tutorial that I tested.

    Link: https://www.dropbox.com/s/c8kjy2e8awskndu/NPC%20tutorial%201.zip?dl=0

    Hope this tutorial helps you out (it is my first tutorial).  :)

    Thank you for your time. :)
     
    #1
  2. GrandmaDeb

    GrandmaDeb Modern Exteriors Posted! Veteran

    Messages:
    4,467
    Likes Received:
    2,875
    Location:
    East Coast, USA
    Hi AwesomeCool. I have been looking over your tutorial. =]


    I am having a brain freeze. Is this just supposed to allow the NPC to walk around you if you stand in a place that blocks an NPC path?


    Because obviously if the NPC freezes until you move, he just goes on about his business once you move out of the way, right?
     
    #2

Share This Page