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

[Script] NPCTokens - Automatically adjust size and bars for NPC Tokens

June 22 (2 years ago)

Hey there,

I made a simple lightweight script to adjust token size and change the bars, when it is added from the journal.
Here is the link to github https://github.com/Kerubis/Roll20Api/tree/master/NPCToken

The script sets the size depending on the npc_type.
Currently supported is: tiny / small / medium / large / huge / gargantuan (giant)

You can assign whatever attribute you want to the bars.
You can choose which bars to show.
You can set the bars to compact.
The attribute npc_hpformula is automatically calculated.

Currently there is no UI or anything because the script has only 7 options, adjust these when inserting the script

    var bar1 = '';
    var bar2 = 'npc_ac';
    var bar3 = 'npc_hpformula';
    var showbar1 = false;
    var showbar2 = false;
    var showbar3 = true;
    var compactbars = `compact`;

I am happy to add functionality if needed, but I want to keep it fairly lightweight.

Known quirks:
The script only works properly with a 70x70 grid.

Cheers Kerubis

Interesting approach to alter the size when a token is dropped on VTT.

June 23 (2 years ago)
Gauss
Forum Champion

Kerubis, you mentioned that the script only works properly with a 70x70 grid. 

Could you describe what happens when it is not a 70x70 grid? I think you may be running into a known bug. 

June 24 (2 years ago)

Edited June 24 (2 years ago)
David M.
Pro
API Scripter

It's because the modifyTokenSize function hardcodes the sizes to a set number of pixels. To get it to work properly on differently scaled maps, you'll need to get the snapping_increment property of the current page and multiply it by the currently hardcoded pixel size.

June 24 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Token mod, for instance, handles this by giving the user the "units" measurement. It does the calculation David describes if you tell it to size something to "2u".

Kerubis, what is the use case for your script? Does it offer functionality beyond just saving a default token at the proper size?

The script changes the size when a character’s token is dropped onto the VTT screen, based on the text of creature type field.

June 24 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

That I understand, but this is also something handled by default token settings, and by the Compendium. I'm trying to discover when this would not be the case. I feel like I am missing something here. Wouldn't it make more sense to set the size once, and save that as the default token? Then you would have a token that obeys the map scale and would not need to be resized programatically on every drop.

June 25 (2 years ago)

Edited June 25 (2 years ago)

A script is only allowed to set default token based on an image in a user art library.

A script is allowed to change the size of all tokens that have been created on a page, including images from the marketplace.

June 25 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter


Martijn S. said:

A script is only allowed to set default token based on an image in a user art library.

A script is allowed to change the size of all tokens that have been created on a page, including images from the marketplace.

A script can set a default token even when the image is only in Marketplace images. (I just verified, using token-mod with !token-mod --set defaulttoken and a marketplace image)

You cannot create an image on the VTT from a marketplace source, but you can change the size, assign permissions, have it represent a character, set default token and so forth.

June 25 (2 years ago)

You could set the default token for every character, but its much more work to do so. I just wanted to have some fast and easy way to set up my npc's.

Maybe I am missing some feature. but as far as I know I always have to drop the token into the map, change it to whatever size I want then save the default token.

I am gonna look into the snapping_increment and multiply it correctly, I did not know about this.