Author Sticky: Post Working Scripts Here
Zinderin Posted: Friday, 05 July 06:44PM
Script Name: Remove placeable if a required item is in the possession of the PC that used the placeable.

What it does: Allows a placeable item in the game to be
removed (with effects) if the PC that last used it is in possesion of a particular item (by tag name).

Notes: See script.

NWScript:
//::///////////////////////////////////////////////

//:: Name      Remove a placeable item with an item.

//:: FileName  sc_remove_plable

//:://////////////////////////////////////////////

/*

    This script will remove a usable placeable from

    the game (permanently) if the PC who last used

    the item is in possession of another item.

    This script goes on the "OnUsed" event of the

    placeable item you want to disappear.

    FOR EXAMPLE:  If a bolder is blocking a cave

    entrance, and the user has the right item in

    his/her inventory, the boulder will disappear

    with an effect.

    REQUIRED:

    1) A placeable item that has been set to usable.

    2) Some inventory item that has a unique tag.

    This script is a "no harm" script.  In other

    words as long as it compiles if anything goes

    wrong, the worse that will happen is for the

    DMs to be notified of the problem.

*/

//:://////////////////////////////////////////////

//:: Created By: Brett Lathrope

//:: Created On: July 5, 2002

//:://////////////////////////////////////////////

void main()

{

  //

  // Set the tag of the item required to remove the placeable.

  // In this script, it is a hard coded tag (string).  It could

  // very easily be a local string on the object that you set

  // at Spawn of some other time during the game.  You would

  // simply replace the line below with your logic.  If you don't

  // understand any of this...don't worry about it...just hard

  // code it by replacing "it_special01" with the tag of what

  // ever item it is you wish to use.

  string sSpItem = "it_special01";

  //

  // Get who the PC was that used the placeable.

  object oPC = GetLastUsedBy();

  //

  // Make sure the object that last used this placeable was in

  // in fact a PC.  If not, just skip the rest of the script.

  if (GetIsPC(oPC)){

    //

    // Get the object they must have in their possession for

    // this to work. NOTE: AS THIS SCRIPT IS WRITTEN, YOU MUS

    object oSpecialItem = GetObjectByTag(sSpItem);

    //

    // Make sure the object is valid.  It may have been destroyed

    // in one way or another.  You must never assume it exists.  If

    // it does not exist, the rest of the script is ignored and a

    // message is sent to the DMs.

    if (GetIsObjectValid(oSpecialItem)){

      //

      // Is the object needed to remove the placeable in the inventory

      // of the PC that last used the placeable?  In otherwords, are

      // we set to go?

      object oPossessedBy = GetItemPossessor(oSpecialItem);

      if (oPossessedBy == oPC){

        //

        // If we get to this point in the script, the PC that last used

        // the placeable has the item we want him to have to remove

        // the placeable.  The effect used can be changed...see the

        // reference docs for VFX_IMP_* options.

        effect eVisual = EffectVisualEffect(VFX_IMP_UNSUMMON,FALSE);

        ApplyEffectToObject(DURATION_TYPE_INSTANT,eVisual,OBJECT_SELF,2.0f);

        DestroyObject(OBJECT_SELF,0.5f);

      }

      else

      {

        //

        // If we get to this part of the script, the PC that last used the

        // placeable item does not possess the item he/she needs to get

        // the placeable to leave the game.  The effect used can be changed...

        // see the reference docs for VFX_IMP_* options.

        effect eVisual = EffectVisualEffect(VFX_IMP_MAGIC_PROTECTION,FALSE);

        ApplyEffectToObject(DURATION_TYPE_INSTANT,eVisual,OBJECT_SELF,2.0f);

      }

    }

    else

    {

      SendMessageToAllDMs(GetName(oPC) + " just used " + GetName(OBJECT_SELF) +

        " which requires a special item that does not exist in the game.");

    }

  }

}