"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:
#include "NW_O2_CONINCLUDE"
void DestroySpawnedTreasure( int nTreasureAmount)
{
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;
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);
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)
{
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 );
}
SetLocalInt( OBJECT_SELF, "NW_DO_ONCE",1);
ShoutDisturbed();
}
Calling Script: Low Treasure Spawn
nl_treasdeslow.nss
NWScript:
#include "nl_treasinclude"
void main()
{
DestroySpawnedTreasure( 1 );
}
Calling Script: Medium Treasure Spawn
nl_treasdesmed.nss
NWScript:
#include "nl_treasinclude"
void main()
{
DestroySpawnedTreasure( 2 );
}
Calling Script: High Treasure Spawn
nl_treasdeshigh.nss
NWScript:
#include "nl_treasinclude"
void main()
{
DestroySpawnedTreasure( 3 );
}
Calling Script: No Treasure Spawn
nl_treasdestroy.nss
NWScript:
#include "nl_treasinclude"
void main()
{
DestroySpawnedTreasure( 0 );
}
Please Test for Errors
Should work as Described but it is rather late....
|