Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

Mod:Token Markers

From Roll20 Wiki

Revision as of 08:53, 9 June 2024 by Andreas J. (Talk | contribs)

Jump to: navigation, search

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);
        }
    });
});