
I'm still working on my data mapping for a completely clean 5e monster import strategy, but I think the API portion of my work is done.
First, how it works. Then the script itself. Any feedback is greatly appreciated. This isn't really my own work. Only sort-of, seeing as I scraped and stole parts from here and there around the web, trying to get it going the way I needed it.
Obviously before any of this works, you'll need API support (be a Mentor) and you'll need to install the script. I'm saying this because until last night this wasn't completely obvious to me... :)
To Export a creature's attributes:
1) Highlight a graphic which is linked to a character (who has its data already populated).
2) Input - !getme foo
Note that the 'foo' isn't relevant. I just patterned my work after others who were expecting input after the command.
3) Copy the chat output to a text file or some other safe place.
Example Output:
To Import a creature's attributes:
1) Highlight a graphic which is linked to a character (populated or un-populated it doesn't matter).
2) Input the string created above, or your own custom string. Format is '--(attributename)|current|max'.
Example Output:
Validate using the character sheet.
To create a new/blank character:
1) Input !createme (Name)
2) Browse to Characters
3) Drag character from library to screen, making it available for Import as above.
And that's it... There's a few more things I'd like to add, but right now I need to clean up my scraped data to make it more usable...
Here's the script, which I call 'createsetget.js':
First, how it works. Then the script itself. Any feedback is greatly appreciated. This isn't really my own work. Only sort-of, seeing as I scraped and stole parts from here and there around the web, trying to get it going the way I needed it.
Obviously before any of this works, you'll need API support (be a Mentor) and you'll need to install the script. I'm saying this because until last night this wasn't completely obvious to me... :)
To Export a creature's attributes:
1) Highlight a graphic which is linked to a character (who has its data already populated).
2) Input - !getme foo
Note that the 'foo' isn't relevant. I just patterned my work after others who were expecting input after the command.
3) Copy the chat output to a text file or some other safe place.
Example Output:
Copy starting here: !setme --is_npc|1 --npc_type|Large giant --npc_alignment|chaotic evil --npc_AC|11 --npc_AC_note|hide armor --npc_HP|59|59 --npc_HP_hit_dice|7d10 + 21 --npc_speed|40 --npc_strength|19 --npc_dexterity|8 --npc_constitution|16 --npc_intelligence|5 --npc_wisdom|7 --npc_charisma|7 --npc_senses|darkvision 60 ft. --npc_languages|Common, Giant --npc_challenge|2 --npc_xp|450
To Import a creature's attributes:
1) Highlight a graphic which is linked to a character (populated or un-populated it doesn't matter).
2) Input the string created above, or your own custom string. Format is '--(attributename)|current|max'.
Example Output:
Set is_npc value 1. Set npc_type value Large giant. Set npc_alignment value chaotic evil.
Validate using the character sheet.
To create a new/blank character:
1) Input !createme (Name)
2) Browse to Characters
3) Drag character from library to screen, making it available for Import as above.
And that's it... There's a few more things I'd like to add, but right now I need to clean up my scraped data to make it more usable...
Here's the script, which I call 'createsetget.js':
(function() { var oldCreateObj = createObj; createObj = function() { var obj = oldCreateObj.apply(this, arguments); if (obj && !obj.fbpath) { obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/"); } else if (obj && !obj.changed && type == 'attribute') { obj.fbpath = '/char-attribs/char/'+ characterID +'/'+ id; } return obj; } }()) on('chat:message', function(msg) { if(msg.type == 'api' && msg.content.indexOf('!setme ') != -1) { if (msg.selected == undefined){sendChat("API"," Please select something to modify.");}; var n = msg.content.split(" --"); var a = 1; while (n[a]) { _.each(msg.selected, function(objInfo) { var obj = findObjs({ _id: objInfo._id, _type: 'graphic', _subtype: 'token' })[0]; var represents = obj.get("represents") if(obj) { Attribute = n[a].substring(0, n[a].indexOf("|")); ValueString = n[a].substring(n[a].indexOf("|") + 1); log(ValueString.indexOf("|")) if(ValueString.indexOf("|") === -1) { Value = n[a].substring(n[a].indexOf("|") + 1); Max = ''; } else { Value = ValueString.substring(0,ValueString.indexOf("|")); Max = ValueString.substring(ValueString.indexOf("|") + 1); }; log(Attribute); log(Value); log(Max); existingattribute = findObjs({_type: "attribute", name: Attribute, _characterid: represents})[0]; if (existingattribute === undefined) { if(Max != ''){ sendChat("", "/desc Create " + Attribute + " value " + Value + " max " + Max + "."); createObj('attribute', { name: Attribute, current: Value, max: Max, _characterid: represents }); } else { sendChat("", "/desc Create " + Attribute + " value " + Value + "."); createObj('attribute', { name: Attribute, current: Value, _characterid: represents }); } } else { if(Max != ''){ sendChat("", "/desc Set " + Attribute + " value " + Value + " max " + Max + "."); existingattribute.set("current", Value); existingattribute.set("max", Max); } else { sendChat("", "/desc Set " + Attribute + " value " + Value + "."); existingattribute.set("current", Value); }; }; } }); a++; } }; }); on('chat:message', function(msg) { if(msg.type == 'api' && msg.content.indexOf('!getme ') != -1) { AttributeExport = "Copy starting here: !setme " if (msg.selected == undefined){sendChat("","/desc Please select something to get.");}; _.each(msg.selected, function(objInfo) { var obj = findObjs({ _id: objInfo._id, _type: 'graphic', _subtype: 'token' })[0]; var represents = obj.get("represents") if(represents) { allattributes = findObjs({_type: "attribute", _characterid: represents}); log(allattributes) _.each(allattributes, function(attrInfo) { log(attrInfo.get("name")) Attribute = attrInfo.get("name") Value = attrInfo.get("current") Max = attrInfo.get("max") if (Value != ""){ if(Max != ""){ AttributeExport = AttributeExport + " --" + Attribute + "|" + Value + "|" + Max } else { AttributeExport = AttributeExport + " --" + Attribute + "|" + Value } } }); sendChat("", "/desc "+AttributeExport); } else { sendChat("","/desc No character is represented."); } }); }; }); on('chat:message', function(msg) { if(msg.type == 'api' && msg.content.indexOf('!createme ') != -1) { var name = msg.content.substring(9); var curPageId = Campaign().get("playerpageid"); var character = createObj('character', { name: name, bio: '', gmnotes: '', archived: false, inplayerjournals: msg.playerid, controlledby: msg.playerid, avatar: 'https://s3.amazonaws.com/files.d20.io/images/5356582/kSzAxQqNOBlRlEKPRwKlUg/thumb.png?1409327289' }); }; });Again, this is community work. I only cobbled together what those before me had posted.