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

Toggle Grid Opacity via API - Is that possible?

September 09 (1 year ago)

Hi! I hope I find you well.

Unfortunately I don't know programming, but I would really appreciate it if someone had a solution to my request. I'd like a script to toggle the opacity of the page's grids between 0% (fully invisible) and the opacity that's currently on the page's grids (let's say it's around 80%).

So I could put the code that activates this script in a macro and then create a button. This way I should have a button to toogle the opacity of the grids to 0% or the previous page's grids.

I don't know if we can ask for such thing in the forum. I hope so!

Could anyone help with this request?

Thanks in advance!

September 09 (1 year ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Hi Ryutord!

I had written and posted a much longer response to your first post, but the system ate it when you deleted the topic. Please don't do that. :) Here's a shorter version. The mod script Dynamic Lighting Tool contains those macro commands. The syntax is:

!dltool-mod --grid_opacity|1

You can replace that 1 value with any value between 0 and 1 and put it in a macro button.

September 09 (1 year ago)

That worked perfectly!

keithcurtis, as always, you rock! Congratulations on the job so well done and for helping so many of us with these beautiful scripts!

Sorry for deleting the previous post... I made a grammatical error in the title and I wasn't able to edit it, just the content. So I thought it would be good to delete that and create another one with the correct title.

Again, thank you very much! Believe me, I'm really happy with the time this will save.

...

And since you answered me... even without wanting to give you more work than I've already done so far... I would like to know if there is an API for another problem I have. I would really appreciate it if you could help with this one too!

(I know I should create another topic for this new request... but I know that this message will already signal directly to you. However, if you think it's better, I will create another topic with this new request!)

This is the following:

In my campaigns I created some items called Light Orbs. Basically they increase Attack or Defense values:

Defending Orb increases AC;

The Melee Orb increases Melee Weapon Attacks;

The Ranged Orb increases Ranged Weapon Attacks;

And the Spell Orb increases Magical Attacks (strictly spells that require a d20 roll to hit).

These Orbs are individual: each player has a set of these Orbs. Unfortunately I can't use the Global Modifier because such Orbs cannot increase Damage, only Attack.

Looking on several sites on how to do this, I found something that works (here) ...but not completely.

In the MODS field of the Defending Orb I use the code “AC +X” to modify the AC to any value I want. For the Spell Orb I use “spell attack +X” to increase Magical Attacks. And they work great!

However, both the code for the Melee Orb “Melee Weapon Attacks +X” and the Ranged Orb “Ranged Weapon Attacks +X” do not work and I have to manually modify every players' weapons with each change made, which is quite time consuming!

About one year ago I sent an email to Roll20 Support, to which I received the response that “We are aware of this error and we will work to correct it.”

I’ve looked for a script that would do this: individually increase Attack damage for Melee and Ranged separately, individually for each player, but unfortunately I have been unsuccessful.

So Mr. Curtis... is it possible to help me with such problem?

Thank you in advance for your help and time! Again!

September 10 (1 year ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

First, thanks for the kind words.


As for your problem, that's a toughie. Melee Damage +n is not intended to be global, but only to affect the equipment item it is defining. Here's a link to all of the equipment mods, if you haven't already found it. This sort of thing is doable with the D&D Shaped Sheet, but that sheet, powerful as it is, hasn't been supported in years. I think the best option is to create a global damage mod and toggle it on and off with ChatSetAttr if you are looking for automation, or just toggle it by clicking it on the sheet. I don't think it can be dependent on the equipment mods. Let m eknow if that was enough to go on, or if there's anything I need to elaborate.

September 10 (1 year ago)

Unfortunately it didn't work. What I basically need is a Magic Item in which I can determine the amount to increase Attack (+n) for Melee or Ranged, without increasing damage (yes, Attack only). And this increase must be per category: the (+n) increase for a Melee weapon will increase all Melee Attacks only; and an increase (+n) of a Ranged weapon would increase all weapons with Ranged Attacks only.

Thus, each player will adopt a different strategy: for example, a Ranger (most probably) will prefer +n in Ranged weapons, unlike a Fighter who will prefer +n in Melee weapons. If they want to multiclass at some point, they can invest in other weapons (or magic)!

Since I can't do this by creating a magical item (using the MODS field on equipment I can only do this for AC and Spell Attacks, but not for Melee/Ranged weapons, dispite of having a code for that - Roll20's support team told those are really broken), I thought if some API would allow me to do this. And I know that doing this one must be very challenging and it must take a lot of time... if it is even possible to do it!

At the three RPG tables I master, players are loving this system I implemented. But unfortunately, I can't find a solution to speed up such process.

Mr. Curtis, still, I thank you very much for your time and attention. Until someday I find a solution, I must make the changes in the same archaic way: make each change directly to each player's weapons, each time the item is activated deactivated.
May GOD bless you!

September 10 (1 year ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

My suggestion would be to put some of the burden upon your players. Explain to them how their magic items work. They can then either:

  1. Roll normally and mentally add the bonuses and report those to you at the time of the attack, the way you would at a table while rolling physical dice.
  2. Create a Global Damage Bonus (these are on the sheet), and they can toggle these on and off as appropriate. An example would be the barbarian, who does this while Raging for melee attacks.


I can explain the reasoning behind the equipment mod workings though. Global bonuses to spell attacks and saving throws are pretty common in magic items: Rod of the Pact Keeper and Ring of Protection are examples of these. Most items which give damage bonuses are specific to that item (ex: +1 sword). The mods developed as the compendium developed, to give players the convenience of dragging in items that would automatically adjust the rolls when used. The current system matches the greatest number of use cases. The rest become outliers, like Bracers of Archery, which give damage bonuses to other weapons (bows), and must be treated with more manual methods, such as filling in the global modifier fields and toggled as appropriate.

September 10 (1 year ago)

Edited September 10 (1 year ago)
Gauss
Forum Champion

The way I have always done it is to simply put the bonus in the appropriate attack. 
If a weapon has a couple ways to be used I create two attacks for it. 

Example: in 5e the Warlock has some major modifications to their attack (such as critical range) when they curse their enemy. So rather than try to figure out some complicated workaround to a single attack I just make two of them. "Battleaxe" and "Battleaxe (Curse)" with "Battleaxe (Curse)" having all the special features due to cursing the enemy. 

September 10 (1 year ago)

Thank you very much, guys. I do appreciate your help!

September 15 (1 year ago)

Following the perfect help from Mr. Curtis, I am using two macros to control the opacity of the grids: the “GRID – ON” macro (!dltool-mod --grid_opacity|0.6 in it) and the “GRID – OFF” (!dltool -mod --grid_opacity|0).

However, I would like to know if it is possible to reduce this to just one macro button. Unfortunately I don't know programming, but my idea is the creation of a new simple script (so I believe!) that could check what the current grid opacity is, then toggle it. Something like this:

IF grid_opacity = 0

THEN grid_opacity = 0.6

ELSE grid_opacity = 0

Thus, this new script would be in just one GRID macro that would serve as a switch button. It is possible?

September 15 (1 year ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Probably with Metascripts (Timmaugh) or ScriptCards (Kurt). I can ping Timmaugh on Discord, but you might want to contact Kurt yourself.

September 15 (1 year ago)
timmaugh
Forum Champion
API Scripter

This can be easily accomplished with the MetaScriptToolbox script (available in the 1-click). The Toolbox gets you all of the metascript toys, but the ones you need for this are APILogic, Fetch, SelectManager, and ZeroFrame.

Solution

Here's the solution (if you want to see how it works, read on):

!dltool-mod --grid_opacity|{&if @(page.@(selected.pageid).grid_opacity) = 0}0.6{&else}0{&end} {&select *,+npc}

Explanation

APILogic runs conditional checks and modifies the command line by leaving/removing text depending on the result of the check. The main body is an IF conditional in this format...

{&if ... }true text{&else}false text{&end}

Our true and false text are the relative grid opacity settings we want, so depending on the outcome of our check we'll end up leaving behind the appropriate value we want DLTools to use.

The value we're testing in the conditional is the grid opacity of the current page, which we get like this:

@(page.@(selected.pageid).grid_opacity)

Which is actually a compound Fetch construction. You can read the components of the outer statement as this:

@(page.identifier.property)

So we're looking for the grid_opacity of a given page. What page? That's where the nested Fetch construction comes in:

@(selected.pageid)

From this, we get the pageid of the page that the currently selected token is on.

But do you need a selected token? Nope. That's what this SelectManager statement is for:

{&select *, +npc}

That selects everything on the current page which is an npc. We only need to act on the first of these (to get the pageid), but as long as there is 1 such object, this will work.

September 16 (1 year ago)

WOW!

That's perfect!!!

Thank you very much, Mr. Curtis (now it's correct! LOL) and timmaugh for your great help!

Now I have one switch to turn the grid ON and OFF.

Amazing!

Again, thank you very much for your time and pacient!

Both methods of manipulating the grid opacity (a specific button to turn it on (opacity = 0.6) and another to turn it off (opacity = 0), as well as the button to turn opacity on/off) have been giving errors lately. (image of errors is attached)

After such errors, I usually restart the APIs, but the error still persists. Sometimes, after restarting, it works two to three times... after that, it's gone. It’s broken errors again.

Note: In the attached image you can see all APIs used in the game. You may note that there are two scripts that are not in English; they don’t manipulate the opacity of the map. Still, their descriptions are below (just in case):

  • auto_tocar_SFX_d20_d1.js = automatically plays a sound if there is a natural 20 and another sound for the natural 1 on the d20 roll result.
  • Remove_from_turno.js = remove the selected token from the Turn Order.

So… If you can find out what you're happening here, I'd be very grateful!



October 02 (1 year ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Both "evaluateCriteria" and "isNPC" are functions in SelectManager. Neither is present in DLTool. But I wouldn't rule out any synergy issues--I'm a dilletant coder. I'll see if I can ping Timmaugh (SelectManager's author) to come take a peek.

It would be very helpful if you could post the text of the macros that you are using that result in the sandbox crash.

October 02 (1 year ago)
timmaugh
Forum Champion
API Scripter

OK, that error is coming from SelectManager... though it is strange that it would get that far. The error would represent there not being a selected token, which should have tripped other processing pathways before that point.

In any case, I've added a trap so that this shouldn't throw an error (which actually slipped under the wire for the merge this week - so if you got SM from the 1-click, you should have the update, now), and I'll be continuing to look into why/how it got this far, to see if there is anything else I need to account for.

If you still have trouble after getting v1.1.6, post back and share your macro text, like Keith asked (even if it's just to say that it's the above suggestion).

If I can't replicate it in my test game, I might need you to invite/promote me, at that point.

But let's see if 1.1.6 gets you sorted.

Both Keithcurtis and Timmaugh, once again, thank you so much for your great help!

Now it's working perfectly.

Thank you very much!  :)

Unfortunately the error returned!

Timmaugh, as you requested, if the error persisted, I sent the link to enter the game privately. There I will promote you to DM so you can check the error.

Thank you very much!