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

Random movement

1455606857

Edited 1455606874
Is there a script out there, or someone much better than I, that, after a player moves their token, can move that token in a random direction a distance based on how far the player originally moved? My players may enter a different plane of existence where distance and direction are much harder to control the further you move.
1455624312
The Aaron
Pro
API Scripter
There isn't one that I know of. The hardest part of such a script would be making sure the token doesn't move into invalid locations. (Through a wall, into solid rock, into a creature, etc. )
That shouldn't be a problem since the area is a mutable void of chaotic nothingness. So there are now walls or rocks.
1455650672
The Aaron
Pro
API Scripter
So, the requirements are: When a player moves their token, their token is moved randomly for a given map: Is the move instead of their original move, or in addition to it? The distance is equivalent?  Move 30', get moved 30' Keep tokens on the map. if they would move off the map, should they instead move the other direction move as far as possible and stop move to the wall then move the remaining distance in another direction wrap around to the other side of the map
1455651283

Edited 1455651391
Moving as far as possible then stopping would be what I would go for. In addition I was thinking that they would be moved half the distance they initially tried to move. So if they move 30 feet they are then moved and additional 15 feet in a random direction. The half distance will give them some semblance of control. They're still moving in the general direction they wanted, but there is difficulty in locking down the actual movement. So shorter movements allow for more precise movements.
1455653209
The Aaron
Pro
API Scripter
The biggest problem I see then, is someone drag moving 5' at a time.  Maybe have the random move be applied on turn change?
Well all my players use the waypoint space key move thing so I don't know how that works.
1455654092
The Aaron
Pro
API Scripter
That would work fine.  So, the next question to answer, which tokens get affected?  In the API we can't tell who moved a token (I've mentioned this to the powers that be and hope for a resolution in the next update, but we'll see...), so how best to handle this? Options: When a token is moved, randomly move it if it is on a particular page and... it is any token on the object layer it is any token on the object layer that CAN be controlled by a player it is any token which has been designated by a particular command it is any token with <choose> status marker on it
unsure what it's called. But it's the far left and fourth row down. "any token with status marker on it" would just be swell!
1455669952
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Can a variation of the bump script be used here? 1) Place status marker on. 2) Player loses control of the actual token.... and gets a clear "bump" png. 3) Now any compeleted movement gets randomized.... also gives you a chance to respect walls... and manage lighting. I also think the dissociation would add to the effect... "I tired to move over here... but my token went the other way." ... plus we will have a pretty good "drunk" script. 
I wanted to give my players a little control. With the way I've described it they should be moving in generl direction they wanted, but sometimes only half as far or a much further distance. And sometimes they go to the left or right, but still in the way they want to go. 
1455685257

Edited 1455715879
The Aaron
Pro
API Scripter
For the record, that's called the "overdrive" symbol.  =D Here ya go, happy Rolling! on('ready',function(){     "use strict";     var distance=function(p1,p2) {              return Math.sqrt(Math.pow(p2[0]-p1[0],2)+Math.pow(p2[1]-p2[1],2));             },         moveDistance=function(lastMove){             return _.chain(lastMove.split(/,/)) .map(parsefloat)                 .groupBy(function(v,k){                     return Math.round((k-1)/2);                 })                 .reduce(function(m,p){                     if(m.pp){                         m.sum+=distance(m.pp,p);                     }                     m.pp=p;                     return m;                 },{                     pp:null,                     sum:0                 })                 .value()                 .sum;         };          on('change:graphic',function(obj,prev){         var page, move, theta,tprime,lprime;         if( 'objects' === obj.get('layer')             && -1 !== obj.get('statusmarkers').indexOf('overdrive')             && (obj.get('top') !== prev.top || obj.get('left') !== prev.left)         ) {             page=getObj('page',obj.get('pageid'));             move = moveDistance(obj.get('lastmove'));             if(!move){                 move=distance([obj.get('left'),obj.get('top')],[prev.left,prev.top]);             }             move/=2;             theta=(randomInteger(360) * (Math.PI/180));             tprime = Math.max(35,Math.min((page.get('height')*70)-35,obj.get('top')+move*Math.sin(theta)));             lprime = Math.max(35,Math.min((page.get('width')*70)-35,obj.get('left')+move*Math.cos(theta)));                          obj.set({                 top: tprime,                 left: lprime             });         }     }); });
would it be possible for you to run me through this script? If not I understand.
1455715858

Edited 1455737711
The Aaron
Pro
API Scripter
Sure.  To use it, all you need to do is put it in a tab on the API Scripts page for your Game.  Then any token on the objects layer with the "overdrive" symbol on it will be randomly repositioned whenever they are moved. If you want to understand what the script is doing, here's an annotated version: // run this function when the api is fully loaded.  light going when the light turns green, instead of one of the yellow ones. on('ready',function(){     // tells the javascript engine to make certain sloppy coding practices into errors     "use strict";          // starts defining things.  first is a distance function     var distance=function(p1,p2) {              // pythagorean theorem for distance between two points             return Math.sqrt(Math.pow(p2[0]-p1[0],2)+Math.pow(p2[1]-p2[1],2));             },         // function to determine how long a move chain was         moveDistance=function(lastMove){             return _.chain(lastMove.split(/,/))   //< break the move string up by commas                 .map(parseFloat)                  //< turn each thing into a number                 .groupBy(function(v,k){           //< break up the array into points                     return Math.round((k-1)/2);                 })                 .reduce(function(m,p){            //< walk the points adding the distance between them.                     if(m.pp){                         m.sum+=distance(m.pp,p);                     }                     m.pp=p;                     return m;                 },{                     pp:null,                     sum:0                 })                 .value()                 .sum;                             //< return just the sum distance         };          // run this function when graphics (tokens) are changed     on('change:graphic',function(obj,prev){         // setup some variables for later use         var page, move, theta,tprime,lprime;         // determine if we want to affect this object         if( 'objects' === obj.get('layer')   /* on the objects layer */             && -1 !== obj.get('statusmarkers').indexOf('overdrive')  /* has the overdrive symbol */             && (obj.get('top') !== prev.top || obj.get('left') !== prev.left)  /* has changed position */         ) {             // grab the page object based on the page the token is on (for later use bounding)             page=getObj('page',obj.get('pageid'));             // figure out how far the token moved             move = moveDistance(obj.get('lastmove'));             if(!move){                 // if it was just dragged directly, the lastmove field won't give us a distance,                 // use the distance between where it is now and where it was instead                 move=distance([obj.get('left'),obj.get('top')],[prev.left,prev.top]);             }             // cut move in half.  move/=2  is the same as move = move/2              move/=2;             // get a random angle in radians             theta=(randomInteger(360) * (math.pi/180));             // calculate the new top, bounded by half a unit from the top and bottom edge of the map             tprime = Math.max(35,Math.min((page.get('height')*70)-35,obj.get('top')+move*Math.sin(theta)));             // calculate the new left, bounded by half a unit from the left and right edge of the map             lprime = Math.max(35,Math.min((page.get('width')*70)-35,obj.get('left')+move*Math.cos(theta)));                          // set the object's new position             obj.set({                 top: tprime,                 left: lprime             });         }     }); });
Those annotation are awesome, thankyou.
1455731691

Edited 1455731961
So maybe I did it wrong, but the script isn't working. I put it in the API with the title Randmove.js and the objects with the overdrive symbol aren't being moved randomly.
1455732085
The Aaron
Pro
API Scripter
Hmm. If you want to pm me an invite and GM me, I can come diagnose it.   You could add some log() statements a few places.  Is the token on the objects layer?  You might need to resale the script if you joined after adding the script. The API Sandbox crashes sometimes on join. 
Sorry, this might be usefel....
:(
1455737672
The Aaron
Pro
API Scripter
And that explains the "indexof" error.  Should have been "indexOf"
1455737775
The Aaron
Pro
API Scripter
(Fixed the prior posts to have the corrected script)
So which one would you suggest I use?
1455738162
The Aaron
Pro
API Scripter
For simplicity, I deleted the duplicates.  You can use either the annotated or unannotated versions. =D
1455738226

Edited 1455738261
Well now it works, however the random movement is often very small. It doesn't seem to be based on half the actual distance moved. Though before we go on, I want to thank you for all your help.
1455738830
The Aaron
Pro
API Scripter
No worries. =D  It's a fun problem.  If you add: log('Move distance is: '+move); right after move/=2; you can see the distance it will adjust by.  (70 == one unit)
I get it. I'm just very meticulous about distances in my games. I set all the maps to be as accurate as possible for the measure tool. The script works fine now. I was testing it with token that were much bigger than they should be on a map that wasn't scaled properly. I switched maps and it works wonderfully. 
1455741854
The Aaron
Pro
API Scripter
Sweet!  =D  Glad to hear it!   I'd love to hear back once you've "used it on your players" about how it went, and if you have any suggestions for improving or expanding it. =D
I'll be sure to keep you informed. It could take a while though, they spent the last 2 months in the same dungeon due to indecisiveness.
1455747671
The Aaron
Pro
API Scripter
I've got time! =D