Sie sind auf Seite 1von 3

Creating Objects

Intended Audience:
By David Gaider
[Printer Friendly / Syntax Highlight]
object CreateItemOnObject(string sItemTemplate, object oTarget = OBJECT_SELF, int
nStackSize = 1)
//In NWN2 it has two additional possible parameters:
object CreateItemOnObject(string sItemTemplate, object
oTarget=OBJECT_SELF, int nStackSize=1, string sNewTag="", int
bDisplayFeedback=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.) //I think this isnt the case in NWN2 (im almost
completely sure this isnt the case in NWN2). In NWN2 NPC can give an item to PC
with ActionGiveItem, and he doesnt have to have it in his inventory at all.
(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:
--------void main()
{
object oWay = GetWaypointByTag("WAYPOINT1");
location lPos = GetLocation(oWay);
vector vPos = GetPosition(oWay); //Vector is a position, - x, y, z coordinates
object oPC = GetNearestCreatureToLocation(CREATURE_TYPE_PLAYER_CHAR,
PLAYER_CHAR_IS_PC, lPos);

location lCreate = Location(GetArea(oWay), vPos, GetFacing(oPC)); //This step would


not be necessary if wizard didnt have to face nearest PC. Just location of the waypoint
would be enough. This location was probably created only because we needed facing
toward the NPC.
//Altough it would seem to me that GetFacing(oPC) would give the direction in which the
oPC is facing at that moment, and so the wizard would mirror the oPC, he would turn to
the same side of the world, and not face the oPC; - But i probably guessed wrong at this;
David Gaider probably knows what hes doing
CreateObject(OBJECT_TYPE_CREATURE, "wizard01", lCreate, TRUE);
}
--------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.

Das könnte Ihnen auch gefallen