Heya, hoping to get some help from more experienced folks! I'm trying to create a quick way to calculate range penalties in my Pathfinder game. Right now I use a calculation that looks like this: [[0-(ceil((?{Distance to target? (max = 300)|5}-50) / 50) * 2)]] This requires myself or the player to measure the distance between their token and the target token before making their attack. I was hoping to change this to a method that takes the position of the selected token and the target token as the attack is made, so the player simply has to have their token selected and click a target. That would look something like this: [[0-(ceil(([[round([[(((abs(@{selected|position-x}-@{target|Target|position-x})*5/70)**2) + ((abs(@{selected|position-y}-@{target|Target|position-y})*5/70)**2))**0.5]]/5)*5]]-50) / 50) * 2)]] I'm also stuck on how to properly calculate the distance in a way that complies with this: (from <a href="https://wiki.roll20.net/Ruler#Square_Grids_have_four_options_for_measuring" rel="nofollow">https://wiki.roll20.net/Ruler#Square_Grids_have_four_options_for_measuring</a>: ) Pathfinder/3.5E Compatible measures a diagonal move as 1.5 units
(rounding down). Thus, when 1 unit equals 5ft, diagonal moves alternate
between 5ft and 10ft increments (i.e. 5ft, 15ft, 20ft, 30ft, etc.). Aside from that, I came across this snippet that The Aaron made a few years back: <a href="https://app.roll20.net/forum/permalink/4610415/" rel="nofollow">https://app.roll20.net/forum/permalink/4610415/</a> on('ready', function(){
"use strict";
on('change:graphic',function(obj,prev){
if( ( _.contains(['gmlayer','objects'],obj.get('layer')) ) &&
( obj.get('left') !== prev.left || obj.get('top') !== prev.top) &&
obj.get('represents') ) {
let a=_.chain(findObjs({type: 'attribute',characterid: obj.get('represents')}))
.filter(a=>a.get('name').match(/^position-[xy]$/))
.each(a=>{
switch(a.get('name')){
case 'position-x':
a.set({current: obj.get('left')});
break;
case 'position-y':
a.set({current: obj.get('top')});
break;
}
});
}
});
}); It records the X and Y positions of a token within two sheet attributes of the token's connected character. This only works with characters represented by a single token. Not very useful when multiple enemy tokens are linked to the same sheet. The main things I'm trying to figure out: Can 'selected' and 'target' functions be used to get non-bar values from a token? (We make use of all 3 token bars, so I'd prefer to avoid changing that if possible; maybe using sight angle and reveal distance instead?) Can the snippet above be changed to store the 'left' and 'top' values in the token values in some way? If either 1 or 2 is impossible, what is an alternative way to store these values that is unique to each token? Maybe automatically creating a unique attribute for each token's x and y positions in a single dedicated character? Is there a way to improve my distance calculation so that it complies with the measurement system mentioned above? It's mostly accurate for distances under 10 units, but beyond that it gets inaccurate.