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 .
×

Is there way to display macro/api button only when conditions are met?

1607538709

Edited 1607543875
title  basically I would like to display button in chat only when custom character value is not equal to 0. (have access to api too)
1607539914

Edited 1607539932
Probably as a macro, but it'll probably require a LOT of setup.  An API could certainly do that.  If you provide more info about exactly what you're trying to do, and what macro/button code you want to display, and what character sheet you are using, then someone could give you a better answer.
I am currently really disappointed with how healing potions are implemented.. Using 5e OGL So I have put healing potions into character sheet atributes - it is holding number of potions on character - and my goal is to have button/macro - which will be showing amount of potions on character - and after pressing a button it will remove one potion from inventory and heal character by rolled amount. Currently I am having this - it will use potion and heal - but I am not sure how to execute this just when there is enough ( >0 ) potions on character !setattr --sel --mod --potion1|-1; !setattr --sel --modb --hp|[[2d4+2]]. or have this - button which is showing amount of potions and will heal when pressed - also again without condition that character must have more than one potion available [Healing Potion -  @{selected|potion1}](!setattr --sel --mod --potion1|-1; !setattr --sel --mod  --hp|[[2d4+2]])
1607544534

Edited 1607544938
The Aaron
Roll20 Production Team
API Scripter
Here's a very simple script that should let you do selective chat output. Basic operation: !do-if <SOME CHECK> --<SOME OUTPUT> <SOME CHECK> should be replaced with something that will result in a number.  If the number isn't 0, it will send whatever is after the -- to chat as whoever called the command.  Example: !do-if @{selected|has_foo} --/w gm Selected character does have foo. or, perhaps: !do-if [[1-@{selected|has_foo}]] --/w gm Selected character does not have foo. In the case of things that might be evaluated by Roll20 chat, like inline rolls or template parts, you can escape them with \: !do-if @{selected|has_foo} --/w gm & \ {template:default}{ \ {name=has foo} \ }{\{roll=[\[1d20]\]}\} Code: on('ready',()=>{ const processInlinerolls = (msg) => { if(msg.hasOwnProperty('inlinerolls')){ return msg.inlinerolls .reduce((m,v,k) => { let ti=v.results.rolls.reduce((m2,v2) => { if(v2.hasOwnProperty('table')){ m2.push(v2.results.reduce((m3,v3) => [...m3,v3.tableItem.name],[]).join(", ")); } return m2; },[]).join(', '); return [...m,{k:`$[[${k}]]`, v:(ti.length && ti) || v.results.total || 0}]; },[]) .reduce((m,o) => m.replace(o.k,o.v), msg.content); } else { return msg.content; } }; const splitOn = (str,regex) => { let first = str.search(regex); if(-1 === first){ return [str]; } return [str.slice(0,first),str.slice(first).replace(regex,'')]; }; const sanitize = (str) => str.replace(/\\(.)/g,(m)=>m[1]); on('chat:message',msg=>{ if('api'===msg.type && /^!do-if(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ let parts = splitOn(processInlinerolls(msg),/\s+--/); let args = parts[0].split(/\s+/); if(parseInt(args[1])){ sendChat(msg.who,sanitize(parts[1])); } } }); });
1607545187
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I'm surprised you didn't write this five years or more ago. This has a lot of potential.
Oh this is amazing! and it works with button too :))) thanks!
Now just to find out how to format it bit nicely (or put it in template :) )
1607545856
The Aaron
Roll20 Production Team
API Scripter
keithcurtis said: I'm surprised you didn't write this five years or more ago. This has a lot of potential. Well, no one had asked the right question yet... =D
Klobass_dummy said: Now just to find out how to format it bit nicely (or put it in template :) ) Try this: &{template:npcaction} {{name=@{selected|race} @{selected|class}}} {{rname=@{selected|character_name}}} {{description=[Healing Potion - @{selected|potion1}](!setattr --sel --mod --potion1|-1; !setattr --sel --mod --hp|[[2d4+2]] #" style="background: none; background-color: transparent; border: none; display: inline; padding: 0px; color: #ce0f69; text-decoration: none;) [Greater Potion - @{selected|potion2}](!setattr --sel --mod --potion2|-1; !setattr --sel --mod --hp|[[4d4+4]] #" style="background: none; background-color: transparent; border: none; display: inline; padding: 0px; color: #ce0f69; text-decoration: none;) [Superior Potion - @{selected|potion3}](!setattr --sel --mod --potion3|-1; !setattr --sel --mod --hp|[[8d4+8]] #" style="background: none; background-color: transparent; border: none; display: inline; padding: 0px; color: #ce0f69; text-decoration: none;) [Supreme Potion - @{selected|potion4}](!setattr --sel --mod --potion4|-1; !setattr --sel --mod --hp|[[10d4+20]] #" style="background: none; background-color: transparent; border: none; display: inline; padding: 0px; color: #ce0f69; text-decoration: none;)}}
Jarren K. said: Try this: &{template:npcaction} {{name=@{selected|race} @{selected|class}}} {{rname=@{selected|character_name}}} {{description=[Healing Potion - @{selected|potion1}](!setattr --sel --mod --potion1|-1; !setattr --sel --mod --hp|[[2d4+2]] #" style="background: none; background-color: transparent; border: none; display: inline; padding: 0px; color: #ce0f69; text-decoration: none;) [Greater Potion - @{selected|potion2}](!setattr --sel --mod --potion2|-1; !setattr --sel --mod --hp|[[4d4+4]] #" style="background: none; background-color: transparent; border: none; display: inline; padding: 0px; color: #ce0f69; text-decoration: none;) [Superior Potion - @{selected|potion3}](!setattr --sel --mod --potion3|-1; !setattr --sel --mod --hp|[[8d4+8]] #" style="background: none; background-color: transparent; border: none; display: inline; padding: 0px; color: #ce0f69; text-decoration: none;) [Supreme Potion - @{selected|potion4}](!setattr --sel --mod --potion4|-1; !setattr --sel --mod --hp|[[10d4+20]] #" style="background: none; background-color: transparent; border: none; display: inline; padding: 0px; color: #ce0f69; text-decoration: none;)}} This is cool and I knew about it - but it does not really work with that nifty script from Aron - at least I did not made it working yet :)
1607549647

Edited 1607549723
The Aaron
Roll20 Production Team
API Scripter
Ah, that would require some row-wise logic, or this little script+ some logic from another script I'm almost done with...
The Aaron said: Ah, that would require some row-wise logic, or this little script+ some logic from another script I'm almost done with... I am curious :)