TokenSwap: !token-swap ID1 ID2 Example: !token-swap @{selected|token_id} @{target|Swap with|token_id} Currently, this would only work on the same layer (I don't think you can change layers while using @{target}) but that shouldn't be a problem for players. Note that it doesn't check ownership of any tokens, so it could be used to swap any tokens on the tabletop. Let me know if that's a problem. Code: on('ready',function(){
"use strict";
on('chat:message',function(msg){
var args, who;
if (msg.type !== "api") {
return;
}
who = getObj('player',msg.playerid).get('_displayname');
args = msg.content.split(/\s+/);
switch(args.shift()) {
case '!token-swap': {
let t1 = getObj('graphic',args[0]);
let t2 = getObj('graphic',args[1]);
if(!t1 || !t2) {
sendChat('TokenSwap', `/w "${who}" Please provide 2 token ids to swap: <code>!token-swap ID1 ID2</code>`);
return;
}
let p1={
top: t1.get('top'),
left: t1.get('left')
};
let p2={
top: t2.get('top'),
left: t2.get('left')
};
t1.set(p2);
t2.set(p1);
if(!playerIsGM(msg.playerid)){
sendChat('TokenSwap', `/w gm <code>${who}</code> just swapped <b>${t1.get('name')}</b> and <b>${t2.get('name')}</b>. <a href="!token-swap ${t1.id} ${t2.id}">Swap Back</a>`);
}
}
break;
}
});
});