To check if targeted item is a weapon

How do you tell if the targeted object is a weapon?
All I can think of is to do… if GetWeaponType(oItem) is not WEAPON_TYPE_NONE

The ginc_item include file has the GetIsWeapon function that might be useful to you.

1 Like

Thank you Travus.

I think I’m doing something wrong still… How would you apply a temporary damage effect to a weapon?
Like in this example, it’s meant to apply 1d6 Sonic damage bonus.
I get the message, so I know it made it past the condition, but no effect goes on the weapon.

void main()
{

	object oTarget = GetItemActivatedTarget(); 
	object oPC = GetItemActivator();

	effect eSonic = EffectDamageIncrease(DAMAGE_BONUS_1d6, DAMAGE_TYPE_SONIC);
	
	if (GetIsWeapon(oTarget)==1)
	{
		SendMessageToPC(oPC, "You've targeted a weapon");
		ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSonic, oTarget, RoundsToSeconds(100)); 
	}
}
#include "ginc_item"
#include "x2_inc_itemprop"

void main()
{
	object oTarget = GetItemActivatedTarget(); 
	object oPC = GetItemActivator();
	
	if (GetIsWeapon(oTarget))
	{
	    itemproperty pBonus = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_SONIC, IP_CONST_DAMAGEBONUS_1d6);
		itemproperty pVisual = ItemPropertyVisualEffect(ITEM_VISUAL_SONIC);
		float fDuration = RoundsToSeconds(100);
		
		IPSafeAddItemProperty(oTarget, pBonus, fDuration);
		IPSafeAddItemProperty(oTarget, pVisual, fDuration);
 	}
	
	else SendMessageToPC(oPC, "The target must be a weapon!");
}
2 Likes

Mr Travus… Thank you, I was trying to think of something in default NWN2 that applied effects to a weapon, and finally remembered alchemists fire, so I looked that script over, and realized I was totally leaving out the itemproperty. It now works well, so big thank you for being online and helping out!

My tester now has a cool sonic hand axe and can beat up on gnolls while testing this level.

2 Likes