|
| 1 | +/** |
| 2 | + * Generates a blank character sheet for any player in the campaign. |
| 3 | + * |
| 4 | + * Syntax: !charsheet |
| 5 | + */ |
| 6 | + |
| 7 | +var Charsheet = Charsheet || {}; |
| 8 | + |
| 9 | +on("chat:message", function(msg) { |
| 10 | + // Exit if not an api command |
| 11 | + if (msg.type != "api") { |
| 12 | + return; |
| 13 | + } |
| 14 | + |
| 15 | + if (msg.content.indexOf('!charsheet') != -1) { |
| 16 | + Charsheet.Generate(msg); |
| 17 | + } |
| 18 | +}); |
| 19 | + |
| 20 | +Charsheet.Generate = function(msg) { |
| 21 | + var generatorversion = "1.2.1"; |
| 22 | + var playerid = msg.playerid; |
| 23 | + var player = msg.who; |
| 24 | + |
| 25 | + /** |
| 26 | + * Templates |
| 27 | + */ |
| 28 | + var template = { |
| 29 | + "gmnotes": "Player: " + player + |
| 30 | + "<br>Generated By: CharacterSheet " + generatorversion, |
| 31 | + "charactername": msg.who + " #" + |
| 32 | + (findObjs({_type: "character", controlledby: playerid}).length + 1) |
| 33 | + } |
| 34 | + template.channelalert = "created a character named \"" + |
| 35 | + template.charactername + "\"!"; |
| 36 | + |
| 37 | + /** |
| 38 | + * Permissions |
| 39 | + * |
| 40 | + * Valid values are "all" or comma-delimited list of player IDs. |
| 41 | + */ |
| 42 | + /* Who can view the sheet */ |
| 43 | + var viewableBy = "all"; |
| 44 | + /* Who can edit the sheet */ |
| 45 | + var controlledby = playerid; |
| 46 | + |
| 47 | + /** |
| 48 | + * Character generation |
| 49 | + */ |
| 50 | + /* Create the base character object */ |
| 51 | + var character = createObj("character", { |
| 52 | + name: template.charactername, |
| 53 | + archived: false, |
| 54 | + inplayerjournals: viewableBy, |
| 55 | + controlledby: controlledby |
| 56 | + }); |
| 57 | + /* Set GM Notes */ |
| 58 | + character.set("gmnotes", template.gmnotes); |
| 59 | + /* Set Player's name */ |
| 60 | + createObj("attribute", { |
| 61 | + name: "player_name", |
| 62 | + current: player, |
| 63 | + _characterid: character.id |
| 64 | + }); |
| 65 | + /* Set Character's name */ |
| 66 | + createObj("attribute", { |
| 67 | + name: "name", |
| 68 | + current: template.charactername, |
| 69 | + _characterid: character.id |
| 70 | + }); |
| 71 | + /* Set script version, used for debugging */ |
| 72 | + createObj("attribute", { |
| 73 | + name: "sheet_generator", |
| 74 | + current: "CharacterSheet v" + generatorversion, |
| 75 | + _characterid: character.id |
| 76 | + }); |
| 77 | + |
| 78 | + sendChat(player, "/me " + template.channelalert); |
| 79 | +}; |
0 commit comments