Difference between revisions of "Mod:Token Markers"
From Roll20 Wiki
Andreas J. (Talk | contribs) m (api docs navbar) |
Andreas J. (Talk | contribs) m |
||
Line 1: | Line 1: | ||
− | {{apibox}}A new function has been added to the Roll20 API to support custom Token Markers. | + | {{apibox}}A new function has been added to the Roll20 [[API]] to support custom [[Token Markers]]. |
This information is stored under the campaign node as ‘token_markers’. it can be accessed from the api via | This information is stored under the campaign node as ‘token_markers’. it can be accessed from the api via | ||
Line 9: | Line 9: | ||
The return value will a stringified JSON array containing an object for each token marker currently in the game. | The return value will a stringified JSON array containing an object for each token marker currently in the game. | ||
− | <pre>{ | + | <pre style="overflow:auto" data-language="javascript">{ |
"id":59, // the database id for the | "id":59, // the database id for the | ||
"name":"Bane", // the name (non-unique) of the marker | "name":"Bane", // the name (non-unique) of the marker | ||
Line 31: | Line 31: | ||
<code>!gettokenmarkers</code> outputs the currently selected token’s statusmarker attribute to the chat | <code>!gettokenmarkers</code> outputs the currently selected token’s statusmarker attribute to the chat | ||
− | <pre>on("ready", () => { | + | <pre style="overflow:auto" data-language="javascript">on("ready", () => { |
const tokenMarkers = JSON.parse(Campaign().get("token_markers")); | const tokenMarkers = JSON.parse(Campaign().get("token_markers")); | ||
const getChatMessageFromTokenMarkers = markers => { | const getChatMessageFromTokenMarkers = markers => { |
Revision as of 18:17, 25 March 2021
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
A new function has been added to the Roll20 API to support custom Token Markers.
This information is stored under the campaign node as ‘token_markers’. it can be accessed from the api via
Campaign().get("token_markers");
This information is read-only.
The return value will a stringified JSON array containing an object for each token marker currently in the game.
{ "id":59, // the database id for the "name":"Bane", // the name (non-unique) of the marker "tag":"Bane::59", // how the token is actually referenced // this will include the id for custom markers, but not // for default markers. "url":"https://s3.amazonaws.com/files.d20.io/images/59/yFnKXmhLTtbMtaq-Did1Yg/icon.png?1575153187" // ^the url for the token marker's image }
We’ve written an example script to show how you can use this to find Token Markers available in your Campaign.
Add this Script to your game and these commands will be available:
!markernames
will output all markers to the chat with the image, name and id
!markerids <name>
will output any/all markers to the chat that match the provided name
!settokenmarker <string>
will add the provided string to the currently selected token’s marker list. Note that this doesn’t do any validation to make sure the Token Marker exists, it simply adds the provided value to the token markers.
!gettokenmarkers
outputs the currently selected token’s statusmarker attribute to the chat
on("ready", () => { const tokenMarkers = JSON.parse(Campaign().get("token_markers")); const getChatMessageFromTokenMarkers = markers => { let chatMessage = ''; _.each(markers, marker => { chatMessage += `<p><img src='${marker.url}'> ${marker.id}: ${marker.name}</p>`; }); return chatMessage; }; on("chat:message", msg => { if(msg.content.split(" ")[0].toLowerCase() === '!markernames') { let chatMessage = getChatMessageFromTokenMarkers(tokenMarkers); sendChat("Token Markers", chatMessage); } else if(msg.content.split(" ")[0].toLowerCase() === '!markerids') { const markerName = msg.content.split(" ")[1].toLowerCase(); let results = []; _.each(tokenMarkers, marker => { if(marker.name.toLowerCase() === markerName) results.push(marker); }); log(results); let chatMessage = getChatMessageFromTokenMarkers(results); chatMessage = chatMessage || 'Unable to find any matching token markers' sendChat("Token Markers", chatMessage); } else if(msg.content.split(" ")[0].toLowerCase() === '!settokenmarker') { const markerName = msg.content.split(" ")[1].toLowerCase(); if (!msg.selected && msg.selected[0]._type == "graphic") return; obj = getObj(msg.selected[0]._type, msg.selected[0]._id); currentMarkers = obj.get("statusmarkers").split(','); currentMarkers.push(markerName); obj.set("statusmarkers", currentMarkers.join(',')); } else if(msg.content.split(" ")[0].toLowerCase() === '!gettokenmarkers') { if (!msg.selected) return; if (msg.selected[0]._type !== "graphic") return; obj = getObj(msg.selected[0]._type, msg.selected[0]._id); currentMarkers = obj.get("statusmarkers"); sendChat("Token Markers", currentMarkers); } }); });