Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Script] Patrolling NPCs With Options

April 26 (7 years ago)

Edited April 26 (7 years ago)
MyRoll20Stuffs
API Scripter
I saw a simple script floating around to make an NPC patrol an area but it was hard coded for 1 NPC and had no way to change settings except in the script itself. I wanted something better and more flexible but also something that didn't use a tokens name or bars so I could still use an NPCs nameplate and stats and have them stop patrolling and join in a battle. 

SO - You set the settings of the patrolling NPC in GM Notes and use the green status marker to toggle patrolling on/off. There are 2 global settings. global_delay (how long to wait between each movement) and unit_size (how big one square on your map is)

The settings in GM Notes are "Direction", "Spaces to Move", "Speed (Percentile)"

So if I put this in GM Notes:
North,5,75

The NPC will move north 5 spaces at 75% speed (With a default unit_size of 70 that means they will move approximately 7 times to traverse 5 squares) then once they reach their destination they will turn rotation of the token to the south and walk back the way they came. This repeats until the green status marker is removed from the token. You can toggle it off in mid-patrol and when you turn it back on the NPC will patrol again exactly from where they left off. Good for instances where the party stops a patrolling city watchman to ask a question and he stops his patrol then resumes it when the party leaves.

Here is a gif (CLICK TO VIEW) of 3 seperate NPCs patrolling, one at 100% speed, one at 75% speed and one at 50% speed.



Here is the gist:
https://gist.github.com/kastion/78091c172d3f2e8ea781d3dd69c0a873

Version 0.4.19
Now saving current position on patrol path so that when the list is made again for new patrol tokens it doesn't restart a patrollers path from 0.

Version 0.4.18
Settings can be changed and updated live now. You no longer need to restart the API to start new NPCs patrols.

Version 0.3.18
Added commands for changing global delay and unit size.

Version 0.2.18
Introduced more error handling. Regardless of what value GM Notes is set to it will not crash API and use default patrol settings.

Version 0.2.17
Case insensitive functionality added when specifying direction in GM Notes (Takes "North" or "north" for example)

Version 0.2.16
Error handling for GM Notes added with default patrol settings specified if omitted.

Version 0.2.15
Updates to help menu for future command integration.

Version 0.2.14
Have the core functionality working as intended.

If anyone has any suggestions for new functionality or changes I should add to this let me know. As it stands right now new PatrolNPCs are only updated and added to the list of patrolling NPCs on API startup. Didn't think much of how I could have it update live but if anyone has any suggestions on how to do that let me know I'm all ears.
EDIT:
Patrol NPCs can now be updated and will take action as soon as the green status marker is toggled. Found a way to clear my interval and do a new setInterval.
April 26 (7 years ago)

Edited April 26 (7 years ago)
Something I think would be a useful addition to this script is to give the user a way to visually set the patrol path. For example you start by moving the token along the patrol path, either using way points or along the path or not, and then run a command that will update the patrol path for the selected token. You can even directly access this information using the lastmove value of the token. Ideally, this could also update the GM info for the token so that the user could copy paste the route into another token.

This looks very cool!
April 26 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
One thing I've wondered about the Patrol script (and now your improvement): is this like animated action going on all the time, or does the patrolling token update on a turn on the turn tracker? I've shied away from things that feel too much like a video game.
April 26 (7 years ago)
MyRoll20Stuffs
API Scripter

keithcurtis said:

One thing I've wondered about the Patrol script (and now your improvement): is this like animated action going on all the time, or does the patrolling token update on a turn on the turn tracker? I've shied away from things that feel too much like a video game.

It's an animated action going on at all times. It's not tied to the turn tracker at all.
April 26 (7 years ago)

Edited April 26 (7 years ago)
MyRoll20Stuffs
API Scripter
I updated the gist and made some changes to the script. Found out how to clear a setInterval and start a new setInterval. Patrol NPCs paths are recalculated on graphic change meaning as soon as the green status marker is toggled on the token it will begin patrolling. No more need to restart API to update the list of patrolling NPCs.

EDIT:
Needs some more work still so it doesn't restart the patrol from midway through it when there is a graphic change. I suspect I will be working on this for a while so check back for updates later or tomorrow if you're interested.
April 26 (7 years ago)

Edited April 26 (7 years ago)
MyRoll20Stuffs
API Scripter

keithcurtis said:

I've shied away from things that feel too much like a video game.
I guess this is where we have different views on how the game should be ran. I'm not using voice / video - running a text only game - and I want as much as possible to be automated or have special FX to give the game world a feel that it is alive and that your actions actually show up on the VTT. For example I have custom written macros for every PCs and NPCs attacks that play appropriate SFX and do a VFX. I'm using this in conjunction with the Pathfinder Community Sheet and Pathfinder Companion Script to streamline gameplay and make it run as smooth as possible. When a PC selects their bow attack from the macro menu in chat, they select a target then hear a twang and see an arrow fly at the targeted token. It's this kind of stuff that I've been using the API for. I guess that's where our views on how the game should be ran when using a VTT differ.

EDIT: I just thought of another thing I did in the same vein as what I described. I have an encounter where the party is going down a river in a boat. 4 lizardfolk rise to the surface of the water and ambush them with nets. I use the token "bounce" script to simulate floating in the water and make it look like the lizardfolk are bobbing up and down in the river. I also use the bounce script for an intelligent bag of holding that bounces around as it "walks". I've got plenty more situations like this where I've used bounce, patrolling npcs, SFX, PageFX or other scripts to make the game world feel alive. I also liberally use background SFX like ambience in a tavern of peoples background conversations or the sound of rushing water when going down that river I mentioned in a boat.
April 26 (7 years ago)
MyRoll20Stuffs
API Scripter

Kyle G. said:

Something I think would be a useful addition to this script is to give the user a way to visually set the patrol path. For example you start by moving the token along the patrol path, either using way points or along the path or not, and then run a command that will update the patrol path for the selected token. You can even directly access this information using the lastmove value of the token. Ideally, this could also update the GM info for the token so that the user could copy paste the route into another token.

This looks very cool!

I was thinking about maybe making it a bit more complex by allowing multiple lines for a path to walk. So the next path would be on the next line in the GM Notes. Example:

North,5,75
East,5,75
South,5,75
West,5,75

Would make the NPC walk in a square 5 x 5 clockwise, then follow the same path backwards counter-clockwise with the way it's setup right now. I'm not looking to get that complex with it just yet - this is my very first attempt at my own API script - but it's something to think about for the future.
April 26 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Kastion said:

keithcurtis said:

I've shied away from things that feel too much like a video game.
I guess this is where we have different views on how the game should be ran. I'm not using voice / video - running a text only game - and I want as much as possible to be automated or have special FX to give the game world a feel that it is alive and that your actions actually show up on the VTT.
I understand where you are coming from. I have a host of similar things (I have a Kill button that X's out a token and plays the Wilhelm Scream, and often attach sound effects to spells and attacks.) I prefer to have them happen at discreet times based on user input. If I had a token moving around on it's own, my players would be bugging me about where it was on their turn, for instance. Likewise, I haven't gotten into the "It's a Trap!" script. I like automation, but of the pushbutton variety, not the sort that operates on its own.

But this is your thread. I did not intend to derail, merely wished to understand how people use this ability. Thanks :)
April 26 (7 years ago)
MyRoll20Stuffs
API Scripter

keithcurtis said:

Kastion said:

keithcurtis said:

I've shied away from things that feel too much like a video game.
I guess this is where we have different views on how the game should be ran. I'm not using voice / video - running a text only game - and I want as much as possible to be automated or have special FX to give the game world a feel that it is alive and that your actions actually show up on the VTT.
I understand where you are coming from. I have a host of similar things (I have a Kill button that X's out a token and plays the Wilhelm Scream, and often attach sound effects to spells and attacks.) I prefer to have them happen at discreet times based on user input. If I had a token moving around on it's own, my players would be bugging me about where it was on their turn, for instance. Likewise, I haven't gotten into the "It's a Trap!" script. I like automation, but of the pushbutton variety, not the sort that operates on its own.

But this is your thread. I did not intend to derail, merely wished to understand how people use this ability. Thanks :)

Oh I totally understand and this is not something I would leave running in the background if a fight broke out. The second it was time to roll for initiative I would disable all patrols on the map (and likely these NPCs would be joining in the fight, which is why I coded this to use the GM Notes field so the bars were free for combat data)

I'm of the same mind I like automation but like you said of the pushbutton variety. This patrol script differs from any other script I've used to date in that it's something that runs on its own in the background. But like I said I would immediately halt it the moment turn order started.
April 26 (7 years ago)
MyRoll20Stuffs
API Scripter
Thanks to some coaching from The Aaron I got the script saving the current position on patrol path so that when the list is made again for new patrol tokens it doesn't restart a patrollers path from 0.

Thanks again Scriptomancer!
April 26 (7 years ago)
Gold
Forum Champion
Might be useful to compare with the Waypoint Patrol API script by Matt, (this is the one I currently use for similar effect but different options), 

https://app.roll20.net/forum/post/2991336/script-p...
April 26 (7 years ago)
MyRoll20Stuffs
API Scripter

Gold said:

Might be useful to compare with the Waypoint Patrol API script by Matt, (this is the one I currently use for similar effect but different options), 

https://app.roll20.net/forum/post/2991336/script-p...

Was not aware this script existed. The only thing I found when searching for scripts related to patrolling NPCs was this:
I'll check it out thanks for the heads up.