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 .
×
Advertisement Create a free account

Custom Names with CharacterSheet API script

is there a way to alter this script so that i can run something like: !charsheet --represents{CharName} instead of the "username sheet #x" that it does right now? i mean, i am sure there is a way to do that i just don't know scripting well enough to make it happen.
1634150806

Edited 1634150961
David M.
Pro
API Scripter
Will this work? Syntax !charsheet                 //previous behavior. Creates character named "PlayerName #1", etc !charsheet --charName        //creates character sheet named charName (if spaces in name, use quotes, i.e. --"Bob the Great") Modified script: /** * Generates a blank character sheet for any player in the campaign. * * Syntax: !charsheet */ var Charsheet = Charsheet || {}; on("chat:message", function(msg) { // Exit if not an api command if (msg.type != "api") { return; } if (msg.content.indexOf('!charsheet') != -1) { let charName = msg.who; let args = msg.content.split(/\s+--/); if (args.length > 1) { charName = args[1].trim(); } Charsheet.Generate(msg, charName); } }); Charsheet.Generate = function(msg, charName) { var generatorversion = "1.2.1"; var playerid = msg.playerid; var player = msg.who; let numString = ''; if (charName === msg.who) { numString = "#" + (findObjs({_type: "character", controlledby: playerid}).length + 1); } /** * Templates */ var template = { gmnotes: "Player: " + player +"<br>Generated By: CharacterSheet " + generatorversion, charactername: charName + numString } template.channelalert = "created a character named \"" + template.charactername + "\"!"; /** * Permissions * * Valid values are "all" or comma-delimited list of player IDs. */ /* Who can view the sheet */ var viewableBy = "all"; /* Who can edit the sheet */ var controlledby = playerid; /** * Character generation */ /* Create the base character object */ var character = createObj("character", { name: template.charactername, archived: false, inplayerjournals: viewableBy, controlledby: controlledby }); /* Set GM Notes */ character.set("gmnotes", template.gmnotes); /* Set Player's name */ createObj("attribute", { name: "player_name", current: player, _characterid: character.id }); /* Set Character's name */ createObj("attribute", { name: "name", current: template.charactername, _characterid: character.id }); /* Set script version, used for debugging */ createObj("attribute", { name: "sheet_generator", current: "CharacterSheet v" + generatorversion, _characterid: character.id }); sendChat(player, "/me " + template.channelalert); };
Yes, this is perfect, thank you! well, almost perfect. the charName is open ended right now, which means it not only doesn't require parentheses to place spaces in the name, but also it operates weirdly when there are multiple commands in the same line: !charsheet --Ham Samwhich !token-mod --set represents|@{Ham Samwhich|character_id} name|Ham Samwhich bar1_max|9 bar2_max|9 defaulttoken will make a character named "Ham Samwhich !token-mod" if the input is !charsheet --Ham Samwhich -- !token-mod --set represents|@{Ham Samwhich|character_id} name|Ham Samwhich bar1_max|9 bar2_max|9 defaulttoken it will make a character named "Ham Samwhich". prolly not the smartest thing for me to hack as i don't know why its doing what its doing, but it works so i'll prolly just run with it
1634164339
David M.
Pro
API Scripter
Lol. The script is now splitting the api command into an array with elements defined by what is between each "--" in the command string. This explains your "Ham Samwich !token-mod" character (its all the stuff between the first two "--"'s). You can avoid this issue by putting the two api commands into separate lines (line break between them) Example macro: !charsheet --Ham Samwhich !token-mod --set represents|@{Ham Samwhich|character_id} name|Ham Samwhich bar1_max|9 bar2_max|9 defaulttoken