Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×

The new D&D 2024 sheet is now available!

Create a free account

[Request] Random character place swapping

After watching The Marvels (no shade please, I loved it). I’d love to include a mechanic where on the press of a button (by me as DM) the characters on the current sheet would randomly swap places with each other.  So the wizard who’s hiding behind a rock, could find themselves randomly swapped with the tank who’s toe to toe with a monster.  My players love this idea, but I am not fluent enough to know where to start.  Is this possible ?
1700235505
timmaugh
Pro
API Scripter
Sure... no problem. With TokenMod and the MetaScriptToolbox installed, you can select one of the tokens involved, then run this command: !{{(^)   !token-mod --set top|@(@{target|token_id}.top) left|@(@{target|token_id}.left)   !token-mod --set top|@(selected.top) left|@(selected.left) {^&select @{target|token_id}} }} {&select @{selected|token_id}} That will ask you to target a token, as well. Target the other token involved in the place-swap (the metascripts will get around the typical Roll20 limitation of not having a selected token if your command line also includes a targeting statement). Here are screenshots of it working: ...and after...
As another alternative using the  ScriptCards mod  to randomize the swapping if you prefer: !scriptcard {{ --/|ScriptCard to randomly swap PC token locations --#title|Random Scatter --~tcount|array;pagetokens;PCTokenArr;[*C:playerpageid];pc -->LibSN_COPY_ARRAY|PCTokenArr;RandomTokenArr -->LibSN_RANDOMIZE_ARRAY|RandomTokenArr --%i|0;[= [&tcount] - 1];1 --+|[*[@PCTokenArr([&i])]:t-name] swaps with [*[@RandomTokenArr([&i])]:t-name] --&t1tid|[*[@PCTokenArr([&i])]:t-id] --&t1top|[*[@PCTokenArr([&i])]:t-top] --&t1left|[*[@PCTokenArr([&i])]:t-left] --&t2top|[*[@RandomTokenArr([&i])]:t-top] --&t2left|[*[@RandomTokenArr([&i])]:t-left] --&t2tid|[*[@RandomTokenArr([&i])]:t-id] --!t:[&t1tid]|top:[&t2top]|left:[&t2left] --!t:[&t2tid]|top:[&t1top]|left:[&t1left] --%| --X| --:LibSN_RANDOMIZE_ARRAY|ArrayToRandomize;Iterations (optional, default 3 * number of items) --=_ITERATIONS|[@[%1%](maxindex)] * 3 --?"[%2%]" -ne ""|=_ITERATIONS;[%2%] --%_loop|0;[$_ITERATIONS] -->LibSN_SWAP_ARRAY_ITEMS|[%1%];[=1d[@[%1%](length)] - 1];[=1d[@[%1%](length)] - 1] --%| --<| --:LibSN_COPY_ARRAY|SOURCE;DEST;START (OPTIONAL);END (OPTIONAL) --&_STARTCOUNT|[%3%] --&_ENDCOUNT|[%4%] --?"[&_STARTCOUNT]" -eq ""|&_STARTCOUNT;0 --?"[&_ENDCOUNT]" -eq ""|&_ENDCOUNT;[@[%1%](maxindex)] --~dummy|array;[%2%];define --=_DESTITEM|0 --%_loop|[&_STARTCOUNT];[&_ENDCOUNT] --&[%2%]([$_DESTITEM.Raw])|[@[%1%]([&_loop])] --=_DESTITEM|[$_DESTITEM] + 1 --%| --<| --:LibSN_SWAP_ARRAY_ITEMS|Array;Item1_Index;Item2_Index --?"X[%2%]" -eq "X" -or "X[%3%]" -eq "X" -or "[%2%]" -eq "[%3%]"|< --&_DUMMY|[@[%1%]([%3%])] --&[%1%]([%3%])|[@[%1%]([%2%])] --&[%1%]([%2%])|[&_DUMMY] --<| }} That uses some functions from  Kurt J's system neutral ScriptCard library  to randomize the token choices. It can result in a tokens not changing locations however so other things can be changed if you want to ensure tokens move. But as of now it will roll through 2 arrays and swap locations as they appear. So in that example run Fighter and Druid tokens swapped with each other twice, so back to their original locations. Then the wizard swapped twice so back to their original location as well so only the Cleric and FighterCleric tokens appear swapped. So timmaugh's method will give you direct control whereas the ScriptCard will randomize it and can lead to disappointing outcomes. Just wanted to provide it as an option.