I have this one that will switch to whatever character's turn is at the top of the turn order, when it is displayed: 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 GetGMs = () => findObjs({type:'player'}).filter(p=>playerIsGM(p.id));
const getTurnArray = () => ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder')));
const getCurrentTurnToken = () => getObj('graphic',(getTurnArray()[0]||{}).id);
const DoOnEachTurn = () => {
let t = getCurrentTurnToken();
let speakingas = '';
if(t){
let c = getObj('character',t.get('represents'));
if(c && !playerCanControl(c)){
speakingas = `character|${c.id}`;
}
}
GetGMs().forEach(p=>p.set({speakingas}));
};
const ResetGMSpeaking = () => {
GetGMs().forEach(p=>p.set({speakingas:''}));
};
on('change:campaign:initiativepage',()=>{
if(false == Campaign().get('initiativepage')){
ResetGMSpeaking();
} else {
DoOnEachTurn();
}
});
on('chat:message', (msg)=>{
if('api'===msg.type && /^!doet\b/i.test(msg.content) && playerIsGM(msg.playerid)){
DoOnEachTurn();
}
});
on('change:campaign:turnorder', ()=>setTimeout(()=>DoOnEachTurn(),1000));
on('chat:message', (msg) => {
if('api'===msg.type && /^![ep]ot\b/.test(msg.content)){
setTimeout(()=>DoOnEachTurn(),1000);
}
});
});