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

Range Calculations on Maps with different scale

1632491799

Edited 1632491812
In last nights game, we noticed that all of the range calculations for scriptcards were doubled.  Fireball, Dawn, etc. were 2x the range they should have been.  We are on a big map (Xonthal's Tower from Tyranny of Dragons) and like the last map (Neronvain's Stronghold), the cell width on the map is set to 0.5 (what a friggin pain!). On maps such as these, do I need to go in and change the range calculation for every scriptcard?  Or is there a different way I should be measuring distance so that it works regardless of what the map scale is set to?     Also, side question on maps that are set to 0.5 scale: is there anything that can be done about the token overlays (health bars, status icons)?  They are 2x the size they are normally.  The tokens are still one square big, but everyone on the token is 2x the size, covering most of the token.   
1632492355
The Aaron
Roll20 Production Team
API Scripter
For the first question, that sounds like a bug in ScriptCards that Kurt will want to fix.  Basically, he just needs to multiply by cell width to get the right measurement value. For the second, there's nothing you can do to fix the UI short of resizing everything so that you can have the cell width set to 1.  I actually have a script for that if you want to try it out on a copy of the map and see how it does.  There's a lot of parts to resizing, and some guess work sometimes, so it's definitely something you'd want to try on a duplicate. =D
1632492754
David M.
Pro
API Scripter
You can retrieve the grid size from the page attributes ( wiki  desc), then multiply as Aaron described. !script {{   --#activepage|playerpage   --=gridSize|[*P:snapping_increment]   --+size|[$gridSize] }}
1632498596
Kurt J.
Pro
API Scripter
Good catch :) The latest version on the GitHub  (v1.4.4) now takes snapping_increment into account for the built-in distance calculation functions. There are some new (unrelated) settings in 1.4.4 as well, so I'll post about it in the main thread.
Awesome!  Thanks guys for the quick response.  I will grab the latest version of Scriptcards this weekend and do some testing before our game next week. And I'd like to take a look at Aaron's resizing script.  I do have a Testing copy of the entire module that I use for my sandbox.  I can look at the resize script on that copy and see what it does.
1632500384
The Aaron
Roll20 Production Team
API Scripter
Here it is.  NormalizePageSize.  When you're on the page, run: !nps to do the current page.  If you're feeling feisty, you can run it for all pages with: !nps-all I'd definitely do that on a copy first. Code: on('ready',() => { const s = { gmNote: `margin-left: -40px; border: 1px solid #ccc; border-radius: .5em; padding: .1em .5em; background-color: #eee; font-size: 10px; font-weight: bold;` }; const scgm=(msg)=>{ sendChat('NPS',`/w gm <div style="${s.gmNote}"> ${msg} </div> `); }; const scaleGraphic = (scale) => (graphic) => { graphic.set({ width: graphic.get('width')*scale, height: graphic.get('height')*scale, left: graphic.get('left')*scale, top: graphic.get('top')*scale }); }; const repositionGraphic = (scale) => (graphic) => { graphic.set({ width: graphic.get('width')*scale, height: graphic.get('height')*scale, left: graphic.get('left')*scale, top: graphic.get('top')*scale }); }; const scaleText = (scale) => { return (text) => { text.set({ left: text.get('left')*scale, top: text.get('top')*scale, font_size: text.get('font_size')*scale }); }; }; const simpleObject = (o) => JSON.parse(JSON.stringify(o)); const scalePathString = (pathstring,scale) => { return JSON.stringify(_.map(JSON.parse(pathstring),(n)=> _.map(n,(i)=> _.isNumber(i) ? scale*i : i ))); }; const scaleDrawing = (scale) => { return (drawing) => { let newpath=_.omit(simpleObject(drawing),['_id','_type']); if(_.contains(['','[]'],newpath._path)){ return; } newpath.path=scalePathString(newpath._path,scale); delete newpath._path; newpath.top*=scale; newpath.left*=scale; newpath.width*=scale; newpath.height*=scale; /*let newPathObj =*/ createObj('path',newpath); drawing.remove(); }; }; const adjustPages = (pages) => { let page=pages.shift(), scale=page.get('scale_number')/5; let mapGraphics = findObjs({ pageid: page.id, type: 'graphic', subtype: 'token', represents: '' }); let mgids = mapGraphics.map(g=>g.id); let otherGraphics = findObjs({ pageid: page.id, type: 'graphic' }) .filter(o=> !mgids.includes(o.id) && o.get('subtype')!=='card' ); let allText = filterObjs((o)=>{ return o.get('pageid')===page.id && o.get('type')==='text'; }); let allDrawings = filterObjs((o)=>{ return o.get('pageid')===page.id && o.get('type')==='path'; }); otherGraphics=_.without(otherGraphics,mapGraphics); scgm(`Adjusting page: <u>${page.get('name')}</u>`); // scale page scgm(`-- Scale from ${page.get('scale_number')}ft to 5ft (x${scale} size)`); page.set({ width: page.get('width')*scale, height: page.get('height')*scale, scale_number: 5 }); // scale all graphics on the map layer scgm(`-- Scaling map images: ${mapGraphics.length}`); _.each(mapGraphics,scaleGraphic(scale)); // reposition all graphics on the other layers scgm(`-- Repositioning other layer images: ${otherGraphics.length}`); _.each(otherGraphics,repositionGraphic(scale)); // reposition and scale all text on all layers scgm(`-- Scaling and Repositioning text: ${allText.length}`); _.each(allText,scaleText(scale)); // redraw all drawings scgm(`-- Redrawing paths to scale: ${allDrawings.length}`); _.each(allDrawings,scaleDrawing(scale)); if(pages.length){ _.delay(adjustPages,100,pages); } }; on('chat:message',(msg) => { let cmds,pages,player; if('api' === msg.type && msg.content.match(/^!nps(?:-all)?\b/) && playerIsGM(msg.playerid)){ cmds=msg.content.split(/\s+/); player=getObj('player',msg.playerid); switch(cmds.shift()){ case '!nps-all': pages=filterObjs((o)=>{ return o.get('type')==='page' && o.get('scale_units')==='ft' && o.get('scale_number')>5 ; }); /* falls through */ case '!nps': pages = pages || filterObjs((o)=>{ return o.get('type')==='page' && o.get('scale_units')==='ft' && o.get('scale_number')>5 && o.id === player.get('lastpage'); }); if(pages.length){ scgm( `Operating on pages: <ul><li>${_.map(pages,(p)=>p.get('name')).join('</li> <li>')}</li></ul>`); _.delay(adjustPages,50,pages); } else { scgm( `No work to do on the specified pages.`); } break; } } }); });
Kurt J. said: Good catch :) The latest version on the GitHub  (v1.4.4) now takes snapping_increment into account for the built-in distance calculation functions. There are some new (unrelated) settings in 1.4.4 as well, so I'll post about it in the main thread. I loaded 1.4.4, but now only the scripcards that use Range to build the array are working.  Anything where the array is defined like a cone or square aren't working.  Looks like the script just stops when it gets to building the array and exits.  So, scripts for Burning Hands, Entangle, Faerie Fire that were all working yesterday now just exit after the Titlecard.  Scripts for Fireball, Dawn and Shatter that are a circular AoE using Range ARE still working.  And it does look like the range calculation is working correctly on the 0.5 square grid maps.  But I think something may have broken with the defined arrays for cones and squares.
1632519723
Kurt J.
Pro
API Scripter
Matt M. said: Kurt J. said: Good catch :) The latest version on the GitHub  (v1.4.4) now takes snapping_increment into account for the built-in distance calculation functions. There are some new (unrelated) settings in 1.4.4 as well, so I'll post about it in the main thread. I loaded 1.4.4, but now only the scripcards that use Range to build the array are working.  Anything where the array is defined like a cone or square aren't working.  Looks like the script just stops when it gets to building the array and exits.  So, scripts for Burning Hands, Entangle, Faerie Fire that were all working yesterday now just exit after the Titlecard.  Scripts for Fireball, Dawn and Shatter that are a circular AoE using Range ARE still working.  And it does look like the range calculation is working correctly on the 0.5 square grid maps.  But I think something may have broken with the defined arrays for cones and squares. They are all still working for me... And shouldn't be impacted by the 1.4.4 changes. I looked at the diffs between 1.4.3 and 1.4.4 and don't see any changes that should relate to arrays at all.
1632519820

Edited 1632520353
When I run !nps on a page set to 0.5 Cell Width I get:   No work to do on the specified pages. I did move the Player Ribbon to the page, just in case that was the issue.  But I still get the message and no rescaling occurs.   The Aaron said: Here it is.  NormalizePageSize.  When you're on the page, run: !nps Update: I ran !nps-all and it did update 4 pages which were set to 0.5 scale.  I'm not sure why it didn't work on the two pages I tried first.   Operating on pages: Greenest Raider Camp Upper Courtyard - Skyreach Caste Ice Tunnels - Skyreach Castle It did scale all of the existing tokens on the page to 4x, which were way too large.  But dragging tokens back onto the page, they were normal sized, and had the smaller (normal) sized health bars and status icons.  So, it seems like this would work (although would have to delete and redrag every token back to the page).  But I still can't get the script to run on a copy of my current campaign page.  Or rather, it thinks there is nothing to rescale. 
1632520640
Kurt J.
Pro
API Scripter
Kurt J. said: Matt M. said: Kurt J. said: Good catch :) The latest version on the GitHub  (v1.4.4) now takes snapping_increment into account for the built-in distance calculation functions. There are some new (unrelated) settings in 1.4.4 as well, so I'll post about it in the main thread. I loaded 1.4.4, but now only the scripcards that use Range to build the array are working.  Anything where the array is defined like a cone or square aren't working.  Looks like the script just stops when it gets to building the array and exits.  So, scripts for Burning Hands, Entangle, Faerie Fire that were all working yesterday now just exit after the Titlecard.  Scripts for Fireball, Dawn and Shatter that are a circular AoE using Range ARE still working.  And it does look like the range calculation is working correctly on the 0.5 square grid maps.  But I think something may have broken with the defined arrays for cones and squares. They are all still working for me... And shouldn't be impacted by the 1.4.4 changes. I looked at the diffs between 1.4.3 and 1.4.4 and don't see any changes that should relate to arrays at all. Ah, I see... the cone macros themselves (which don't use the distance functions) have the 70s hardcoded into them. Since they are completely separate animals, I'll need to update them as David suggests above to support non 1.0 snapping increments.
1632521961
Kurt J.
Pro
API Scripter
The sample scripts on the github have now been updated to support non-1.0 grid scales by creating scaler variables and replacing the hard coded 70s, 35s, 140s, and 210s with these variables. Version 1.4.4 of scriptcards isn't necessary for these versions of the scripts since they don't use the distance functions.
Kurt J. said: The sample scripts on the github have now been updated to support non-1.0 grid scales by creating scaler variables and replacing the hard coded 70s, 35s, 140s, and 210s with these variables. Version 1.4.4 of scriptcards isn't necessary for these versions of the scripts since they don't use the distance functions. OK.  I see.  My macros using defined arrays for cone and square are still not working with the 1.4.4 on pages with 0.5 cell sizing.  They do work fine on 1.0 cell sizing maps. I'll have to figure out what changes to make to the array definitions in order for them to work on both map sizes.  I was missing that piece since all my testing and development was on a 1.0 cell size map.  This was the first time I tried executing them on a 0.5 cell size map. The Range-based arrays work fine on both page sizings.