CreateObject crashes game
Dragonfolk2000
Member Posts: 388
So to explain the situation: I have a 'fun' value that is a random number between 0 and 9. When the module is loaded for the first time this number is generated and doesn't change for that playthrough. I'm trying to make certain random events happen based on that number.
Right now I'm trying to spawn a merchant who sells scrolls. The idea is that when the PC enters the area for the first time it checks if the creature has already spawned and the fun value is the correct amount (right now I'm just looking for higher than 0). The script runs in the OnEnter for the area. As soon as the player enters the area though the game crashes (becomes non-responsive). As far as I can tell something in CreateObject is not functioning.
Where is the problem here?
Right now I'm trying to spawn a merchant who sells scrolls. The idea is that when the PC enters the area for the first time it checks if the creature has already spawned and the fun value is the correct amount (right now I'm just looking for higher than 0). The script runs in the OnEnter for the area. As soon as the player enters the area though the game crashes (becomes non-responsive). As far as I can tell something in CreateObject is not functioning.
Where is the problem here?
int nFun = GetLocalInt(GetModule(), "fun"); void main() { location lLoc = GetLocation(GetWaypointByTag("NW_WAYPOINT001")); object oNearestObject = GetNearestObjectToLocation(OBJECT_TYPE_CREATURE, lLoc); if(nFun > 1 && GetTag(oNearestObject) != "npc_scrollmer001") { int nObjectType = OBJECT_TYPE_CREATURE; string sTemplate = "npc_scrollmer001"; int bUseAppearAnimation = FALSE; CreateObject(nObjectType, sTemplate, lLoc, bUseAppearAnimation); } }
0
Comments
If it only crashes with this script, then I'd try giving your waypoint a unique tag and confirming that the tag of the scroll merchant and it's resref are both npc_scrollmer001. (Though that shouldn't be a reason for it to crash. If those were wrong it just wouldn't spawn the merchant.)
Is there something wrong with the NPC you made? What if you just place the merchant in the area in the toolset and enter the area? Does their store open when you talk to them?
Also, the script can be shortened a bit:
- It doesn't crash when it isn't in the AreaOnEnter handle.
- I gave the waypoint a unique tag and the tag and resref are correct for the scroll merchant.
- I've made a new NPC from scratch. The first one was copied from an existing character so I thought there may have been a problem with that. It still crashes on load.
Also, I'd put conditions like nFun > 1 in parentheses (nFun > 1) when using operators like && so that the order of evaluation is unambiguous.
The script is creating a merchant, who fires OnEnter, perhaps creating another merchant... ad infinitum until the module crashes or TMI kicks in.
It looks like you had it right. The on area enter seemed to have been firing for every creature that entered, including the newly spawned merchant. Now it spawns a merchant every time you enter the area but I think I can sort it out from here. In case anyone needs it here is the current state of the code (with the merchant that spawns every time someone enters the map).
Update: The 'spawn another one every time you enter' was a result of the incorrect tag in the if statement.