Ok, here's super rough little snippet that should give the functionality you want. See if this works for you. Commands !7si --clear Usable by the GM only, clears the turn order !7si --sort Usable by the GM only, sorts the turn order in ascending order !7si ATTR_NAME Usable by anyone, for each selected token, gets the attribute specified and rolls that many d10s (default 1), then adds each token to the turn order with each of those rolls. Code: on('ready',()=>{
/* eslint-disable no-unused-vars */
const getTurnArray = () => ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder')));
const setTurnArray = (ta) => Campaign().set({turnorder: JSON.stringify(ta)});
const addTokenTurn = (id, pr) => setTurnArray([...getTurnArray(), {id,pr}]);
const addCustomTurn = (custom, pr) => setTurnArray([...getTurnArray(), {id:"-1",custom,pr}]);
const removeTokenTurn = (tid) => setTurnArray(getTurnArray().filter( (to) => to.id !== tid));
const removeCustomTurn = (custom) => setTurnArray(getTurnArray().filter( (to) => to.custom !== custom));
const clearTurnOrder = () => Campaign().set({turnorder:'[]'});
const sorter_asc = (a, b) => a.pr - b.pr;
const sorter_desc = (a, b) => b.pr - a.pr;
const sortTurnOrder = (sortBy = sorter_desc) => Campaign().set({turnorder: JSON.stringify(getTurnArray().sort(sortBy))});
/* eslint-enable no-unused-vars */
const times = (n,f) => Array(n).fill(n).map(f);
const d10 = ()=>randomInteger(10);
on('chat:message',msg=>{
if('api'===msg.type && /^!7si(\b\s|$)/i.test(msg.content) ){
let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');
let args = msg.content.split(/\s+/).slice(1);
if(args.includes('--sort')){
if(playerIsGM(msg.playerid)){
sortTurnOrder(sorter_asc);
} else {
sendChat('',`/w "${who}" <div><code>Only the GM can sort the turn order.</code></div>`);
}
} else if(args.includes('--clear')){
if(playerIsGM(msg.playerid)){
clearTurnOrder();
} else {
sendChat('',`/w "${who}" <div><code>Only the GM can clear the turn order.</code></div>`);
}
} else {
(msg.selected || [])
.map(o=>getObj('graphic',o._id))
.filter(g=>undefined !== g)
.map(o=>({
t: o,
a: (findObjs({name:args[0], type: 'attribute', characterid: o.get('represents')})[0] || {get:()=>1})
}))
.forEach( o => times(parseInt(o.a.get('current'))||1,d10).forEach( n => addTokenTurn(o.t.id,n)))
;
}
}
});
});