Smart Pathfinding

Discussion in 'JS Plugin Releases (RMMV)' started by Shaz, Oct 24, 2015.

  1. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Smart Pathfinding
    2015.10.21
    by Shaz
     
    Introduction
    This plugin allows you to set up smart pathfinding for events.
     
    How to use
    Add to your plugins folder (file name does not really matter, but I call mine SmartPath.js).  There are no parameters to set.
     
    Use the plugin command SmartPath eventID1 eventID2 to make event 1 find a path to event 2
    Use the plugin command SmartPath eventID x y to make the event find a path to x, y on the map
    Use the plugin command SmartPath eventID cancel to cancel pathfinding for the event
     
    eventID, eventID1 and eventID2 can be a number for a specific event (no leading zeros), 0 for the event issuing the plugin call, -1 for the player, or $gameVariables.value(id) to get the event number from the specified variable (replace id with the variable id, no leading zeros).
     
    x and y can be map coordinates or $gameVariables.value(id) to get the x or y value from the specified variable (replace id with the variable id, no leading zeros).

    The event will continue to follow its target until told to stop. So if the target is another event or the player, if the target moves, the event will adjust its course or follow, depending on how close it is to the target.
     
    Plugin
    Download from pastebin
     
    Credit
    - Shaz
     
    Terms
    - free for use in commercial games
     
    Note
    - the plugin says it works for events OR the player, but I'm not sure that it does work for the player.  I need to re-test that.
     
    Last edited by a moderator: Oct 28, 2015
    #1
    Bex, Leon_Artmann, JLowther and 20 others like this.
  2. Kane Hart

    Kane Hart Elmlor.com Veteran

    Messages:
    656
    Likes Received:
    166
    Location:
    Barrie, Ontario, Canada
    First Language:
    English
    Great Plugin Shaz. Thanks for putting them up on here.
     
    #2
  3. terwilliker

    terwilliker Veteran Veteran

    Messages:
    49
    Likes Received:
    1
    Thanks
     
    #3
  4. Naoya

    Naoya Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    Portuguese
    I think I got a bug:

    SyntaxError: Unexpected number

        at Game_Interpreter.command355 (rpg_objects.js:10436)

        at Game_Interpreter.executeCommand (rpg_objects.js:8894)

        at Game_Interpreter.update (rpg_objects.js:8802)

        at Game_Map.updateInterpreter (rpg_objects.js:6080)

        at Game_Map.update (rpg_objects.js:5987)

        at Scene_Map.updateMain (rpg_scenes.js:417)

        at Scene_Map.updateMainMultiply (rpg_scenes.js:409)

        at Scene_Map.update (rpg_scenes.js:398)

        at Function.SceneManager.updateScene (rpg_managers.js:1673)

        at Function.SceneManager.updateMain (rpg_managers.js:1641)

     

    This happened whenever the script run (I tried putting the call on the movement of the event, and later tried to activate it on a On Key event. I tried the following script calls and all lead to the same error:

     

    SmartPath 0 6

    SmartPath 4 6

    SmartPath 4 1 14

    SmartPath 0 1 14
     
    #4
  5. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    You're using Script Command.  You need to use Plugin Command.
     
    Last edited by a moderator: Oct 26, 2015
    #5
  6. Naoya

    Naoya Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    Portuguese
    Woops, you are right :x Worked flawlessly now
     
    #6
  7. dragoonkain

    dragoonkain Villager Member

    Messages:
    20
    Likes Received:
    16
    First Language:
    English
    This little plugin has made life so much better

    I've made a couple of little tweaks I thought I would share in case they would come in handy for anyone. 

    https://github.com/caseylutz/KCL-MV/blob/master/KCL_SmartPath.js

    First off the ability to reference events by name. I actually created a separate module for this. It adds a findEvent call to the gameInterpeter to allow you to query events by numerical ID or canonical name. You can either include the FindEventsByName script and SmartPath by event names or  you can not include it and just use the numbers. This version of SmartPath will only use the additional script if it's present.

    e.g.:

    SmartPath Lab_001_Hero Lab_001_ExitSmartPath -1 Field_001_CenterSmartPath 3 7I also added a plugin call for waiting until the smart path is reached. 

    SmartPath <event_target> WAITI also added an auto-cancelling trigger to clear the auto-path target once it's reached. This is useful if you are controlling the player and want to stop targeting at the end of the path. If you don't clear his target then he will constantly try to re-acquire it every time you move. 

    SmartPath <event_target> AUTO_CANCELIf your target is actually impassible for whatever reason I've also added a cancellation near (so if you're within 1 tile...)

    SmartPath <event_target> AUTO_CANCEL_NEARNow if you have an event where you want the hero to walk to a given location, wait on him, do a cutscene or whatever, and then resume play you can do that like so:

    Plugin Command: SmartPath -1 Event_LocationPlugin Command: SmartPath -1 Auto_CancelPlugin Command: SmartPath -1 WaitYou can also have some actions take place before the Wait if, for instance, you'd like to have a conversation but make sure the event waits for the target to reach its destination.
     
    Last edited by a moderator: Nov 16, 2015
    #7
  8. jamzkie143

    jamzkie143 CuteGranny Member

    Messages:
    21
    Likes Received:
    12
    First Language:
    English
    Primarily Uses:
    N/A
    how to edit event's direction where it is facing?
     
    #8
  9. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    does that question have anything to do with this plugin?
     
    #9
  10. jamzkie143

    jamzkie143 CuteGranny Member

    Messages:
    21
    Likes Received:
    12
    First Language:
    English
    Primarily Uses:
    N/A
    Hi Shaz, yes. Is there a way to change which direction the event/sprite is facing after it reaches its destination?  
     
    Last edited by a moderator: Oct 28, 2015
    #10
  11. wizaerd

    wizaerd Adventurer Member

    Messages:
    219
    Likes Received:
    26
    First Language:
    English
    You can use the Move Route command to turn or face a character in any position you want...  Doesn't necessarily need to be part of the plugin itself...
     
    #11
  12. dragoonkain

    dragoonkain Villager Member

    Messages:
    20
    Likes Received:
    16
    First Language:
    English
    You could potentially "wait" for the path-finding to finish and then issue a Move Route like wizaerd said. You'd have to "wait" long enough for the subject to find its target, cancel the smart-path and then set your direction. If you use the extensions I mentioned above you can alternatively use the plugin "WAIT" command to halt your event until the subject reaches the target, auto-cancel the smart path and then use move route (this prevents you from having to know exactly how many frames you need before you change direction). 
     
    #12
  13. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    You can add a loop that keeps checking to see if the event's x and y coordinates are where you want them to be - once they are, cancel the pathfinding and use a Set Move Route to make them face the direction you want.  Make sure your loop includes a Wait command so it can come up for air and let other things do their stuff.
     
    #13
    Bex likes this.
  14. djDarkX

    djDarkX Retro & Remastered Music Guru Veteran

    Messages:
    2,699
    Likes Received:
    1,887
    Location:
    Currently unsure...
    First Language:
    Music
    Primarily Uses:
    RMMV
    Shaz, any plans on adding support for followers?  This would make things a lot easier for scripted scenes.
     
    #14
  15. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    The Ace scripts that did that ... what did they do when the cutscene was over and it was time for everyone to get back in line?
     
    #15
  16. djDarkX

    djDarkX Retro & Remastered Music Guru Veteran

    Messages:
    2,699
    Likes Received:
    1,887
    Location:
    Currently unsure...
    First Language:
    Music
    Primarily Uses:
    RMMV
    No, I mean as in having followers, at the start or during a scene (I guess my use of the word scripted was not a wise choice lol), move to various locations instead of using Move Routes with script calls to get them to go where you want during such a scene. Plus if you have the player talk to an NPC and you want followers to be at a very specific place, doing conditional branches to detect where the player is and move the followers accordingly would be tedious. I remember doing this in Ace and it was never fun. I had used Jet's Path Finding with a Follower Script (I believe Tsukihime's) to do what I needed to do. That's what I meant.
     
    #16
  17. jamzkie143

    jamzkie143 CuteGranny Member

    Messages:
    21
    Likes Received:
    12
    First Language:
    English
    Primarily Uses:
    N/A
    Thank you very much for the help, everyone. 
     
    #17
  18. dragoonkain

    dragoonkain Villager Member

    Messages:
    20
    Likes Received:
    16
    First Language:
    English
    I'm quickly running into the same desire myself in cut scenes where multiple people (events) are walking together. It's very tedious. I'm new to RM in general and find "Move Routes" to be very un-intuitive (I wish it let you draw paths visually). I may try to hit up the follower code over the weekend if nobody else tries to tackle it. 

    The other major feature I could see being desirable here is a switch to A* or D*-style pathing. 
     
    #18
  19. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,419
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I know what you mean - my question still stands.  For those Ace scripts that let you control the followers, what did they do (or what did you have to do) when the cutscene was over, to get everyone back where they should be?  I imagine you can't just walk off with your followers scattered all over the map - they don't just automatically go back into line, do they?
     
    #19
  20. djDarkX

    djDarkX Retro & Remastered Music Guru Veteran

    Messages:
    2,699
    Likes Received:
    1,887
    Location:
    Currently unsure...
    First Language:
    Music
    Primarily Uses:
    RMMV
    OH, I'm sorry.  My bad.  I didn't really see how you stated your question (was late night for me and I was derping lol).  Totally my bad.  Um, usually I'd just either have them get controlled via the pathfinding script to the main actor or, if they were clustered around the main actor, just use "Gather Followers".
     
    Last edited by a moderator: Oct 29, 2015
    #20

Share This Page