Skip to content

Craft Item/Destroy Ingredients

Got a small script that is working partially. All but destroying the craft items that is... Just need them to go away after item creation.
Tried using DestroyObject. It works, but for only the MITHRIL_BAR. The other two ingredients remain?
Thanks in advance.

Code so far:
void main()
{
    object oPC = GetLastSpellCaster();
    if (!GetIsPC(oPC)) return;

        if (GetLastSpell() == SPELL_STONESKIN)
        {

        object oSelf = OBJECT_SELF;

       // Only fire once.
      if ( GetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF)) )
        return;
      SetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);

      // If Gumdulmach has the item "MITHRIL_BAR".
    if ( GetItemPossessedBy(OBJECT_SELF, "MITHRIL_BAR") != OBJECT_INVALID )
    {
        // If Gumdulmach has the item "IRON_SPIKES".
        if ( GetItemPossessedBy(OBJECT_SELF, "IRON_SPIKES") != OBJECT_INVALID )
        {
            // If Gumdulmach has the item "WOODEN_HANDLE".
            if ( GetItemPossessedBy(OBJECT_SELF, "WOODEN_HANDLE") != OBJECT_INVALID )
            {
                // Give Mjordulstiehl to us.
                DestroyObject(GetObjectByTag("MITHRIL_BAR"), 0.3);
                DestroyObject(GetObjectByTag("IRON_SPIKES"), 0.6);
                DestroyObject(GetObjectByTag("WOODEN_HANDLE"), 0.9);

                ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect
                (VFX_FNF_MYSTICAL_EXPLOSION), OBJECT_SELF);
                CreateItemOnObject("mjordulstiehl", oSelf);
            }
        }
    }

  }

}

Comments

  • MelkiorMelkior Member Posts: 181
    edited November 2022
    The first thing I'd do is not to nest "if"s like that. I'd instead use && (logical AND) to combine all of the conditions into a single "if" statement.
    Secondly, DestroyObject doesn't run until after the script has ended anyway (which is in case you're trying to destroy the object which the script is running on), which probably makes the delays redundant.
    Thirdly and most importantly, you're destroying the first object tagged "MITHRIL_BAR", the first object tagged "IRON_SPIKES" and the first object tagged "WOODEN_HANDLE" no matter where they exist in the game, even if they aren't the ones held by the player.

    The first thing you should do in the script right after finding the PC is use GetItemPossessedBy to try to find the three items on the player and assign them to object variables, then use those object variables in both the "if" and in the DestroyObject commands.

    Also, did you really mean for OBJECT_SELF to refer to the object the script is running on instead of to the player? If so, then it should work. If not, you may be getting other strange effects.

    Another note: I usually check for GetIsObjectValid rather than checking that the object is not equal to OBJECT_INVALID but either way should work.

    Try this and see if it does what you want (untested of course):
    void main()
    {
        object oPC = GetLastSpellCaster();
        if (!GetIsPC(oPC)) return;
        object oBar=GetItemPossessedBy(oPC,"MITHRIL_BAR");
        object oSpikes=GetItemPossessedBy(oPC,"IRON_SPIKES");
        object oHandle=GetItemPossessedBy(oPC,"WOODEN_HANDLE");
            if (GetLastSpell() == SPELL_STONESKIN)
            {
    
            object oSelf = OBJECT_SELF;
    
           // Only fire once.
          if ( GetLocalInt(GetModule(), "DO_ONCE__" + GetTag(oSelf)) )
            return;
          SetLocalInt(GetModule(), "DO_ONCE__" + GetTag(oSelf), TRUE);
    
          // If Gumdulmach has the items "MITHRIL_BAR", "IRON_SPIKES" and "WOODEN_HANDLE".
        if ( oBar != OBJECT_INVALID && oSpikes != OBJECT_INVALID && oHandle != OBJECT_INVALID )
                {
                    // Give Mjordulstiehl to us.
                    DestroyObject(oBar);
                    DestroyObject(oSpikes);
                    DestroyObject(oHandle);
    
                    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect
                    (VFX_FNF_MYSTICAL_EXPLOSION), oSelf);
                    CreateItemOnObject("mjordulstiehl", oSelf);
                }
            }
    
    }
    
    Editing to add, this script might not work correctly in some situations which could arise in a multi-player module but should work fine for single-player.
  • ZephiriusZephirius Member Posts: 411
    Works like a charm. Thanks for the help Melkior.
Sign In or Register to comment.