Author Sticky: Post Working Scripts Here
bylogic Posted: Sunday, 23 June 01:25AM
"Destroy Spawned Items"

2nd Posting Sorry for the Duplicate. Posted under wron topic.

The following set of files is based on the Treasure Spawning scripts.

When added to the OnDeath Event of a Chest(or any object) it will destroy items spawned based on a probability. For example, If a Potion is spawned when a chest is bashed open there is a 90% chance that the potion would be destroyed.

This will be useful in deterring bashing chests instead of unlocking.

Main Include File:
nl_treasinclude.nss
NWScript:
//::///////// ////// /////// ////////////// ///////////

//:: Destroys Spawned Treasure & Inventory

//:: Uses Bioware General Treasure Spawn Script in NW_O2_CONINCLUDE.nss

//:: filename nl_treasinclude

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

/*

    This script destroys objects Generated by Treasure Spawn Script

    Destruction Probability determined by Base Type

*/

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

//:: Created By:   Nevelle Laiche

//:: Created On:   June 20, 2002

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

#include "NW_O2_CONINCLUDE"

//input  int nTreasureAmount

//    0  Spawn No Treasure  -  this destroys inventory

//    1  Spawn Low Treasure

//    2  Spawn Medium Treasure

//    3  Spawn High Treasure

void DestroySpawnedTreasure( int nTreasureAmount)

{

///  Constants

    //// Base Type Destruction Probability

    int AMULET_DESTROY = 75;

    int ARMOR_DESTROY = 5;

    int ARROW_DESTROY = 25;

    int BELT_DESTROY = 25;

    int BOLT_DESTROY = 25;

    int CLOAK_DESTROY = 10;

    int DART_DESTROY = 25;

    int GEM_DESTROY = 45;

    int LIGHTCROSSBOW_DESTROY = 35;

    int HEAVYCROSSBOW_DESTROY = 30;

    int HEALERSKIT_DESTROY = 45;

    int HELMET_DESTROY = 5;

    int MAGICROD_DESTROY = 80;

    int MAGICWAND_DESTROY = 80;

    int MAGICSTAFF_DESTROY = 30;

    int POTIONS_DESTROY = 90;

    int RING_DESTROY = 15;

    int SCROLL_DESTROY = 35;

    int SPELLSCROLL_DESTROY = 35;

    int BULLET_DESTROY = 0;

    int CLUB_DESTROY = 0;

    int GOLD_DESTROY = 0;

    int THIEVESTOOLS_DESTROY = 65;

    int TRAPKIT_DESTROY = 65;

    int OTHER_DESTROY = 5;  //Anything Not Listed...Mostly Weapons

// variables

    int nBaseItemType;

    int nDestroyProbability = -1;

    if (GetLocalInt( OBJECT_SELF,"NW_DO_ONCE" ) != 0)

    {

       return;

    }

    object oLastOpener = GetLastOpener();

    switch (nTreasureAmount)

    {

        case 1: GenerateLowTreasure( oLastOpener, OBJECT_SELF); break;

        case 2: GenerateMediumTreasure( oLastOpener, OBJECT_SELF); break;

        case 3: GenerateHighTreasure( oLastOpener, OBJECT_SELF); break;

    }

    object oItem = GetNextItemInInventory(OBJECT_SELF); // prime while loop

    while (GetIsObjectValid(oItem))

    {

      nBaseItemType = GetBaseItemType( oItem );

      switch (nBaseItemType)

      {

        case BASE_ITEM_AMULET: nDestroyProbability = AMULET_DESTROY; break;

        case BASE_ITEM_ARMOR: nDestroyProbability = ARMOR_DESTROY; break;

        case BASE_ITEM_ARROW: nDestroyProbability = ARROW_DESTROY; break;

        case BASE_ITEM_BELT: nDestroyProbability = BELT_DESTROY; break;

        case BASE_ITEM_BOLT: nDestroyProbability = BOLT_DESTROY; break;

        case BASE_ITEM_CLOAK: nDestroyProbability = CLOAK_DESTROY; break;

        case BASE_ITEM_DART: nDestroyProbability = DART_DESTROY; break;

        case BASE_ITEM_GEM: nDestroyProbability = GEM_DESTROY; break;

        case BASE_ITEM_LIGHTCROSSBOW: nDestroyProbability = LIGHTCROSSBOW_DESTROY; break;

        case BASE_ITEM_HEAVYCROSSBOW: nDestroyProbability = HEAVYCROSSBOW_DESTROY; break;

        case BASE_ITEM_HEALERSKIT: nDestroyProbability = HEALERSKIT_DESTROY; break;

        case BASE_ITEM_HELMET: nDestroyProbability = HELMET_DESTROY; break;

        case BASE_ITEM_MAGICWAND: nDestroyProbability = MAGICWAND_DESTROY; break;

        case BASE_ITEM_MAGICROD: nDestroyProbability = MAGICROD_DESTROY; break;

        case BASE_ITEM_MAGICSTAFF: nDestroyProbability = MAGICSTAFF_DESTROY; break;

        case BASE_ITEM_POTIONS: nDestroyProbability = POTIONS_DESTROY; break;

        case BASE_ITEM_RING: nDestroyProbability = RING_DESTROY; break;

        case BASE_ITEM_SCROLL: nDestroyProbability = SCROLL_DESTROY; break;

        case BASE_ITEM_SPELLSCROLL: nDestroyProbability = SPELLSCROLL_DESTROY; break;

        case BASE_ITEM_BULLET: nDestroyProbability = BULLET_DESTROY; break;

        case BASE_ITEM_CLUB: nDestroyProbability = CLUB_DESTROY; break;

        case BASE_ITEM_GOLD: nDestroyProbability = GOLD_DESTROY; break;

        case BASE_ITEM_THIEVESTOOLS: nDestroyProbability = THIEVESTOOLS_DESTROY; break;

        case BASE_ITEM_TRAPKIT: nDestroyProbability = TRAPKIT_DESTROY; break;

      }

      if (nDestroyProbability<0) // switch didn't find Type Constant

      {

         nDestroyProbability = OTHER_DESTROY;

      }

      if (Random(100)+1 < nDestroyProbability)

      {

        SpeakString( GetName( oItem )+ " Was Destroyed on Impact");

        DestroyObject(oItem);

      }

      else

      {

        dbSpeak(GetName(oItem)+ " Was Not Destroyed");

      }

      oItem = GetNextItemInInventory( OBJECT_SELF );

    } // end while loop

    SetLocalInt( OBJECT_SELF, "NW_DO_ONCE",1);

    ShoutDisturbed();

}



Calling Script: Low Treasure Spawn
nl_treasdeslow.nss

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

//:: Name

//:: FileName   nl_treasdeslow.nss

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

/*

     See nl_treasinclude for description

*/

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

//:: Created By:   Nevelle Laiche      bylogic@lycos.com

//:: Created On:   June 21, 2002

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

#include "nl_treasinclude"

void main()

{

    DestroySpawnedTreasure( 1 );

}



Calling Script: Medium Treasure Spawn
nl_treasdesmed.nss

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

//:: Name

//:: FileName   nl_treasdesmed.nss

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

/*

    See nl_treasinclude for description

*/

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

//:: Created By:   Nevelle Laiche     bylogic@lycos.com

//:: Created On:   June 21, 2002

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

#include "nl_treasinclude"

void main()

{

    DestroySpawnedTreasure( 2 );

}



Calling Script: High Treasure Spawn
nl_treasdeshigh.nss

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

//:: Name

//:: FileName   nl_treasdeshigh.nss

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

/*

     See nl_treasinclude for description

*/

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

//:: Created By:   Nevelle Laiche  bylogic@lycos.com

//:: Created On:   June 21, 2002

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

#include "nl_treasinclude"

void main()

{

    DestroySpawnedTreasure( 3 );

}



Calling Script: No Treasure Spawn
nl_treasdestroy.nss

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

//:: Name

//:: FileName   nl_treasdestroy.nss

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

/*

     See nl_treasinclude for description

*/

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

//:: Created By:   Nevelle Laiche      bylogic@lycos.com

//:: Created On:   June 21, 2002

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

#include "nl_treasinclude"

void main()

{

    DestroySpawnedTreasure( 0 );

}



Please Test for Errors
Should work as Described but it is rather late....