Archived

This topic is now archived and is closed to further replies.

mightywidekiller

Pathfinder script and how to use it?

37 posts in this topic

Okay this is my first time here, and i appologize if this is not the right place for my request.

 

I am currently making my own game, with a monster that can chase the character and cause 'game over' when the enemy reaches the character. So far i am good, but the enemy can't chase me around obstacles.. It get's stuck and keeps trying to move through the obstacle which is really stupid. ;_; I've tried yanfly's and modern algebra's pathfinding script, but i don't know how to use them, and i need to make the enemy follow the character..  

 

Any pro out there willing to help a newbie? 

 

Thanks in advance!  :)

Share this post


Link to post
Share on other sites

Hi Mightywidekiller, welcome!

 

What you're asking for is kinda' a tough one. The problem you will encounter, even with a path-finding script, is making the engine know when to path find, and when to follow the player. Because the player will probably not be on a linear path, it makes using a path-finding script almost useless. The only way I could see it is one of two ways:

 

1. The only time the monsters chase the player is in a hallway of some sorts (Terrible idea)

 

or 

 

2. create different events around obstacles that tell the monster what to do when the player steps on them. So example, monster is chasing a player. Player runs up to a rock, and runs around it. The original event would look something like this:

 

Move route: Monster

move towards player

 

with the box checked off to ignore if can't move.

 

An event set to player touch near the rock would be something like:

 

If players x,y = this event x,y then

path find monster to around the rock.

 

If I get some spare time, I'll see if I can rig up some kind of demo for you. I think this would work. Now, there are probably easier methods using scripting, but I'm not too great with Ruby yet.

 

Sindaine

Share this post


Link to post
Share on other sites

Thank you very much for the answer

You asked when the monster needs to find a path. Can't it be set so the monster continually  search for a path towards the player, even though the player moves around? I've read somewhere that you can do something with variables that updates your players x and y so you can use that to set the monsters target, but i haven't figured out how to that properly.. 
Thank you again for your help

Share this post


Link to post
Share on other sites

I'm playing with the path-finding scripts, but none of them seem to accept the "$game_variables[n]" to call a variable. Basically, if you can figure a way to do that, then any of these path finding scripts would work fine. The problem is updating the path-finder with where the player currently is. Yes, this is possible, but again, I'm just not very good with ruby. I'm sure there's someone out here that knows how to make the scripts take variables.

 

Sindaine

Share this post


Link to post
Share on other sites

Can you post which pathfinder script are you using?

 

It would be basically running a parallel process event which checks for the x & y position of the player, checks if it has moved and if moved, run pathfinder call to current player x & y, via call script command.

 

if @test_variable.nil?  @test_variable = [$game_player.x, $game_player.y]endif @test_variable != [$game_player.x, $game_player.y]  @test_variable = [$game_player.x, $game_player.y]  pathfinder_command($game_player.x, $game_player.y)end

 

You need to replace pathfinder_command($game_player.x, $game_player.y) with the real call for the pathfinding script that you are using.

Share this post


Link to post
Share on other sites

ALL pathfinder scripts are cpu intensive. If your target is moving and your event has to pathfind with every move, your game is going to lag noticeably.

Share this post


Link to post
Share on other sites

I'm playing with the path-finding scripts, but none of them seem to accept the "$game_variables[n]" to call a variable. Basically, if you can figure a way to do that, then any of these path finding scripts would work fine. The problem is updating the path-finder with where the player currently is. Yes, this is possible, but again, I'm just not very good with ruby. I'm sure there's someone out here that knows how to make the scripts take variables.

 

Sindaine

Thank you Sindain for you time. I also get the same error which is very bad :(

 

Can you post which pathfinder script are you using?

 

It would be basically running a parallel process event which checks for the x & y position of the player, checks if it has moved and if moved, run pathfinder call to current player x & y, via call script command.

 

if @test_variable.nil?  @test_variable = [$game_player.x, $game_player.y]endif @test_variable != [$game_player.x, $game_player.y]  @test_variable = [$game_player.x, $game_player.y]  pathfinder_command($game_player.x, $game_player.y)end

 

You need to replace pathfinder_command($game_player.x, $game_player.y) with the real call for the pathfinding script that you are using.

Could you please make a video or a picture tutorial where you do the things you just said, cuz it's pretty confusing for me.. Sorry for my stupidity put it'll really help me out if you could! Thanks in advance! :)

 

ALL pathfinder scripts are cpu intensive. If your target is moving and your event has to pathfind with every move, your game is going to lag noticeably.

I've read about that, but then how can you explain why the monster in the game "Ao Oni" is able to pathfind it's way around obstacles, without lag?

Share this post


Link to post
Share on other sites

I'm not familiar with the game - I don't even know if it's an RPG Maker game. So I couldn't tell you. I'm just saying pathfinding scripts do a lot of processing and if you're telling it to re-find its path on every movement (or worse still, on every frame), you'll probably notice it.

Share this post


Link to post
Share on other sites

I'm not familiar with the game - I don't even know if it's an RPG Maker game. So I couldn't tell you. I'm just saying pathfinding scripts do a lot of processing and if you're telling it to re-find its path on every movement (or worse still, on every frame), you'll probably notice it.

It is a game made with RPG Maker XP, and if you want to examine it you can find a lot of gameplay on youtube.

 

Well let's decide there no way around the lag, isn't it possible to make it refind let say every 20 frams or something like that? Making the total of refindprocess smaller but still leaving it effective?

Share this post


Link to post
Share on other sites

Yes. You could do that, or make it pathfind every time the player actually moves (which may be more or less often). I suggest you just find a way to make it pathfind first, and then worry about lag if you experience it.

Share this post


Link to post
Share on other sites

can you tell me how to this? As i said above i'm completely lost, after a bunch of errors and fails... Pics and videos will be a great help also

Share this post


Link to post
Share on other sites

As I said, you need to find a way to make it pathfind first. I'm not aware of all the pathfinding scripts out there, or if any of them will let you pathfind for an event rather than the player. So that's what you have to search for first.

Also, please don't double post, as it's against forum rules. Edit your last post instead.

Share this post


Link to post
Share on other sites

The code I posted earlier is meant to be used in a call script event command, in an event that is set to parallel process. But as I said, you need to replace "pathfinder_command($game_player.x, $game_player.y)" with the actual script call of the pathfinding script that you want to use, that is why I asked you to tell which one you are using :)

Share this post


Link to post
Share on other sites

The code I posted earlier is meant to be used in a call script event command, in an event that is set to parallel process. But as I said, you need to replace "pathfinder_command($game_player.x, $game_player.y)" with the actual script call of the pathfinding script that you want to use, that is why I asked you to tell which one you are using :)

I tried using Modern Algebra's pathfinding script, but with no luck :/

 

As I said, you need to find a way to make it pathfind first. I'm not aware of all the pathfinding scripts out there, or if any of them will let you pathfind for an event rather than the player. So that's what you have to search for first.

Also, please don't double post, as it's against forum rules. Edit your last post instead.

Hmm okay thanks!

Share this post


Link to post
Share on other sites

Okay, I checked a link for his VX pathfinding script. The script command is find_path (x, y) but it is meant to be called inside a move route. So, for using the solution I presented, you need to add this script above Main.

 

class Interpreter  def lph_event    $game_map.events[@event.id]  endend

 

And in the code I posted before, replace pathfinder_command($game_player.x, $game_player.y) with self.lph_event.find_path($game_player.x, $game_player.y)

 

Remember to set the event to parallel process.

Share this post


Link to post
Share on other sites

I tried doing that, where i put the the modern algebra's script code and your solution script in the script editor. Afterwards i made a parallel event with the  find_path (x, y) inside but i get a syntaxerror when every time i activate the monster.. :/ 

 

Edit: i figured out in the end how to make the monster go to a defined x and y, but how do i make it actually follow the character, since the x and y for the character changes as the character move?

Share this post


Link to post
Share on other sites

Open the script editor and put this above Main.

class Interpreter  def lph_event    $game_map.events[@event.id]  endend

 

Create a parallel process event (the event that is going to chase the player) and put a call script command in it. Inside the call script command, put this.

 

if @test_variable.nil?  @test_variable = [$game_player.x, $game_player.y]endif @test_variable != [$game_player.x, $game_player.y]  @test_variable = [$game_player.x, $game_player.y]  self.lph_event.find_path($game_player.x, $game_player.y)end

 

That is it. :)

Share this post


Link to post
Share on other sites

It sounds so simple but i'm still getting that damned syntaxerror

I've taken som screenshot so you can see if i'm doing something wrong or missing something

 

 

The first pic is from the script editor where i copied the long script code from modern algebra's site:

http://i1358.photobucket.com/albums/q768/mightywide/Udklip_zps0acb5c07.png

 

The second pic is also from the script editor where i put the code you told me to above main:

http://i1358.photobucket.com/albums/q768/mightywide/sdfeds_zps9c42b6f3.png

 

This is the event that activates the chase event:

http://i1358.photobucket.com/albums/q768/mightywide/sfesfr_zps649fb0b2.png

 

This is the first event page of the chasing event. It beats the player half to death upon touch, (screen goes red as a part of blood effect) pauses, and then recommences the chase, and makes a game over upon second hit/touch:

http://i1358.photobucket.com/albums/q768/mightywide/sfesf_zpsb010d574.png

 

This is the second event page of the chasing event. Here i put the script you told me to, in a script call:
http://i1358.photobucket.com/albums/q768/mightywide/adweafeas_zps38be09e9.png

 

Hope the pics helped :/

Share this post


Link to post
Share on other sites

What does the error message says? I suppose it could be the way the text gets fitted into the script command window (self.lph_event.find_path its in one line and ($game_player.x, $game_player.y) in the other. Try to making the text look similar to how it appears in my post by deleting spaces.

 

By the way, is not modern algebra's script intended for VX? (And, also, remember to set a graphic for the parallel process event! I don't think you want a ghost chase)

Share this post


Link to post
Share on other sites

Lots of inept posts in here. How about actually informing about the topic before posting misleading statements?

mightywidekiller, there's exactly one single pathfinding script out there in the complete RM universe that does exactly what you want. It's the best implementation of the extremely efficient A* algorithm and uses a dynamic pathfinder request queue which means hardly any noticeably lag, even with a dozen events chasing the player.

 

Here it is: Lagless Path Finder

 

Use in combination with the VX Ace engine to further decrease any lag to nothing.

I for one have a huge map with 5 events on it going for the player: 57fps.

Share this post


Link to post
Share on other sites

ALL pathfinder scripts are cpu intensive. If your target is moving and your event has to pathfind with every move, your game is going to lag noticeably.

Then they are not written very well (assuming a scenario of one event trying to get to tile X). Makes me want to take this as a little weekend project...

♥SOURCE♥ likes this

Share this post


Link to post
Share on other sites

I've set the code up in the exact same format as you wrote it but i still get this error:
 
"Syntax error occured while running the script"
 
And i just found out the modern algebra script isn't for RPG XP, so that might be the thing that causes the problem... do you know a RPG XP compatible pathfinder? Thanks!  :)
 

Share this post


Link to post
Share on other sites

Here it is: Lagless Path Finder

 

I tried the link you provided, but which call script should i use to make my enemy with ID:001 chase the character (which is obviously on the move) ?

Share this post


Link to post
Share on other sites

class Interpreter  def lph_event    $game_map.events[@event.id]   endend

 

should be

 

class Interpreter  def lph_event    $game_map.events[@event_id]  endend

 

One of the many script calls for the script that Terv provided is PathFinder.request(C_ID, X, Y)

C_ID is the id of the event that you want to move, if the event id is 1, use it like this:

 

if @test_variable.nil?  @test_variable = [$game_player.x, $game_player.y]endif @test_variable != [$game_player.x, $game_player.y]  @test_variable = [$game_player.x, $game_player.y]  PathFinder.request(1, $game_player.x, $game_player.y)end

 

@Terv.-

 

Lots of inept posts in here. How about actually informing about the topic before posting misleading statements?

mightywidekiller, there's exactly one single pathfinding script out there in the complete RM universe that does exactly what you want. It's the best implementation of the extremely efficient A* algorithm and uses a dynamic pathfinder request queue which means hardly any noticeably lag, even with a dozen events chasing the player.

Here it is: Lagless Path Finder

Use in combination with the VX Ace engine to further decrease any lag to nothing.

I for one have a huge map with 5 events on it going for the player: 57fps.

 

 

It seems that you do not like people to make misleading statements, so I'll call you on this one. You are making a misleading statement by saying "I for one have a huge map with 5 events on it going for the player: 57fps." as if the size of the map would be the only thing that could test the efficiency of the algorithm implementation.

No, the size of the map is not the most influential thing in regard to lag or time taken to generate the path using A*. It is more important how many obstacles are between the objective and the character, and the distance between both. A* 'aims' the search towards the best looking nodes based on the total cached cost to get to the current node and an estimated cost to get from there to the goal node, so if it founds obstacles in the way, the search is branched towards other nodes and thus it needs additional iterations, resulting in more time to calculate the path.

 

So, it is not just about how big is the map or how many events are "chasing the player" but about the distance between the events and the player and the number of obstacles between both too.

 

And I have taken a look at the code, and it is not the best implementation of A* that I have seen for RPG Maker.. What makes it good is how it manages the use of the implementation with a limit of iterations per frame.

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.