Sitting and nCount

Is there a way to know if a chair is currently occupied then to move on to the next one if not, until an open chair is found? Such as setting up a while loop for GetIsObjectValid?

Without having tested it - I think the distance of the nearest creature to the chair in use should be nil, or at least < 0.1 (with the creature being valid), because the creature should be getting jumped right on top of the position of the chair placeable. Plus, there’s GetCurrentAction(), to check whether they’re sitting.

What’s the situation? Do you have a large amount of people to sit down in one go for a cutscene or for area setup, or is it a recurring thing, like citypeople randomly sitting down on benches while passing by them?

In the first case, you could cycle through all the NPCs once, assigning them the closest free chair, storing the NPC on the chair as a local object (this is how we know that the chair isn’t free, and it lets us retrieve the NPC for any given chair), and the chair on the occupant as a local object too, so they can be prompted to return to their seat as needed, or so you can do a distance check to the chair + a current action check as well to see whether that chair’s occupant is currently in their seat.

If it’s the latter, I think I’d try to do the distance check, see if that works. If you want people to randomly sit down for some time and get up again, you’d need to store an integer on the chair and remove it again when they get up, so maybe a pseudoheartbeat that handles all the NPC AI actions should check what their current action is and clean the variables on them and on their chair if they’re no longer sitting.

:thinking:

    int i = 1;
    object oChair = GetNearestObjectByTag("CHAIR", oSourceObject, i);
    while (GetLocalObject(oChair, "OCCUPANT") != OBJECT_INVALID)
        {
        oChair = GetNearestObjectByTag("CHAIR", oSourceObject, ++i);
        }

The local integer method - set when someone sits and cleared when they stand up - is reliable when used with GetNearestObjectByTag.

1 Like

The situation is there are 5 NPCs around a round table in a tavern. All stools have the same tag, all 5 NPCs have the same tag, all 5 NPCs are running the same HB script. During the day they just sit, which is easy with a simple sit on chair command with the tag because their initial state is being closest to the nearest chair with said tag. At night they have a set of random actions which gets them out of their chair. When it becomes day again, usually 3 out of 5 sit back down but 2 can’t seem to find an empty chair again. I tried assigning GetSittingCreature to a variable which might be a good check but couldn’t get a loop to work right. I could assign each NPC to a uniquely tagged stool, give them each a unique script but thought that was a little silly.

In your example, what is oSourceObject? Is that the tag of the NPC? What is “OCCUPANT”?

If they’re all reliably sitting in their closest chair at spawn, you could just store that chair on them as a local object, and make them sit in that stored local object chair again from then on.

    object oChair = GetLocalObject(OBJECT_SELF, "CHAIR");

    if (oChair == OBJECT_INVALID)
        {
        oChair = GetNearestObjectByTag("CHAIR");
        SetLocalObject(OBJECT_SELF, "CHAIR", oChair);
        }

    ActionSit(oChair);

In my example, oSourceObject is a hypothetical source object from whose position the “GetNearest” check is done. “OCCUPANT” is the name of the string under which the local object is stored on the chair.

PERFECT! I knew it had to be something easy. Thanks! There is a huge contrast in the tavern between day and night.

Day: Everyone but the waitress just sits. Bartender just stands.

Night: 2 guys at the bar stand do random actions. Every time one says “MORE WINE” that sound plays, the man walks up to the bar, the BT walks to the liquor cabinet opposite the man, gets mid for a few secs, then walks back toward the guy, gets mid for a few secs. Same thing happens with the other guy at the bar who yells, “I NEED MORE ALE!” They have that BT moving back and forth constantly. Meanwhile 2 guys in the corner do random actions like drink or threaten each other with their voice chat. Once in awhile they take a swing at each other. Each time they do, the 5 guys standing around the table nearby quit their random actions and animate cheer and voice chat cheer while a clap sound is played. It’s hilarious!

1 Like

How about GetSittingCreature(object oChair)?

1 Like