Jump to content

Recommended Posts

Hello all,

 

So I have been working on a mission that utilizes essentially a town full of people.  From the start of the mission they'll just walk around (I gave them waypoints), but once the fighting begins, I needed them to run around (using a doMove ... command).

 

It works fine, however, there are some problems.  I am now slowly starting to optimize my mission, and having over 40 civilian units each with defined variables takes a toll on fps and performance when executing scripts.  Not to mention the hassle of dealing with so many unit icons on the editor map..

 

Is there a way to just spawn civilians randomly in a zone and have them just walk around until an event occurs causing them to just frantically run?  I tried to create a script for this (spawning them, that is), but due to my lack of time and little scripting knowledge I'm smacking into some dead ends. 

 

Here is what I have created thus far, in case any of you guys would like to look at it:

_civilianGroup = ["C_man_1","C_man_1_1_F","C_man_1_2_F","C_man_1_3_F","C_man_polo_1_F","C_man_polo_2_F","C_man_polo_3_F","C_man_polo_4_F","C_man_polo_5_F","C_man_polo_6_F","C_man_p_fugitive_F"];
_civilianSpawn = ["civspawn1"]; //civspawn1 is a marker on my map

_radius = 200;
_amount = 0;

_grp = createGroup civ;

while {_amount < 10} do {	
				sleep 3;
				_civUnit = _civilianGroup call BIS_fnc_selectRandom;
				hint format ["the civilian will be: %1",_civUnit]; //hints were just used for testing each line of code..
				
                                sleep 2;
				_markerPos = _civilianSpawn call BIS_fnc_selectRandom;
				hint format ["the marker will be: %1",_markerPos];
				
                                _civie = _civUnit createUnit [getMarkerPos _markerPos,_grp];

				_distance = [1,_radius] BIS_fnc_randomInt; // I believe this part and below are the areas that are causing problems
				_direction = [0,359] BIS_fnc_randomInt;

				_randomPos = [_civie,_distance,_direction] call BIS_fnc_relPos;
			};


Once again thanks in advance for any help you guys can bring.

 

Bonus Question:  If there are any general methods to optimize a single player mission, I'd love to know!

 

-Jake

Share this post


Link to post
Share on other sites
_civilianGroup = ["C_man_1","C_man_1_1_F","C_man_1_2_F","C_man_1_3_F","C_man_polo_1_F","C_man_polo_2_F","C_man_polo_3_F","C_man_polo_4_F","C_man_polo_5_F","C_man_polo_6_F","C_man_p_fugitive_F"];
_civilianSpawn = ["civspawn1"]; //civspawn1 is a marker on my map

_radius = param [0,200];
_amount = param [1,10];

for "_i" from 1 to _amount do
{
    _grp = createGroup civilian;
    _civUnit = _civilianGroup call BIS_fnc_selectRandom;
    _markerPos = _civilianSpawn call BIS_fnc_selectRandom;
    _civUnit createUnit [getMarkerPos _markerPos,_grp,"tempCivie = this;"];
    
    _wp1 = _grp addWaypoint [[tempCivie,random _radius,random 360] call BIS_fnc_relPos,0];
    _wp2 = _grp addWaypoint [[tempCivie,random _radius,random 360] call BIS_fnc_relPos,0];
    _wp3 = _grp addWaypoint [[tempCivie,random _radius,random 360] call BIS_fnc_relPos,0];
    _wp4 = _grp addWaypoint [[tempCivie,random _radius,random 360] call BIS_fnc_relPos,0];
    
    {
        _x setWaypointBehaviour "SAFE";
        _x setWaypointSpeed "LIMITED";
        _x setWaypointType "MOVE";
    } forEach [_wp1,_wp2,_wp3,_wp4];
    
    _wp4 setWaypointType "CYCLE";
    
    
    tempCivie = nil;
};

That's what I came up with, I believe the issue you had, was that createUnit unfortunately does not return the unit. You have to seperately define a variable for the spawned unit, in this case tempCivie. I afterwards use this variable to find the _randomPos. Last but not least I delete the tempCivie variable by assigning a nil value to it.

 

At this point I am not sure how to proceed. Do you now want to give every unit a waypoint, so they move randomly after they were spawned? I am asking, because that part is completely missing in your script.

 

I've also added the waypoint part, it seems to work. In addition you can now forward some parameters to the script so it's more versatile. If you have any questions, something you don't understand, feel free to ask.

Share this post


Link to post
Share on other sites

I've found the easiest way to do it in the past is to use BangaBob's awesome Civilian Occupation System 

https://forums.bistudio.com/topic/165747-civilian-occupation-system-cos/

 

That will spawn civilians when you get within a certain distance of a town, gives them waypoints etc so they wander around. It's pretty easy to set up and works really well

  • 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
Sign in to follow this  

×