If your players stick together, there is an API that allows you to link DL lines with a token and the DL will move with the token. on('ready',()=>{
const scriptName = 'DLLink';
const version = '0.1.0';
const schemaVersion = 0.1;
const lastUpdate = 1662075424;
let pendingToken;
const checkInstall = () => {
log(`-=> ${scriptName} v${version} <=- [${lastUpdate}]`);
if (
!state.hasOwnProperty(scriptName) ||
state[scriptName].version !== schemaVersion
) {
log(` > Updating Schema to v${schemaVersion} <`);
switch (state[scriptName] && state[scriptName].version) {
case 0.1:
/* break; // intentional dropthrough */ /* falls through */
case "UpdateSchemaVersion":
state[scriptName].version = schemaVersion;
break;
default:
state[scriptName] = {
version: schemaVersion,
options: {},
links: {}
};
break;
}
}
};
checkInstall();
on('chat:message',msg=>{
if('api'===msg.type && /^!dl-link(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){
let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');
let objs = (msg.selected || [])
.map(o=>getObj(o._type,o._id))
.filter(g=>undefined !== g)
;
objs.forEach(o=>{
if('graphic' === o.get('type')){
pendingToken = o;
} else if('path'=== o.get('type')){
if(pendingToken){
state[scriptName].links[pendingToken.id] = [...(state[scriptName].links[pendingToken.id]||[]), o.id];
}
}
});
}
});
on('change:graphic', (obj,prev)=>{
let s=state[scriptName].links[obj.id];
if(s){
let dR = obj.get('rotation')-prev.rotation;
let dX = obj.get('left')-prev.left;
let dY = obj.get('top')-prev.top;
s.map(id=>getObj('path',id))
.filter(g=>undefined !== g)
.forEach(p=>p.set({
rotation: p.get('rotation')+dR,
left: p.get('left')+dX,
top: p.get('top')+dY
}));
}
});
});