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 .
×

[Script] Patrolling Token (gmnotes based)

1403200178

Edited 1403201132
In an attempt to make my GM's life easier I wanted to rig up a script for patrolling units where he didn't have to go modify javascript to change the paths of units. So I worked with the only field I could find on the token that he wasn't using and was long enough to hold a big patrol path, gmnotes. This script allows the GM to enter in directions in the gmnotes field and the script will interpret what the pathing of the token is. Setup required: Name the token: Guard insert instructions into the GM Notes field ( in CAPS, with no spaces) [Optional] Set Aura 1 to set the Line of Sight of the unit [Optional] Set Bar 2 to the desired perception roll for stealth detection Set the green status marker on the token. Maybe restart the script if the unit doesn't being patrolling. There are 5 commands currently implemented: U - up D - down L - left R - right H - hold A simple closed loop of square movement would be: LURD There is currently no limitation on how large of a patrol path one enters in so long as it fits in the gmnotes field on the token. One important thing to note is that there is no return to home logic built in. The GM needs to make sure that they implement a full circuit returning to the starting position to prevent the token from wandering aimlessly off into the map as the script loops endlessly until it detects a unit. There are a number of things I'd like to improve with this script but this is a first pass for him to get working with in our campaign. Todo List: Implement a reverse path command, so that the GM doesn't have to worry about the token going crazy if they don't close the circuit themselves. Rotate token to "face" the direction it is moving. This will require the GM to have it facing the direction of the first move command since tokens are uniquely designed. Make script generic so that it can run multiple tokens if they are all named the same or similar each on their own unique gmnotes path. BIGGIE! This is the one I really want to implement but am not currently sure how to do if it's even possible. That last one I haven't delved enough into the API to know if it's possible, I rigged this up in a couple hours basing it on the brilliant work of Riley and Emile's patrolling scripts Thread of their awesomeness . Ideally I want to be able to grab all the objects with a similar name like "Guard1", "Guard2", "Guard3" based on the Guard bit so that each token can have a unique name to make the GM's life easier but still get detected and run by the script. I'll be digging into the API to see if this is possible and how to get this stuff in. If anyone knows how to accomplish any of this feel free to chime in, fork the code, or whatever. Happy gaming all. gmnotespatrol.js
1403202547
Lithl
Pro
Sheet Author
API Scripter
My recommendation? Instead of grabbing tokens based on the token name, grab the tokens based on a specific prefic in the GM Notes. Example: var danielb_patrol = danielb_patrol || {}; on('ready', function() { var patrollingTokens = filterObjs(function(obj) { if (obj.get('type') != 'graphic' || obj.get('subtype') != 'token') return false; var gmNotes = obj.get('gmnotes'); return gmNotes.indexOf('patrolPath:') === 0; }); _.each(patrollingTokens, function(token) { danielb_patrol.executePatrolPath(token); }); }); danielb_patrol.executePatrolPath = function(token) { var path = token.get('gmnotes').substring(11); // patrol logic }; Given that example, any token whose GM Notes field begins with "patrolPath:" would work, and the names could all be different. You could also only look at the first line of the GM Notes field (should be: path = path.substring(0, Math.max(path.length, path.indexOf('\n'))); ), so that your GM would be free to still add notes to the token if he wanted to.