Spawn Creature and Loot on opening a item.

This section was made to share custom scripts for Neverwinter Nights 2. Feel free to share!

Moderators: Tandamar, Solomon

User avatar
Posts: 269
Joined: Mon Jun 29, 2015 7:27 am
Location: MA/USA

Spawn Creature and Loot on opening a item.

Postby LoneNurgling » Mon Dec 07, 2015 1:30 pm

Original Author: shannonjoeker
Edited by: Clangeddin.86

Nwn Vault Link (for orignal): ... wns-zombie

1) Open your toolset, go to the scripts tab (default on your left). Create a new script, and name it what you want (I would put a prefix on it of "onopen_" so its easy to find).
2) Copy and past the script below into your newly created script, the only thing you need to edit is line 23. (OBJECT_TYPE_CREATURE, "ln_shadow", lTarget) "ln_shadow" needs to be replaced with the creature's tag of what you want spawned in.
3) Save the script, place the script on the "on open" script section in the properties window of the item. Make sure the item isn't set to static and is usable.

Optional) The following can be edited to change the random loot spawned in: ("x0_o2_clthme", oCHEST); Just the "x0_o2_clthme" would be changed, its defaulted for meddium valued cloth based items, boots, gloves, etc.
Other options are (but not limited to):
nw_o2_generallow (general purpose items)
nw_o2_generalmed (same as above, but more value added)
nw_o2_bookshelf (scrolls, books, misc)
x0_o2_mleemed (medium value melee weapon)
nw_o2_classweap (class based magic weapon)

Side Note: All those option loot options can be spawned as well as being used as just a "on open" script of a item.

Code: Select all

/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3

Original Author: shannonjoeker
Edited by: Clangeddin.86

For download info, please visit:
Nwn Vault Link (for orignal):    */

//Put this script OnOpen
#include "nw_i0_generic"

void main()
object oPC = GetLastOpenedBy();
if (!GetIsPC(oPC)) return;
int DoOnce = GetLocalInt(oCHEST, GetTag(oCHEST));
if (DoOnce==TRUE) return;
ExecuteScript("x0_o2_clthme", oCHEST);//this script called for in the quotes is for loot, default loot script is medium random loot
SetLocalInt(oCHEST, GetTag(oCHEST), TRUE);
location lTarget = GetLocation(oPC);
object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "ln_shadow", lTarget);//tag of the creature to spawn in is in the quotes, in this case its ln_shadow
SetIsTemporaryEnemy(oPC, oSpawn);
AssignCommand(oSpawn, ActionAttack(oPC));
AssignCommand(oSpawn, DetermineCombatRound(oPC));

Return to “Custom NWN2 Scripts for All to Use”

Who is online

Users browsing this forum: No registered users and 0 guests