Difference between revisions of "Mod:Short Community Scripts"
From Roll20 Wiki
Andreas J. (Talk | contribs) m (Blind Rolls) |
Andreas J. (Talk | contribs) m (→Blind Roll (TheAaron)) |
||
Line 24: | Line 24: | ||
3d20+8 Weird attack.. | 3d20+8 Weird attack.. | ||
</pre> | </pre> | ||
− | + | {| role="presentation" class="wikitable mw-collapsible mw-collapsed" | |
− | <pre data-language="javascript"> | + | | Blind Roll API code |
+ | |- | ||
+ | | <pre data-language="javascript"> | ||
/******************************************************************************* | /******************************************************************************* | ||
* rollers.js - Provides specialized dice rolling alternatives. | * rollers.js - Provides specialized dice rolling alternatives. | ||
Line 177: | Line 179: | ||
} | } | ||
}); | }); | ||
− | </pre> | + | </pre>|} |
===Blind Roll (Stephen)=== | ===Blind Roll (Stephen)=== |
Revision as of 15:07, 5 December 2021
Page Updated: 2021-12-05 |
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 |
Chat
Blind Roll (TheAaron)
Example:
!blindroll [[@{selected|skill}+1]]d20+[[ [[@{selected|attack]]+@{target|ac} ]] Weird attack..
Results in player seeing:
Blind roll sent to GM 3d20+8 Weird attack..
Blind Roll API code |
}
Blind Roll (Stephen)Works just like a GM Roll.... only the player doesn't see the dice roll result. !broll 1d100+10 to pick pocket Jimmy<pre> Would result in the players seeing: :''"Secret roll sent to GM (1d100+10 to picket pocket Jimmy)"'', with no dice roll result. <pre data-language="javascript"> on("chat:message", function(msg) { var cmdName = "!broll "; var msgTxt = msg.content; var msgWho = msg.who; var msgFormula = msgTxt.slice(cmdName.length); if(msg.type == "api" && msgTxt.indexOf(cmdName) !== -1) { sendChat(msgWho, "/gmroll " + msgFormula); sendChat(msgWho, "/w " + msgWho + " secret roll sent to GM (" + msgFormula + ")"); }; }); TokenMake Rollable Table TokensLittle 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 (
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 TooltipShowtooltip(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('')}`); } } }); });
DropTorchDropTorch(Forum), A little script that lets you and your players drop their light source on the ground. RetrieveTokensRetrieveTokens(Forum) -- get graphics that are off the page HeathStatMapToggleDaylightToggleDaylight(Forum) turn daylight mode on, off, or toggle it for LDL or UDL on the current page.
Other Community APIs
|