Announcement

Collapse
No announcement yet.

Sector Control + Passive AI Command Script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [GUIDE] Sector Control + Passive AI Command Script

    I have two posts here, one being a script that allows for capturing of points in sort of a conquest sort of mode, and one is the script that controls AI behavior for those points. I will post the full scripts and then go over each part to explain how to implement them.

    SECTOR CONTROL
    any questions please quote section and clearly state your question.

    heres the script I used:
    Code:
    _number = 0;
    capture = 1;
    while {(capture) == 1} do {
    _number1 = count markers;
    _number = _number + 1;
    red_fuel = red_fuel + 0.12;
    red_mp = red_mp + 6;
    sleep 2;
    blue_fuel = blue_fuel + 0.12;
    blue_mp = blue_mp + 6;
    
    
    while {_number1 >= 0} do
    	{
    _number1 = _number1 - 1;
    _marker = markers select _number1;
    _veh = nearestObject [getmarkerpos _marker,"FlagPole_EP1"];
    _side1 = _veh getvariable "side";
    _control1 = _veh getvariable "control";
    _in1 = _veh getvariable "in";
    _rsc1 = _veh getvariable "resource";
    
    _objs = nearestObjects [getmarkerpos _marker,["land"], 50];
    if ((count _objs)==0) then {_veh setvariable ["in","none"]};
    if ((count (_objs))>0) then
    	{
    	
    	{
    if ((count (crew _x))>0) then 
    	{	
    if ((side _x)==west) then 
    	{
    	_veh setvariable ["in","west"];
    	};
    if (((side _x)==east)&&((_in1)=="west")) then 
    	{
    	_veh setvariable ["in","none"];
    	};
    if ((side _x)==east) then 
    	{
    	_veh setvariable ["in","east"];
    	};
    if (((side _x)==west)&&((_in1)=="east")) then
    	{
    	_veh setvariable ["in","none"];
    	};
    	};
    } foreach _objs;
    };
    
    
    if (((_control1)<=10)&&((_control1)>= -10)) then 
    	{
    //&&(((_side1)=="none")||((_side1)=="east"))&&((_in1)=="west")
    	
    	if ((((_control1)<10))&&(((_side1)=="none")||((_side1)=="east"))&&((_in1)=="west")) then 
    		{
    		_control1 = _control1 + 1;
    		_veh setvariable ["control",_control1];
    		};
    
    	if ((((_control1)>-10))&&(((_side1)=="none")||((_side1)=="west"))&&((_in1)=="east")) then 
    		{
    		_control1 = _control1 - 1;
    		_veh setvariable ["control",_control1];
    		};
    
    	if (((_control1)>=10)&&((_side1)=="none")&&((_in1)=="west")) then
    		{
    			_veh setvariable ["side","west"];
    			_veh setvariable ["e_attack","false"];
    			_marker setmarkercolor "colorblue";
    			(_marker + "_a") setmarkercolor "colorblue";
    		};
    
    	if (((_control1)<=-10)&&((_side1)=="none")&&((_in1)=="east")) then
    		{
    			_veh setvariable ["side","east"];
    			_veh setvariable ["w_attack","false"];
    			_marker setmarkercolor "colorred";
    			(_marker + "_a") setmarkercolor "colorred";
    		};
    		
    	if (_control1==0) then
    		{
    		_veh setvariable ["side","none"];
    		_marker setmarkercolor "colorblack";
    		(_marker + "_a") setmarkercolor "colorblack";
    		};
    			
    
    };
    {
    _side1 = _veh getvariable "side";
    _rsc1 = _veh getvariable "resource";
    switch (_side1) do
    {
    case "west":
    	{
    
    	switch (_rsc1) do
    	{
    	case "ammo":{blue_ammo = blue_ammo + 0.12; publicvariable "blue_ammo";};
    	case "fuel":{blue_fuel = blue_fuel + 0.12; publicvariable "blue_fuel";};
    	case "mp":{blue_mp = blue_mp + 1; publicvariable "blue_mp";};
    	};
    	};
    case "east":
    	{
    
    	switch (_rsc1) do
    	{
    	case "ammo":{red_ammo = red_ammo + 0.12; publicvariable "red_ammo";};
    	case "fuel":{red_fuel = red_fuel + 0.12; publicvariable "red_fuel";};
    	case "mp" :{red_mp = red_mp + 1; publicvariable "red_mp";};
    	};
    	};
    case "none": {};
    };
    
    } foreach markers;
    
    
    
    };
    };
    now this may seem complicated to some of you so I will break it down and explain the bread and butter of this script.

    take this block for example:
    Code:
    _marker = markers select _number1;
    _veh = nearestObject [getmarkerpos _marker,"FlagPole_EP1"];
    _side1 = _veh getvariable "side";
    _control1 = _veh getvariable "control";
    _in1 = _veh getvariable "in";
    _rsc1 = _veh getvariable "resource";

    this block is the main controller for the whole script. it grabs all the variables for its loop and acts on them based on the variables set to the flagpole _veh.
    it runs on a large loop, going through each index of an array of markers that are your sector points, (the array is set in the init).

    in this instance I found using nearestObjects, getVariable and setVariable was the best way to get unit counts inside of the sector areas.
    getVariable
    setVariable
    nearestObjects

    after the current variables for the flagpole are extracted (which are:
    _side1: the current side that is in control of that sector.
    _control1: I use a counter to decide how much longer it will take to capture the sector (like the progress bar in battlefield for example). it goes from -10 to 10.
    _in1: the current faction capturing the sector. this is decides with LOTS of if-then statements.
    _rsc1: the type of resource granted to the controlling faction.)

    I use several blocks of code to change these based on the units inside and current control counter.

    lets take this block for example:

    Code:
    _objs = nearestObjects [getmarkerpos _marker,["land"], 50];
    if ((count _objs)==0) then {_veh setvariable ["in","none"]};
    if ((count (_objs))>0) then
    	{
    	
    	{
    if ((count (crew _x))>0) then 
    	{	
    if ((side _x)==west) then 
    	{
    	_veh setvariable ["in","west"];
    	};
    if (((side _x)==east)&&((_in1)=="west")) then 
    	{
    	_veh setvariable ["in","none"];
    	};
    if ((side _x)==east) then 
    	{
    	_veh setvariable ["in","east"];
    	};
    if (((side _x)==west)&&((_in1)=="east")) then
    	{
    	_veh setvariable ["in","none"];
    	};
    	};
    } foreach _objs;
    };
    this block, at the start of the loop goes through each unit which is 50 meters or less from the flagpole and sets the variable _in1 to their side. if _in1 is equal to the opposing faction (id est "east" for west and vice versa) then it resets it to "none".

    this next block is responsible for adding or subtracting from the control counter (once every loop if a side controls it). it goes up one if _in1 is "west", and down one if _in1 is "east", stopping at either -10 or 10.

    Code:
    if (((_control1)<=10)&&((_control1)>= -10)) then 
    	{
    //&&(((_side1)=="none")||((_side1)=="east"))&&((_in1)=="west")
    	
    	if ((((_control1)<10))&&(((_side1)=="none")||((_side1)=="east"))&&((_in1)=="west")) then 
    		{
    		_control1 = _control1 + 1;
    		_veh setvariable ["control",_control1];
    		};
    
    	if ((((_control1)>-10))&&(((_side1)=="none")||((_side1)=="west"))&&((_in1)=="east")) then 
    		{
    		_control1 = _control1 - 1;
    		_veh setvariable ["control",_control1];
    		};
    
    	if (((_control1)>=10)&&((_side1)=="none")&&((_in1)=="west")) then
    		{
    			_veh setvariable ["side","west"];
    			_veh setvariable ["e_attack","false"];
    			_marker setmarkercolor "colorblue";
    			(_marker + "_a") setmarkercolor "colorblue";
    		};
    
    	if (((_control1)<=-10)&&((_side1)=="none")&&((_in1)=="east")) then
    		{
    			_veh setvariable ["side","east"];
    			_veh setvariable ["w_attack","false"];
    			_marker setmarkercolor "colorred";
    			(_marker + "_a") setmarkercolor "colorred";
    		};
    		
    	if (_control1==0) then
    		{
    		_veh setvariable ["side","none"];
    		_marker setmarkercolor "colorblack";
    		(_marker + "_a") setmarkercolor "colorblack";
    		};
    I also set the marker color to black (I meant to change the flag texture but i didnt get around to it).

    this last block gives out resources based on sectors that are controlled. note that _rsc1 does not change but is set in the init (not shown).

    Code:
    {
    _side1 = _veh getvariable "side";
    _rsc1 = _veh getvariable "resource";
    switch (_side1) do
    {
    case "west":
    	{
    
    	switch (_rsc1) do
    	{
    	case "ammo":{blue_ammo = blue_ammo + 0.12; publicvariable "blue_ammo";};
    	case "fuel":{blue_fuel = blue_fuel + 0.12; publicvariable "blue_fuel";};
    	case "mp":{blue_mp = blue_mp + 1; publicvariable "blue_mp";};
    	};
    	};
    case "east":
    	{
    
    	switch (_rsc1) do
    	{
    	case "ammo":{red_ammo = red_ammo + 0.12; publicvariable "red_ammo";};
    	case "fuel":{red_fuel = red_fuel + 0.12; publicvariable "red_fuel";};
    	case "mp" :{red_mp = red_mp + 1; publicvariable "red_mp";};
    	};
    	};
    case "none": {};
    };
    
    } foreach markers;
    pretty basic.

    second post incoming for AI Control
    Last edited by Yink; 01-14-2014, 01:09 AM.
    Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team


  • #2
    Re: Sector Control + Passive AI Command Script

    here is the big one.

    this script takes all non playable units on the map, assigns them to an array and assigns them assignments based on priority. priority is set by the order in which the sector markers are in the array. because of this, each factions array are usually reversed.
    this script seems long, but about 3/7ths of it is actually just a mirror. 1 section for west and 1 for east (i would of made it mirrored as a function but that takes time and effort).

    ai control script:
    Code:
    group_w = [ ];
    p_group_w = [ ];
    group_e = [ ];
    p_group_e = [ ];
    _attack_w = [ ];
    _defend_w = [ ];
    _idle_w = [ ];
    _attack_e = [ ];
    _defend_e = [ ];
    _idle_e = [ ];
    _needs_w = ["mp","fuel","ammo","defense","offense"];
    _needs_e = ["mp","fuel","ammo","defense","offense"];
    _build_w = ["infantry","armor","indirect"];
    _build_e = ["infantry","armor","indirect"];
    _order_w = 0;
    _order_e = 0;
    
    _list_w = ["cp1_0","ap1_0","ap1_2","fp1_1","fp1_3","cp1_2","ap1_1","fp1_2","cp1_1"];
    _list_e = ["cp1_1","fp1_2","ap1_1","cp1_2","fp1_3","fp1_1","ap1_2","ap1_0","cp1_0"];
    //start group allocation
    
    while {boolean1} do
     {
    	
    	{
    		if ((!(_x in group_w))&&((side _x)==west)&&((_x getvariable "assign")!="player")) then
    			{
    			_x setvariable ["assign","none"];
    			group_w = group_w + [_x];
    			};
    		
    		if ((!(_x in group_e))&&((side _x)==east)&&((_x getvariable "assign")!="player")) then
    			{
    			_x setvariable ["assign","none"];
    			group_e = group_e + [_x];
    			};
    		publicvariable "group_w";
    		publicvariable "group_e";
    		if ((count (units _x))==0) then
    			{
    			deletegroup _x;
    			};
    		
    	} foreach allGroups;
    	
    	{
    		if ((group _x) in group_w) then
    			{
    			group_w = group_w - [(group _x)];
    			};
    		if !((group _x) in p_group_w) then
    			{
    			p_group_w = p_group_w + [(group _x)];
    			};
    	} foreach playableunits;
    	
    	_temp_group = group_w;
    	_idle_w = group_w;
    	_current_w = _list_w select _order_w;
    	
    //end group allocation	
    		publicvariable "group_w";
    		publicvariable "group_e";
    //start counter defense priority	
    
    for [{_a=(count _list_w)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_current_w = _list_w select _a;
    	_veh = nearestObject [getmarkerpos _current_w,"FlagPole_EP1"];
    	_side1 = _veh getvariable "side";
    	_in1 = _veh getvariable "in";
    	sleep 0.25;
    	if ((_side1!="west")&&(_in1=="east")) then
    		{
    		_counter1 = (count group_w) - 1;
    		while {_bool2} do 
    			{
    				_ran1 = round(random (_counter1));
    				_c_unit = group_w select _ran1;
    				if (((_c_unit getvariable "assign")=="none")||((_c_unit getvariable "assign")=="patrol")) then
    				{
    					_counter1 = _counter1 - 1;
    					_temp_group = _temp_group - [_c_unit];
    					(units _c_unit) domove (getpos _veh);
    					_defend_w = _defend_w + [_c_unit];
    					_c_unit setbehaviour "combat";
    					_c_unit setvariable ["assign",_current_w];
    					_bool2 = false;
    				};
    			};	
    		};
    	};
    
    
    //end counter defense priority	
    
    
    //start attack section
    	
    	_task1 = true;
    	_count_w = count group_w;
    
    			_bool1 = true;
    			_counter = 0;
    	while {_counter<(count _list_w)} do
    		{
    	//select location to attack
    				_current_w = _list_w select _counter;
    				_veh = nearestObject [getmarkerpos _current_w,"FlagPole_EP1"];
    				_var1 = _veh getvariable "side";
    				if (_var1 == "west") then
    					{
    					_veh setvariable ["order","friendly"];
    					};	
    	//assign attacker		
    		if ((((_veh getvariable "side")=="east")||((_veh getvariable "side")=="none"))&&(((_veh getvariable "in")=="none")||((_veh getvariable "in")=="east"))&&((_veh getvariable "w_attack")=="false")) then
    			{
    			
    			_counter1 = _count_w - 1;
    
    		_bool1 = true;	
    	for [{_a=_count_w},{_a>=0},{_a=_a-1}] do 
    				{
    			_ran1 = round(random (_counter1));
    			_c_unit = _temp_group select _ran1;
    			if ((_c_unit getvariable "assign")=="none") then
    					{
    					sleep 0.25;
    					_veh setvariable ["w_attack","true"];
    					_counter1 = _counter1 - 1;
    					_temp_group = _temp_group - [_c_unit];
    					(units _c_unit) domove (getpos _veh);
    					_attack_w = _attack_w + [_c_unit];
    					_c_unit setFormation "STAG COLUMN";
    					_c_unit setvariable ["assign",_current_w];
    					_a = -1;
    					};
    				};
    			};
    		_counter = _counter + 1;
    		};
    //end attack section
    
    //start patrol
    if ((count group_w)>(count _list_w)) then
    {
    	for [{_a=(_count_w)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_w select _a;
    	_var1 = _c_unit getvariable "assign";
    		{
    		_pos2 = _x getvariable "assign";
    		if (_pos2 == "none") then
    			{
    			_random1 = round(random (count _list_w)) - 1;
    			_veh = nearestObject [getmarkerpos (_list_w select _random1),"FlagPole_EP1"];
    			_x setvariable ["assign","patrol"];
    			_x domove (getpos _veh);
    			};
    		} foreach group_w;
    	};
    };
    // end patrol
    
    //start reset patrol
    if ((count group_w)<(count _list_w)) then
    {
    	for [{_a=(_count_w)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_w select _a;
    	_var1 = _c_unit getvariable "assign";
    		{
    		_pos2 = _x getvariable "assign";
    		if (_pos2 == "patrol") then
    			{
    				_x setvariable ["assign","none"];
    			};
    			
    		} foreach group_w;
    	};
    };
    // end reset patrol
    
    
    //reset idle for ATTACKERS & COUNTER RESPONSE ONLY
    
    for [{_a=(_count_w)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_w select _a;
    	_var1 = _c_unit getvariable "assign";
    
    	if (_var1!="none") then {_idle_w = _idle_w - [_c_unit]};
    		{
    
    		_pos2 = _x getvariable "assign";
    		if ((_pos2 != "none")||(_pos2 != "patrol")) then
    			{
    			_veh = nearestObject [getmarkerpos _pos2,"FlagPole_EP1"];
    			if ((_veh getvariable "side")=="west") then
    				{
    				_x setvariable ["assign","none"];
    				};
    		sleep 1;
    			};
    		} foreach group_w;
    	};
    
    //end idle for ATTACKERS & COUNTER RESPONSE ONLY
    
    total_w = 0;
    //count owned
    {
    _veh = nearestObject [getmarkerpos _x,"FlagPole_EP1"];
    if ((_veh getvariable "side")=="west") then
    	{
    	total_w = total_w + 1;
    	};
    } foreach markers;
    
    
    //end count owned
    
    //start patrol section	
    
    _bool1 = true;
    _task1 = true;
    _count_w = count group_w;
    _counter = 0;
    
    {
    if (total_w == 9) then {
    _x setvariable ["assign","east_hq"];
    (units _x) domove (getmarkerpos "east_hq");
    hq_red allowdamage true;
    };
    }foreach group_w;
    
    
    
    
    
    
    
    
    
    //german start------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    	
    	_temp_group = group_e;
    	_idle_e = group_e;
    	_current_e = _list_e select _order_e;
    	
    //end group allocation	
    
    //start counter defense priority	
    
    for [{_a=(count _list_e)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_current_e = _list_e select _a;
    	_veh = nearestObject [getmarkerpos _current_e,"FlagPole_EP1"];
    	_side1 = _veh getvariable "side";
    	_in1 = _veh getvariable "in";
    	sleep 0.25;
    	if ((_side1!="east")&&(_in1=="west")) then
    		{
    		_counter1 = (count group_e) - 1;
    		while {_bool2} do 
    			{
    				_ran1 = round(random (_counter1));
    				_c_unit = group_e select _ran1;
    				if (((_c_unit getvariable "assign")=="none")||((_c_unit getvariable "assign")=="patrol")) then
    				{
    					_counter1 = _counter1 - 1;
    					_temp_group = _temp_group - [_c_unit];
    					(units _c_unit) domove (getpos _veh);
    					_defend_w = _defend_w + [_c_unit];
    					_c_unit setbehaviour "combat";
    					_c_unit setvariable ["assign",_current_e];
    					_bool2 = false;
    				};
    			};	
    		};
    	};
    
    //end counter defense priority	
    
    
    //start attack section
    	
    	_task1 = true;
    	_count_e = count group_e;
    
    			_bool1 = true;
    			_counter = 0;
    	while {_counter<(count _list_e)} do
    		{
    	//select location to attack
    				_current_e = _list_e select _counter;
    				_veh = nearestObject [getmarkerpos _current_e,"FlagPole_EP1"];
    				_var1 = _veh getvariable "side";
    				if (_var1 == "east") then
    					{
    					_veh setvariable ["order","friendly"];
    					};	
    	//assign attacker		
    		if ((((_veh getvariable "side")=="west")||((_veh getvariable "side")=="none"))&&(((_veh getvariable "in")=="none")||((_veh getvariable "in")=="west"))&&((_veh getvariable "e_attack")=="false")) then
    			{
    			
    			_counter1 = _count_e - 1;
    
    		_bool1 = true;	
    	for [{_a=_count_e},{_a>=0},{_a=_a-1}] do 
    				{
    			_ran1 = round(random (_counter1));
    			_c_unit = _temp_group select _ran1;
    			if ((_c_unit getvariable "assign")=="none") then
    					{
    					sleep 0.25;
    					_veh setvariable ["e_attack","true"];
    					_counter1 = _counter1 - 1;
    					_temp_group = _temp_group - [_c_unit];
    					(units _c_unit) domove (getpos _veh);
    					_attack_w = _attack_w + [_c_unit];
    					_c_unit setFormation "STAG COLUMN";
    					_c_unit setvariable ["assign",_current_e];
    					_a = -1;
    					};
    				};
    			};
    		_counter = _counter + 1;
    		};
    //end attack section
    
    //start patrol
    if ((count group_e)>(count _list_e)) then
    {
    	for [{_a=(_count_e)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_e select _a;
    	_var1 = _c_unit getvariable "assign";
    		{
    		_pos2 = _x getvariable "assign";
    		if (_pos2 == "none") then
    			{
    			_random1 = round(random (count _list_e)) - 1;
    			_veh = nearestObject [getmarkerpos (_list_e select _random1),"FlagPole_EP1"];
    			_x setvariable ["assign","patrol"];
    			_x domove (getpos _veh);
    			};
    		} foreach group_e;
    	};
    };
    // end patrol
    
    //start reset patrol
    if ((count group_e)<(count _list_e)) then
    {
    	for [{_a=(_count_e)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_e select _a;
    	_var1 = _c_unit getvariable "assign";
    		{
    		_pos2 = _x getvariable "assign";
    		if (_pos2 == "patrol") then
    			{
    				_x setvariable ["assign","none"];
    			};
    			
    		} foreach group_e;
    	};
    };
    // end reset patrol
    
    
    //reset idle for ATTACKERS & COUNTER RESPONSE ONLY
    
    for [{_a=(_count_e)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_e select _a;
    	_var1 = _c_unit getvariable "assign";
    
    	if (_var1!="none") then {_idle_e = _idle_e - [_c_unit]};
    		{
    
    		_pos2 = _x getvariable "assign";
    		if ((_pos2 != "none")||(_pos2 != "patrol")) then
    			{
    			_veh = nearestObject [getmarkerpos _pos2,"FlagPole_EP1"];
    			if ((_veh getvariable "side")=="east") then
    				{
    				_x setvariable ["assign","none"];
    				};
    		sleep 1;
    			};
    		} foreach group_e;
    	};
    
    //end idle for ATTACKERS & COUNTER RESPONSE ONLY
    
    total_e = 0;
    //count owned
    {
    _veh = nearestObject [getmarkerpos _x,"FlagPole_EP1"];
    if ((_veh getvariable "side")=="east") then
    	{
    	total_e = total_e + 1;
    	};
    } foreach markers;
    
    
    //end count owned
    
    //start patrol section	
    
    _bool1 = true;
    _task1 = true;
    _count_e = count group_e;
    _counter = 0;
    
    {
    if (total_e == 9) then {
    _x setvariable ["assign","east1_hq"];
    (units _x) domove (getmarkerpos "east1_hq");
    hq_red allowdamage true;
    };
    }foreach group_e;
    
    
    
    
    
    
    
    
    
    
    
    
    };
    OK, lets get started.

    this first part we will look at is the assignment block. this goes through all non playable units on the map and assigns them to an array based on their groups and faction sides.
    it first checks if the unit is in the array for the groups (group_w or group_e) and (yes spamming getVariable and setVariable is very good) the getVariable for "Assign" (its assignment, will determine what it will do) and makes sure its not assigned as a player (it shouldn't anyway, mostly a debug.)

    by the way im only going over each section once because theyre mirrored.

    heres the block:
    Code:
    while {boolean1} do
     {
    	
    	{
    		if ((!(_x in group_w))&&((side _x)==west)&&((_x getvariable "assign")!="player")) then
    			{
    			_x setvariable ["assign","none"];
    			group_w = group_w + [_x];
    			};
    		
    		if ((!(_x in group_e))&&((side _x)==east)&&((_x getvariable "assign")!="player")) then
    			{
    			_x setvariable ["assign","none"];
    			group_e = group_e + [_x];
    			};
    		publicvariable "group_w";
    		publicvariable "group_e";
    		if ((count (units _x))==0) then
    			{
    			deletegroup _x;
    			};
    		
    	} foreach allGroups;
    	
    	{
    		if ((group _x) in group_w) then
    			{
    			group_w = group_w - [(group _x)];
    			};
    		if !((group _x) in p_group_w) then
    			{
    			p_group_w = p_group_w + [(group _x)];
    			};
    	} foreach playableunits;
    the second part is another debug. it just checks if a player is in the AI array, and if so it removes him. remember this is all on a loop.

    ok moving on.
    this is the counter attack block.
    this block is very similar to the attack order block (you could probably do without it, but i think it works as a good debug). ill explain its concepts in the attack section
    Code:
    for [{_a=(count _list_w)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_current_w = _list_w select _a;
    	_veh = nearestObject [getmarkerpos _current_w,"FlagPole_EP1"];
    	_side1 = _veh getvariable "side";
    	_in1 = _veh getvariable "in";
    	sleep 0.25;
    	if ((_side1!="west")&&(_in1=="east")) then
    		{
    		_counter1 = (count group_w) - 1;
    		while {_bool2} do 
    			{
    				_ran1 = round(random (_counter1));
    				_c_unit = group_w select _ran1;
    				if (((_c_unit getvariable "assign")=="none")||((_c_unit getvariable "assign")=="patrol")) then
    				{
    					_counter1 = _counter1 - 1;
    					_temp_group = _temp_group - [_c_unit];
    					(units _c_unit) domove (getpos _veh);
    					_defend_w = _defend_w + [_c_unit];
    					_c_unit setbehaviour "combat";
    					_c_unit setvariable ["assign",_current_w];
    					_bool2 = false;
    				};
    			};	
    		};
    	};
    this next block is the attack section
    the first part sets all the variables.
    then it goes down the list and looks for a flagpole that isnt owned by their side. if it isnt owned, it set their variable "assign" to the name of the assigned marker. a neutral assign is "none".

    Code:
    //start attack section
    	
    	_task1 = true;
    	_count_w = count group_w;
    
    			_bool1 = true;
    			_counter = 0;
    	while {_counter<(count _list_w)} do
    		{
    	//select location to attack
    				_current_w = _list_w select _counter;
    				_veh = nearestObject [getmarkerpos _current_w,"FlagPole_EP1"];
    				_var1 = _veh getvariable "side";
    				if (_var1 == "west") then
    					{
    					_veh setvariable ["order","friendly"];
    					};	
    	//assign attacker		
    		if ((((_veh getvariable "side")=="east")||((_veh getvariable "side")=="none"))&&(((_veh getvariable "in")=="none")||((_veh getvariable "in")=="east"))&&((_veh getvariable "w_attack")=="false")) then
    			{
    			
    			_counter1 = _count_w - 1;
    
    		_bool1 = true;	
    	for [{_a=_count_w},{_a>=0},{_a=_a-1}] do 
    				{
    			_ran1 = round(random (_counter1));
    			_c_unit = _temp_group select _ran1;
    			if ((_c_unit getvariable "assign")=="none") then
    					{
    					sleep 0.25;
    					_veh setvariable ["w_attack","true"];
    					_counter1 = _counter1 - 1;
    					_temp_group = _temp_group - [_c_unit];
    					(units _c_unit) domove (getpos _veh);
    					_attack_w = _attack_w + [_c_unit];
    					_c_unit setFormation "STAG COLUMN";
    					_c_unit setvariable ["assign",_current_w];
    					_a = -1;
    					};
    				};
    			};
    		_counter = _counter + 1;
    		};
    //end attack section
    at first it finds a control point that isnt assigned.
    about halfway down we start getting to the real part. it asks if the current unit (_c_unit) is assigned, and if it isnt if it assigned it to the next marker in priority.

    again, priority is established by checking the variable "assign" on each flagpole in a specified and preset order.

    after the unit is assigned, it is ordered to attack.

    next block is the patrol block. this block takes extra units that arent assigned as has them move between controlled and contested points.
    Code:
    //start patrol
    if ((count group_w)>(count _list_w)) then
    {
    	for [{_a=(_count_w)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_w select _a;
    	_var1 = _c_unit getvariable "assign";
    		{
    		_pos2 = _x getvariable "assign";
    		if (_pos2 == "none") then
    			{
    			_random1 = round(random (count _list_w)) - 1;
    			_veh = nearestObject [getmarkerpos (_list_w select _random1),"FlagPole_EP1"];
    			_x setvariable ["assign","patrol"];
    			_x domove (getpos _veh);
    			};
    		} foreach group_w;
    	};
    };
    // end patrol
    same idea, but i never liked this blocked. it never seems to work that well and i think its not a good module. i might change it.

    this resets patrol, its probably broken, because the script works fine.

    Code:
    //start reset patrol
    if ((count group_w)<(count _list_w)) then
    {
    	for [{_a=(_count_w)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_w select _a;
    	_var1 = _c_unit getvariable "assign";
    		{
    		_pos2 = _x getvariable "assign";
    		if (_pos2 == "patrol") then
    			{
    				_x setvariable ["assign","none"];
    			};
    			
    		} foreach group_w;
    	};
    };
    // end reset patrol
    this next block is very important. this block resets the "assign" variable on attacking units.
    pretty standard.

    Code:
    //reset idle for ATTACKERS & COUNTER RESPONSE ONLY
    
    for [{_a=(_count_w)-1},{_a>=0},{_a=_a-1}] do
    	{
    	_c_unit = group_w select _a;
    	_var1 = _c_unit getvariable "assign";
    
    	if (_var1!="none") then {_idle_w = _idle_w - [_c_unit]};
    		{
    
    		_pos2 = _x getvariable "assign";
    		if ((_pos2 != "none")||(_pos2 != "patrol")) then
    			{
    			_veh = nearestObject [getmarkerpos _pos2,"FlagPole_EP1"];
    			if ((_veh getvariable "side")=="west") then
    				{
    				_x setvariable ["assign","none"];
    				};
    		sleep 1;
    			};
    		} foreach group_w;
    	};
    
    //end idle for ATTACKERS & COUNTER RESPONSE ONLY
    this is final block, it just cleans up everything and counts total sectors controlled. if all sectors are controlled, its sends all units onto the enemy hq (marker).

    Code:
    _veh = nearestObject [getmarkerpos _x,"FlagPole_EP1"];
    if ((_veh getvariable "side")=="west") then
    	{
    	total_w = total_w + 1;
    	};
    } foreach markers;
    
    
    //end count owned
    
    //start patrol section	
    
    _bool1 = true;
    _task1 = true;
    _count_w = count group_w;
    _counter = 0;
    
    {
    if (total_w == 9) then {
    _x setvariable ["assign","east_hq"];
    (units _x) domove (getmarkerpos "east_hq");
    hq_red allowdamage true;
    and that loops again for the germans.

    note that both of these are on while - do loops and can sometimes have nested layers of for loops.
    these dont hinder performance as long as you call them every few seconds.
    NEVER PUT SLEEP TIMERS IN BETWEEN THE BLOCKS. REALLY. IT MESSES IT UP.

    PLEASE ASK QUESTIONS. I PROBABLY WASNT CLEAR ON SOME THESE STATEMENTS AND WAS PROBABLY BABBLING TO MY SELF AT THE TIME. THANK YOU.



    i also have a dialog that goes along with this for manually controlling all the units with an in built map and building menu, to make a game mode like an RTS.
    (these scripts came out of my company of heroes game mode for i44)

    I HAVE A 900 LINES OF FUNCTION THAT I CAN SHARE TOO. your choice.
    Last edited by Yink; 01-14-2014, 03:49 AM.
    Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team

    Comment


    • #3
      Re: Sector Control + Passive AI Command Script

      heres the init (and bump)

      Code:
      markers = ["ap1_0","ap1_1","ap1_2","cp1_0","cp1_1","cp1_2","fp1_1","fp1_2","fp1_3"];
      _markers_a = [ ];
      blue_ammo = 50;
      red_ammo = 50;
      blue_fuel = 15;
      red_fuel = 15;
      blue_mp = 800;
      red_mp = 800;
      boolean1 = true;
      buildings_w = [ ];
      buildings_e = [ ];
      w_barracks_wait = 1;
      w_wps_wait = 1;
      w_mp_wait = 1;
      w_td_wait = 1;
      current_w_array = [ ];
      w_current2 = [ ];
      markers_map_w = [ ];
      markers_map_e = [ ];
      boolean_w = true;
      e_barracks_wait = 1;
      e_wps_wait = 1;
      e_mp_wait = 1;
      e_td_wait = 1;
      current_e_array = [ ];
      e_current2 = [ ];
      boolean_e = true;
      group_e = [ ];
      p_group_e = [ ];
      called_e = 1;
      
      
      execVM "dialog_actions\functions.sqf";
      [ ] spawn loop_w;
      [ ] spawn loop_e;
      [ ] spawn variable_update_e;
      
      if !(isserver) exitwith { };
      /*create markers*/{
      _marker = createMarker [format["%1_a",_x], getmarkerpos _x ];
      _markers_a = _markers_a + [_marker];
      (_x + "_a") setMarkerShape "ELLIPSE";
      (_x + "_a") setMarkerBrush "GRID";
      (_x + "_a") setMarkerColor "Colorblack";
      (_x + "_a") setmarkersize [50,50];
      _veh = "FlagPole_EP1" createvehicle (getmarkerpos _x);
      _veh setvariable ["side","none"];
      _veh setvariable ["in","none"];
      _veh setvariable ["control",0];
      _veh setvariable ["w_attack","false"];
      _veh setvariable ["e_attack","false"];
      _veh setflagtexture "\ca\ca_e\data\flag_white_co.paa";
      sleep 0.2;
      hint _marker;
      } foreach markers;
      
      if (1==1) then 
      	{
      _veh = nearestObject [getmarkerpos "ap1_0","FlagPole_EP1"];
      _veh setvariable ["resource","ammo",true];
      
      _veh = nearestObject [getmarkerpos "ap1_1","FlagPole_EP1"];
      _veh setvariable ["resource","ammo",true];
      
      _veh = nearestObject [getmarkerpos "ap1_2","FlagPole_EP1"];
      _veh setvariable ["resource","ammo",true];
      
      _veh = nearestObject [getmarkerpos "cp1_0","FlagPole_EP1"];
      _veh setvariable ["resource","mp",true];
      
      _veh = nearestObject [getmarkerpos "cp1_1","FlagPole_EP1"];
      _veh setvariable ["resource","mp",true];
      
      _veh = nearestObject [getmarkerpos "cp1_2","FlagPole_EP1"];
      _veh setvariable ["resource","mp",true];
      
      _veh = nearestObject [getmarkerpos "fp1_3","FlagPole_EP1"];
      _veh setvariable ["resource","fuel",true];
      
      _veh = nearestObject [getmarkerpos "fp1_1","FlagPole_EP1"];
      _veh setvariable ["resource","fuel",true];
      
      _veh = nearestObject [getmarkerpos "fp1_2","FlagPole_EP1"];
      _veh setvariable ["resource","fuel",true];
      _veh allowdamage false;
      };
      _nul = [ ] spawn build_que_w;
      _nul = [ ] spawn build_que_e;
      execVM "control.sqf";
      execVM "ai_control.sqf";
      
      hq_blue = "Land_enterable_large_whitewash" createvehicle (getmarkerpos "west_hq");
      hq_blue setdir 90;
      hq_red = "Land_enterable_large_whitewash" createvehicle (getmarkerpos "east_hq");
      hq_red setdit 90;
      Yink | Vanilla Pilot | Killer of Stirling | CS GOD | Projects Team

      Comment

      Connect

      Collapse

      TeamSpeak 3 Server

      Collapse

      Advertisement

      Collapse

      Twitter Feed

      Collapse

      Working...
      X