I am using CreateObject, and it is causing me problems. It compiles fine in the toolset, but seems to crash NWN when I use it in code.
NOTE:
bazaarmerchant+doubledigitnumber is the tag of a merchant
q_bazaarmerchant is the resref of the creature that acts as a merchant for the merchant
Merchantof sets which merchant object the creature will be linked to.
CODE (on enter script for an area):
void main()
{
int iNumMerchants=7;
int a;
location lSpawn;
string sSpawn;
a=Random(2);
while(a<iNumMerchants)
{
if(a>9)
{
sSpawn="bazaarmerchant"+IntToString(a);
} else
{
sSpawn="bazaarmerchant0"+IntToString(a);
}
lSpawn=GetLocation(GetObjectByTag(sSpawn));
sSpawn="q_"+sSpawn;
CreateObject(OBJECT_TYPE_CREATURE,"q_bazaarmerchant",lSpawn,FALSE,sSpawn);
SetLocalInt(GetObjectByTag(sSpawn),"Merchantof",a);
a=a+1+Random(2);
}
}
CONDENSED CODE TO CHECK CreateObject (another OnEnter script):
void main()
{
int a=1;
location lSpawn;
string sSpawn;
sSpawn="bazaarmerchant0"+IntToString(a);
lSpawn=GetLocation(GetObjectByTag(sSpawn));
CreateObject(OBJECT_TYPE_CREATURE,"q_bazaarmerchant",lSpawn);
}
Now, am I doing something wrong, or is CreateObject just messed up?
Having issues with CreateObject
Moderator: Event DM
- Titanium Dragon
- Sage
- Posts: 2916
- Joined: Sun Apr 27, 2003 5:18 pm
- Location: Corvallis, OR (GMT - 7)
- Contact:
Having issues with CreateObject
Gilkin> ouch. how often do you roll a 20?
Cath> once every 20 rolls?
Cath> once every 20 rolls?
- Jordicus
- Team Member; Retired with Honors
- Posts: 8042
- Joined: Tue Jan 21, 2003 3:46 pm
- Location: Whitehall, PA (GMT -4)
- Contact:
from Lexicon
so the CreateObject itself triggers the OnEnter as you have it written... hope that helps..Creating a creature during the OnEnter event without first checking to see what's actually entering the area causes NWN to enter an infinite loop of creating creatures (as each creature created causes the OnEnter event to fire its attached script again). This can be avoided by testing if GetIsPC(GetEnteringObject()) is true (if its true, then create the creature(s); if its false then a creature that was created fired the event).
You see things and you say, "Why?" But I dream things that never were and say, "Why not?" George Bernard Shaw
- Titanium Dragon
- Sage
- Posts: 2916
- Joined: Sun Apr 27, 2003 5:18 pm
- Location: Corvallis, OR (GMT - 7)
- Contact: