Skip to content

ActivateItem Script Question

Just trying to create a potion of Cause Serious Wounds. Didn't see any in the toolset.

As is it now the PC goes through all of the animations, but no spell?
}
     // Potion of Cause Serious Wounds
     object oUsed7 = GetItemActivated();
     if (GetTag(oUsed7) == "SERIOUS_WOUNDS")
     {

     object oPC = GetItemActivatedTarget();
     //object oPC = GetItemActivator();
     AssignCommand(oPC, ActionCastSpellAtObject
     (SPELL_INFLICT_SERIOUS_WOUNDS, oPC, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));
     }

Comments

  • NeverwinterWightsNeverwinterWights Member Posts: 339
    Hmm. How are you wanting to implement this? Tag based script or are you using the modules OnActivate script? And is it a grenade type potion to cause serious wounds on a target or just a regular potion that you can drink to cause serious wounds to yourself?
  • ZephiriusZephirius Member Posts: 419
    On Activate and a potion you can drink yourself.
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    Technically this does work:
    object oPC = GetItemActivator();
        AssignCommand(oPC, ActionCastSpellAtObject
        (SPELL_INFLICT_SERIOUS_WOUNDS, oPC, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));
    
    But it is a "touch" spell and I'm not sure how that works (on successful touch) if a player does it on themselves and so may not function as you intend.

    It might be best just to apply effects in this case rather than having the player cast a spell. Something like:
    effect eDamage = EffectDamage(d8(3));
        AssignCommand(oPC, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC));
    
  • ZephiriusZephirius Member Posts: 419
    edited January 2022
    Yeah, I'd already made a work around - not happy with it though :(
    // Potion of Cause Serious Wounds
         object oUsed7 = GetItemActivated();
         if (GetTag(oUsed7) == "SERIOUS_WOUNDS")
         {
    
         object oPC = GetItemActivatedTarget();
         //object oPC = GetItemActivator();
         effect ePotion = EffectVisualEffect(VFX_IMP_HEAD_EVIL);
         ApplyEffectToObject(DURATION_TYPE_INSTANT, ePotion, oPC);
         effect eDamage = EffectDamage(d6(3), DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL);
         ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC);
         //AssignCommand(GetItemActivatedTarget(), ActionCastSpellAtObject
         //(SPELL_INFLICT_SERIOUS_WOUNDS, oPC, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));
    

    As a touch attack it does "work". In the chat window the feedback indicates a successful hit occurred on the PC. But that's all that happens.
  • ForSeriousForSerious Member Posts: 466
    edited January 2022
    In X0_I0_SPELLS, line 613 it only applies the spell effect if the target is an enemy. You could just remove that if statement, or add special cases for the inflict wounds spells.
  • ZephiriusZephirius Member Posts: 419
    Thanks for the heads up Serious!
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    edited February 2022
    #include "x2_inc_switches"

    void main()
    {
    if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
    object oPC = GetItemActivator();
    object oItem = GetItemActivated();
    {
    //do stuff here
    }
    }

    Post edited by 4BOLTMAIN on
  • TarotRedhandTarotRedhand Member Posts: 1,481
    @4BOLTMAIN Here is your code indented and simplified -
    #include "x2_inc_switches"
    
    void main()
    {
        if (GetUserDefinedItemEventNumber() == X2_ITEM_EVENT_ACTIVATE)
        {
            object oPC = GetItemActivator();
            object oItem = GetItemActivated();
    
            //do stuff here
        }
    }
    
    BTW Just a couple of things - By rejigging the if() statement I've removed the need for that return statement which in turn makes it so there is only a single exit point from the function. Doing so is said to make code easier to debug.

    Also I removed your extraneous { } around your comment as it served no purpose and if you are not careful can cause problems in whatever code you place there.

    TR
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    Thanks for the correction. I always use oPC = GetItemActivator on custom potions and they all work as intended.

    I never declare variables inside brackets (after an if statement) I always declare them at the top of the script. Im not sure if this is a good or bad thing but its just a habit I developed over the years.
  • meaglynmeaglyn Member Posts: 151
    I prefer 4BOLTMAIN's version (minus the extra braces although they don't hurt anything, and with actual formatting). That way you get to work with less indentation for the main code (which is good because I like full 8 space indents). Doing quick early exits like that is a fine practice and doesn't hurt debugging. It makes code easier to read, IMO.

    As to variables declared in smaller scopes, it just depends. If for example in this case you had them before the if so they were executed even if it was not ACTIVATE then you'd be doing a few extra "syscalls" and instructions. As written there's really no difference here. If you do all your variables that way then you are probably doing a few extra instructions here or there in your scripts but I don't think that will matter much. We are beyond the days of having to micro optimize instruction counts :)
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    This is what I came up with. The only thing I don't like is that the log says "someone damages 4BOLTMAIN".
    #include "x2_inc_switches"
    
    // Potion of Cause Serious Wounds
    void main()
    {
    if (GetUserDefinedItemEventNumber() == X2_ITEM_EVENT_ACTIVATE)
        {
        object oPC = GetItemActivator();
        object oItem = GetItemActivated();
        if (GetTag(oItem) == "serious_wounds")
            {
            int iHD = GetHitDice(oPC);
            effect eDamage = EffectDamage(d8(3) + iHD, DAMAGE_TYPE_NEGATIVE, DAMAGE_POWER_NORMAL);
            effect eVisual = EffectVisualEffect(VFX_IMP_NEGATIVE_ENERGY);
            DelayCommand(0.8, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisual, oPC));
            DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC));
            }
        }
    }
    
Sign In or Register to comment.