Jump to content
Aurora152

Ai Spawn Loop Limit

Recommended Posts

Hello All,

 

I have a mission where I need a constant flow of civilians coming through an alleyway. They spawn at 2 spawn locations, follow 2 waypoints then go to a waypoint to be deleted.

However, the rate at which the civilians are spawning is faster than they are being deleted causing low FPS. I need to set a limit to the amount of units in the group.

So far I have this:

 

_civ = _civgroup createUnit [_x, getMarkerPos [selectRandom ["civspawn1", "civspawn2"]], [], 0, "NONE"];

AUR_spawn = [] spawn { 

    AUR_civ_array = 
	[
		"LOP_Tak_Civ_Man_01",
		"LOP_Tak_Civ_Man_02",
		"LOP_Tak_Civ_Man_03",
		"LOP_Tak_Civ_Man_04",
		"LOP_Tak_Civ_Man_05",
		"LOP_Tak_Civ_Man_06",
		"LOP_Tak_Civ_Man_07",
		"LOP_Tak_Civ_Man_08",
		"LOP_Tak_Civ_Man_09",
		"LOP_Tak_Civ_Man_10",
		"LOP_Tak_Civ_Man_11",
		"LOP_Tak_Civ_Man_12",
		"LOP_Tak_Civ_Man_13",
		"LOP_Tak_Civ_Man_14",
		"LOP_Tak_Civ_Man_15",
		"LOP_Tak_Civ_Man_16"
	];
	
    while {(count units group _civ) < 25} do {
        {	
            _civgroup = createGroup [civilian, true]; 
            _civ = _civgroup createUnit [_x, getMarkerPos [selectRandom ["civspawn1", "civspawn2"]], [], 0, "NONE"];
			
			_wp1 = _group addWaypoint [getmarkerpos "civwypt1", 0];  
            _wp1 setWaypointType "MOVE";  
            _wp1 setWaypointSpeed "FULL";  
            _wp1 setWaypointBehaviour "CARELESS"; 
			
			_wp2 = _civgroup addWaypoint [getmarkerpos "civwypt2", 0];  
            _wp2 setWaypointType "MOVE";  
            _wp2 setWaypointSpeed "FULL";  
            _wp2 setWaypointBehaviour "CARELESS"; 
			
			_wp3 = _civgroup addWaypoint [getmarkerpos "civwypt3", 0];  
            _wp3 setWaypointType "MOVE";  
            _wp3 setWaypointSpeed "FULL";  
            _wp3 setWaypointBehaviour "CARELESS"; 
			
            _wp4 = _civgroup addWaypoint [getmarkerpos [selectRandom ["civend1", "civend2", "civend3"]], 0];  
            _wp4 setWaypointType "MOVE";  
            _wp4 setWaypointSpeed "FULL";  
            _wp4 setWaypointBehaviour "CARELESS"; 
            _wp4 setWaypointStatements ["true", "{deleteVehicle _x} forEach units this"]; 
            sleep 0.5;
        } forEach AUR_civ_array;
        sleep 1;
    };
};

However, I am getting an undefined variable error from the _civ in

while {(count units group _civ) <25}

 

I thought that it may be because the unit hadn't actually been spawned yet, so I put the top line in but still got the same thing. 

Any suggestions?

 

TIA,

 

Aurora

 

Share this post


Link to post
Share on other sites

Managed to get rid of the undefined variable error however, now the units don't seem to be adhering to their waypoints and I don't think the loop restarts when a unit is deleted.

I have this at the moment:

civgroup = createGroup [civilian, true];
civ = civgroup createUnit ["LOP_Tak_Civ_Man_01", getMarkerPos "civspawn1", [], 0, "NONE"];

AUR_spawn = [] spawn { 

    AUR_civ_array = 
	[
		"LOP_Tak_Civ_Man_01",
		"LOP_Tak_Civ_Man_02",
		"LOP_Tak_Civ_Man_03",
		"LOP_Tak_Civ_Man_04",
		"LOP_Tak_Civ_Man_05",
		"LOP_Tak_Civ_Man_06",
		"LOP_Tak_Civ_Man_07",
		"LOP_Tak_Civ_Man_08",
		"LOP_Tak_Civ_Man_09",
		"LOP_Tak_Civ_Man_10",
		"LOP_Tak_Civ_Man_11",
		"LOP_Tak_Civ_Man_12",
		"LOP_Tak_Civ_Man_13",
		"LOP_Tak_Civ_Man_14",
		"LOP_Tak_Civ_Man_15",
		"LOP_Tak_Civ_Man_16"
	];
	
    while {(count units group civ) < 25} do {
        {	 
            civ = civgroup createUnit [_x, getMarkerPos [selectRandom ["civspawn1", "civspawn2"]], [], 0, "NONE"];
			
			_wp1 = civgroup addWaypoint [getmarkerpos "civwypt1", 0];  
            _wp1 setWaypointType "MOVE";  
            _wp1 setWaypointSpeed "FULL";  
            _wp1 setWaypointBehaviour "CARELESS"; 
			
			_wp2 = civgroup addWaypoint [getmarkerpos "civwypt2", 0];  
            _wp2 setWaypointType "MOVE";  
            _wp2 setWaypointSpeed "FULL";  
            _wp2 setWaypointBehaviour "CARELESS"; 
			
			_wp3 = civgroup addWaypoint [getmarkerpos "civwypt3", 0];  
            _wp3 setWaypointType "MOVE";  
            _wp3 setWaypointSpeed "FULL";  
            _wp3 setWaypointBehaviour "CARELESS"; 
			
            _wp4 = civgroup addWaypoint [getmarkerpos [selectRandom ["civend1", "civend2", "civend3"]], 0];  
            _wp4 setWaypointType "MOVE";  
            _wp4 setWaypointSpeed "FULL";  
            _wp4 setWaypointBehaviour "CARELESS"; 
            _wp4 setWaypointStatements ["true", "{deleteVehicle _x} forEach units this"]; 
            sleep 0.5;
        } forEach AUR_civ_array;
        sleep 1;
    };
};

 

Share this post


Link to post
Share on other sites

 

...

Try this

Edited by Rimsiakas
Deleted, because didn't work

Share this post


Link to post
Share on other sites

@Rimsiakas Unfortunately, that hasn't worked. It does seem like respects the limit and it doesn't restart the loop once one unit has been deleted. 

Share this post


Link to post
Share on other sites
AUR_civ_counter = 0;
AUR_spawn = [] spawn {
     _civilianTypes = [
        "LOP_Tak_Civ_Man_01",
        "LOP_Tak_Civ_Man_02",
        "LOP_Tak_Civ_Man_03",
        "LOP_Tak_Civ_Man_04",
        "LOP_Tak_Civ_Man_05",
        "LOP_Tak_Civ_Man_06",
        "LOP_Tak_Civ_Man_07",
        "LOP_Tak_Civ_Man_08",
        "LOP_Tak_Civ_Man_09",
        "LOP_Tak_Civ_Man_10",
        "LOP_Tak_Civ_Man_11",
        "LOP_Tak_Civ_Man_12",
        "LOP_Tak_Civ_Man_13",
        "LOP_Tak_Civ_Man_14",
        "LOP_Tak_Civ_Man_15",
        "LOP_Tak_Civ_Man_16"
    ];

    while {true} do {
        {
            waitUntil {AUR_civ_counter < 25};

            _civgroup = createGroup [civilian, true];
            _civ = _civgroup createUnit [_x, getMarkerPos [selectRandom ["civspawn1", "civspawn2"]], [], 0, "NONE"];
            AUR_civ_counter = AUR_civ_counter + 1;

            _wp1 = _civgroup addWaypoint [getmarkerpos "civwypt1", 0];
            _wp1 setWaypointType "MOVE";
            _wp1 setWaypointSpeed "FULL";
            _wp1 setWaypointBehaviour "CARELESS";

            _wp2 = _civgroup addWaypoint [getmarkerpos "civwypt2", 0];
            _wp2 setWaypointType "MOVE";
            _wp2 setWaypointSpeed "FULL";
            _wp2 setWaypointBehaviour "CARELESS";

            _wp3 = _civgroup addWaypoint [getmarkerpos "civwypt3", 0];
            _wp3 setWaypointType "MOVE";
            _wp3 setWaypointSpeed "FULL";
            _wp3 setWaypointBehaviour "CARELESS";

            _wp4 = _civgroup addWaypoint [getmarkerpos [selectRandom ["civend1", "civend2", "civend3"]], 0];
            _wp4 setWaypointType "MOVE";
            _wp4 setWaypointSpeed "FULL";
            _wp4 setWaypointBehaviour "CARELESS";
            _wp4 setWaypointStatements ["true", "{deleteVehicle _x; AUR_civ_counter = AUR_civ_counter - 1;} forEach units this"];
            sleep 0.5;
        } forEach _civilianTypes;
    };
};

Tried this one myself, seems to work.

  • Like 1

Share this post


Link to post
Share on other sites
13 hours ago, Rimsiakas said:

AUR_civ_counter = 0;
AUR_spawn = [] spawn {
     _civilianTypes = [
        "LOP_Tak_Civ_Man_01",
        "LOP_Tak_Civ_Man_02",
        "LOP_Tak_Civ_Man_03",
        "LOP_Tak_Civ_Man_04",
        "LOP_Tak_Civ_Man_05",
        "LOP_Tak_Civ_Man_06",
        "LOP_Tak_Civ_Man_07",
        "LOP_Tak_Civ_Man_08",
        "LOP_Tak_Civ_Man_09",
        "LOP_Tak_Civ_Man_10",
        "LOP_Tak_Civ_Man_11",
        "LOP_Tak_Civ_Man_12",
        "LOP_Tak_Civ_Man_13",
        "LOP_Tak_Civ_Man_14",
        "LOP_Tak_Civ_Man_15",
        "LOP_Tak_Civ_Man_16"
    ];

    while {true} do {
        {
            waitUntil {AUR_civ_counter < 25};

            _civgroup = createGroup [civilian, true];
            _civ = _civgroup createUnit [_x, getMarkerPos [selectRandom ["civspawn1", "civspawn2"]], [], 0, "NONE"];
            AUR_civ_counter = AUR_civ_counter + 1;

            _wp1 = _civgroup addWaypoint [getmarkerpos "civwypt1", 0];
            _wp1 setWaypointType "MOVE";
            _wp1 setWaypointSpeed "FULL";
            _wp1 setWaypointBehaviour "CARELESS";

            _wp2 = _civgroup addWaypoint [getmarkerpos "civwypt2", 0];
            _wp2 setWaypointType "MOVE";
            _wp2 setWaypointSpeed "FULL";
            _wp2 setWaypointBehaviour "CARELESS";

            _wp3 = _civgroup addWaypoint [getmarkerpos "civwypt3", 0];
            _wp3 setWaypointType "MOVE";
            _wp3 setWaypointSpeed "FULL";
            _wp3 setWaypointBehaviour "CARELESS";

            _wp4 = _civgroup addWaypoint [getmarkerpos [selectRandom ["civend1", "civend2", "civend3"]], 0];
            _wp4 setWaypointType "MOVE";
            _wp4 setWaypointSpeed "FULL";
            _wp4 setWaypointBehaviour "CARELESS";
            _wp4 setWaypointStatements ["true", "{deleteVehicle _x; AUR_civ_counter = AUR_civ_counter - 1;} forEach units this"];
            sleep 0.5;
        } forEach _civilianTypes;
    };
};

Tried this one myself, seems to work.

@Rimsiakas That appears to have worked perfectly. Thank you!

  • Like 1

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

×