#Execute as GM in midiQOL in macros

1 messages ยท Page 1 of 1 (latest)

crude citrus
next mural
#

Okay thanks a lot

crude citrus
#

should have done this a bit sooner, always forgot we helpers can create threads ๐Ÿ™‚

next mural
#

That's cool ahah

wise hornet
#

My main suggestion when writing Midi and DAE macros is,...
DAE args to Midi args โŒ
Midi args to DAE args ๐Ÿ†—

#

because they both use args[0]

crude citrus
#

if you have a question on this topic i think you can ping us here and the thread will appear in the side bar for the pinged user, right?

next mural
#

Yes

next mural
wise hornet
#

so you're using macro.execute launched from which source? Dae?

#

DAE > launches on the target
On Use Midi > launches on the caster

next mural
#

from ... I can't remember let me check

wise hornet
#

both have different provided variables

next mural
#

So your rule for macro.executes is?

wise hornet
#

usually when called in an active effect it's launched through DAE

#

so all your midi args won't work in it

next mural
#

So I use OnUse ItemMacro, then from the ItemMacro I create and item (with margeObject) that has a dae with macro.execute in it

wise hornet
#

yeah then you step into DAE at that point

next mural
#

yep

wise hornet
#

You could technically run both an on use and dae macro on top of it eachother, but you have to start from on use

next mural
#

In the macro.execute I use lastArg does that change anything?

wise hornet
#

everything, the variables are different

next mural
#

So I have no way of fixing the code?

#

I have do redo part of it?

wise hornet
#

You can piggy back and transfer over variables from On use into the active effect you're creating if you want

#

I stuff in all sorts of data

#

You can either create your own midi flag, or toss it in under dae flags

next mural
#

I actually already doing that, I create an Active Effect from the ItemMacro OnUse and then what?

wise hornet
#

depends what you're end result is

#

like do you need to refer to back to the caster?

#

do you need to refer to one of the casters stats?

next mural
#

Okay so, the end result for this specific thing is to deal additional damage based on data on the original item

#

It's an infusion of ammunition so I have to "mark" the target so it takes more damage from the ammunition

wise hornet
#

You could just write a DamageBonus macro

#

apply an active effect to the target with nothing special on it

next mural
#

Yeah I didn't know of its existence at the time

#

Maybe I should just re-write it

wise hornet
#

on the DamageBonus macro you check for the effect, check if they have that ammo equipped on the weapon

next mural
#

it was junky as heck

wise hornet
#

it's just a bunch of filtering

next mural
#

Yeah

#

It's doable

#

Okay yeah I'll re-write it

#

But not now my brain hurts I have like 2 hours of sleep at best right now

#

Thank you so much, I'll come back later when I had a bit of sleep

wise hornet
#

sure have a good night

next mural
#

Sadly it's morning ahaha I'll try to rest a bit, see you later!

burnt slate
#

In fact, you use the exact same syntax regardless of ownership

next mural
#

After a bit of work and a close inspection I have the last two items that don't work

#

But I'm a bit stuck

next mural
#

I have this macro that throws this error: dae | Error evaluating macro for onUpdateActor ReferenceError: targetActor is not defined

#

The macro is a macro.execute called form dae => flags.dae.onUpdateTarget

next mural
#

Okay found the problem it was a small silly thing

next mural
burnt slate
#

the readme is the official API documentation, the wiki has examples and discussion of its use

next mural
#

So in the read me I find everything I need correct?

burnt slate
next mural
next mural
#

So I opted for a super convoluted solution

#

Which works even tho it's super ugly in my opinion

#

But now that I think about it maybe there's a way to make that also work

#

If I modify the item so the effects is on transfer and on it

wise hornet
next mural
#

Yeah

#

I'm trying to rewrite it right now

#

How do I save a previous item effect when I mergeObject to create the new one with the new effect?

#

Like if the item before had an active effect I don't want to overwrite it

#

But how do I save the one there was before?

wise hornet
#

well it's only going to apply it when transfer to equipped is checked

next mural
#

Sorry I don't understand

wise hornet
next mural
#

I'm doing a mergeObject to overwrite the old item to give it the new infusion active effect that deals the additional damage under the right conditions, and I want to save the old active effect that the item could have had

wise hornet
#

You can just use duplicate

next mural
wise hornet
#

then update the duplicant and update the active effect, if you want to modify it on the fly

#

although it depends, is this a permanent change?

next mural
#

like in concept what I want to do is: new_effect = new_effect + old_effect (if present);

wise hornet
#

you could use warpgate and modify the flags

next mural
next mural
#

Like a c++ list if you know what I mean

wise hornet
#

active effects just flags

next mural
#

[old_data] ---pointer--->[new_data]

next mural
wise hornet
#

if you don't want to use warpgate, then you'll need to look up the active effect, duplicate it to a temporary object. Make the changes to that object, then update the main active effect with those changes.

next mural
#

I just did this:
let old_effect = duplicate(weaponItem.data.effects);

bla bla stuff stuff
effects: [new_effect, old_effect]

next mural
wise hornet
next mural
wise hornet
#

it wouldn't be that way, you would need to push in the new flags

#

if new effects were being added

next mural
#

What if all this is in a margeObject?

#

Shouldn't that do exactly that?

wise hornet
#

so lets say.. this is our primary effect..

let effectData = [{
            changes: [
                { key: `flags.midi-qol.disadvantage.attack.all`, mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM, value: 1, priority: 20 },
                { key: `flags.midi-qol.grants.advantage.attack.mwak`, mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM, value: 1, priority: 20 },
                { key: `flags.midi-qol.grants.advantage.attack.msak`, mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM, value: 1, priority: 20 },
                { key: `flags.midi-qol.grants.disadvantage.attack.rwak`, mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM, value: 1, priority: 20 },
                { key: `flags.midi-qol.grants.disadvantage.attack.rsak`, mode: CONST.ACTIVE_EFFECT_MODES.CUSTOM, value: 1, priority: 20 },
                { key: `data.attributes.movement.walk`, mode: CONST.ACTIVE_EFFECT_MODES.OVERRIDE, value: Math.floor(target.actor.data.data.attributes.movement.walk / 3), priority: 20 }
            ],
            origin: itemUuid,
            disabled: false,
            flags: conditionFlags,
            duration: { rounds: 10, startRound: gameRound, startTime: game.time.worldTime },
            icon: conditionIcon,
            label: condition
        }];
        let prone = target.actor.effects.find(i => i.data.label === condition);
        if (!prone) await MidiQOL.socket().executeAsGM("createEffects", { actorUuid: target.actor.uuid, effects: effectData });
next mural
burnt slate
#

arrays are merged as atomic values, btw

#

if there are two changes array, they will not be concatenated

next mural
#

ehm yes I totally know what that means, totallyyyy ahaha sorry I'm kinda new to Javascript

burnt slate
#

you also wont be able to update the embedded ActiveEffect collection of an owned item

burnt slate
#

well....i guess this way you can, but its a bit dangerous. Typically you do not update collections by updating its parent embedded array directly

wise hornet
#

then you'd need to find it..

let effect = token.actor.effects.find(i=> i.data.label === "prone");
let updates = duplicate(effect.changes);
await updates.push({ key: "flags.dnd5e.meleeCriticalDamageDice", mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: 1, priority: 20 });
effect.update([updates]);

haven't actually tested this, paths are probably wrong to changes

next mural
#

uhmmmm I'm gonna be honest here, I'm understanding little of this, I'll try and test all this stuff to try and make the end of it

wise hornet
#

Actually i think theres a much easier method with SetProperty, oh wait that's for updating

burnt slate
#

what's the overall goal again?

next mural
#

The overall goal is to infuse a weapon or ammunition in order to make it deal more damage (damage depends on the item that "summons" the infusion)

#

With a save and stuff

wise hornet
#

why not just warpgate the item?

#

instead of messing with the AE

next mural
#

I have the code for it and it works I'm just trying to clean it up using DamageBonusMacro

burnt slate
#

yea, the number of hoops you will need to jump through for this operation in core is...as you can tell...a bit much

next mural
#

Okay I'll go and study Warpgate ahah

wise hornet
#

AE is great for duration effects

next mural
#

Ah yes this is a duration effect

#

After a minute it vanishes

#

Again I actually made it work, I just wanted to make it look prettier

wise hornet
#

I mean you could add additional active effects.. but i think in this case, warpgate might just be easier

burnt slate
next mural
#

Okay so I should just leave it be for the moment you think?

#

I'm actually a bit proud of it, it's just doesn't look super good

wise hornet
#

oh anything you don't need in your active effect, don't include it

burnt slate
#

for example, this will make the target's Longsword a +1 weapon

const updates = {
  embedded: { Item: {
    'Longsword':
      'data.attackBonus': '+1',
      'data.damage.parts': [['1d8 + @mod + 1', 'slashing']],
      'name': 'Longsword +1'
  }}}

await warpgate.mutate(game.user.targets.first(), updates, {}, {name: 'Magical Weapon'});
#

and thats all you need!

burnt slate
wise hornet
#

I remade Shillelagh in warpgate, made things a lot of easier

burnt slate
#

i just did Magic Stone as well

next mural
#

Thank you all!

wise hornet
#
let itemId = html.find('[name=weapons]')[0].value;
                        let weaponItem = tactor.items.get(itemId);
                        let weaponName = weaponItem.name;
                        let weaponDamage = weaponItem.data.data.damage.parts[0][0];
                        let adjustedDamage = weaponDamage.replace(/1d(4|6)/g, "1d8");
                        let itemUpdates = {
                            "data": {
                                "ability": tactor.data.data.attributes.spellcasting,
                                "properties.mgc": true,
                                "damage": { "parts": [[adjustedDamage, "bludgeoning"]] }
                            }
                        };
                        let updates = { embedded: { Item: { [weaponItem.name]: itemUpdates } } };
                        await warpgate.mutate(target.document, updates, {}, { name: itemName });
burnt slate
#

lovely, even going as far as modifying the actual damage die portion, rather than just flat replacing it!

wise hornet
#

theres a ton more logic before that hehe

#

but that's the main guts after all the filtering

wise hornet
#

Shillelagh in warpgate

#

well a snippet from my macro of it

#

I get the weapon from a list of available weapons on the actor, then pass that through a dialog which the player selects. Then you get the weapon properties and make the changes needed. then you use warpgate to apply those changes

next mural
#

Ah yes I did something similar just with macros

#

Warpgate seems really really cool I'm sure I'll look into it soon enough!

#

Probably tomorrow morning or something

crude citrus
#

warpgate is the bomb

next mural
#

I am biased to favourite midi but just because tposney is basically my teacher at this point

#

But yes Warpgate seems like an extremely powerful tool

burnt slate
#

(its about to get twice as powerful in the near future, too)

next mural
#

Ahaha yeah I like foundry for the freedom I have as a programmer

#

Tbh it's pretty straightforward too since it's been like, how much? A month at best that I started programming in it and I'm already doing some interesting stuff in it

#

I don't even care to do insane things with it, just practical stuff

wise hornet
#

Yeah I often revise my stuff all the time after I've learned better techniques when writings things