From 13f64cfaf7cdb0974c1ca75b4800e8241c93b406 Mon Sep 17 00:00:00 2001 From: KimJacobsen1 Date: Sat, 24 May 2025 11:49:51 +0200 Subject: [PATCH 1/3] Create feartracker.js Adds a simple and styled API script to track Fear Points for a named character in Daggerheart-style games. No token required. Supports +, -, set, and show commands with immersive chat card output. --- DaggerheartFearPointsTracker/feartracker.js | 107 ++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 DaggerheartFearPointsTracker/feartracker.js diff --git a/DaggerheartFearPointsTracker/feartracker.js b/DaggerheartFearPointsTracker/feartracker.js new file mode 100644 index 000000000..6a9313a31 --- /dev/null +++ b/DaggerheartFearPointsTracker/feartracker.js @@ -0,0 +1,107 @@ +// Daggerheart Fear Points Tracker (Card Style, Max Cap, No Token Needed, Set Command) +// Version 1.0 – May 2025 +// Author: Kim Jacobsen +// +// Description: +// Tracks Fear Points for a single character with immersive chat cards. +// Works without needing a token or custom character sheet. +// +// 📌 Setup Instructions: +// 1. Create a character in your Roll20 Journal with the exact name below: +// let characterName = "Kim the Brave"; // <-- Change this if needed +// 2. The script will automatically create an attribute called "fear_points". +// +// 🛠️ Customization: +// - Change the name in `characterName` to target another character +// - Change `MAX_FEAR` to increase or decrease the fear cap +// +// 💬 Chat Commands: +// !fear +2 → Add 2 fear points +// !fear -1 → Remove 1 fear point +// !fear set 5 → Set fear points to exactly 5 +// !fear show → Display current fear points +// +// 🧠 Tip: You can create macros or abilities for these commands +// for easier in-game use. + +on('chat:message', function(msg) { + if (msg.type !== 'api') return; + if (!msg.content.startsWith('!fear')) return; + + let args = msg.content.split(' '); + let cmd = args[1] || 'show'; + let amount = parseInt(args[1], 10); + + // Set your maximum here! + const MAX_FEAR = 12; + + // Always use the same character (set your character's name here) + let characterName = "Kim the Brave"; + let character = findObjs({ type: 'character', name: characterName })[0]; + + if (!character) { + sendChat('Fear Points', '/w "' + msg.who + '" Character sheet not found! Please check the name in the script.'); + return; + } + + let attr = findObjs({ type: 'attribute', characterid: character.id, name: 'fear_points' })[0]; + + if (!attr) { + attr = createObj('attribute', { + characterid: character.id, + name: 'fear_points', + current: 0 + }); + } + let current = parseInt(attr.get('current'), 10) || 0; + + function fearCard(title, body, total, maxed = false) { + return `/direct
+
+ 😱 ${title} +
+
+ ${body} + ${maxed ? "
⚠️ Maximum Fear reached!
" : ""} +
+
+ Total: ${total} / ${MAX_FEAR} +
+
`; + } + + if (cmd === 'set' && !isNaN(args[2])) { + let setTo = Math.max(0, Math.min(parseInt(args[2], 10), MAX_FEAR)); + attr.set('current', setTo); + sendChat('Fear Points', fearCard( + character.get('name') + "'s Fear Points Set!", + `Fear Points set to ${setTo}.`, + setTo, + setTo === MAX_FEAR + )); + } else if (cmd === 'show' || isNaN(amount)) { + sendChat('Fear Points', fearCard( + character.get('name') + "'s Fear Points", + `You currently have ${current} Fear Point${current === 1 ? '' : 's'}.`, + current, + current >= MAX_FEAR + )); + } else if (amount > 0) { + let newTotal = Math.min(current + amount, MAX_FEAR); + attr.set('current', newTotal); + sendChat('Fear Points', fearCard( + character.get('name') + ' Gained Fear!', + `Gained ${Math.min(amount, MAX_FEAR - current)} Fear Point${Math.min(amount, MAX_FEAR - current) === 1 ? '' : 's'}!`, + newTotal, + newTotal === MAX_FEAR + )); + } else if (amount < 0) { + let newTotal = Math.max(0, current + amount); + attr.set('current', newTotal); + sendChat('Fear Points', fearCard( + character.get('name') + ' Lost Fear', + `Lost ${Math.abs(amount)} Fear Point${Math.abs(amount) === 1 ? '' : 's'}.`, + newTotal + )); + } +}); From eb54da4e376bb6aa4f5e6a2a2e8ec55f6a1abd49 Mon Sep 17 00:00:00 2001 From: KimJacobsen1 Date: Sat, 24 May 2025 12:09:50 +0200 Subject: [PATCH 2/3] DaggerheartFearPointsTracker/script.json --- DaggerheartFearPointsTracker/script.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 DaggerheartFearPointsTracker/script.json diff --git a/DaggerheartFearPointsTracker/script.json b/DaggerheartFearPointsTracker/script.json new file mode 100644 index 000000000..3276461aa --- /dev/null +++ b/DaggerheartFearPointsTracker/script.json @@ -0,0 +1,15 @@ +{ + "name": "Daggerheart Fear Points Tracker", + "script": "feartracker.js", + "version": "1.0", + "previousversions": [], + "description": "Tracks Fear Points for a specific character in Daggerheart-style games, using chat card visuals with a max cap and no token dependency.\n\tUse commands like `!fear +1`, `!fear -1`, `!fear show`, or `!fear set 5`.\n\tAutomatically creates the attribute `fear_points` if it doesn't exist.\n\tCustomize max value and character name directly in the script.\n\tStyled output for immersive chat cards.", + "authors": "Kim Jacobsen", + "roll20userid": "4642624", + "patreon": "", + "tipeee": "", + "useroptions": [], + "dependencies": [], + "modifies": ["attribute:read", "attribute:write"], + "conflicts": [] +} From 4a9929ab1e0ffa8bfd9492fbc974cdaafcd4ff58 Mon Sep 17 00:00:00 2001 From: KimJacobsen1 Date: Fri, 30 May 2025 09:21:01 +0200 Subject: [PATCH 3/3] Update script.json --- DaggerheartFearPointsTracker/script.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DaggerheartFearPointsTracker/script.json b/DaggerheartFearPointsTracker/script.json index 3276461aa..0b43f6758 100644 --- a/DaggerheartFearPointsTracker/script.json +++ b/DaggerheartFearPointsTracker/script.json @@ -10,6 +10,11 @@ "tipeee": "", "useroptions": [], "dependencies": [], - "modifies": ["attribute:read", "attribute:write"], + "modifies": { + "attribute": [ + "read", + "write" + ] + }, "conflicts": [] }