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 .
×
Create a free account

Shuffle card order on table

Sometimes I need players to play cards face down onto an imaginary 'discard pile', which works okay for us. But for this to work in the way we would like, we would need to be able to 'shuffle' this pile.  Is there a way to do something like this in Roll20?  Various ideas (which I don't think are possible) are: A temporary deck players can drop their cards into Macros to shuffle a selected group of cards A faux player which these cards could be given to (which we could then shuffle) in a very manual/dumb way Thanks for any tips, Dan
1586712633
The Aaron
Roll20 Production Team
API Scripter
The only way to do this without the API would be to deal yourself all the cards remaining in the deck, have all the players discard their cards, then shuffle the deck with just those cards and real them out or redraw them.  With the API (a Pro subscriber perk) you can use a script to adjust the order of the cards on the table to be randomly repositioned. I have one explicitly for that purpose. 
Would it be possible to see the script you use? I may be able to tempt my players to chip in to do it, but would be good to see it as an example I could use to understand whether I may have the time to write my own too.  Thanks for the advise,  Dan
1586798053
The Aaron
Roll20 Production Team
API Scripter
Sure thing!  Sorry for the delay, I had to rewrite it because it was ugly. =D I PM'd you a join link for a game where you can try it out. Here's the script source: const RandomDepth = (() => { // eslint-disable-line no-unused-vars const version = 0.2; // eslint-disable-line no-unused-vars const fixedToBack = (()=>{ let queue=[]; let last=0; const DELAY = 100; let callbacks = []; const burndownQueue = ()=>{ let o = queue.shift(); toBack(o); last = Date.now(); if(queue.length){ setTimeout(burndownQueue,DELAY); } else { let cblist = [...callbacks]; callbacks = []; cblist.forEach(cb => cb()); } }; return (obj, cb = ()=>{}) => { callbacks.push(cb); if(queue.length){ queue.push(obj); } else { let t = Date.now(); if(last+DELAY > t){ queue.push(obj); setTimeout(burndownQueue,(last+DELAY-t)); } else { toBack(obj); last = t; } } }; })(); const randomToFrontList = (l,cb) => { while( l.length > 1) { let i = randomInteger(l.length)-1; fixedToBack(l[i]); l = l.filter((o,k)=>k!==i); } fixedToBack(l[0],cb); }; const handleMessages = (msg) => { if('api' !== msg.type ) { return; } let args = msg.content.split(/\s+/); let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); switch(args.shift()) { case '!shuffle-selected': case '!random-depth': { let tokens = (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) ; let count = tokens.length; if(count){ randomToFrontList(tokens,()=>{ sendChat('',`/w "${who}" Finished shuffling."`); }); sendChat('',`/w "${who}" Shuffling ${count} items."`); } else { sendChat('',`/w "${who}" Please select something and run the command again."`); } } break; } }, registerEventHandlers = function(){ on('chat:message',handleMessages); }; on('ready',registerEventHandlers); return { }; })();