Help with spawning item script

ok so im trying to set up a system to let me test dropping certain items, identifying them, and posibly changing there name.

// Spawn Stones using Pull Chain

void main()
//where to spawn the items

object oTarget = GetObjectByTag(“StoneBarrel”);

int nStackSize = 0;

object iColdStone = GetObjectByTag(“ColdStone”);

object iFireStone = GetObjectByTag(“FireStone”);

object CreateItemOnObject(iFireStone, object oTarget, int nStackSize=1, string sNewTag="");

object CreateItemOnObject(iColdStone, object oTarget, int nStackSize=1, string sNewTag="");


This will not compile, I’m confused on how to use it exactly.
Any Help is appreciated.

Basically when i activate the chain pull, i want it to spawn those two items in the barrel

Barrels tag is StoneBarrel
Stones are ColdStone, FireStone respectively.

With CreateItemOnObject you need to use the resref rather than the tag. Also the syntax for calling CreateItemOnObject is wrong.


Yeh I literally copy paste from the lexicon and tried to fill in the blanks.
Obviously I’m using it wrong. I’ll have to get the resref for the stones and try again tmrw.
Thanks pscythe.

@heavymetal2000 always check the example at the bottom on nwnlexicon.

CreateItemOnObject is a function, not an object. You pass your data types inside that function, not declare them in the function.

Try this:

//Spawn Stones using Pull Chain

void main()
	//Where to spawn the items
	object oTarget = GetObjectByTag(“StoneBarrel”);

	//Create one item
	int nStackSize = 1;

	//Create one Cold Stone in the barrel
	CreateItemOnObject("ColdStone”, oTarget, nStackSize);

	//Create one Fire Stone in the barrel
	CreateItemOnObject("FireStone”, oTarget, nStackSize);

You can also declare those stone objects if you want to use them later on (as you did with GetObjectByTag) or you can declare the tags as strings with GetTag function.

1 Like

Thanks silentrocks, i just ended up copy/pasting from the toolset and trying to fill in the blanks as i mentioned.
makes more sense when you put it that way.

in the end i’d like to declare all the stones indiviually beforehand as there will be quite a few more in the final version.

Thanks again for the help guys!

Not sure if this was clear from other posts: When you declare the new objects, you actually need to name them and then have them equal the CreateItemOnObject
string sFireStone = GetResRef(iFireStone);
string sColdStone = GetresRef(iColdStone);
object oObject1 = CreateItemOnObject(sFirestone, oTarget);

object oObject2 = CreateItemOnObject(sColdStone, oTarget);

In restrospect, I would use CopyItem(sFireStone, oTarget); instead of the CreateItemOnObject

Perfect! Thanks for the tips and advice guys. I’m sitting back down with it now to give it another go! hopefully i can get this sorted.

Mannast, it seems CopyItem is much simple which is great. But if I’m looking to say Use one ResRef of the basic stone and then utilize the NewTag option of create item on object I’m guessing that’s not possible with that method right?

The idea being that if possible I use the base stone then apply a unique name within the game so the forge script will use the items new name and not it’s original.
If working correctly this would allow me to have multiple versions of a stone (EX: Cold Stone +1,+2, +3 etc…) while only consuming one resource.
True? Or am I dreaming haha?

CopyItem doesn’t allow changing the tag, but CopyObject does:
object oColdStone = GetObjectByTag(“ColdStone”);
object oStone01 = CopyObject(oColdStone, GetLocation(oTarget), oTarget, “New Tag”);
I actually use this a ton in my systems, especially for the crafting system I wrote.


That’s perfect, thanks mannast!
I’ll try that out too tonight.
Things are looking up.

1 Like

Can anyone give me any info on the quickest ways to identify particular variables/sub strings and then determine what to do?

Like can formulas utilize multiple variables and then process them or do you need an individual if statement for each property?

If I have 5 base stones EB, cold, fire, magic, divine
And each stone can be from +1 to as high as +10
Can you have a general script identify and store the type and +variable then apply it to the weapon? Or do I need to individually walk it through each possibly outcome?

You certainly can combine multiple variable tests into the one if statement.

Check out @Tarot_Redhand’s guides:

Boolean Algebra
Branching statements and Decision Making Basics


you’re the man psythe!
thanks for that. reading material for tonight as well as the future.

ok so i think my toolset is missing some things or corrupt? I’ve noticed lately that when looking through the toolset i can’t find functions for certain things im trying to do yet there on the Lexicon.
When i try to use them anyways i get errors because the toolset can’t identify them?

two that come to mind that i recently looked at are

any ideas? I’m on Linux so i don’t know if something broke during the transfer.

I’m going to ty grabbing the folders of my desktop and transfer them again but if anyone has seen this before feel free to lmk if theres a bug/known issue.


Your toolset is fine. There’re two “types” of functions: primary ones and those that are derived from them. You can’t modify primary functions, their prototypes can be found in the nwnscript.nss file and their definitions “buried” deep inside the game engine. But you can use them to construct your own functions that would perform more complicated tasks. And after that you can store these new functions in separate *.nss files, so called include files or external script libraries. To use these functions in your code, you just need to insert a new line at the very beginning of you code:

#include "name_of_include_file"

There’re many such “custom” functions written by the game developers, particularly the ones you are talking about.

For exmaple, if you open the page for the GetMeleeWeapon function, you’ll see the header named “Requirements” and the text under it:.
#include " x2_i0_spells "

1 Like

Be prepared for tutorial overload. Seeing as you (I’m guessing) have already grabbed half of the set of the Basics tutorials that I wrote you should really check out the other two. They’ll both help you with your scripting (I hope). There’s the really basic scripting concepts one and the one that explains about all the operators in NWScript. After those it is probably a good idea to check out the scripting FAQs (sorry but they wrote 2 of them). Finally, you should check out this thread as there’s links to a whole bunch of tutorials that you may find useful (and it’s a good idea to bookmark that thread so you can come back to it as needed).


Man the support here is fantastic! :slight_smile:
Thanks for the links and information guys! I spend a lot of time reading material so this will make for some good reads.

As for the include"…" part, I did this last night and it said that it could not locate the file I was talking about.

Could this be dur to missing resources? I’ll google it some too as linux is not the best for the toolset I’m seeing but it’s just so much nicer then running windows!

Make sure you are spelling it right. I’ve used Linux with NWN for years and have not seen anything with base game scripts being missing. You’d need to have corrupted, but only slightly or specifically corrupted, bif files or key files to just lose some of the bioware scripts.

I’ll double check tonight. Could of store it was spelled properly I’m pretty sure I even tried a copy paste right from the lexicon.

In order to get the toolset I had to manually move it as well as a few other folders on to linux go from my windows install… maybe I missed something but it doesnt seem likely if it’s working for the most part.

Meaglyn, does the script editor work well for you on linux? Mine is buggy when I actually try scripting within it so I just use a text editor then move the script into the toolset to compile it.

It works okay but does throw an error when I close it, but that seems to be code building the tree on the left panel. But I don’t use it for real scripting. Just for tweaking things while in the toolset. I do real scripting in a text editor, too. Also, there are command line compilers so you don’t need to compile in toolset either.

Maybe you are missing parts. I run the toolset via wine directly from the windows partition on my system so I’ve got all the pieces. Or from the beamdog install directory, which also will have all the pieces. Try opening one of the standard module event scripts, like the on load one or something, and recompiling that.

1 Like

So I’m only using Linux Mint atm as I’m still pretty new to the linux world and it seems to be pretty user friendly while still allowing me to utilize the terminal to get used to it.

Initially i just did the install via terminal and the Diamond DVD then grabbed the toolset.exe utils folder and a few other missing folders from a windows install I have on a USB.

It always launches with an error but as soon as I ok the error the toolset pops up.

The only real issues are texture rendering in the toolset (most textures are white/lack texture)
And the script editor itself in the toolset is out of whack. If I use backspace it will delete multiple characters then if I replace them it sometimes begins creating characters in places other then where I’m actually typing and it stretches all the typing into odd lines with varying spacing between letters/numbers… again no biggie just seems odd and makes using the toolset editor impossible for creating scripts.
It does compile them fine though.

Is there an external compiler you would reccomend?

I did see some articles on how to fix the texture issue so I will give that a try at some point.

It’s unfortunate that it’s so much work to just have a working linux version of nwn and the toolset.
The game plays flawlessly which is great.