Author Topic: [XP] Advanced Pathfinding by Event Name  (Read 6580 times)

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
[XP] Advanced Pathfinding by Event Name
« on: October 12, 2011, 05:45:33 PM »
Advanced Pathfinding & Carrots
Authors: ForeverZer0, modifications by mad.array
Version: 1.01a
Type: Path finding by Event Name, includes array support.
Key Term: Custom Movement System

Introduction

A modification of ForeverZer0s Advanced Pathfinding script (Found here). As well as using tile co-ordinates, the path finding target can now be defined as an event with a specific name. An array of event names can also be input and will be randomly selected.

If multiple events with the given name are found, the script will find the nearest instance and move to that example. Note that unless the target events Through flag is set, you will need to have a range of 1 or more.

The main reason I decided to work on this was to help achieve the feeling of a busy town. I wanted people to have their own little routines and go to specific places such as market stalls and blacksmiths. But how to do it? Well after looking at Pathfinding in general I stumbled accross ForeverZer0s script and started tinkering (I actually came accross it while researching something unrelated, but that just personifies my inability to focus).

Features

  • All the features of ForeverZer0s Advanced Pathfinding.
  • Move to location of another event.
  • Will find the nearest instance of event with the right name.
  • Can choose between events with different names.

Screenshots

No screen shots, as they don't really show movement.

Demo

No demo at the moment. Sorry!

Script

Insert above Main & below default scripts.
(click to show/hide)

Instructions

Place script below default scripts and above "Main".
Further instructions are within the script and demo.

Compatibility
Should be compatible with most scripts. Cannot be used in conjunction with the original Pathfinding script, but it shouldn't need to, should it?

Credits and Thanks

  • ForeverZer0 for the original script
  • Credit goes to Peter Hart, Nils Nilsson and Bertram Raphael for the original search algorithm that was implemented

Author's Notes

To use the pathfinding script you can follow ForeverZer0s instructions for the default methods or... to move to an event with a specific name use the Script command with these details:

Code: [Select]
pathfind("carrot",y, e, r)
  • "carrot" is the name of the event to search for. It is case sensitive but only needs to be in quotation marks in the script call, not in the actual event!
  • Y isn't strictly needed for this mode, but cannot be left blank so I advise just putting a 0 in
  • E is the event number, identical to ForeverZer0s script
  • R is range. How many tiles away the moving event will be from its destination before it's satisfied and stops

If you want your event to choose from multiple events then your Script call should look like this:

Code: [Select]
pathfind(["carrot","orange","apple],y, e, r)
Pretty much the same as before. Just be aware of the limitations of the Script call in RMXP...

I'm afraid I'm a rather haphazard coder so if there are any problems then let me know.


History

Version 1.01a

  • $game_actor changed to $game_player as actor has no x or y.
  • Fixed problem with 'normal' move routes crashing the game when blocked due to not having awareness of the failure_proc

Enjoy
« Last Edit: January 16, 2012, 02:41:58 PM by mad.array »
"To walk at speed, manage or oversee..."

"RUN!"

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19906
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: [XP] Advanced Pathfinding by Event Name
« Reply #1 on: October 12, 2011, 06:14:59 PM »
I just wanted to point out that the A* algorithm is public domain so you technically don't have to credit the people who originally invented it.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #2 on: October 12, 2011, 06:21:12 PM »
I didn't think so, but I just chose to give proper credit to them anyways.
Others don't have to for their games, so maybe I should have placed that in Author's Notes instead of Credits. :P
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #3 on: October 12, 2011, 06:30:44 PM »
Duly noted Blizzard. I hope everything else fits the standard.
"To walk at speed, manage or oversee..."

"RUN!"

Offline Poe

  • Awakened Visionist
  • **
  • Posts: 55
  • LV: 2
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #4 on: November 10, 2011, 09:58:54 PM »
i got an error running this, and i just started with scripts this week so i figured i'd use this opportunity to learn something and find it myself.:p

at line 151 about it refers to $game_actor to get x and y positions, but that inherits from game_battler which has no x&y variables, so this needs to be $game_player to get them from game_character i think. works now anyway.

also:
Quote
E is the event name or number, identical to ForeverZer0s script
if it's a name to check for, wouldn't that give some trouble with this thing on line 147?
Code: [Select]
     if args[0] >  0cos it's a string and not an integer... <- not sure about that and i wouldn't know how to fix it either.


could you add a check on this so it ignores erased events?
« Last Edit: November 11, 2011, 01:45:04 PM by Poe »

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #5 on: January 12, 2012, 06:03:46 PM »
@Poe: I'm going to have to look through this. I'm not at my home computer at the moment and looking through it in Wordpad isn't very productive. Adding a check for erased events shouldn't be too tough. Sorry I couldn't provide a swifter response, I've not been online for some time. I'll have to get back to you I'm afraid.
"To walk at speed, manage or oversee..."

"RUN!"

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #6 on: January 17, 2012, 12:42:43 AM »
I've gone ahead and done a minor update to the script. $game_actor has been changed to $game_player thanks to Poe being on the ball.

Also I've altered a line of code from a part of ForeverZer0s original script. I'm not sure if I was the only one having this problem but when using the APF script and I had an events 'normal' move route interrupted, it threw an error relating to the default move route not understanding failure_procs. I didn't want to post in FZs original thread because I wasn't sure if it was a necro (I've never found the rules for this place). But if people are having the same problem and are interested in fixing it then do the following:

Line 466 should just read 'else'. Change it to 'elsif paths[0] != nil'. Without the quotation marks. This will only call failure_procs if the event is using the pathfinding and if there ARE failure_procs.

So, happy pathfinding!
"To walk at speed, manage or oversee..."

"RUN!"

Offline Raziel 0128

  • Trained Member
  • *
  • Posts: 13
  • LV: 0
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #7 on: January 08, 2013, 07:09:01 PM »
Apologies for bumping an old topic.

I had a quick question about using the success proc function. I'm trying to use this script on an NPC enemy moving around on the map. I'm trying to make it head towards the exit of the map unless the player is within 5 tiles of the player in which case it'll chase after you until you get too far away and return to heading to the exit. Once at the exit I'd like to activate either a regular switch or a self switch to turn the event off permanently.

The event itself is a parallel process event with an enemy graphic, and uses the [url =Event Range Conditions]http://forum.chaos-project.com/index.php/topic,9516.0.html[/url] script inside a conditional branch to determine how close the player is. It the activates a "Set move route" and move towards the player with if the player is close and in the "else" branch is uses this script to return to its route.

I've used the following code inside a call script.
Code: [Select]
pathfind("Exit",0, 48, 1, Proc.new {
$game_switches[434] = true })

The event will successfully aggro and break aggro with the player however once it reaches the exit event the game crashes and gives the following error:
Quote
Script: 'Game_Map' line 216: SystemStackError occured.
stack level too deep

How do I solve this issue? Thanks for any help.

Offline Mason Wheeler

  • Trained Member
  • *
  • Posts: 28
  • LV: 2
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #8 on: March 28, 2016, 01:52:22 PM »
This looks very nice, but I see one thing that's a bit worrisome: a class in the global namespace called "Node".  That's a generic enough name that it could easily conflict with other scripts that work with trees or graphs.  It might be better to call it PathfindNode or AStarNode or something.

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2957
  • LV: 369
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #9 on: March 28, 2016, 08:12:08 PM »
mad.array hasn't been on for a couple years, so this kind of is grave digging.

While I guess "Node" is a generic class name, I don't really know of any scripts that even use "Node". Anything that does is most likely for path finding, which I don't know why anyone would use two path finding scripts.

It's not even that big of a problem either. The game would tell you that straight away.



(click to show/hide)
NNID: KK20-CP

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19906
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: [XP] Advanced Pathfinding by Event Name
« Reply #10 on: March 28, 2016, 11:08:00 PM »
You can use my script if it bothers you too much. xD
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Mason Wheeler

  • Trained Member
  • *
  • Posts: 28
  • LV: 2
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #11 on: March 29, 2016, 01:53:55 PM »
It's not even that big of a problem either. The game would tell you that straight away.
Would it?  It looks like if you declare a class with the same name in two different places, Ruby just treats it like all the same class and merges everything together.

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2957
  • LV: 369
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: [XP] Advanced Pathfinding by Event Name
« Reply #12 on: March 29, 2016, 05:30:00 PM »
I meant that the way Node class would be used would be different in both scripts. Clearly one is going to dominate over the other (i.e. no use of alias) so one of the scripts is going to crash as soon as you create a Node instance.



(click to show/hide)
NNID: KK20-CP