There are many scripts out there allowing to set a percent chance for a specific item to drop from a defeated monster, but most of them have lots of additional features that might not be desired by some. Anyway, I've been using my own, very basic script, to handle chances of loot dropping.
/*Simple random loot system by Grani: this script generates up to 10 loot items on the dead enemy, as specified with variables of the creature it is attached to. The variables should be set as follows: loot_XX - an integer, write in it the percent chance of drop (value from 1 to 99) resref_XX - a string, write in it the resref of the loot item So, for the first loot item, use variables loot_01 and resref_01, for the next one use loot_02 and resref_02, etc. The script can also generate one stack of stackable items. The variables for this are: loot_stack - an integer, the percent chance of drop resref_stack - a string, the resref of the loot item amount_stack - an integer, the amount of items in a dropped stack Note: in case of standard palette loot items, use the item's tag instead of resref!*/ void main() { ExecuteScript("nw_c2_default7", OBJECT_SELF); //Get resrefs of loot and chances of drop specified in variables int nL1 = GetLocalInt(OBJECT_SELF, "loot_01"); string sL1 = GetLocalString(OBJECT_SELF,"resref_01"); int nL2 = GetLocalInt(OBJECT_SELF, "loot_02"); string sL2 = GetLocalString(OBJECT_SELF,"resref_02"); int nL3 = GetLocalInt(OBJECT_SELF, "loot_03"); string sL3 = GetLocalString(OBJECT_SELF,"resref_03"); int nL4 = GetLocalInt(OBJECT_SELF, "loot_04"); string sL4 = GetLocalString(OBJECT_SELF,"resref_04"); int nL5 = GetLocalInt(OBJECT_SELF, "loot_05"); string sL5 = GetLocalString(OBJECT_SELF,"resref_05"); int nL6 = GetLocalInt(OBJECT_SELF, "loot_06"); string sL6 = GetLocalString(OBJECT_SELF,"resref_06"); int nL7 = GetLocalInt(OBJECT_SELF, "loot_07"); string sL7 = GetLocalString(OBJECT_SELF,"resref_07"); int nL8 = GetLocalInt(OBJECT_SELF, "loot_08"); string sL8 = GetLocalString(OBJECT_SELF,"resref_08"); int nL9 = GetLocalInt(OBJECT_SELF, "loot_09"); string sL9 = GetLocalString(OBJECT_SELF,"resref_09"); int nL10 = GetLocalInt(OBJECT_SELF, "loot_10"); string sL10 = GetLocalString(OBJECT_SELF,"resref_10"); int nStack = GetLocalInt(OBJECT_SELF, "loot_stack"); string sStack = GetLocalString(OBJECT_SELF,"resref_stack"); int nNumber = GetLocalInt(OBJECT_SELF, "amount_stack"); //generate the loot; or not if (d100()<=nL1) { CreateItemOnObject(sL1, OBJECT_SELF); } if (d100()<=nL2) { CreateItemOnObject(sL2, OBJECT_SELF); } if (d100()<=nL3) { CreateItemOnObject(sL3, OBJECT_SELF); } if (d100()<=nL4) { CreateItemOnObject(sL4, OBJECT_SELF); } if (d100()<=nL5) { CreateItemOnObject(sL5, OBJECT_SELF); } if (d100()<=nL6) { CreateItemOnObject(sL6, OBJECT_SELF); } if (d100()<=nL7) { CreateItemOnObject(sL7, OBJECT_SELF); } if (d100()<=nL8) { CreateItemOnObject(sL8, OBJECT_SELF); } if (d100()<=nL9) { CreateItemOnObject(sL9, OBJECT_SELF); } if (d100()<=nL10) { CreateItemOnObject(sL10, OBJECT_SELF); } if (d100()<=nStack) { CreateItemOnObject(sStack, OBJECT_SELF, nNumber); } } |
The way it works is simple:
1. Put the script in the OnDeath script field of your monster.
2. Open the monster's variables.
3. Add a string variable called "resref_01", with the resref of the item as its value (note: in case of standard palette items, the tag should be used instead)
4. Add an integer variable called "loot_01" with percent chance of drop as its value (eg. "40")
Now there will be a chance of an item generating in the body of killed creature. You can add more items that way (up to 10 by default), by using variables such as "loot_02" and "resref_02".
You can even add a stack of items that way, the variables for this are:
loot_stack - an integer, the percent chance of drop
resref_stack - a string, the resref of the loot item
amount_stack - an integer, the amount of items in a dropped stack
That's all, hope some of you will find this useful. :)
Attachment | Size |
---|---|
![]() | 927 bytes |
Really useful, and you might want to put "return;" after every CreateItemOnObject just in case if you don't players dropping more than one item at once.
Just stumbled across this - Will the creatures still drop the standard NWN loot that seems hardcoded, like gold or potion etc? Or does this replace that?
Seems perfect for what I'm after either way, thanks!