Jump to content


Photo

Pathfinder script and how to use it?

rpg maker xp scipt script enemy chase follow path finding

This topic has been archived. This means that you cannot reply to this topic.
36 replies to this topic

#1 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 05 March 2013 - 05:37 AM

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!  :)



#2 Sindaine

Sindaine

    Tired Gamerz Studio

  • Members
  • 149 posts

Posted 05 March 2013 - 06:20 AM

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


Edited by Sindaine, 05 March 2013 - 06:21 AM.


#3 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 05 March 2013 - 06:28 AM

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



#4 Sindaine

Sindaine

    Tired Gamerz Studio

  • Members
  • 149 posts

Posted 05 March 2013 - 08:00 AM

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



#5 Breaking Owl

Breaking Owl

    We are the cooks.

  • Early Adopter
  • 268 posts

Posted 05 March 2013 - 09:16 AM

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]
end
if @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.


FR2_zpse30d9ab6.png


#6 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 14,513 posts

User's Awards

        

Posted 05 March 2013 - 03:08 PM

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.
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com

#7 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 05 March 2013 - 04:03 PM

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]
end
if @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?



#8 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 14,513 posts

User's Awards

        

Posted 05 March 2013 - 04:09 PM

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.
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com

#9 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 05 March 2013 - 04:20 PM

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?



#10 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 14,513 posts

User's Awards

        

Posted 05 March 2013 - 04:24 PM

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.
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com

#11 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 05 March 2013 - 04:43 PM

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



#12 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 05 March 2013 - 04:44 PM

or just a step by step description would be fine



#13 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 14,513 posts

User's Awards

        

Posted 05 March 2013 - 05:02 PM

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.
Avatar by Nio Kasgami

18169c77d45bf093.jpg18169c77ee71a21e.png18169c77eb8a1676.png47e3eb338e149021.png47e3eb33011708d4.jpg47e3eb33c3fcdd85.jpg43b995025d32e369.jpg18169c77d1548695.jpg18169c77d05acf45.jpg43aa62e584d51b37.jpg18057e87da521186.jpg

Amaranth Games
http://www.amaranthia.com

#14 Breaking Owl

Breaking Owl

    We are the cooks.

  • Early Adopter
  • 268 posts

Posted 05 March 2013 - 06:02 PM

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 :)


FR2_zpse30d9ab6.png


#15 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 06 March 2013 - 12:53 AM

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!



#16 Breaking Owl

Breaking Owl

    We are the cooks.

  • Early Adopter
  • 268 posts

Posted 06 March 2013 - 06:34 AM

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]
  end
end

 

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.


FR2_zpse30d9ab6.png


#17 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 06 March 2013 - 08:00 AM

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?


Edited by mightywidekiller, 06 March 2013 - 08:32 AM.


#18 Breaking Owl

Breaking Owl

    We are the cooks.

  • Early Adopter
  • 268 posts

Posted 06 March 2013 - 09:23 AM

Open the script editor and put this above Main.

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

 

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]
end
if @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. :)


FR2_zpse30d9ab6.png


#19 mightywidekiller

mightywidekiller

    Member

  • Members
  • 17 posts

Posted 06 March 2013 - 02:34 PM

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.photobu...zps0acb5c07.png

 

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

http://i1358.photobu...zps9c42b6f3.png

 

This is the event that activates the chase event:

http://i1358.photobu...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.photobu...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.photobu...zps38be09e9.png

 

Hope the pics helped :/



#20 Breaking Owl

Breaking Owl

    We are the cooks.

  • Early Adopter
  • 268 posts

Posted 06 March 2013 - 07:08 PM

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)


FR2_zpse30d9ab6.png