Spawn item in placeable periodically script help needed

I’ve been attempting to spawn items into a placeable with inventory to no avail (not sure why that isn’t working), let alone spawn once per game day which is what I would like. For example having a tree or bush spawn fruit item into its inventory once per day, but stop spawning when the inventory qty reached x.

I’m doing a similar thing in NWN2 so maybe I could help - can you post the script you’re using?

When are you calling the spawn and how are you getting the placeable you are spawning into?

The placeable exists already. I’d like to treat it as a container and spawn items into it.
I can’t even get the following, generated by Lilac’s Soul to work:

void main()
object oSelf = OBJECT_SELF;

// Get the creature who triggered this event.
object oPC = GetLastOpenedBy();

// Give "hen_lin3qt001" to us.
CreateItemOnObject("hen_lin3qt001", oSelf);


When the placeable is opened, there are no items there. No matter what ResRef is used, the results are the same. Until we pass this simple sanity check, there is no point in complicating the script further with conditions.

Are you sure your script is attached to the OnOpen slot of the given placeable? Get into the habit of adding some debug messages when something doesn’t work for you. That way you will quickly locate the source of the problem.

SendMessageToPC(GetFirstPC(), "message text");

The only things that come into my mind are:

  • wrong item resref
  • forgot to actually put the scirpt in “OnOpened”
  • some sort of confilt between override and hakpaks resulting in the item not existing

The first 2 are pretty obvious, the second one can be easily tested by creating the same item on something else, like the PC.

Also, like Aqvilinus suggested, try sending messages to yourself, so that you know what part of script is being run. For example:

void main()

object oSelf = OBJECT_SELF;
SendMessageToPC(GetFirstPC(), “The script is running…”);

object oItem = CreateItemOnObject(“hen_lin3qt001”, oSelf);

SendMessageToPC(GetFirstPC(), “But it didn’t spawn the item…”);


It’s none of those, because nothing happens when I try to give gold either as a test. If I use a standard original NWN script as found in the standard chests, that works. I dunno.

Just tested the script in NWN2 and it works fine… Wierd stuff :stuck_out_tongue:

Though I did get a compilation error after copy-pasting the script directly from the thread - the quotation marks got all wierd. I had to delete them and type in new ones to get a successful compilation.

The debugging messages I also find really important - here you can find if the script is breaking somewhere:
void main()
object oSelf = OBJECT_SELF;
object oPC2 = GetFirstPC()://this gets the first PC in the module
SendMessageToPC(oPC2, "I was opened - "+GetTag(oSelf));
// Get the creature who triggered this event.
object oPC = GetLastOpenedBy();
SendMessageToPC(oPC2, "PC who opened me "+GetName(oPC));

// Give “hen_lin3qt001” to us.
object oItem = CreateItemOnObject(“hen_lin3qt001”, oSelf);
if(oItem!=OBJECT_INVALID) SendMessageToPC(oPC2, "Success "+GetTag(oItem));
else SendMessageToPC(oPC2, “Nothing created.”);

If things are working correctly and you are playtesting by yourself you should get all of the messages.

I just had an idea - can you spawn items on the player? Or is it broken too? Cause you said these are supposed to be fruits on a bush right? How about this: instead of spawning them on placeable OnOpen you spawn them on pc OnUsed. This way you could tie the amout of fruits to something - like to the pc survival skill, or his race/class so that the “foresty” pcs get more fruits than others :stuck_out_tongue: And send them a message like “you suck at fruit collecting so you only get 1 fruit” :smiley:


When i am making similar scripts and items don’t appear on the container, 8 cases on 10 point to a problem with the item name.
Try using the item ResRef name, if it doesn’t work try using the item Tag name. I don’t remember exactly but there is a difference when creating a custom item (from the custom palette) or a standard OC item. Omnibus and Lexicon are an invaluable scripting info trove, get and use them.


Typo in the script name in the placeable’s event seems like a fairly likely culprit, too, if nothing at all happens when the placeable gets opened.

I’d suggest posting screenshots. Placeable properties, item properties, script itself, so we can see all the names of all the things involved, and see that everything’s in the right slots, and whatnot.

Create item on PC is broken too.

I’ve been cut and pasting names from the tool editor so I know the resref name is correct.

Did you try using the Tag name in place of the ResRef ?

It’s correct to use the resref. Tag will always fail unless it happens to be identical.

If you’re taking the resref from the toolset, try copying it from the preview window. For standard resources, the edit window is implicitly “edit copy”, which gives you a generated resref for a copy, not the resref of the original.

Diagnostic lines to add to the script before the final curly bracket:

object oItem = CreateItemOnObject(“hen_lin3qt001”, oSelf);

SendMessageToPC(oPC, "Script run by " + GetName(oSelf));
SendMessageToPC(oPC, “Item=” + GetName(oItem));

That will tell you if the container is running the script and creating an item.

To get the proper resref I often place a copy in the toolset and then look at the properties of that placed one. If you try to open it in the pallete, it creates a new resref instead of the one you want to see. I copy and paste into a text file I use then go into the script to paste things accordingly

Yes, that works, too.

Open Preview Window is the last icon on the right of the long toolbar at the top of the toolset. I find it’s the quickest way, especially when I need to find resrefs or tags for a whole bunch of objects.

1 Like

I have tested the code with a good resref and it works fine.

I believe your problem is the resref. While testing the script I got a resref for the test run by editing a copy of a default blueprint. lol. My script failed, Since the resref was incorrect. When editing a copy of a blueprint the toolset generates a new resref for the item, this is where I am guessing the 001 is coming from in your blueprint name, The simplest way to get the correct ResRef is to use the preview window. You can find it in the view menu. Once it is open just click on the item you want to view in the palette to get the correct resref.

just a foot note, CreateItemOnObject uses OBJECT_SELF as a default so you do not need that as a parameter. CreateItemOnObject(“ResRef”); will work just fine.