How do you check if an object is in a certain room with using a script?

I need a character in the game to be in room 1 and the player to be in room 2 for an event to happen in the game.
If I use the 'After entering the room' script for room 1 then how do I check if the character (object) is in room 1?


A few ways to do it. In this case, either will probably work; but it's good to know the difference

if (npc.parent = room1) {

This tests if the room is the direct parent of the NPC; they are directly in the room. So this will be true if the NPC is in the room, but not if they're in a box in the room.


if (Contains (room1, npc)) {
This finds both objects inside the room, and objects inside an object in the room, and objects in an object in the room. It will also be true if the player is in the room and the npc is in their inventory. (This probably won't be a case you care about for an NPC, but for other objects it might be.
if (ListContains (ScopeVisibleForRoom (room1), npc)) {
This basically tests "If the player were in that room, could they see the NPC?" - if the NPC is in a container in the room, it checks if the box is open or transparent. It will be false if the NPC themself is invisible, and will be false if the room was dark the last time the player was there and the NPC isn't a light source. (Note - Quest's core darkness library only updates a room's light/dark status when the player is there; so if the player walks out of a room taking the torch with them, the room will continue to be lit until they return)

An NPC in the player's inventory would be counted as in the room only if the player is actually there.


if (ListContains (ScopeReachableForRoom (room1), npc)) {
As above, but excluding if the npc is in a transparent-but-closed cage. "If the player were in that room, could they touch the NPC?"
if (ListContains (ScopeVisibleNotHeldForRoom (room1), npc)) {
and
if (ListContains (ScopeReachableNotHeldForRoom (room1), npc)) {
As above, but excluding objects in the player's inventory.

Thanks mrangel.

if (Contains (room1, npc)) { was what I was looking for. The other commands will be useful to know if I need to use them.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums