Author Sticky: Post Working Scripts Here
Allroy Posted: Tuesday, 25 June 07:55PM
Script name: Randomtreasure

What it does: On the death of a NPC this script rolls a random number to determine what items are dropped. Items must be pre-existing items. (this does not generate new ones.

NWScript:
//::

//:: Set NPC to drop treasure from a pregenerated list

//:: of loot.

//::  RandomTresure

//::  Copyright (c) 2002 Chris Wilson

//::

/*

    This script rolls a d100 (100 sided die) and then

    determines the reward by the number that is rolled.

*/

//

//:: Created By: Chris Wilson

//:: Created On: June 26, 2002

//::



void main()

{

  int nDiceRoll = d100(1);

  if(nDiceRoll <= 10)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

    else if(nDiceRoll <= 20)

    {

    CreateItemOnObject("item,", OBJECT_SELF, 1);

    }

     else if(nDiceRoll <= 30)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

     else  if(nDiceRoll <= 40)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

     else if(nDiceRoll <= 50)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

    else if(nDiceRoll <= 60)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

     else  if(nDiceRoll <= 70)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

    else if(nDiceRoll <= 80)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

    else if(nDiceRoll <= 90)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

    else if(nDiceRoll <= 95)

    {

    CreateItemOnObject("item", OBJECT_SELF, 1);

    }

    else

     CreateItemOnObject("item", OBJECT_SELF, 1);



 }



In the OnDeath script for the NPC put this command in the line:

ExecuteScript("TresureSelector");

In the "item" areas put the BlueprintResRef name there.
Bam, random Treasure from a preselected loot table.
If you want more than one item just add more CreateItemOnObject statements within the brackets.

Hope this helps.

_________________
I don't hold a grudge. I have no surviving enemies... at all.

- Galen