Guide on how to prevent a player from blocking npc paths
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.
[*]https://www.dropbox.com/s/kiy7c8peif10vhc/Regions%20and%20Events%20-%20AwesomeCool.rb?dl=0 by Me
[*]http://forums.rpgmakerweb.com/index.php?/topic/35677-theo-pathfinding-and-event-chase-player/?hl=%2Btheo+%2Bpathfinding by Theo
[*]https://www.dropbox.com/s/849fwy8v1y9yy6q/theo%20pathfinding%20bug%20fix.rb?dl=0 by me (used to fix some issues with theos 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:
http://i.imgur.com/dzD90Ma.png?1
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.
http://i.imgur.com/C991LZp.png?1
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:
http://i.imgur.com/RWkbxnP.png?1
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:
http://i.imgur.com/rmOpzqX.png?1
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):
http://i.imgur.com/SVgfMC5.png?1
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.
本贴来自国际rpgmaker官方论坛作者:AwesomeCool处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/guide-on-how-to-prevent-a-player-from-blocking-npc-paths.39329/
页:
[1]