Fix for Temporary Item Properties

Started by LoveLess, March 17, 2021, 02:09:13 PM

Previous topic - Next topic

LoveLess

A minor inconvenience, but it would be helpful for when you have to relog due to a bug and don't want to lose any buffs to your items. This is aimed at the following spells:
Magic Weapon
Greater Magic Weapon
Flame Weapon/Darkfire
Bless Weapon
Sonic Weapon
Magic Vestment
Keen Weapon
Continual Flame

When a player logs in, this script would fire and check if they have any effects that need to get applied. There are some edge cases where it might get weird, such as if they dropped the weapon already or gave it away, but none of the properties stack so it may just look weird when they have multiple of the same buff. I did not account for this in the below, because it's extra weight to tag the item properties and deal with removing them.

Put simply, since all of these buffs have a cessate vfx that is placed on the character, what this does is allow a buff to remain on the character that can be detected and it's duration is not paused when they log off. Now to ensure that people are not abusing it to buff all of their items, you make sure only the item in question is getting enhanced, so add these two lines to all of the spells in question:

For the spell scripts:
            string sTargetItemID(GetObjectUUID(oTargetItem));
            eVis = TagEffect(eVis, sTargetItemID);


Now this next part will require a little extra work, as you may need to make some scripts that could be very long (Flame Weapon for example) and bundle them into a function, then include that script in this new one.

#include "x2_i0_spells"

void main()
{
    object oEnteringPC = GetEnteringObject();
    effect eEffect = GetFirstEffect(oEnteringPC);
    while (GetIsEffectValid(eEffect))
    {
        int nID = GetEffectSpellId(eEffect);

        if (nID == SPELL_MAGIC_WEAPON)
        {
            int nDuration = GetEffectDuration(eEffect);
            object oTargetItem = GetObjectByUUID(GetEffectTag(eEffect));
            IPSafeAddItemProperty(oTargetItem, ItemPropertyEnhancementBonus(1), IntToFloat(nDuration), X2_IP_ADDPROP_POLICY_KEEP_EXISTING ,TRUE,TRUE);
        }
        else if (nID == SPELL_MAGIC_VESTMENT)
        {
            int nLevel = GetEffectCasterLevel(eEffect);
            int nDuration = GetEffectDuration(eEffect);
            object oTargetItem = GetObjectByUUID(GetEffectTag(eEffect));
            // do magic vestment script here... get caster level, do math, apply effect
        }
        else if (nID == SPELL_FLAME_WEAPON)
        {
            int nLevel = GetEffectCasterLevel(eEffect);
            int nDuration = GetEffectDuration(eEffect);
            object oTargetItem = GetObjectByUUID(GetEffectTag(eEffect));
            // your flame weapon script... or perhaps function??
        }
        // so on and so forth
        eEffect = GetNextEffect(oEnteringPC);
    }

}


I've tested (and implemented) a version of this and there is no issue with the durations, they match up perfectly.

Dillusionist

will check it out. not sure of the timetable.

my main concern is people passing around the items where the item itself becomes decoupled from the cessate duration on the target pc

and just looping through inventory

cool idea though!

LoveLess

Quote from: Dillusionist on March 18, 2021, 03:36:47 AM
my main concern is people passing around the items where the item itself becomes decoupled from the cessate duration on the target pc

and just looping through inventory

Considering it would be grabbing the UUID of the object, which is uniquely assigned to each item and cannot be reused, this should not occur.  It's like a MAC address for objects. Each cessate would be tagged with that address, it would be paired with that object/item, and that only.