Add Item Property to Specific Item in Slot

I’ve been working at this script for awhile and haven’t gotten anywhere with it, so I could use some help figuring out what I’ve done wrong.

From a conversation, when players turn in a quest, they are then given a reward.

Part of that reward is to add an item property to an amulet (only if it’s tag is “epicamulet” and is currently equipped).

As the player turns in quests, an int is added to the amulet. Each time that int reaches a certain number, a different item property needs to be added.

Here’s what I have so far.

#include “x2_inc_itemprop”
void main()
{
object oPC = GetPCSpeaker();
object oItem = GetItemInSlot(INVENTORY_SLOT_NECK, oPC);

int nPCcount = GetLocalInt(oItem, "STR_COUNTER");
++nPCcount;
SetLocalInt(oItem, "STR_COUNTER", nPCcount);

if ( GetLocalInt(oItem, "STR_COUNTER") == 3 )
{
itemproperty str1 = ItemPropertyAbilityBonus(IP_CONST_ABILITY_STR, 1);
IPSafeAddItemProperty(oItem, str1, 0.0f, X2_IP_ADDPROP_POLICY_REPLACE_EXISTING);
}
if ( GetLocalInt(oItem, "STR_COUNTER") == 6 )
{
itemproperty str2 = ItemPropertyAbilityBonus(IP_CONST_ABILITY_STR, 2);
IPSafeAddItemProperty(oItem, str2, 0.0f, X2_IP_ADDPROP_POLICY_REPLACE_EXISTING);
}

}

the code looks fine so far, all you have to do is to check if GetTag(oItem) == “epicamulet”

i would check that twice, fist as a standalone script in coversation to make it so NPC will have different reply and won’t let you add the itemproperty in first place, then in this script again

1 Like

The STR_COUNTER variable seems to need to reach certain threshold to work, did you try this 3 times to trigger the first the +1 in strength?

also the tag “epicamulet” is not checked anywhere, any equipped amulet with that var will get the item property.

Try with this script below, I changed it to require only 2 var counts instead of 6 for easier testing. (you can change that back later)

#include "x2_inc_itemprop"

void main()
{
    object oPC = GetPCSpeaker();
    object oITEM = GetItemInSlot(INVENTORY_SLOT_NECK, oPC);
    if (GetTag(oITEM) != "epicamulet") return; //Not the right amulet

    int nSTR = GetLocalInt(oITEM, "STR_COUNTER");
    if (nSTR > 1) return; //Already has the +2 STR bonus

    SetLocalInt(oITEM, "STR_COUNTER", nSTR + 1);
    itemproperty iPROP = ItemPropertyAbilityBonus(IP_CONST_ABILITY_STR, nSTR + 1);
    IPSafeAddItemProperty(oITEM, iPROP);
}
1 Like

Got it to work. Something I had running in the script along with this was causing the trouble. After separating the scripts and using execute script commands, everything worked as needed!