Mod:Short Community Scripts
From Roll20 Wiki
Page Updated: 2021-10-11 |
This page is about a Roll20 feature exclusive to Pro-subscribers (and often to players in a Game created by a Pro-subscriber). If you'd like to use this feature, consider upgrading your account. |
Main Page: API:Script Index
This is a collection of shorter API scripts and snippets created the community, which haven't ended up in the one-click menu for for being so situational or small.
Roll20 Mod
Use Mods
- Use & Install
- Mod:Script Index & Suggestions
- Short Community Scripts
- Meta Scripts
- User Documentation
- Mod Scripts(Forum)
- Mod Update 2024🆕
- Macro Guide
Mod Development
Reference
- Objects
- Events
- Chat Events & Functions
- Utility Functions
- Function
- Roll20 object
- Token Markers
- Sandbox Model
- Debugging
Cookbook
Contents |
Token
Make Rollable Table Tokens
Little script for making Rollable Table Tokens. Just select a bunch of graphics on the page and run:
!make-rtt
and it will zip them up in a Rollable Table Token. it sorts them in order from top to bottom, left to right. If any graphics are from the marketplace, it will put the dead X on them and not include them. It places the new token at the lop left of the tokens (or at (0,0
if you have some bizzare selected tokens that are somewhat off screen..)
on('ready',()=>{ const s = { err: "padding: 1px 1em; size:.8em; font-weight:bold; background: #cccccc; border:2px solid black; border-radius:1em; color: #990000;" }; 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 positionalSorter = (a,b) => { let at = Math.round((a.get('top')+17)/35); let bt = Math.round((b.get('top')+17)/35); let al = Math.round((a.get('left')+17)/35); let bl = Math.round((b.get('left')+17)/35); let abt = at-bt; let abl = al-bl; return (0 === abt ? abl : abt); }; const findTraits = (b) => (o) => { let x = parseFloat(o.get('left')); let y = parseFloat(o.get('top')); let w = parseFloat(o.get('width')); let h = parseFloat(o.get('height')); b.minX = Math.min(b.minX,x-(w/2)); b.minY = Math.min(b.minY,y-(h/2)); b.maxX = Math.max(b.minX,x+(w/2)); b.maxY = Math.max(b.minY,y+(h/2)); b.layer = o.get('layer'); b.pageid = o.get('pageid'); return o; }; on('chat:message',msg=>{ if('api'===msg.type && /^!make-rtt(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); let traits = { minX: Number.MAX_SAFE_INTEGER, minY: Number.MAX_SAFE_INTEGER, maxX: -Number.MAX_SAFE_INTEGER, maxY: -Number.MAX_SAFE_INTEGER, layer: 'objects', pageid: '' }; if(0===(msg.selected||[].length)){ sendChat('',`/w "${who}" <div style="${s.err}">Please selected some tokens.</div>`); return; } let images = (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .sort(positionalSorter) .map(findTraits(traits)) .reduce((m,g)=>{ let i = getCleanImgsrc(g.get('imgsrc')); if(i){ m.push(i); } else { g.set('status_dead',true); } return m; },[]) ; if(images.length){ let token = createObj('graphic',{ pageid: traits.pageid, layer: traits.layer, left: traits.minX||0, top: traits.minY||0, width: 70, height: 70, imgsrc: images[0], sides: images.map(encodeURIComponent).join('|') }); if(token){ toFront(token); } else { sendChat('',`/w "${who}" <div style="${s.err}">Failed to create token!</div>`); } } else { sendChat('',`/w "${who}" <div style="${s.err}">Only marketplace images found!</div>`); } } }); });
Show Tooltip
Showtooltip(Forum) by Aaron
Shows Token Tooltip of selected tokens in the chat.
!show-tip //show in chat to all !wshow-tip //whisper to self
on('ready',()=>{ const s = { container: `display:inline-block;border:1px solid #999;border-radius:.2em; padding: .1em;background-color:white;width:100%;`, img: `max-width: 5em;max-height:5em;display:block;overflow:auto;background-color:transparent;float:left;margin:.5em;`, quote: `font-weight: bold;font-style:italic;padding:.3em;`, clear: `clear:both;` }; const f = { container: (d,q) => `<div style="${s.container}">${d}${q}${f.clear()}</div>`, item: (d)=>`<img src="${d}" style="${s.img}">`, quote: (q)=>q?`<div style="${s.quote}">${q}</div>`:'', clear: () => `<div style="${s.clear}"></div>` }; on('chat:message',msg=>{ if('api'===msg.type && /^![w]?show-tip(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let who = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); let whisper = /^!w/i.test(msg.content); let msgs = (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .filter(g=>0 !== g.get('tooltip').length) .map(t=>f.container(f.item(t.get('imgsrc')),f.quote(t.get('tooltip')))) ; if(msgs){ sendChat('',`${whisper ? `/w "${who}" `: ''}${msgs.join('')}`); } } }); });
DropTorch
DropTorch(Forum), A little script that lets you and your players drop their light source on the ground.
RetrieveTokens
RetrieveTokens(Forum) -- get graphics that are off the page
Map
ToggleDaylight
ToggleDaylight(Forum) turn daylight mode on, off, or toggle it for LDL or UDL on the current page.
Other Community APIs
- API:Script Index#APIs needing manual install - list of API that aren't in the one-click install
- shdwjk/Roll20API - The Aaron's collection of APIs, so which aren't found in the install menu