Okay, so the real deal here is the same as always: the only way to rest with monsters close by is if the monsters are non-hostile to the PC, which means they either have to start non-hostile, or we have to perform a faction change (or script hiding them). Right now I believe I'm script hiding them when the PC enters a safe room...
I start mine as HOSTILE and then change them to MONSTER (my own faction) when spawned, keeping track of which have changed.
I do like the idea of turning them hostile when perception fires. I had not thought of that.
It has its own difficulties that I am currently resolving ... mainly to do with PCs being invisible. It's fine of the PC is not invisible, but I like to cater for all circumstances.
Question: Do monsters in closed rooms perceive the party before the door to that room opens? Because if they do not... that solves a huge problem. Normally I spawn creatures inside rooms as non-hostile, and then I have a script on the door that flips the creature to hostile when the door is opened. But if I can handle this with a perception script on the creature, that's way better... No more having to put additional scripts on doors.
It depends on the monsters settings and ability to perceive either by sight or sound. Going by door opening (in your current situation) is the safest way to go. E.g. What would happen if an invisible PC opened the door and the monster does not perceive them?
Lots of food for thought here.
And there's more ...
One thing I can see being an issue, with the way my dungeons are setup at least, is that if a monster perceives the party and switches to hostile, he may run and attack the nearest creature of the MONSTER faction instead, right? But I believe the correct way to handle that is to make the MONSTER faction friendly to the enemy faction... So they'd be on the same team, just one would be hostile to the PC and the other faction would not. So problem solved.
As you say, you answered your own point here.
The only downside to this whole thing is that the creatures have to be spawned as non-hostile. I do that sometimes, for cut-scenes and stuff, but I'm not sure how I feel about non-hostile creatures running around the dungeon. If the user is in 3rd person mode and sees the creature in the distance as non-hostile, the player might be taken aback by the creature turning hostile. They might think, "Oh, it's a non-hostile, I can go talk to it or something". How the player interprets this is my only issue with this solution.
I am working in reverse to this logic, in that while everything does spawn HOSTILE, I change anything the party cannot see into MONSTER that does not prevent resting. I don't think I have any situations where a player could see a monster in another part of the dungeon and have that problem. Maybe redesigning your layout might help ... i.e. Don't allow players to see monsters before they should ... In my situation, by the time the party see a monster it has gone permanently HOSTILE.
I may just have to code and try it, see how it feels when the creatures switch to hostile on perception. If it plays well... no problem.
I don't think it matters too much whether you go ScriptHidden or Faction Changing method. The one thing I think you do need to consider though, is the same thing I had about TRACKING ... i.e. When the player makes their PC do TRACKING, they should be able to detect (if they have the ability) the HOSTILE creatures. Therefore, whichever method you use, you need to make sure the creatures can be detected. In my case, I switch the HOSTILE back if the player turns off TRACKING and the monsters have not yet been actually seen.
Cheers,
Lance.