Area crashing - AI question

I have an area that often crashes when a combat starts. The area has a lot of stuff so I’m guessing that’s the problem. However, I’d like to keep it as it is, but I was wondering…I have quite a lot of wandering NPCs that have waypoint sets and whatnot. Where the battle takes place there are no NPCs around. So I was thinking, maybe there’s some way to turn of the AI for the NPCs temporarily or just make them stop doing anything. Maybe then the area/game will have an easier time not crashing…Is there some way to do this, maybe through a script of some sort?

Iterating this through the NPCs might be helpful…


Alright, so do I put that script on all the NPCs heartbeat scripts then?

Turn all NPCs that cannot be seen (or interacted with) “ScriptHidden” (inc scripts) - and reverse this after the battle. From a gaming perspective, if the NPCs are in a place where they are not interacted with, then this will help.

Oh, that actually sounds even better. Then the NPCs won’t do anything, and that should help the area not crashing, right?
One caveat with this, but I don’t think this will ever happen, is that the PC and the party may run from the fight, having the enemies following them all the way to the village where the NPCs are and see that they are gone for the moment, but…there’s such a small chance of this happening since it’s not a boss fight or anything, that I think I’ll take my chances with this…

What exactly do you mean here? Isn’t script hidden preventing all the scripts of the NPCs from running? Or was that what you meant?

EDIT: I still wonder if turning all those, like 10-15 NPCs script hidden all at once will make the game crash…

I don’t think I would have hung around if there was a battle raging nearby. i.e. They would have made themselves scarce!

SetScriptHidden has an optional parameter to make the scripts stop too. This would be set TRUE in this case. (Although it is already TRUE by default I believe.)

If all the villagers hid while there’s a fight surely that’s even better and makes it more realistic ?

Stick in some reason why the player should go back to the fight area eg. a chest with a key from a dead baddy, open the chest, run some sort of on open thing that includes a journal so it has to be done, no more hiding villagers and village life continues.

It would be a very small loop - no issues.

EDIT: I loop all areas all objects sometimes - now that’s a loop! :wink:

MINOR SPOILERS FOR MY (PERHAPS) UPCOMING SIXTH MODULE: (still have to release 4 and 5 first, though 5 is questionable if it will ever be finished)

Ok, so this is in a small woods just outside of the village and the party is fighting a bunch of wolves.

Mmm, could do that, I guess, but…I think I’m a bit too lazy for that.

Yeah, that actually makes sense.

Alright, I’ll try it out and see what happens. Hopefully it will help diminish crashes.

1 Like

Urrgh. I just tested this and it made no difference at all it seems. The game still crashed just in the middle of the fight as usual. It crashes about 50 % of the time with this particular fight. That’s why I wanted to do something about it. :roll_eyes:

Doing the fight again, this time it didn’t crash, I checked to see if my ScriptHidden had worked, and lo and behold, EVERY single one of the NPCs where still there walking around, so my script must be terribly wrong, LOL.

Might as well show you my faulty script, I guess (can’t see what I’m doing wrong at the moment, but it is certainly something obvious like always):

(Removed my faulty script)

EDIT: Ok, this is interesting. Turns out that actually oGovernor and oSailor are script hidden but not the others, so there must be something wrong with my loop (wouldn’t be the first time). I have a bunch of villagers with tag villager1 and so on, as well as citizen1 and so on. I tried something like this before in another thread which then didn’t work either for some reason. Maybe I’ll try and see how it was solved there. I think there was some limit to how many of each tag…

EDIT2: Changed the script to something that kevL_s did recently for me in another thread. Now it worked, even though I actually found one single NPC wandering around. It didn’t crash either, so hopefully this will help with that now. The solution to scripting this is in this thread:

Did you try with GetObjectByTag instead? (assuming of course that there aren’t several villager1 and citizen1 in the module)

Yes, that was the first I tried, but that didn’t work either. See my post above how I solved it.

@Lance_Botelle (or anyone else that might be able to maybe answer this) - When turning the NPCs visible again it says in the function:

    //If bHidden is TRUE, bDisableUI can be set to FALSE or TRUE to control
    //whether or not the AI is disabled while the object is hidden.
    //If bHidden is FALSE, bDisableUI doesn't do anything.

So, if I do it like this: SetScriptHidden(oNPC,FALSE,FALSE); the last FALSE won’t do anything? But how am I to be sure that the AI is turned back on then?

EDIT: In any case, when turning the NPCs visible again with the function above, everything seems to be fine, so I’m glad this seemed to work all the way.

Use …


and then …


Ignore the parameter in this case. :slight_smile:

1 Like

If there’s a mechanic that knows when there’s a fight ( must be because music changes ) can it be used to switch off memory draining things like effects eg. torches or shadows so you can have massive fights without worrying ?

Just a thought and way beyond my understanding of how things work.

1 Like

That’s a really good question @Tsongo! I’d like to know as well.

Of course there are functions to know this.

The easiest to use is GetIsInCombat


I didn’t mean to go around setting everything to go off if there’s a fight and really don’t see how this works but can the mechanic that detects fights and switches music be used to automatically turn off unnecessary background things during fights ?


Here is a sample taken from 16 Cygni : Strike Back

The player must retrieve valuable information from the city’archives remaining unnoticed. The quest marker is carried by an uninvolved main NPC. The player must find an access badge in order to open the computer room then read the information on the computer terminal.

OnEnter Area :

// enter archives shoot warning, autosave

void main()
	object oLaurin = GetObjectByTag("laurin");
	string s = (GetGlobalInt("FR")) ? "Le plus discret d'entre nous devrait explorer" : "The stealthiest of us should explore.";
	DelayCommand(0.5f, AssignCommand(oLaurin, SpeakString(s)));

OnHeartbeat every civvie or guard in the area : mission marked as failed if spotted

// if player spotted in the archives, flag quest as failed (recurrent - archives personnel)

void main()
	object oSeverin = GetObjectByTag("severin");
	if (GetLocalInt(oSeverin, "Fail") < 1) 
		if (GetIsInCombat(OBJECT_SELF)) SetLocalInt(oSeverin, "Fail", 1);
	ExecuteScript("nw_c2_default1", OBJECT_SELF);	

OnDeath every civvie or guard in the area : double penalty

// civ/guard killed in the archives, flag quest as double failed (on death)

void main()
	object oSeverin = GetObjectByTag("severin");
	SetLocalInt(oSeverin, "Fail", 2);
	ExecuteScript("nw_c2_default7", OBJECT_SELF);

Insert the badge in the control panel to open the computer room (OnInventoryModification of the control panel)

// archives insert badge -> open computer room

void main()
	object oPanel = OBJECT_SELF;
	if (GetLocalInt(oPanel, "Open")) return; // already done
	object oItem = GetInventoryDisturbItem();
	if (!(GetTag(oItem)=="badge")) return; // not the badge
	object oDoor = GetObjectByTag("door_computer");
	SetLocked(oDoor, 0);
	AssignCommand(oDoor, ActionOpenDoor(oDoor));
	SetLocalInt(oPanel, "Open", 1);

Read Info on the computer terminal (OnUse and OnClick of the computer terminal) : Advance journal

// player has read info on CTC archives computer terminal

void main()
	object oPC = GetFirstPC();
	if (GetJournalEntry("q_benga", oPC) < 50) AddJournalQuestEntry("q_benga", 50, oPC);		

Reward granted when the player reports back :
Yeah. Not only you have been spotted but you have killed civilians …
[Bonus XP 50] Yeah. You could have been more discreet. At least you didn’t kill anyone …
[Bonus XP 300] You haven’t been spotted …

1 Like