#Reagent Worldscript

1 messages · Page 1 of 1 (latest)

oak arch
#

So a worldscript is a small module you make for the world, you tend to use them over macros when you want something done automatically every time something happens.

You "hook" onto an event, such as when an actor is updated, and then the worldscript reacts whenever that thing happens with what you may want.

You could definitely have a worldscript that looks at every actor when it receives an item/updates its' inventory, checks whether the update contains an item from your lists and move them into a corresponding container.

How are you storing the lists?

carmine mauve
#

still haven't created any of it, it was just the idea on how to do it

#

don't really know if it's the best way of doing it

#

i do like the added value of the named items, but it would definitelly be easier to redo the gathering tables with just the simplified materials for crafting

#

so i'm looking into this option, to get the best of both worlds

oak arch
#

The script needs the "which bag to put x"-information somehow, so some data entry will be necessary regardless of which option you choose, but it's very doable. It could be in rollTables, it could be that you categorize them in a compendium with folders. Just somewhere the script can fetch the info, really, else you face having to write it manually in the code and long lists like that tend to be unfun to update in code, better to change it with something in Foundry

carmine mauve
#

how would i go about creating this world script?

#

i've dealt with changing macros, and writing the roll formulas, but haven't gone into worldscripts yet

oak arch
#

Then instead of these "one and done" examples in dnd5e (like deleting languages, adding, whatever), you Hook on instead of once to do something every time something happens. I have an example of a worldscript I made for someone to make bags weightless when unequipped.

Hooks.on("preUpdateItem", (...args) => {
    // If the item is a container and is being unequipped, add weightless contents to its' properties.
    if (args[1].type == "container" && args[1].system.equipped == false) {
        const itemProperties = args[0].system.properties;
        itemProperties.delete("weightlessContents");
        args[1].system.properties = Array.from(itemProperties);
    };

    // If the item is a container and is being equipped, remove weightless contents to its' properties.
    if (args[1].type == "container" && args[1].system.equipped == true) {
        const itemProperties = args[0].system.properties;
        if (!itemProperties.has("weightlessContents")) {
            itemProperties.add("weightlessContents");
        };
        args[1].system.properties = Array.from(itemProperties);
    };
});```
#

It's a little old, but hopefully get the concept across.

We hook onto the preUpdateItem hook, which fires just before an item is actually edited. If you're unsure what hook your change happens, you can run the script CONFIG.debug.hooks = true and then look through your console (F12) to see which hook(s) and with what arguments fires when you're doing your thing.

Every time someone changes an item, the preUpdateItem hook fires, so our script runs. But we're only interested in containers. args[1] in this case is the item's values being changed (if I remember correctly, I shot myself in the foot being lazy naming arguments here), so I filter for what I want (containers) to make sure we don't run the script on unrelated items. This is where you would check for the item's name/type/something to make sure it's a reagent item.

Then if that's true, you have your code run where you move the item into a bag. That'd probably be a four step process of looking up the reagent -> bag information, checking if the actor (which is also in the arguments of most hooks) has the right bag, update the bag to contain a copy of the item and delete the original item.

carmine mauve
#

gonna give it a read tonight, gotta finish some map designs first, but i'll pay attenttion to this over the next couple of days and probably bother you again

#

thanks