Jump to content
Cigs4

Make ai move and return

Recommended Posts

Hello,

I need help please.
I'm trying to move some civilians from their positions to the same location and then return them to their original positions. They are all in different positions at the start.
I know how to make them go to the first position, but I have no idea how to get them back to their original position.
It's for a dedicated server.
Any help would be greatly appreciated.
 

Share this post


Link to post
Share on other sites

Maybe you could add any simple object at their starting positions, like a crate let's say, even making it invisible ( _this hideObjectGlobal true; ), and give each one of them a variable name.

So when you activate a trigger or whatever which commands civilians to walk towards original position, you could use the same method you are using for the initial move, but adding something like "GetPos _crate1" from the specific objects at the positions you want them to move.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks, JCataclisma. I'll try that. 

Share this post


Link to post
Share on other sites

Instead of relying on placed objects you could also have the unit remember where it came from by using setVariable/getVariable appropriately.

 

Example: Coming to a browser near you later this evening!

// Before doing the move
_unit setVariable ["spot", getPos _unit];

// Do your move here...

// When you want them to return
private _position = _unit getVariable "spot";

// Make your unit move to _position

 

  • Like 3

Share this post


Link to post
Share on other sites

Thank you guys!

I got help from Charlie at SML Scripting & Moding and Prisoner and LeonZ at Arma 3 Scripting & Goodies. Prisoner is the author of the script I'm going to share here, in case anyone else needs something similar.
 

0 = []spawn { 
    private _civs = units civilian; 
    private _newPos = getPosATL newpos; 
    {
        private _unit = _x; 
        private _oldPosition = getPosATL _unit; 
        _unit setVariable ["TAG_oldPosition",_oldPosition];
        _unit forceWalk true;
        _unit commandMove _newPos; 
    } forEach _civs; 

    sleep 20; 
 
    { 
        private _unit = _x; 
        private _orginalPosition = _unit getVariable "TAG_oldPosition"; 
        _unit forceWalk true; 
        _unit commandMove _orginalPosition; 
    } forEach _civs;
};



Thanks again! This community is awesome.
Cheers!

  • Like 1

Share this post


Link to post
Share on other sites
{
  _x spawn {
    params ["_unit","_oldpos"];
    _oldpos = getpos _unit;
    _unit doMove newpos;
    waitUntil {sleep 1; unitready _unit};
    _unit domove _oldPos;
  };
} forEach units civilian;

or, sticking to your code:

{
  _x spawn {
    params ["_unit","_oldpos"];
    _oldpos = getpos _unit;
    _unit doMove newpos;
    sleep 20;
    _unit domove _oldPos;
  };
} forEach units civilian;

 

  • Like 3

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

×