Jump to content
thursday_0451

Attempting to make ambient civillian AI occasionally sit on benches and chairs

Recommended Posts

Hello! I am a total noob to Arma 3 scripting, but have experience programming in javascript, python, lua, etc as both a hobbyist and a professional.

 

I'm attempting to make my own game mode where one of the features will be ambient civillian AI will populate Tanoa to add a sense of life to the game.

 

I want to be able to have the civillian AI interact with as many objects as possible, but for starters, it would be nice if I could get them to sit in benches and chairs.

 

So, two real questions:

 

1) Is it possible via sqf scripting to tell an AI civillian to sit in a chair or bench?

 

2) What function would I use to say, make an array of all nearby sittable chairs and benches? I have tried nearObjects and nearestObjects and allSimpleObjects, but none of them return anything like benches or chairs. I am either unaware of how to use the syntax properly ("EMPTY" doesn't work "empty" doesn't work) or there is maybe another function I haven't found yet? I was succesful in using nearestTerrainObjects to return all buildings and some other objects and classify them for the purpose of spawning appropriately clothed civillians according to building type, but I cannot figure out how to reference... would you call them props?... such as benches and chairs.

 

Any help would be appreciated. If someone has already made a script that does something like this, I could probably reverse engineer it / use the same method they did.

Edited by thursday_0451

Share this post


Link to post
Share on other sites

Hey, welcome to the forums. Just a little help from my part:

Quote

hint str (nearestObjects [player, [], 5]);

 

nearestObjects returns me a bench from world objects:

Quote

[60615: bench_01_f.p3d]

 

ACE3 has a whole system for sitting but it's player only:

fnc_sit.sqf

sitting.md

sitting-framework.md

Edited by RCA3
  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the help RCA3! I was overloading nearestObjects with too many arguments, apparently. I had two false on the end after the distance, got rid of both of those and it works... but...

 

It grabs literally every object if you leave the category array empty. Is there a way to grab only benches and things like that, without grabbing things that nearestTerrainObjects grabs? I've already sorted through all the buildings, calling every object again is redundant, and I think there are so many trees that its overloading something, as attempting to make an array of object and making a map marker for them is taking over an hour for my computer to do.

 

I thought that nearestObjects [player, ["EMPTY"], 100]; is supposed to work... but it just grabs nothing.

  • Like 1

Share this post


Link to post
Share on other sites

Adapted from @killzone_kid note at nearestObjects:
 

Quote

private _benchs = [];

private _chairs = [];
{
    if (str _x find ": bench_" > -1) then {
        _benchs pushBack _x; //you can use _benchs pushBack (getPos _x) here for positions.
    };

    if (str _x find ": chair" > -1) then {
        _chairs pushBack _x; //you can use _chairs pushBack (getPos _x) here for positions.
    };
} forEach nearestObjects [player, [], 100];

hint str [_benchs, _chairs];

 

 

  • Like 1

Share this post


Link to post
Share on other sites
Quote
Quote

    for [{_i = 0}, {_i < 10}, {_i = _i + 1}] do

    {

        {

            if (

                (str _x find "bench" > -1)

            ) then {

                _allSittable pushBack _x; //you can use _benchs pushBack (getPos _x) here for positions.

            };

        } forEach nearestObjects [[worldSize / 2, worldsize / 2, 0], [], worldsize*2];

    };

 

    {

        if (_debugObjects) then {

            [str _x, getPos _x, "mil_triangle", "ColorPink", str ((getModelInfo _x) select 0)] call SetDebugMarkerAllClients;

        };

    } forEach _allSittable;

 

In case anyone else is trying to do the same thing I'm doing, this is what ended up working for me. I had to put the whole thing in a for loop because for some reason it wouldn't grab everything with just one pass.

Share this post


Link to post
Share on other sites
4 hours ago, thursday_0451 said:

for [{_i = 0}, {_i < 10}, {_i = _i + 1}] do

I don't see any sense in calling nearestObjects on the whole terrain 10 times in rapid succession....

 

private _allSittable  = (nearestObjects [[worldSize / 2, worldsize / 2, 0], [], worldsize*2]) select {"bench" in str _x};

Better, but still pretty terrible.

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×