Neverwinter Nights: Enhanced Edition

Neverwinter Nights: Enhanced Edition

Adventures await!
Gather your mods before venturing forth. Discover planes filled with player-created adventures in Steam Workshop, then build your own Neverwinter Nights modules using the Aurora Toolset to share!
Learn More
Need help on 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);
}

}
}
< >
Showing 1-5 of 5 comments
wendigo211 3 1 Aug, 2018 @ 4:04am 
To start with it should be:
swtich (controlvariable)
{
case state:
instructions;
break;
default:
break;
}

You only have one case, so I guess you don't really need the break statement and default case. But I don't think I've ever seen a switch work without the case in {}. Still, you might want to add a default case with a command that logs the state of your control variable for debugging purposes.

Secondly, your logic looks a little wierd, I think you want something like:
if (!GetIsObjectValid(oTarget)) return;
if (oTarget==oShield) ...
else if (oTarget==oArmor) ...
else if (oTarget==oWeapon)...
else
{
FloatingTextStringOnCreature("The potion has no effect", oPC, FALSE);
}

A better option might be to test the item type of oTarget and see if it's armor, shield or a weapon. It does get a little messy since each type of weapon has it's own type. You'll also need to discriminate between ranged and melee weapons since ranged weapons don't have enhancement bonuses, they get attack bonuses instead.
Calous Caine 1 1 Aug, 2018 @ 6:47am 
not quite seeing where you're going here.
you're not applying any effects, nor targeting the appropriate objects.
maybe you missed the point of the original post some how?
Last edited by Calous Caine; 1 Aug, 2018 @ 6:49am
wendigo211 3 1 Aug, 2018 @ 9:37am 
*Sigh* just try this and see if it works for you:

#include "x0_i0_position"
#include "x2_inc_switches"
#include "x2_inc_itemprop"


itemproperty DetermineBonus(object oTarget)
{
itemproperty ipBonus;
if (!GetIsObjectValid(oTarget)) return ItemPropertyVisualEffect(ITEM_VISUAL_HOLY);
int iItemType=GetBaseItemType(oTarget);
switch (iItemType)
{
case BASE_ITEM_ARMOR:
case BASE_ITEM_LARGESHIELD:
case BASE_ITEM_SMALLSHIELD:
case BASE_ITEM_TOWERSHIELD:
ipBonus=ItemPropertyACBonus(1);
break;
case BASE_ITEM_HEAVYCROSSBOW:
case BASE_ITEM_LIGHTCROSSBOW:
case BASE_ITEM_LONGBOW:
case BASE_ITEM_SHORTBOW:
case BASE_ITEM_SLING:
ipBonus=ItemPropertyAttackBonus(1);
break;
case BASE_ITEM_BASTARDSWORD:
case BASE_ITEM_BATTLEAXE:
case BASE_ITEM_CLUB:
case BASE_ITEM_DAGGER:
case BASE_ITEM_DART:
case BASE_ITEM_DIREMACE:
case BASE_ITEM_DOUBLEAXE:
case BASE_ITEM_DWARVENWARAXE:
case BASE_ITEM_GREATAXE:
case BASE_ITEM_GREATSWORD:
case BASE_ITEM_HALBERD:
case BASE_ITEM_HANDAXE:
case BASE_ITEM_HEAVYFLAIL:
case BASE_ITEM_KAMA:
case BASE_ITEM_KATANA:
case BASE_ITEM_KUKRI:
case BASE_ITEM_LIGHTFLAIL:
case BASE_ITEM_LIGHTHAMMER:
case BASE_ITEM_LIGHTMACE:
case BASE_ITEM_LONGSWORD:
case BASE_ITEM_MORNINGSTAR:
case BASE_ITEM_QUARTERSTAFF:
case BASE_ITEM_RAPIER:
case BASE_ITEM_SCIMITAR:
case BASE_ITEM_SHORTSPEAR:
case BASE_ITEM_SHORTSWORD:
case BASE_ITEM_SHURIKEN:
case BASE_ITEM_SICKLE:
case BASE_ITEM_THROWINGAXE:
case BASE_ITEM_TRIDENT:
case BASE_ITEM_TWOBLADEDSWORD:
case BASE_ITEM_WARHAMMER:
case BASE_ITEM_WHIP:
ipBonus=ItemPropertyEnhancementBonus(1);
break;
default:
ipBonus=ItemPropertyVisualEffect(ITEM_VISUAL_HOLY);
break;
}
return ipBonus;
}

void main()
{
//major variables
object oPC = OBJECT_SELF;
object oTarget = GetItemActivatedTarget();
effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
effect eVis = EffectVisualEffect(VFX_IMP_AC_BONUS);
int nDur = 10;
int nEvent = GetUserDefinedItemEventNumber(); //Which event triggered this

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
itemproperty ipBonus=DetermineBonus(oTarget);
if (GetItemPropertyType(ipBonus)==ITEM_PROPERTY_VISUALEFFECT)
{
FloatingTextStringOnCreature("The potion has no effect", oPC, FALSE);
return;
}
else
{
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oPC);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDur, oPC, RoundsToSeconds(nDur));
IPSafeAddItemProperty(oTarget, ipBonus, RoundsToSeconds(nDur), X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, FALSE, TRUE);
return;
}
break;
}
}
Calous Caine 1 1 Aug, 2018 @ 12:44pm 
I like the conversion, save for the ranged weapons, I'd rather the extra dmg or enhancement be on the ammo than the ranged wep.
Calous Caine 1 7 Aug, 2018 @ 4:52pm 
I've actually found a simpler way to do this. Thank you everyone for your input.
< >
Showing 1-5 of 5 comments
Per page: 1530 50