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

Is it possible to generate an API/Script that auto fills a Starfinder NPC Section in the Official Sheet?

I was tinkering a bit with AI and knowing crap about code it prompted me this: // Listens for pasted text command on('chat:message', function(msg) {     if (msg.type === 'api' && msg.content.indexOf('!createMonster ') === 0) {         let text = msg.content.replace('!createMonster ', '');         createMonster(msg.playerid, text);     } }); // Function to create monster function createMonster(playerId, text) {     let lines = text.split('\n');     let character = createObj('character', {         name: lines[0], // Assumes the first line is the monster's name         controlledby: playerId     });     // Loop through each line of text and set attributes accordingly     lines.forEach(function (line) {         let [attribute, value] = line.split(': '); // Assumes each line is "attribute: value"         if (attribute && value) {             createObj('attribute', {                 name: attribute.trim(),                 current: value.trim(),                 characterid: character.id             });         }     });     // Output to chat that monster was created     sendChat('API', '/w gm Monster "' + lines[0] + '" created'); } // You would also add additional parsing logic here to handle more complex attribute setups, // such as attack details or special abilities and ensure they match the attribute names on the Starfinder sheet. So this is the start, would it be possible to make an auto fill script? This would help me greatly in adding custom monsters rather than relying on the bestiary.
1708556017
The Aaron
Roll20 Production Team
API Scripter
That is a way to pursue an importer.  There are some things about that which would not work, but the concept is possible.   That probably isn't the way I would do it personally for several reasons, not the least of which is the problem of appropriately escaping multiline content in the chat. If I were doing this, I would base it on the gm notes of a token, such that you paste structured data in the gm notes section of the token, then save it and call a script to pull the contents from the token, then use that token to represent the creature in question.  Look at UniversalVTTImporter starting at importUVTTonGraphic() on line 757 for an example of the flow for reading data from the gm notes.