Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Help] Using token-mod with Script cards

Hi, I'm trying to use the Token-mod + Fetch scripts to replace the @{selected|token_id} of the Script cards to a @{CharacterToken|token_id}. However, I'm stuck on how to set a Scriptcard variable with token-mod.. Here is an example of what I'm trying to do: !scriptcard {{ --#title|Spell --=specificplayertarget| --@token-mod _ids@(CHARACTERTOKEN.token_id) --#sourceToken|[$specificplayertarget] --#targetToken|@{target|token_id} --#emoteText|@{CHARACTERTOKEN|character_name} used a Spell against @{target|token_name}! }} Of course, replace " CHARACTERTOKEN " with the player's character name. Any idea ?
1677205116
timmaugh
Pro
API Scripter
Hey, Kinji... let me see if I can help. I'm a bit confused, though, so help me if I don't  understand what you are wanting to do. First, TokenMod is only going to handle token properties... it isn't going to return anything to the command line and won't do anything internal to the ScriptCard command text. Also, ScriptCards will dispatch other mod scripts, but that's a fire-and-forget arrangement... nothing that's going to wait for the result of an action (short of a re-entrant method, but that's not really what you're looking for, either). Fetch, as a metascript, will return things to the command line, and it will run before ScriptCards gets a hold of the message, so that by the time ScriptCards sees the syntax, the Fetch construction will have already been replaced with the returned/fetched result. I *think* you are intending (yourself, manually) to replace the CHARACTERNAME with the name of the character so that your Fetch construction saved into the ScriptCards command line might read: @(Bob the Hirsute.token_id) ...and then you want to save the returned tokenID to a ScriptCards variable. If that's right, Fetch will return the fetched value for that formation to your command line. You just have to code  your ScriptCards as if it's there already. --=specificplayertarget|@(Bob the Hirsute.token_id) Or are you trying to do something more intricate ... like getting the tokenID of the default/primary character associated with a player?
I didn't think about that, I feel so dumb lmao It worked like a charm, thank you! While you're still here, do you know by chance how I could tinker with Aura/Tint Healthcolor (or an alternative) to trigger the aura change only when the token reaches respectively [75% | 50% | 25% | 10%] of his HP ?
1677214863

Edited 1677245476
timmaugh
Pro
API Scripter
You can handle most of that with meta scripts. APILogic can handle the conditionals, MathOps can handle deriving the percentage... Leaving just the question of how/when the command would be run. If Aura/Tint doesn't have a listener waiting to take action based on an event, you will still be left with running the command manually... Even though the conditional will make your life easier in terms of knowing which one to apply. A listener script could be written, and I've had one in the back of my head for a while now, but the complication there is that scripts don't generate events for other scripts to listen for. Scripts can only answer events generated by game actions taken by players... if that makes sense. I have an idea for a workaround for that problem, but it will take a few days to put it together to see if it works. If you are happy with a manually triggered command line, then post your aura command lines, and I can help you adapt them using the metascripts I mentioned.
1677262498

Edited 1677262527
Couldn't it listen the same way Aura/Tint is listening ? The script is updating the token aura each time its bar value changes (and adding fx) I want it to do the exact same things Aura/Tint is doing (changing the token aura color) but instead of updating the color each time the hp changes, I'd want it to change to specific colors when health reaches respectively 100%, 75%, 25%, 10%, 0%
1677264564
timmaugh
Pro
API Scripter
Kinji said: Couldn't it listen the same way Aura/Tint is listening ? The script is updating the token aura each time its bar value changes (and adding fx) I want it to do the exact same things Aura/Tint is doing (changing the token aura color) but instead of updating the color each time the hp changes, I'd want it to change to specific colors when health reaches respectively 100%, 75%, 25%, 10%, 0% Exactly... I didn't know if it had this functionality built in. But now that I think about it, that means it might not be running a straight command line (through chat), but handling it on the backend directly in the sandbox. Let me look at the script...
1677264611

Edited 1677264769
Isn't it this: !scriptcard {{ --#title|Spell --#emoteText|@{Selected|character_name} used a Spell against @{target|token_name}! }} What specifically are you trying to modify on the Token?   FYI - I don't believe Token-Mod can return values back to scriptcards.  However, almost every object and most fields are available natively to Scriptcards.  Just need to know the syntax for retrieval.  
Will M. said: Isn't it this: !scriptcard {{ --#title|Spell --#emoteText|@{Selected|character_name} used a Spell against @{target|token_name}! }} What specifically are you trying to modify on the Token?   FYI - I don't believe Token-Mod can return values back to scriptcards.  However, almost every object and most fields are available natively to Scriptcards.  Just need to know the syntax for retrieval.   This issue was solved, thanks tho!
timmaugh said: Kinji said: Couldn't it listen the same way Aura/Tint is listening ? The script is updating the token aura each time its bar value changes (and adding fx) I want it to do the exact same things Aura/Tint is doing (changing the token aura color) but instead of updating the color each time the hp changes, I'd want it to change to specific colors when health reaches respectively 100%, 75%, 25%, 10%, 0% Exactly... I didn't know if it had this functionality built in. But now that I think about it, that means it might not be running a straight command line (through chat), but handling it on the backend directly in the sandbox. Let me look at the script... How do you inspect the code of a One-click script ?
1677271450
timmaugh
Pro
API Scripter
You can either choose to "Import" it into your game instead of "Install"ing it, or  grab it directly from the GitHub repo, which is what I did. It's HealthColors, correct?
Damn, didn't know about that, also yes that's right, HealthColors
1677276415
timmaugh
Pro
API Scripter
I haven't spent a ton of time with the code, but I think the bit you want to change is this function, at line 377 (for the starting comment): //PERC TO RGB------------ PercentToHEX = function (percent) {   var HEX;   if(percent > 100) HEX = "#0000FF";   else {     if(percent === 100) percent = 99;     var r, g, b = 0;     if(percent < 50) {       g = Math.floor(255 * (percent / 50));       r = 255;     }     else {       g = 255;       r = Math.floor(255 * ((50 - percent % 50) / 50));     }     HEX = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);   }   return HEX; } I think the only reason the reassignment of percent to be 99 (if it equals 100) is there is for the math and the bitwise operation, below. So if you wanted, you could replace that whole bit with a four-stage if statement that assigned the HEX value you want, directly: //PERC TO RGB------------ PercentToHEX = function (percent) {   let HEX;   if(percent > 100) HEX = "#0000FF";   else  if(percent === 100) HEX = " #04aa0d" ;   else if(percent >= 75)  HEX = " #8caa04 " ;   else if(percent >= 50) HEX = " #ff7272" ;   else if(percent >=25) HEX = " #ff0000" ;   return HEX; } Obviously you can pick your own colors. That should take effect for every aura, then.
I think the Aura supports a 2 digit transparent color component if you add it to the end.  You could take the damage percentage, convert it to a 2 digit number and then use that to slowly blend the damage in.
1677427985

Edited 1677428548
timmaugh said: I haven't spent a ton of time with the code, but I think the bit you want to change is this function, at line 377 (for the starting comment): //PERC TO RGB------------ PercentToHEX = function (percent) {   var HEX;   if(percent > 100) HEX = "#0000FF";   else {     if(percent === 100) percent = 99;     var r, g, b = 0;     if(percent < 50) {       g = Math.floor(255 * (percent / 50));       r = 255;     }     else {       g = 255;       r = Math.floor(255 * ((50 - percent % 50) / 50));     }     HEX = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);   }   return HEX; } I think the only reason the reassignment of percent to be 99 (if it equals 100) is there is for the math and the bitwise operation, below. So if you wanted, you could replace that whole bit with a four-stage if statement that assigned the HEX value you want, directly: //PERC TO RGB------------ PercentToHEX = function (percent) {   let HEX;   if(percent > 100) HEX = "#0000FF";   else  if(percent === 100) HEX = " #04aa0d" ;   else if(percent >= 75)  HEX = " #8caa04 " ;   else if(percent >= 50) HEX = " #ff7272" ;   else if(percent >=25) HEX = " #ff0000" ;   return HEX; } Obviously you can pick your own colors. That should take effect for every aura, then. Worked, thanks!
1677441682

Edited 1677441758
Here's another issue of mine tho, I'm trying to write a scriptcard like this: !scriptcard {{ --i|t;target1;Target --=targethp|@{[&target1]|bar1} --+|[$targethp] }} However, it doesn't work because Roll20 reads the "@{}" before the "--i" part of the scriptcard. I just wanna be able to read the target bar1 value, but in a way that I could do it with multiple targets on the same scriptcard, ideally I'd have "target1", "target2", etc..
1677477266
timmaugh
Pro
API Scripter
I'm not sure what you're doing with the ScriptCards syntax there, but what do you gain by not using the standard targeting syntax of Roll20? @{target|Target1|bar1} ? Then you could use a similar construction for Target2, etc.
I can't use @{Target] if I plan the scriptcard to read multiple targets, like that: !scriptcard {{ --i|t;target1;Target||t;target2;Target 2||t;target3;Target 2 --=targethp|@{[&target1]|bar1} --=target2hp|@{[&target2]|bar1} --=target2hp|@{[&target3]|bar1} --+|[$targethp] [$target2hp] [$target3hp] }}
1677516352

Edited 1677562492
timmaugh
Pro
API Scripter
So, clearly the @{} syntax is breaking because you want it to resolve after ScriptCards can populate data, which isn't going to happen. What I'm not sure is how ScriptCards would know which token should be represented by Target, Target2, and Target3 (to then use in those   @{}   constructions) short of using Roll20's targeting syntax. If ScriptCards doesn't offer you a native way to get info from a token to solve this problem (and it seems that it does, but I'm just not fluent enough in it to steer you), then you can change the @{} formations to Fetch contstructions... @() The timing to be aware of, here, is that Fetch will run before ScriptCards, so you can't use constructions that you intend ScriptCards to resolve WITHIN the Fetch construction. You can use the Targeting syntax, however: @(@{target|Target1|token_id}.bar1) @(@{target|Target2|token_id}.bar1) @(@{target|Target3|token_id}.bar1)
Oh nice, I didn't know Fetch could work inside Scriptcard! Thank you!