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

Snap to Center grid API?

Hey there, I'm fairly new to Roll20 and brand new to using API. Does anybody know if there is a script for toggling the map grid so tokens automatically snap to the center of the squares when you move them? I've been using 75% sized tokens to represent small creatures so that my players can easily differentiate them from the tiny ones and medium ones, but the small tokens in my compendium come sized the same as the medium creatures. If there was an easy way for me to snap them onto the grid properly I could resize them in just a couple clicks, but the way I have to do it currently has me creating entirely new token art every time I want to resize them--which is kinda sucky lol. so yeah, anybody know if there are any solutions using the API, or is this not possible?
1591750495
The Aaron
Roll20 Production Team
API Scripter
Sure, here's one I call CenterSmalls: on('ready', () => { const precise = true; const sigma = 1; on('change:graphic',function(obj,prev){ if( ( ['gmlayer','objects'].includes(obj.get('layer')) ) && ( !obj.get('isdrawing') ) && ( obj.get('left') !== prev.left || obj.get('top') !== prev.top) && ( obj.get('width') < 70 || obj.get('height') < 70) ){ let w=obj.get('width'), h=obj.get('height'), t=obj.get('top')-(h/2), l=obj.get('left')-(w/2); if( !precise || ((t%70)<=sigma && (l%70)<=sigma) ){ obj.set( { left: obj.get('left')+35-(obj.get('width')/2), top: obj.get('top')+35-(obj.get('height')/2) }); } } }); });
1591750615
The Aaron
Roll20 Production Team
API Scripter
Also, you can use TokenMod to set the size of selected tokens: !token-mod --set size|.75g And if you want to store that as the default token so it's right the next time you pull it out: !token-mod --set size|.75g defaulttoken
Awesome, thank you. This sounds perfect.
Very cool!