Here's a first pass solution.
Use:
!att Text
Adds the selected tokens to the turn order and sets their value to whatever comes after the !att command. You can select as many as you like and run it. Players can use it. It always adds the turns to the top, so you'll have to sort it afterwards. Also, it doesn't check if a token is in the turn order currently, so you can get duplicate entries. Hope that helps!
Code (AddTextTurn):
on('ready', () => {
const processInlinerolls = (msg) => {
if(msg.hasOwnProperty('inlinerolls')){
return msg.inlinerolls
.reduce((m,v,k) => {
let ti=v.results.rolls.reduce((m2,v2) => {
if(v2.hasOwnProperty('table')){
m2.push(v2.results.reduce((m3,v3) => [...m3,(v3.tableItem||{}).name],[]).join(", "));
}
return m2;
},[]).join(', ');
return [...m,{k:`$[[${k}]]`, v:(ti.length && ti) || v.results.total || 0}];
},[])
.reduce((m,o) => m.replace(o.k,o.v), msg.content);
} else {
return msg.content;
}
};
on('chat:message',(msg) => {
if('api' === msg.type) {
if(msg.content.match(/^!att\b/) ){
let who=(getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');
let text = processInlinerolls(msg).split(/\s+/).slice(1).join(' ');
if(text){
let turns = _.chain(msg.selected)
.map((o)=>getObj('graphic',o._id))
.reject(_.isUndefined)
.map((t)=>({id: t.id, pr: text, _pageid: t.get('pageid')}))
.value();
if(turns.length){
let to=turns.concat(JSON.parse(Campaign().get('turnorder'))||[]);
Campaign().set('turnorder',JSON.stringify(to));
} else {
sendChat('ATT',`/w "${who}" <div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"><div style="background-color: #ffeeee;">Nothing selected capable of having a turn.</div></div>`);
}
} else {
sendChat('ATT',`/w "${who}" <div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"><div style="background-color: #ffeeee;">Use <b><pre>!act ${'&'+'lt'+';'}text${'&'+'gt'+';'}</pre> -- add turns for selected tokens with the supplied text as the value of their turn.</b></div></div>`);
}
}
}
});
});
Edit 2023-09-30: Fixed for breaking changes in TurnOrder.