BioWare Atari
BioWare Info BioWare Games Support Forums Visit the BioWare Store
Neverwinter Nights Home
Neverwinter Nights Home

Creating Objects

Intended Audience: For Builders
By David Gaider

[Printer Friendly / Syntax Highlight]

object CreateItemOnObject(string sItemTemplate, object oTarget = OBJECT_SELF, int nStackSize = 1)

This creates an item (with the tag of the 'sItemTemplate') in the oTarget object's inventory. We use this often when items are 'given' to a PC... or if, say, an NPC is supposed to have an object on them only at certain times.

If I'm in dialogue and the NPC rewards the PC he's talking to with a regular longsword, I would put a script with this line in the 'Actions Taken' section:

CreateItemOnObject ("NW_WSWLS001", GetPCSpeaker());

If I want to put 12 regular arrows into a chest that has the tag "CHEST05":

CreateItemOnObject ("NW_WAMAR001", GetObjectByTag ("CHEST05"), 12);

(NOTE: If you use ActionGiveItem to have an NPC give an inventory item to the PC, that item must actually exist in the NPC's inventory in order for the action to complete. ActionGiveItem will transfer the item to the PC's inventory... CreateItemOnObject creates an entirely new one there.)

(2nd NOTE: I mention that the sItemTemplate used in the command is the item's 'tag'... this is true ONLY for the standard items that come with the game. Sorry, my bad: this is all I'm used to using with this command. If you are trying to use the command with custom items, you must use the blueprint resref for the item... not the tag.)


The 'CreateObject' command is a little bit different. It actually creates the object on the map... this is often referred to as 'spawning'. The object could be a creature or an item. It's structure is as follows:

object CreateObject (int nObjectType, string sTemplate, location lLoc, int bUseAppearAnimation = FALSE)

The 'nObjectType' is a constant that defines what class of object is being created. OBJECT_TYPE_CREATURE, for example, or OBJECT_TYPE_ITEM. This comes from the list of Constants in your script editor.

The 'sTemplate' string is its 'blueprint resref'. Yes, I know... almost every other command uses an object's tag. This one refers to the resref, usually found under the Advanced tab of the object.

NOTE: The above is a very common misconception! If you use a tag instead of a resref, it will not work!

The location consists of an area, an xyz map co-ordinate (which, itself, is known as a 'vector') and a facing. It is easiest to use a GetLocation(object oObject) command to get all this information from a waypoint or another object (if you use an object such as a creature, then the spawn will occur in the nearest 'valid' location to it). If need be, you can also construct a location using Location(object oArea, vector vPosition, float fOrientation)... though that, quite frankly, is often easily avoided.

The default, obviously, is for the standard appearance animation to not be used... you can opt to use it by specifying TRUE for 'bUseAppearAnimation'.

So... to create a bugbear at an already-laid waypoint that has the tag "WAYPOINT1"...

location spawn1 = GetLocation (GetWaypointByTag ("WAYPOINT1"));
CreateObject (OBJECT_TYPE_CREATURE, "NW_BUGBEARA", spawn1);

To spawn in a wizard (with the tag "wizard01") with the creation effect, facing the nearest PC...

NWScript:

ONE LAST THING ABOUT TAGS: Remember that they are case-sensitive! If the tag reads on your creature "wizard01" don't refer to it in your scripts as "WIZARD01" or "Wizard01"... it will not acquire the creature object properly and you will get a badger spawned in. Why a badger? This was simply the 'default summon' used during testing in case an invalid object was referenced for a spawn.

 

 

BioWare Store
Neverwinter Nights 2 Forums
Hide/Show

English
Deutsch
Français
Español
Italiano

Hide/Show

View Latest Screenshots 

View Latest Screenshots
Hide/Show

Multiplayer Games at Neverwinter Connections

Today
Schedule a Game...



Current time is: (set time)
Sun, 08 November 2009 03:47AM

Hide/Show

Buy Premium Modules

Top NWN: HotU Modules:
1. Good vs Evil III
2. More...

Top NWN: SoU Modules:
1. Good vs Evil III
2. More...

Top CEP Modules:
1. The Lord of Terror The Diablo Campa...
2. More...

Top Modules - NWVault:
1. Hall of Fame
2. More...

Total Modules: 4423

Hide/Show

4,828,578 BioWare Users:
  162 Logged In
  9 Hidden
  1165 Guests

1271 Playing Online
  100% NWN
  100% NWN: SoU
  99% NWN: HotU

446 Registered Guilds

8,715,400 posts in forums

Newest Forum Topics:
1. Strength Cheat? (Dragon Age: Origins General Discussion)

2. I found Kreia! (Dragon Age: Origins General Discussion)

3. Lost in Dreams (Dragon Age: Origins Story and Plot (Spoilers) Forum)

4. 4Aces/KMA - Needs Texture Defs +... (Dragon Age Toolset Forum)

5. How do I make a key ring? (NWN2: Builders - NWN2 Scripting)