Page 1 of 1

Spawning the same object in a chest

PostPosted: Thu Jun 27, 2002 1:38 pm
Author: Orleron
Got this off the nwn boards, looks useful:

1) In your area place a chest. Let's give the chest a unique tag like NewGearChest

2) Mark the chest as a plot item so it can not be destroyed.

3) Now head over to the script tab and delete the default scrips for OnOpen and OnDeath

4) In the OnOpen event click edit and paste the code below (Assuming you have created a weapon with the tag of "PlayerSword")


/*
This script checks the PC for an item.
If the PC does NOT have the item it is
created on the chest object and the PC
can then take it.
/*
// Created Jun 22, 2002 by: Raligard

#include "NW_O2_CONINCLUDE"


void main()
{
object oPC = GetLastOpener();
object oPlayerSword;
oNewbieDagger = GetItemPossessedBy(oPC, "PlayerSword");
if(!GetIsObjectValid(oPlayerSword))
{
CreateItemOnObject("PlayerSword", OBJECT_SELF, 1);
}
ShoutDisturbed();
}



5) If the player closes the chest and doesn't take the item it will remain. Then the next player who opens the chest will make it create a new one, there will be 2 items, then 3... then 4... you get the idea, so let's also prevent this!

6) In the OnClose event click the edit button and paste the text below (Again, assuming the item with the tag "PlayerSword" exists)


#include "NW_O2_CONINCLUDE"

void main()
{
object oPlayerSword = GetItemPossessedBy(OBJECT_SELF, "PlayerSword");
if(GetIsObjectValid(oPlayerSword))
{
DestroyObject(oPlayerSword);
}
}