Created
April 16, 2023 12:35
-
-
Save lslavkov/2a1e03378447ada336d1f12c13bc863a to your computer and use it in GitHub Desktop.
FoundryVTT Macro for character creation. It uses Dialog window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function createUser(username) { | |
| username = username.trim() | |
| let actor = await Actor.implementation.create({ | |
| name: username, | |
| type: 'character', | |
| }) | |
| let user = await User.create({ name: username, role: 2, character: actor }) | |
| let id = user.id | |
| let permissions = actor.data.permission | |
| permissions[id] = 3 | |
| actor.update({ | |
| permission: permissions, | |
| }) | |
| game.logOut() | |
| } | |
| async function generateDialog() { | |
| let d = new Dialog({ | |
| title: 'New Dialog', | |
| content: ` | |
| <form> | |
| <div class="form-group"> | |
| <label> | |
| Enter your name | |
| </label> | |
| <input type='text' name='nameField'></input> | |
| </div> | |
| </form>`, | |
| buttons: { | |
| yes: { | |
| icon: "<i class='fas fa-check'></i>", | |
| label: `Create account`, | |
| }, | |
| }, | |
| default: 'yes', | |
| close: (html) => { | |
| let result = html.find('input[name="nameField"]') | |
| if (result.val() !== '') { | |
| createUser(result.val()) | |
| } | |
| }, | |
| }).render(true) | |
| } | |
| generateDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment