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

Making an NPC character sheet with a mod

I'm attempting to write a mod that will generate an NPC character sheet with an associated token, then place the token next to the player (i.e. the Drake Companion feature of the Drakewarden). I know the API can generate character sheets for player characters, but how do I generate an NPC character sheet?
1685451228
David M.
Pro
API Scripter
Sounds like you're talking about the 5e by Roll20 sheet. I haven't tried this, but can you just set the "npc" attribute to "1"?
J1n G1taxias said: I'm attempting to write a mod that will generate an NPC character sheet with an associated token, then place the token next to the player (i.e. the Drake Companion feature of the Drakewarden). I know the API can generate character sheets for player characters, but how do I generate an NPC character sheet? David M. said: Sounds like you're talking about the 5e by Roll20 sheet. I haven't tried this, but can you just set the "npc" attribute to "1"? I'll also assume you're asking about the 'D&D 5E by Roll20' character sheet. Are you looking for a Mod script that will fill out an NPC character sheet, or one that will simply place a token on the VTT for a specified character that has already been created? There is a Mod ('BeyondImporter') that can take the .json data from D&D Beyond and create character sheets in Roll20 (though it is prone to occasional breaking whenever DDB updates their .json info). But that is to fill out the character sheet. There are other Mods (such as 'Spawn Default Token' or 'Its a Trap') that can place tokens on the VTT which are linked to a character sheet. Those will work already for NPC characters. I'm not aware of any Mod that will correctly/fully fill out all of the NPC sheets for D&D 5th Edition.  Some of the fields for a PC are the same as what are used for NPCs, but many of them are not.  ChatSetAttr can fill out attributes, but you'll need some way to parse the data so that it is readable by the script, and it may be a little tricky to automate it. If you had the NPC data in an Excel/Google Docs spreadsheet, it would be pretty easy for me to walk you through that.
1685466946
David M.
Pro
API Scripter
Looks like OP is writing a custom mod script.
For clarification, I am using the 5e sheet, and this is a custom script. My goal is that, in absence of a custom NPC sheet being created before running, one is generated before placing the token. My specific use case is that one of my players has the Drakewarden subclass, which can spawn a Drake with traits that are based on the players proficiency bonus and ranger level. I did try just setting the npc field to 1, but by default the npc attribute doesn't exist, and returns as undefined. I'm wondering if there is a visible attribute that I can change to accomplish this. 
1685525421

Edited 1685526242
Gauss
Forum Champion
Hi J1n G1taxias,  My suggestion is to approach this from a different direction.  1)  There are a number of issues with the stats when it comes to 5e companions such as the Drake because they are not in autocalculated fields on the NPC sheet.  For attacks and damage that works out fine, NPC attack and damage fields are autocalculated and can pull from another character's bonuses. But for things like saving throws, it needs extra help since they are not calculated fields.  Solution: An api script such as ChatSetAttr can probably take care of that.  So what you can do is create an NPC normally, then use the script to set the AC, HP, Dex Save, Wisdom Save every time there is a level up.  Example:  Upon level up hit a macro that has the script set the following: (note, doing this off of memory so some attributes might be inaccurate) set @{charactername|npc_ac} to the calculated value of 14+@{charactername|PB} set  @{charactername|hp|max} to  the calculated value of  5+5*@{charactername|level} set  @{charactername|npc_dex_save} to  the calculated value of  1+@{charactername|PB} set  @{charactername|npc_wis_save} to  the calculated value of  2+@{charactername|PB} 2) Placement when summoned.  Your solution of placing it next to the character doesn't require generating the NPC at that time.  Make a character, assign the token appropriately.  Next, have the player drag and drop from the journal, or if you really want to automate it in some fashion the API may be able to do that. Either by dropping the token to the sheet (not sure if it can do that, one of the API gurus would know more than I would) or by copying a token and dropping the copy from somewhere (pretty sure that can be done if the Teleport script is any indication). Note: placing the token next to the character is not accurate to the rules as you are allowed to summon the Drake anywhere within 30 feet. So automating that doesn't really solve any particular problem as the player can simply drag and drop from the journal or if using a script should be able to click the destination of where they want the Drake.  However, regarding the missing NPC attribute, it appears only when the character sheet is manually switched from PC to NPC. It is an event generated attribute. 
1685530732

Edited 1685532191
David M.
Pro
API Scripter
In that case you could use the Spawn script, using this Echo Knight example as a baseline to override the AC and hp bar values of the token. You could use Gauss' method to update the drake's character sheet on level up so the spawned companion would have the correct attack values and saving throws !Spawn {{ --name|Drake Companion --offset|1,0 --bar1|[[5 + 5*@{selected|level}]] --bar2|[[14 + @{selected|pb}]] }} For the attack/damage values of the npc character sheet, you can edit the att/dam fields of the Bite action to the following, substituting the ranger's character name accordingly. This will automatically increase as the ranger levels. TO HIT:    3+@{charName|pb} ON HIT:    1d6+@{charName|pb} When clicked to roll in chat, it will use the referenced values. Note if you mouseover the results there will be a strange +0 at the end of the rolls which you can just ignore. Unfortunately, the saving throws can't use references like this :(
Thank you all for your responses. I will try a mix of these approaches later today, and I will respond with what ended up working. I'm still relatively curious why the ability to generate an NPC character sheet for the 5E sheet is not possible, but if this is the one luxury I'm not afforded with the API system, I believe I can live with that
1685565644

Edited 1685566415
Gauss
Forum Champion
J1n G1taxias said: Thank you all for your responses. I will try a mix of these approaches later today, and I will respond with what ended up working. I'm still relatively curious why the ability to generate an NPC character sheet for the 5E sheet is not possible, but if this is the one luxury I'm not afforded with the API system, I believe I can live with that I think you actually should be able to, but it requires a bit more work. Unless I am mistaken (I am not a script guru) the API has to create the attributes before filling them out. I believe ChatSetAttr can do that. But, honestly, you would be doing a lot of work to do something that only needs to be done once and can be done just by copying the existing Drake from the compendium, or by doing it by hand. 
In this instance, you're probably right. I think I might just keep what I have as an exercise, in case this is something I would need to do. Like if I needed to generate NPC's for an encounter that I didn't know how many I needed or something to that effect
1685582128
Gauss
Forum Champion
J1n G1taxias said: In this instance, you're probably right. I think I might just keep what I have as an exercise, in case this is something I would need to do. Like if I needed to generate NPC's for an encounter that I didn't know how many I needed or something to that effect When you say "that I didn't know how many I needed" that indicates to me you might be creating duplicate characters for NPCs rather than duplicate tokens.  For example, if you are creating 10 Orcs you only need one character for them, just drop 10 tokens on the table. Am I misreading your statement? 
This probably leads into operator error, but I have had tokens with linking stats, most importantly current HP, that I found was alleviated with duplicate, separate characters (i.e. duplicating an orc 10 times). But also, to give a concrete example, I had an encounter where both each mistake in a puzzle spawned an enemy, and a full turn rotation spawned an enemy. My party survived by solving the puzzle, but I ended up using ~12-15 enemies.
1685588496

Edited 1685588623
Gauss
Forum Champion
J1n G1taxias said: This probably leads into operator error, but I have had tokens with linking stats, most importantly current HP, that I found was alleviated with duplicate, separate characters (i.e. duplicating an orc 10 times). But also, to give a concrete example, I had an encounter where both each mistake in a puzzle spawned an enemy, and a full turn rotation spawned an enemy. My party survived by solving the puzzle, but I ended up using ~12-15 enemies. You are correct that the token's HP should not be linked to the character for non-unique NPCs/Monsters. Set the HP (and even AC if desired) by linking then unlinking it (setting it to none). The number will remain but the link will not remain and you can change the values without affecting other tokens. Additionally, duplicating characters that many times can cause performance degradation as each character requires memory and processing power, and not an insubstantial amount. The more characters you open during a session the more of a performance hit a user may experience.  All characters used to be pre-loaded when you joined a campaign but that was discovered to cause performance issues and eventually the Devs resolved that by only loading characters as they were opened (the Lazy Loading update).  Spawning multiple enemies can be as simple as copying the token or dragging it from the journal tab. The character does not need to be duplicated. 
Interesting. I'll have to remember that if I'm ever in that position again. Thank you for the background. 
Gauss said: J1n G1taxias said: [...] I'm still relatively curious why the ability to generate an NPC character sheet for the 5E sheet is not possible, but if this is the one luxury I'm not afforded with the API system, I believe I can live with that I think you actually should be able to, but it requires a bit more work. Unless I am mistaken (I am not a script guru) the API has to create the attributes before filling them out. I believe ChatSetAttr can do that. But, honestly, you would be doing a lot of work to do something that only needs to be done once and can be done just by copying the existing Drake from the compendium, or by doing it by hand. I'll echo what others have said that the specific functionality you're looking for sounds like it is probably better handled with existing mods -- but will just confirm that it IS definitely possible to create a new NPC character sheet via the API! You'd use the createObj() function first to make a new character, and then again to create the appropriate attributes for an NPC sheet, if they don't exist by default (depends on your campaign settings - if you set the default for new sheets to be NPCs it will exist). In 5e it is indeed "npc" with value 1, which is usually triggered by the event of toggling the sheet type in the options as Gauss said, but it can also be done by the API or even manually in the "Attributes & Abilities" tab. If you don't see the attribute there, you can just click "+Add" at the top next to Attributes and type in npc for the name. The sheet doesn't know or care how it got there, if it sees that there is an attribute npc with value 1, it will transition to NPC style (or back to PC if you set it to 0). This is usually true of 'hidden' attributes that only appear when something else on the sheet triggers them -- if you know the syntax and create an attribute with the exact name, it should behave the same as if it were made automatically. In actual code I'd include a findObjs() check first to make sure you aren't duplicating things that already exist, only creating these if it returns undefined, but you could do something like this: var obj = createObj('character', {name: 'Drake Companion'}); createObj('attribute', {name: 'npc', current: 1, characterid: obj.id});