Skip to content

Instantly share code, notes, and snippets.

@lslavkov
Created April 16, 2023 12:35
Show Gist options
  • Select an option

  • Save lslavkov/2a1e03378447ada336d1f12c13bc863a to your computer and use it in GitHub Desktop.

Select an option

Save lslavkov/2a1e03378447ada336d1f12c13bc863a to your computer and use it in GitHub Desktop.
FoundryVTT Macro for character creation. It uses Dialog window
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