BioWare Atari
BioWare Info BioWare Spiele Support Foren 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
Anzeigen/Verbergen

English
Deutsch
Français
Español
Italiano

Anzeigen/Verbergen

Neueste Bildschirmfotos anzeigen 

Neueste Bildschirmfotos anzeigen
Anzeigen/Verbergen

Multiplayer Games at Neverwinter Connections

Today
Schedule a Game...



Aktuelle Uhrzeit: (Zeit einstellen)
Sa, 21 November 2009 09:57

Anzeigen/Verbergen

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

Anzeigen/Verbergen

5,047,091 BioWare-Benutzer:
  62 Eingeloggt
  3 Verborgen
  228 Gäste

1535 Playing Online
  100% NWN
  100% NWN: SoU
  100% NWN: HotU

447 Registered Guilds

8,768,265 Einträge in den Foren

Neueste Themen in den Foren:
1. Stupid MAKO!! (Mass Effect 1 General Discussion (No spoilers allowed))

2. An Idea Realized and Marquee Abi... (Mass Effect 2 General Discussion (No Spoilers Allowed))

3. I've never playe... (Baldur's Gate II: SoA and ToB General Discussion)

4. Why are you developers scared to... (Mass Effect 2 General Discussion (No Spoilers Allowed))

5. hidden trail (NWN2: Builders - NWN2 Toolset)