Sure im doing something daft. Works with HEX(V).
Ive amended the script a bit for what I wanted. It now gives the range modifier for Hero system, when selecting 2 tokens. Only a minor tweak, but will save us having to keep looking the range mods up :-)
// Computes the distances between 2 tokens by ID
// Use the macro target picker to fill in the ID
// Script command
// !range @{target|1st Target|token_id} @{target|2nd Target|token_id}
on("chat:message", function(msg) {
if(msg.type == "api" && msg.content.indexOf("!range") != -1) {
log(msg);
var n = msg.content.split(" ", 4)
var cmd = n[0];
var id1 = n[1];
var id2 = n[2];
var token1 = getObj("graphic", id1);
var token2 = getObj("graphic", id2);
if (token1 && token2) {
var distance = tokenDistance(token1, token2);
/* sendChat("", "/desc Distance between Token1 & Token2 is " + distance); */
sendChat("", "/desc Range modifier is " +rangeMod(distance));
rangeMod(distance)
} else {
if (!token1)
sendChat("Range Finder","/w " + msg.who + " Could not locate first token!");
if (!token2)
sendChat("Range Finder","/w " + msg.who + " Could not locate second token!");
}
}
});
function tokenDistance(token1, token2) {
if (token1.get('pageid') != token2.get('pageid')) {
log('Cannot measure distance between tokens on different pages');
return;
}
var distance;
var page = getObj('page', token1.get('pageid'));
var gridType = page.get('grid_type');
switch(gridType) {
case 'hex':
distance = hexVDistance([token1.get("left"), token1.get("top")], [token2.get("left"), token2.get("top")]);
break;
case 'hexh':
distance = hexHDistance([token1.get("left"), token1.get("top")], [token2.get("left"), token2.get("top")]);
break;
}
return distance;
}
function hexHDistance(unit1, unit2) {
var q1, q2, r1, r2;
q1 = Math.round((unit1[0] - 46.48512749037782) / 69.58512749037783);
r1 = Math.round((unit1[1] - 39.8443949917523) / 39.8443949917523);
r1 = Math.floor(r1 / 2);
q2 = Math.round((unit2[0] - 46.48512749037782) / 69.58512749037783);
r2 = Math.round((unit2[1] - 39.8443949917523) / 39.8443949917523);
r2 = Math.floor(r2 / 2);
return cubeDistance(oddQToCube(q1, r1), oddQToCube(q2, r2));
}
function hexVDistance(unit1, unit2) {
var q1, q2, r1, r2;
q1 = Math.round((unit1[0] - 37.59928099223013) / 37.59928099223013);
r1 = Math.round((unit1[1] - 43.86582782426834) / 66.96582782426833);
q1 = Math.floor(q1 / 2);
q2 = Math.round((unit2[0] - 37.59928099223013) / 37.59928099223013);
r2 = Math.round((unit2[1] - 43.86582782426834) / 66.96582782426833);
q2 = Math.floor(q2 / 2);
return cubeDistance(oddRToCube(q1, r1), oddRToCube(q2, r2));
}
function oddRToCube(q, r) {
var x, y, z;
x = q - (r - (r & 1)) / 2;
z = r;
y = -x - z;
return [x, y, z];
}
function oddQToCube(q, r) {
var x, y, z;
x = q;
z = r - (q - (q & 1)) / 2;
y = -x - z;
return [x, y, z];
}
function cubeDistance(cube1, cube2) {
return Math.max(Math.abs(cube1[0] - cube2[0]), Math.abs(cube1[1] - cube2[1]), Math.abs(cube1[2] - cube2[2]));
}
function rangeMod(distR) {
switch(true) {
case (distR < 5):
return 0;
break;
case (distR < 9):
return -2;
break;
case (distR < 17):
return -4;
break;
case (distR < 33):
return -6;
break;
case (distR < 65):
return -8;
break;
default:
log('not a coded range');
}
}