Skip to content

Help with an item script that applies bonus dmg to weapons

AtrophiedericAtrophiederic Member, Mobile Tester Posts: 147
Greetings, all!

I have been working on figuring out this script for a few weeks now. The concept is having an item that gives a 1d10 sonic damage bonus to a weapon targeted by the item's unique power.

I don't have a very firm grasp of scripting, so I have been using Lilac Soul's Script Generator heavily. I also open up modules to see how others have accomplished their scripting. But so far, resolution has eluded me.
#include "x2_inc_itemprop"
void main()
{
    effect eEffect;
    object oEventItem = GetItemActivated();
    object oActTarget = GetItemActivatedTarget();
    location lActTarget = GetItemActivatedTargetLocation();
    object oActivator = GetItemActivator();

    object oPC = oActivator;

    // Apply an effect.
        itemproperty ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_SONIC, IP_CONST_DAMAGEBONUS_1d10);
        eEffect = SupernaturalEffect(EffectDamageIncrease(DAMAGE_BONUS_1d10, DAMAGE_TYPE_SONIC));
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oActTarget);
    // Float message over PC.
        FloatingTextStringOnCreature("Sonic Damage 1d10 added.", oPC);
}
Any help that can be offered is really appreciated!
Thank you, and Happy Hollidays!

Comments

  • AtrophiedericAtrophiederic Member, Mobile Tester Posts: 147
    I have also looked online in various forums, and also perused the Lexicon. Unfortunately, I was unable to find answers in those places.
  • AschentAschent Member Posts: 15
    Hi Atrophiederic,

    The issue you're facing is caused by the use of an Effect on an item. Effects can only be applied to Creatures. Item Properties on the other hand can be applied to items so you're almost there:
    #include "x2_inc_itemprop"
    void main()
    {
        effect eEffect;
        object oEventItem = GetItemActivated();
        object oActTarget = GetItemActivatedTarget();
        location lActTarget = GetItemActivatedTargetLocation();
        object oActivator = GetItemActivator();
    
        object oPC = oActivator;
    
       	 // Apply an effect.
            itemproperty ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_SONIC, IP_CONST_DAMAGEBONUS_1d10);
    	AddItemProperty(DURATION_TYPE_PERMANENT, ipAdd, oActTarget);
        	// Float message over PC.
            FloatingTextStringOnCreature("Sonic Damage 1d10 added.", oPC);
    }
    

    Give that a shot and let me know if the problem is fixed.
  • AtrophiedericAtrophiederic Member, Mobile Tester Posts: 147
    Friend @Aschent ,

    Thank you so much for the speedy reply and help!
    As soon as my NwN finishes updating, I will give it a spin!
  • AtrophiedericAtrophiederic Member, Mobile Tester Posts: 147
    Friend @Aschent ,

    The script works beautifully!

    Only issue I'm seeing is it is applying the 1d10 property twice.
    I don't see anything in the script that would prompt that.
  • AschentAschent Member Posts: 15
    I believe in that case you'll want to make use of
    IPSafeAddItemProperty()
    
    which you should have access to via your include.

    Try:
    #include "x2_inc_itemprop"
    void main()
    {
        effect eEffect;
        object oEventItem = GetItemActivated();
        object oActTarget = GetItemActivatedTarget();
        location lActTarget = GetItemActivatedTargetLocation();
        object oActivator = GetItemActivator();
    
        object oPC = oActivator;
    
       	 // Apply an effect.
            itemproperty ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_SONIC, IP_CONST_DAMAGEBONUS_1d10);
    	IPSafeAddItemProperty(oActTarget, ipAdd);
        	// Float message over PC.
            FloatingTextStringOnCreature("Sonic Damage 1d10 added.", oPC);
    }
    

    I'm not sure why it would be adding twice unless another event is firing to add the IP. However IPSafeAdd.. will remove any existing versions of the IP.
  • AtrophiedericAtrophiederic Member, Mobile Tester Posts: 147
    I altered the very last line, changing "oPC" to "oActivator" and the double property disappeared. It now fires properly, and only one enhancement property is added. (This change also removed another bug - the script was firing for the item when I removed it from a container, and again when I used the item's unique power. but after the change, removing the item from the container produces no script fire.)

    An interesting tick, though ... The "FloatingTextStringOnCreature" still gives a double message.
    Odd.

    I may just remove that part completely, to alleviate the issue.
    Regardless, friend @Aschent , I thank you so much for your help!
Sign In or Register to comment.