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

Script to auto roll token tables

So I currently have a number of characters that have rollable tokens, basically I make a table of all the Guard Tokens and then assign that table as a default token for the sheet. Is there any scripts to make the table automatically roll when the token is placed? 
1705637125
The Aaron
Roll20 Production Team
API Scripter
Yup!  Here's one.  Should randomly change the face of any token added to the tabletop which isn't a player token. on('ready',()=>{ const playerCanControl = (obj, playerid='any') => { const playerInControlledByList = (list, playerid) => list.includes('all') || list.includes(playerid) || ('any'===playerid && list.length); let players = obj.get('controlledby') .split(/,/) .filter(s=>s.length); if(playerInControlledByList(players,playerid)){ return true; } if('' !== obj.get('represents') ) { players = (getObj('character',obj.get('represents')) || {get: function(){return '';} } ) .get('controlledby').split(/,/) .filter(s=>s.length); return playerInControlledByList(players,playerid); } return false; }; const getCleanImgsrc = (imgsrc) => { let parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)([^?]*)(\?[^?]+)?$/); if(parts) { return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`); } return; }; const isString = (s)=>'string'===typeof s || s instanceof String; let tokenIds = []; const saveTokenId = (obj) => { tokenIds.push(obj.id); }; const setTokenRandomSide = (obj,prev,force=false) => { if(tokenIds.includes(obj.id) || force){ tokenIds=tokenIds.filter(id => id !== obj.id); if( 'graphic' === obj.get('type') && 'token' === obj.get('subtype') && ! playerCanControl(obj)){ let sideText = obj.get('sides'); if( sideText.length ){ let sides = sideText.split(/\|/).map(decodeURIComponent).map(getCleanImgsrc).filter(isString); if(sides.length){ obj.set({ imgsrc: sides[randomInteger(sides.length)-1] }); } } } } }; on('add:graphic', saveTokenId); on('change:graphic', setTokenRandomSide); });
The Aaron said: Yup!  Here's one.  Should randomly change the face of any token added to the tabletop which isn't a player token. on('ready',()=>{ const playerCanControl = (obj, playerid='any') => { const playerInControlledByList = (list, playerid) => list.includes('all') || list.includes(playerid) || ('any'===playerid && list.length); let players = obj.get('controlledby') .split(/,/) .filter(s=>s.length); if(playerInControlledByList(players,playerid)){ return true; } if('' !== obj.get('represents') ) { players = (getObj('character',obj.get('represents')) || {get: function(){return '';} } ) .get('controlledby').split(/,/) .filter(s=>s.length); return playerInControlledByList(players,playerid); } return false; }; const getCleanImgsrc = (imgsrc) => { let parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)([^?]*)(\?[^?]+)?$/); if(parts) { return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`); } return; }; const isString = (s)=>'string'===typeof s || s instanceof String; let tokenIds = []; const saveTokenId = (obj) => { tokenIds.push(obj.id); }; const setTokenRandomSide = (obj,prev,force=false) => { if(tokenIds.includes(obj.id) || force){ tokenIds=tokenIds.filter(id => id !== obj.id); if( 'graphic' === obj.get('type') && 'token' === obj.get('subtype') && ! playerCanControl(obj)){ let sideText = obj.get('sides'); if( sideText.length ){ let sides = sideText.split(/\|/).map(decodeURIComponent).map(getCleanImgsrc).filter(isString); if(sides.length){ obj.set({ imgsrc: sides[randomInteger(sides.length)-1] }); } } } } }; on('add:graphic', saveTokenId); on('change:graphic', setTokenRandomSide); }); Worked like a charm! Thanks!