Here's a version of that script that works with UDL: on('ready',()=>{
const playerCanControl = (obj, playerid='any') => {
const playerInControlledByList = (list, playerid) => list.includes('all') || list.includes(playerid) || ('any'===playerid && list.length);
let players = obj.get('controlledby')
.split(/,/)
.filter(s=>s.length);
if(playerInControlledByList(players,playerid)){
return true;
}
if('' !== obj.get('represents') ) {
players = (getObj('character',obj.get('represents')) || {get: function(){return '';} } )
.get('controlledby').split(/,/)
.filter(s=>s.length);
return playerInControlledByList(players,playerid);
}
return false;
};
const setHasSightByClass = (args) => {
let filter = () => true;
switch(args.type.toLowerCase()){
default:
case 'npcs':
filter=(t)=> ! playerCanControl(t);
break;
case 'players':
filter=(t)=> playerCanControl(t);
break;
case 'all':
break;
}
let opts = {
type: 'graphic',
subtype: 'token'
};
let setOpts = {};
let msgs = [];
if(args.hasOwnProperty("value")){
setOpts.has_bright_light_vision = args.value;
msgs.push(args.value?'Has Sight':'No Sight');
}
if(args.hasOwnProperty("light") && false === args.light){
setOpts.light_radius = "";
setOpts.light_dimradius = "";
msgs.push("no light");
} if(setOpts.hasOwnProperty("has_bright_light_vision")) {
opts.has_bright_light_vision = !setOpts.has_bright_light_vision; // only need to look at ones we would be changing =D
}
let tokens = findObjs(opts).filter(filter);
let tokenCount = tokens.length;
const burndown = () => {
if(tokens.length) {
let t = tokens.shift();
if(t) {
t.set(setOpts);
}
setTimeout(burndown,0);
} else {
sendChat('',`/w gm Set ${tokenCount} token(s) to ${msgs.join(", ")}`);
}
};
burndown();
};
on('chat:message',(msg)=>{
if('api' === msg.type && /!set-has-sight\b/i.test(msg.content) && playerIsGM(msg.playerid)){
let args = msg.content.split(/\s+/).map(s=>s.toLowerCase());
let opts = {
type: "npcs"
};
if(args.includes('--npcs') || args.includes('--npc')){
opts.type = 'npcs';
} else if(args.includes('--pcs') || args.includes('--pc') || args.includes('--players') || args.includes('--player') ){
opts.type = 'players';
} else if(args.includes('--all') ){
opts.type = 'all';
}
if(args.includes('--sight') || args.includes('--true') ) {
opts.value = true;
} else if( args.includes('--blind') || args.includes('--false') ) {
opts.value = false;
}
if(args.includes('--no-light') ) {
opts.light=false;
}
if(Object.keys(opts).length > 1){
setHasSightByClass(opts);
} else {
sendChat('',`/w gm Please specify one or more of --sight or --blind, and --no-light`);
}
}
});
});