Server Totals
Deglos - (1)
Visimontium - (1)
Le'Or - (0)
Ferrell - (0)
Elysia - (0)
M'Chek - (0)
Mikona - (0)
Wilderness - (0)
Underdark - (0)
Total players: 2
Gallery
  • Winter Ball 2015
    Album name: DM Events
    Uploaded by: Ronan
    Uploaded: Sat Jan 03, 2015 4:41 pm

Links Menu

Spawning the same object in a chest

Moderators: Nighthawk4, Dungeon Masters

Spawning the same object in a chest

PostAuthor: Orleron » Thu Jun 27, 2002 1:38 pm

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);
}
}
"Truth has no form."
--Idries Shah

World of Avlis Page

Avlis Project FAQ
User avatar
Orleron
World Advisor, Co-founder
World Advisor, Co-founder
 
Posts: 14905
Joined: Fri Sep 14, 2001 9:48 pm
Timezone: GMT-5

Return to NWN Scripting

Who is online

Registered users: Bing [Bot], Google [Bot], Gorgon