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

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&nbsp; <a href="https://github.com/Kerubis/Roll20Api/tree/master/NPCToken" rel="nofollow">https://github.com/Kerubis/Roll20Api/tree/master/NPCToken</a> 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 &nbsp; &nbsp; var bar1 = ''; &nbsp; &nbsp; var bar2 = 'npc_ac'; &nbsp; &nbsp; var bar3 = 'npc_hpformula'; &nbsp; &nbsp; var showbar1 = false; &nbsp; &nbsp; var showbar2 = false; &nbsp; &nbsp; var showbar3 = true; &nbsp; &nbsp; 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.
1687540470
Gauss
Forum Champion
Kerubis, you mentioned that the script only works properly with a 70x70 grid.&nbsp; Could you describe what happens when it is not a 70x70 grid? I think you may be running into a known bug.&nbsp;
1687601513

Edited 1687601535
David M.
Pro
API Scripter
It's because the&nbsp;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.
1687619647
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.
1687645166
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.
1687729257

Edited 1687729308
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&nbsp; images from the&nbsp; marketplace.
1687731899
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&nbsp; images from the&nbsp; 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.
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&nbsp; snapping_increment &nbsp;and multiply it correctly, I did not know about this.