BioWare Atari
Information de BioWare Jeux BioWare Assistance 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 Blog
Neverwinter Nights 2 Forums
Cacher/Afficher

English
Deutsch
Français
Español
Italiano

Cacher/Afficher

Voir les dernières captures d'écran 

Voir les dernières captures d'écran
Cacher/Afficher

Multiplayer Games at Neverwinter Connections

Today
Schedule a Game...



Il est actuellement: (régler heure)
dim, 22 novembre 2009 04:00

Cacher/Afficher

Download 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

Cacher/Afficher

5,050,433 utilisateurs sur le site de BioWare:
  57 connectés
  3 invisibles
  203 invités

1239 Playing Online
  100% NWN
  101% NWN: SoU
  101% NWN: HotU

447 Registered Guilds

8,768,639 messages dans les forums

Sujets les plus récents dans les forums:
1. Drowned Dead Test (NWN2: Players - Storm of Zehir (Spoilers Warning))

2. 2 newb problems: Lever puzzle, a... (NWN2: Builders - NWN2 Scripting)

3. Vorcha + Krogans o_0 (Mass Effect 2 General Discussion (No Spoilers Allowed))

4. Video games? (NWN 1: General Discussion (No Spoilers Allowed))

5. How to Change the Death Message (NWN 1: Toolset)