I just streamlined the script, so it now works for PCs and GMs with the same command, !find-token. If you're a GM , it will ping all players and focus their view on the token. You can add --true or --1 to the command, and it will limit the ping to the gm only. eg. --!find-token --Kastion --1 If you're a PC, and run this, it will ping only you, but only if you control the token. You cant use this to find NPCs. Here's the updated script on('ready', () => {
const getPageForPlayer = (playerid) => {
let player = getObj('player', playerid);
if (playerIsGM(playerid)) {
return player.get('lastpage');
}
let psp = Campaign().get('playerspecificpages');
if (psp[playerid]) {
return psp[playerid];
}
return Campaign().get('playerpageid');
};
const getToken = (name, page, id, gm) => {
const tokens = findObjs({
_pageid: page,
_type: "graphic",
_name: name
}).filter((token) => {
let controlledby = (getObj('character', token.get('represents')) || token).get('controlledby');
return gm || controlledby.split(",").includes('all') || controlledby.split(",").includes(id); });
return tokens[0] || '';
};
on('chat:message', (msg) => {
if ('api' === msg.type && /^!find-token\b/i.test(msg.content)) {
const gm = playerIsGM(msg.playerid);
const pname = getObj('player', msg.playerid).get('_displayname');
const args = msg.content.split("--");
const token_name = (args[1] || '').trim();
const focus_gm = args[2] || '';
if (token_name) {
const playerPageID = getPageForPlayer(msg.playerid);
const t = getToken(token_name, playerPageID, msg.playerid, gm);
if (t) {
sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, true, (gm && !focus_gm ? null : msg.playerid));
} else {
sendChat('FindToken', `/w ${pname} No tokens named <code>${token_name}</code> and owned by you found on your current page.`);
}
} else {
sendChat('FindToken', `/w ${pname} Please use the format <code>!find-token --token name</code>.`);
}
}
});
log("-=> Find Token Loaded (!find-token) [Last Edited Jan 29th 2020] <=-");
});