Need some help with a script

Alright, trying to get this to work as a tag based script on an item, but I seem to be having some issues. If anyone has any advise, please lend a hand. It should be adding properties depending on the targeted item, ie, shield, armor, or weapon. I have tag based turned on, so not really sure why it’s not working.

#include “x0_i0_position”
#include “x2_inc_switches”
#include “x2_inc_itemprop”

void main()
{
//major variables
object oPC = OBJECT_SELF;
object oTarget = GetItemActivatedTarget();
object oArmor = GetItemInSlot(INVENTORY_SLOT_CHEST, oTarget);
object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oTarget);
object oShield = GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oTarget);
effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
effect eVis = EffectVisualEffect(VFX_IMP_AC_BONUS);
int nDur = 10;
int nEvent = GetUserDefinedItemEventNumber(); //Which event triggered this
object oItem;
location lSpellLocation;

{
switch (nEvent)

case X2_ITEM_EVENT_ACTIVATE:
// * This code runs when the Unique Power property of the item is used
// * Note that this event fires for PCs only

oPC = GetItemActivator(); // The player who activated the item
oItem = GetItemActivated(); // The item that was activated
lSpellLocation = GetItemActivatedTargetLocation(); // The target creature

{
if (GetIsObjectValid(oTarget))

{
if (GetIsObjectValid (oShield))
{
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oPC);
itemproperty iProp = ItemPropertyACBonus(1);

IPSafeAddItemProperty(oShield, iProp, RoundsToSeconds(nDur), X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, FALSE, TRUE);
}
}

else if (GetIsObjectValid(oTarget))
{

if (GetIsObjectValid (oArmor))
{

ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oPC);
itemproperty iProp = ItemPropertyACBonus(1);

IPSafeAddItemProperty(oArmor, iProp, RoundsToSeconds(nDur), X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, FALSE, TRUE);
}
}

else if (GetIsObjectValid(oTarget))
{
if (GetIsObjectValid (oWeapon))
{
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oPC);
itemproperty iProp = ItemPropertyEnhancementBonus(1);
IPSafeAddItemProperty(oWeapon, iProp, RoundsToSeconds(nDur), X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, FALSE, TRUE);
}
}
else FloatingTextStringOnCreature(“The potion has no effect”, oPC, FALSE);
}

}
}

Taking a look at that the code it seems like a potion you drink and it enchants your weapon, your shield AND your armor, if any. However, this contradicts your statement in the opening post.
This should be a sort of a lotion you apply to an item (so you must target it), correct?

In that case, the code that does what you’re looking for, should be the following:

#include "x2_inc_switches"
#include "x2_inc_itemprop"

void main()
{
	// * This code runs when the Unique Power property of the item is used
	// * Note that this event fires for PCs only
	if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
	
	//major variables
	object oPC = GetItemActivator();
	object oTarget = GetItemActivatedTarget();
	itemproperty iProp;
	
	if (IPGetIsMeleeWeapon(oTarget) == TRUE) iProp = ItemPropertyEnhancementBonus(1);
	else if (IPGetIsRangedWeapon(oTarget) == TRUE) iProp = ItemPropertyEnhancementBonus(1);
	else
	{
		int nType = GetBaseItemType(oTarget);
		switch (nType)
		{
			case BASE_ITEM_ARMOR:
			case BASE_ITEM_SMALLSHIELD:
			case BASE_ITEM_LARGESHIELD:
			case BASE_ITEM_TOWERSHIELD:
				iProp = ItemPropertyACBonus(1);
				break;
			default:
				FloatingTextStringOnCreature("The potion has no effect", oPC, FALSE);
				return;
		}
	}
	
	ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_AC_BONUS), oPC);
	IPSafeAddItemProperty(oTarget, iProp, RoundsToSeconds(10));
}
1 Like

First thing I see is that the tag based script is run by the item, not the PC, so oPC is not OBJECT_SELF, it is GetItemActivator().

He actually changes it to GetItemActivator a few lines down, so I doubt that would be the problem anyway. That was just redundancy.

I might be wrong, but I’m pretty certain ranged weps can only take attack bonus’s and not enhancements. I’ll have to double check to see if I’m wrong.
I’d prefer the bonus to be on the ammo and not the ranged wep when it comes to it. Whether dmg or enhancement.