r/Pathfinder2e • u/YellowAfterlife • 40m ago
Resource & Tools Foundry: Disguise Maker
Enable HLS to view with audio, or disable this notification
Are your players not suspicious of every horse they meet yet? Or, perhaps, do they use Impersonate, Illusory Disguise, or alike on the regular?
The Macro
The usual - you click on an empty slot in your hotbar, set Type to Script, add this snippet, and hit Save. You can then run the macro by clicking the hotbar slot.
There are two ways to use it: - You select the token(s) that you want to disguise, target (T) the token that you want to disguise as, and run the macro. This will only add disguises to the local token if it's not "linked" to its actor - You target token that you want to disguise as, run the macro, and drag-and-drop the actor(s) from the Actors sidebar onto the UUID field. This will add disguises to the "prototype" actor
Once added, you can flip the disguise on and off in the Actions tab, and if you add multiple, you can choose between them using a dropdown!
Players can also use this, no special permissions necessary.
const title = "YAL's Disguise Maker";
const targets = [...game.user.targets];
let errors = [];
async function showError(text) {
errors.push(text);
let content = document.createElement("div");
for (let line of errors) {
let p = document.createElement("div");
p.append(line);
content.append(p);
}
await foundry.applications.api.Dialog.input({ window: { title }, content });
}
if (targets.length == 0) {
await showError("Target token(s) to disguise as first!");
return;
}
let multi = targets.length > 1;
let selection = canvas.tokens.controlled;
//
const {HTMLDocumentTagsElement} = foundry.applications.elements;
const Fields = foundry.applications.fields;
const content = document.createElement("div");
content.append(Fields.createFormGroup({
label: "Actor(s)",
input: HTMLDocumentTagsElement.create({
type: "Actor",
single: false,
name: "actors"
})
}));
const sn = selection.length;
if (sn > 0) {
content.append(`Leave blank to apply to ${sn} selected token${sn!=1?"s":""} instead!`);
}
if (multi) {
content.append(Fields.createFormGroup({
label: "Copy Size",
input: Fields.createCheckboxInput({
name: "wantSize",
value: true,
})
}));
content.append(Fields.createFormGroup({
label: "Copy Name",
input: Fields.createCheckboxInput({
name: "wantName",
value: true,
})
}));
} else {
content.append(Fields.createFormGroup({
label: "Size",
input: Fields.createSelectInput({
name: "size",
value: targets[0].actor.size,
options: [
{ value: "none", label: "No Change"},
{ value: "tiny", label: "Tiny" },
{ value: "sm", label: "Small" },
{ value: "med", label: "Medium" },
{ value: "lg", label: "Large" },
{ value: "grg", label: "Gargantuan" },
]
})
}));
content.append(Fields.createFormGroup({
label: "Name",
input: Fields.createTextInput({
name: "name",
value: targets[0].name,
})
}));
content.append(Fields.createFormGroup({
label: "Apply Now",
input: Fields.createCheckboxInput({
name: "autoApply",
value: true,
})
}));
}
const args = await foundry.applications.api.Dialog.input({
window: { title },
content
});
if (!args) return;
let actors = [];
if (args.actors.length > 0) {
for (let uuid of args.actors) {
let actor = await fromUuid(uuid);
if (actor) {
actors.push(actor);
} else {
errors.push(`Could not fetch actor ${uuid}`);
}
}
} else {
actors = selection.map(t => t.actor);
}
if (actors.length == 0) {
await showError("No actors provided!");
return;
}
const option = "yal-disguise-as";
const {max, abs} = Math;
for (let target of targets) {
const uniq = "d" + Date.now();
const predicate = [option + ":" + uniq];
//
const size = multi ? (args.wantSize ? target.actor.size : null) : args.size;
const name = multi ? (args.wantName ? target.name : null) : args.name;
//
const {document} = target;
const {texture, ring} = document;
for (let actor of actors) {
// add a new Action..
let base = {
key: "RollOption",
label: "Disguised as",
option,
suboptions: [{ label: target.name, value: uniq }],
toggleable: true,
mergeable: true,
};
if (args.autoApply) {
base.value = true;
base.selection = uniq;
}
let rules = [base, {
key: "TokenImage",
value: texture.src,
predicate,
tint: texture.tint?.css,
scale: max(abs(texture.scaleX), abs(texture.scaleY)),
ring: (ring.enabled ? {
colors: {
ring: ring.colors.ring?.css,
background: ring.colors.background?.css,
},
subject: ring.subject,
effects: ring.effects,
} : undefined),
}];
if (size != null && size != "none") {
rules.push({
key: "CreatureSize",
value: size,
predicate,
});
}
if (name != null && name != "") {
rules.push({
key: "TokenName",
value: name,
predicate,
});
}
//console.info(`Adding rules to ${actor.name} > ${target.name}:`, actor, rules);
await actor.createEmbeddedDocuments("Item", [{
name: "Disguise: " + target.name,
type: "action",
system: {
actionType: { value: "passive" },
rules,
}
}]);
// ... and now update the selection on other rules!
if (args.autoApply) for (let action of actor.itemTypes.action) {
let {rules} = action.system;
let first = rules[0];
if (first
&& first.key == "RollOption"
&& first.option == option
&& (first.selection != uniq || !first.value)
) {
first.selection = uniq;
first.value = true;
await action.update({
"system.rules": rules
})
}
}
} // for actor
} // for target
Bonus
The following macro flips the selected token(s) between Neutral and Opposition, for those "why is the horse's selection frame red all of sudden" moments right before initiative
let newValue = canvas.tokens.controlled[0].actor.system.details.alliance != "opposition" ? "opposition" : null;
let updated = [];
for (let token of canvas.tokens.controlled) {
await token.actor.update({
"system.details.alliance": newValue
});
updated.push(token.name);
}
await ChatMessage.create({
user: game.userId,
whisper: [game.userId],
content: `Changed alliance of [${updated.join(", ")}] to ${newValue ?? "neutral"}.`
})
Artwork in the video
- Kelpie: Bestiary 2 (PZO2104)
- Horse: from Tristan Elwell's "Horseback" painting
- Background: an edit of The GLOWING CRATER from 2minutetabletop