Difference between revisions of "Mod:Token Markers"
From Roll20 Wiki
Andreas J. (Talk | contribs) m |
Andreas J. (Talk | contribs) m (1223200 moved page API:Token Markers to Mod:Token Markers) |
||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
− | {{revdate}}{{API dev}}{{apibox}} | + | {{revdate}}{{API dev}}{{apibox}}Roll20 [[Mod]] as a function to support custom [[Token Markers]]. |
− | This information is stored under the campaign node as | + | This information is stored under the campaign node as {{c|token_markers}}. it can be accessed via |
<code>Campaign().get("token_markers");</code> | <code>Campaign().get("token_markers");</code> |
Latest revision as of 08:53, 9 June 2024
Page Updated: 2024-06-09 |
This is related to Mods, which require Pro info to be able to use.Main Page: Mod:Development |
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
Roll20 Mod as a function to support custom Token Markers.
This information is stored under the campaign node as token_markers
. it can be accessed 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); } }); });