Jump to content
Sign in to follow this  
-Coulum-

Ai suppression script help

Recommended Posts

@tpw

About the latest changes, I was wondering would the unit suppressed will regain his original skill back? Because I can't really tell from the script... I'm just a beginner in scripting anyway

Share this post


Link to post
Share on other sites

Yep. Once a unit has not been shot at for 5 or so seconds he will regain his original skills.

@tpw

About the latest changes, I was wondering would the unit suppressed will regain his original skill back? Because I can't really tell from the script... I'm just a beginner in scripting anyway

---------- Post added at 22:48 ---------- Previous post was at 22:22 ----------

Just to convince people that it's working, here's a debug version in which red balls appear above units suppressed by enemy fire and disappear once the unit is not suppressed.

/*
ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m
BULLETS FIRED FROM LESS THAN 25m ARE IGNORED 
BULLETS FROM SMG AND PISTOLS ARE IGNORED
BULLETS FROM OWN SIDE CAUSE UNIT TO KNEEL/CROUCH
BULLETS FROM ENEMY SIDE CAUSE UNIT TO KNEEL/DROP, AND TEMPORARY DECREASE IN SKILL

Original code idea by -Coulum-
TPW 20120620 
*/

//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};

private ["_supnextime","_unit","_bc","_shots","_skill"]; 

//Pistol and SMG  ammo to ignore
tpw_mags =["30rnd_9x19_MP5",
"30rnd_9x19_MP5SD",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9SD",
"7Rnd_45ACP_1911",
"8Rnd_9x18_Makarov",
"8Rnd_9x18_MakarovSD",
"64Rnd_9x19_Bizon",
"64Rnd_9x19_SD_Bizon",
"13Rnd_9mm_SLP",
"17Rnd_9x19_glock17",
"6Rnd_45ACP",
"30Rnd_9x19_UZI",
"30Rnd_9x19_UZI_SD"];

//Main function
tpw_sup =  
{ 
   {
if ((vehicle _x == _x) and (alive _x))then 
	{
	_unit = _x; 
	_SupNextTime = _unit getVariable ["SupNextTime", -1]; 
	if (_SupNextTime == -1) then 
		{
		_ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["SupBall",_ball];//debugging
		_unit setVariable ["SupNextTime", diag_tickTime];
		_unit setVariable ["SupSkill", skill _unit];
		_unit setvariable ["SupSide", side _unit]; 
		_unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}];
		};
	if (diag_tickTime >= _SupNextTime) then 
		{
		_unit setVariable ["SupShots", 0];
		_unit setunitpos "auto";
		_unit setskill (_unit getvariable "SupSkill");
		_ball = _unit getvariable "SupBall"; _ball hideobject true; //debugging
		};
	if !(isnull tpw_bullet) then 
		{
		_bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]);
		if (_bc > 0) then 
			{
			if ((tpw_fired distance _unit) > 25) then 
				{
				if !(tpw_mag in tpw_mags) then 
					{
					_unit setVariable ["SupNextTime", diag_tickTime + 3 + random 5];
					_shots = _unit getVariable "SupShots";
					_unit setVariable ["SupShots", _shots + _bc];
					_shots = _unit getVariable "SupShots";
					_skill = _unit getVariable "SupSkill";		
					_ball = _unit getvariable "SupBall";//debugging					
					if (side tpw_fired != _unit getVariable "SupSide") then 
						{ 
						_ball hideobject false;//debugging
						if (_shots > 0) then {_unit setunitpos "middle"; _unit setskill _skill * 0.8;};
						if (_shots > 5) then {_unit setunitpos "down"; _unit setskill _skill * 0.6;};
						} 
						else
						{
						if (_shots > 0) then {_unit setunitpos "middle"};
						};
					};
				};
			};
		};
	}; 
} forEach allunits;
};

//Call function using per frame eventhandler so computer doesn't explode
[tpw_sup,0] call cba_fnc_addPerFrameHandler;

Edited by tpw

Share this post


Link to post
Share on other sites

I try to add the bolded part, so that the skill will actually decrease overtime the longer they are suppressed and hopefully they will disengage and flee. I found that they will stop firing but not flee. Not fleeing is not really a problem, but the problem is after they are no longer suppressed their original skill will not return.

Of course it's not your fault, just trying to try a few thing...Mainly trying to further reduce the skill the longer he is suppressed. Can you explain how the flow of the script goes?

/*
ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m
BULLETS FIRED FROM LESS THAN 25m ARE IGNORED 
BULLETS FROM SMG AND PISTOLS ARE IGNORED
BULLETS FROM OWN SIDE CAUSE UNIT TO KNEEL/CROUCH
BULLETS FROM ENEMY SIDE CAUSE UNIT TO KNEEL/DROP, AND TEMPORARY DECREASE IN SKILL

Original code idea by -Coulum-
TPW 20120620 
*/

//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};

private ["_supnextime","_unit","_bc","_shots","_skill"]; 

//Pistol and SMG  ammo to ignore
tpw_mags =["30rnd_9x19_MP5",
"30rnd_9x19_MP5SD",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9SD",
"7Rnd_45ACP_1911",
"8Rnd_9x18_Makarov",
"8Rnd_9x18_MakarovSD",
"64Rnd_9x19_Bizon",
"64Rnd_9x19_SD_Bizon",
"13Rnd_9mm_SLP",
"17Rnd_9x19_glock17",
"6Rnd_45ACP",
"30Rnd_9x19_UZI",
"30Rnd_9x19_UZI_SD"];

//Main function
tpw_sup =  
{ 
   {
if ((vehicle _x == _x) and (alive _x))then 
	{
	_unit = _x; 
	_SupNextTime = _unit getVariable ["SupNextTime", -1]; 
	if (_SupNextTime == -1) then 
		{
		_ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["SupBall",_ball];//debugging
		_unit setVariable ["SupNextTime", diag_tickTime];
		_unit setVariable ["SupSkill", skill _unit];
		_unit setvariable ["SupSide", side _unit]; 
		_unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}];
		};
	if (diag_tickTime >= _SupNextTime) then 
		{
		_unit setVariable ["SupShots", 0];
		_unit setunitpos "auto";
		_unit setskill (_unit getvariable "SupSkill");
		_ball = _unit getvariable "SupBall"; _ball hideobject true; //debugging
		};
	if !(isnull tpw_bullet) then 
		{
		_bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]);
		if (_bc > 0) then 
			{
			if ((tpw_fired distance _unit) > 25) then 
				{
				if !(tpw_mag in tpw_mags) then 
					{
					_unit setVariable ["SupNextTime", diag_tickTime + 3 + random 5];
					_shots = _unit getVariable "SupShots";
					_unit setVariable ["SupShots", _shots + _bc];
					_shots = _unit getVariable "SupShots";
					_skill = _unit getVariable "SupSkill";		
					_ball = _unit getvariable "SupBall";//debugging					
					if (side tpw_fired != _unit getVariable "SupSide") then 
						{ 
						_ball hideobject false;//debugging
						if (_shots > 0) then {_unit setunitpos "middle"; _unit setskill _skill * 0.8;};
						if (_shots > 5) then {_unit setunitpos "down"; _unit setskill _skill * 0.6;};
[b]_unit setVariable ["SupSkill", skill _unit];[/b]
						} 
						else
						{
						if (_shots > 0) then {_unit setunitpos "middle"};
						};
					};
				};
			};
		};
	}; 
} forEach allunits;
};

//Call function using per frame eventhandler so computer doesn't explode
[tpw_sup,0] call cba_fnc_addPerFrameHandler;

Just realized that code dont have the bolded part, but anyway, it's this part:

if (_shots > 0) then {_unit setunitpos "middle"; _unit setskill _skill * 0.8;};

if (_shots > 5) then {_unit setunitpos "down"; _unit setskill _skill * 0.6;};

_unit setVariable ["SupSkill", skill _unit];

[edit]

I hope I'm not stepping into anyone toes here... sorry if it does.

Edited by Mr_Centipede

Share this post


Link to post
Share on other sites
Just realized that code dont have the bolded part, but anyway, it's this part:

if (_shots > 0) then {_unit setunitpos "middle"; _unit setskill _skill * 0.8;};

if (_shots > 5) then {_unit setunitpos "down"; _unit setskill _skill * 0.6;};

_unit setVariable ["SupSkill", skill _unit];

From what I understand, this would detect the skill of the unit, even after he has been suppressed. So if his original skill was 1, then he was suppressed and his skill was made to 0.8, _unit setVariable ["SupSkill", skill _unit]; will detect that his skill is 0.8. Then when the script repeats itself, at this point:

if (diag_tickTime >= _SupNextTime) then 
           {
           _unit setVariable ["SupShots", 0];
           _unit setunitpos "auto";
-------->_unit setskill (_unit getvariable "SupSkill");
           _ball = _unit getvariable "SupBall"; _ball hideobject true; //debugging

The line indicated will use that detected skill of 0.8 and set it as the unit's new skill even if he isn't suppressed anymore. As the script repeats itself over and over again, and the unit is suppressed more and more, this skill will degenerate faster and faster and will never recover, all because of that _unit setVariable ["SupSkill", skill _unit]; at the end of the script. Or at least that's how I understand it. A good way to see the skill of the ai you are shooting at is to put "hint str (skill ai);" in to the script right after "_unit = _x;", and name the soldier you are testing on ai.

ie.

tpw_sup =  
{ 
   {
   if ((vehicle _x == _x) and (alive _x))then 
       {
       _unit = _x;
-----> hint str (skill ai); <--------
       _SupNextTime = _unit getVariable ["SupNextTime", -1];

--edit--

Anyhow, if you wanted the ai's skill to constantly decrease while being suppressed, then you could simply add the indicated lines:

if (diag_tickTime >= _SupNextTime) then 
           {
           _unit setVariable ["SupShots", 0];
           _unit setunitpos "auto";
           _unit setskill (_unit getvariable "SupSkill");
           _ball = _unit getvariable "SupBall"; _ball hideobject true; //debugging
           }    <---------------------------------------------------------------------
    else<---------------------------------------------------------------------
    {    <---------------------------------------------------------------------
    _unit setskill ((skill _unit)-.0001);<---------------------------------
    };<------------------------------------------------------------------------
       if !(isnull tpw_bullet) then 
           {
           _bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]);
           if (_bc > 0) then 

So that as long as a unit is suppressed his skills decrease by .0001 per frame (actually pretty fast). As soon as he stops being suppressed for a few seconds his skills will then return. Try the below out with one unit named "ai" and you will see how it works (ai's accuracy will be displayed in the top right of the screen).

/*/*
ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m
BULLETS FIRED FROM LESS THAN 25m ARE IGNORED 
BULLETS FROM SMG AND PISTOLS ARE IGNORED
BULLETS FROM OWN SIDE CAUSE UNIT TO KNEEL/CROUCH
BULLETS FROM ENEMY SIDE CAUSE UNIT TO KNEEL/DROP, AND TEMPORARY DECREASE IN SKILL

Original code idea by -Coulum-
TPW 20120620 
*/

//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};

private ["_supnextime","_unit","_bc","_shots","_skill"]; 

//Pistol and SMG  ammo to ignore
tpw_mags =["30rnd_9x19_MP5",
"30rnd_9x19_MP5SD",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9SD",
"7Rnd_45ACP_1911",
"8Rnd_9x18_Makarov",
"8Rnd_9x18_MakarovSD",
"64Rnd_9x19_Bizon",
"64Rnd_9x19_SD_Bizon",
"13Rnd_9mm_SLP",
"17Rnd_9x19_glock17",
"6Rnd_45ACP",
"30Rnd_9x19_UZI",
"30Rnd_9x19_UZI_SD"];

//Main function
tpw_sup =  
{ 
   {
   if ((vehicle _x == _x) and (alive _x))then 
       {
       _unit = _x; 
hint str (skill ai);
       _SupNextTime = _unit getVariable ["SupNextTime", -1]; 
       if (_SupNextTime == -1) then 
           {
           _ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["SupBall",_ball];//debugging
           _unit setVariable ["SupNextTime", diag_tickTime];
           _unit setVariable ["SupSkill", skill _unit];
           _unit setvariable ["SupSide", side _unit]; 
           _unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}];
           };
       if (diag_tickTime >= _SupNextTime) then 
           {
           _unit setVariable ["SupShots", 0];
           _unit setunitpos "auto";
           _unit setskill (_unit getvariable "SupSkill");
           _ball = _unit getvariable "SupBall"; _ball hideobject true; //debugging
           }
    else
    {
    _unit setskill ((skill _unit)-.0001);	
    };
       if !(isnull tpw_bullet) then 
           {
           _bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]);
           if (_bc > 0) then 
               {
               if ((tpw_fired distance _unit) > 25) then 
                   {
                   if !(tpw_mag in tpw_mags) then 
                       {
                       _unit setVariable ["SupNextTime", diag_tickTime + 3 + random 5];
                       _shots = _unit getVariable "SupShots";
                       _unit setVariable ["SupShots", _shots + _bc];
                       _shots = _unit getVariable "SupShots";
                       _skill = _unit getVariable "SupSkill";        
                       _ball = _unit getvariable "SupBall";//debugging                    
                       if (side tpw_fired != _unit getVariable "SupSide") then 
                           { 
                           _ball hideobject false;//debugging
                           if (_shots > 0) then {_unit setunitpos "middle"; _unit setskill _skill * 0.8;};
                           if (_shots > 5) then {_unit setunitpos "down"; _unit setskill _skill * 0.6;};
                           } 
                           else
                           {
                           if (_shots > 0) then {_unit setunitpos "middle"};
                           };
                       };
                   };
               };
           };
       }; 
   } forEach allunits;
};

//Call function using per frame eventhandler so computer doesn't explode
[tpw_sup,0] call cba_fnc_addPerFrameHandler;  

Or something like this will make it so they decrease in skill every shot getting closer and closer to zero. Once again, if you don't keep the rate of fire up they will get their skill restored back to normal.

Original code idea by -Coulum-
TPW 20120620 
*/

//Start hint
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};

private ["_supnextime","_unit","_bc","_shots","_skill"]; 

//Pistol and SMG  ammo to ignore
tpw_mags =["30rnd_9x19_MP5",
"30rnd_9x19_MP5SD",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9SD",
"7Rnd_45ACP_1911",
"8Rnd_9x18_Makarov",
"8Rnd_9x18_MakarovSD",
"64Rnd_9x19_Bizon",
"64Rnd_9x19_SD_Bizon",
"13Rnd_9mm_SLP",
"17Rnd_9x19_glock17",
"6Rnd_45ACP",
"30Rnd_9x19_UZI",
"30Rnd_9x19_UZI_SD"];

//Main function
tpw_sup =  
{ 
   {
   if ((vehicle _x == _x) and (alive _x))then 
       {
       _unit = _x; 
hint str (skill ai);
       _SupNextTime = _unit getVariable ["SupNextTime", -1]; 
       if (_SupNextTime == -1) then 
           {
           _ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["SupBall",_ball];//debugging
           _unit setVariable ["SupNextTime", diag_tickTime];
           _unit setVariable ["SupSkill", skill _unit];
           _unit setvariable ["SupSide", side _unit]; 
           _unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}];
           };
       if (diag_tickTime >= _SupNextTime) then 
           {
           _unit setVariable ["SupShots", 0];
           _unit setunitpos "auto";
           _unit setskill (_unit getvariable "SupSkill");
           _ball = _unit getvariable "SupBall"; _ball hideobject true; //debugging	
    };
       if !(isnull tpw_bullet) then 
           {
           _bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]);
           if (_bc > 0) then 
               {
               if ((tpw_fired distance _unit) > 25) then 
                   {
                   if !(tpw_mag in tpw_mags) then 
                       {
                       _unit setVariable ["SupNextTime", diag_tickTime + 3 + random 5];
                       _shots = _unit getVariable "SupShots";
                       _unit setVariable ["SupShots", _shots + _bc];
                       _shots = _unit getVariable "SupShots";
                       _skill = _unit getVariable "SupSkill";        
                       _ball = _unit getvariable "SupBall";//debugging                    
                       if (side tpw_fired != _unit getVariable "SupSide") then 
                           { 
                           _ball hideobject false;//debugging
                           if (_shots > 0) then {_unit setunitpos "middle"; _unit setskill ((skill _unit)*.95);};
                           if (_shots > 5) then {_unit setunitpos "down"; _unit setskill ((skill _unit)*.85);};
                           } 
                           else
                           {
                           if (_shots > 0) then {_unit setunitpos "middle"};
                           };
                       };
                   };
               };
           };
       }; 
   } forEach allunits;
};

//Call function using per frame eventhandler so computer doesn't explode
[tpw_sup,0] call cba_fnc_addPerFrameHandler;  

Are those closer to what you are looking for?

Edited by -Coulum-

Share this post


Link to post
Share on other sites

Nice one -Coulum-. It might also be possible to tie unit skill in with the number of shots thusly:

if (_shots > 0) then {_unit setunitpos "middle"};
if (_shots > 5) then {_unit setunitpos "down"};
_loss = _skill * _shots * 0.02; 
if (_loss > _skill) then {_loss = _skill};
_skill = _skill - _loss;
_unit setskill _skill;

This will cause a unit to lose 2% skill for every shot.

So if the unit is being suppressed by a few isolated shots, he will crouch and lose up to 10% skill (up to 5 bullets). If he's really surrounded by hot lead, then he'll hit the dirt and the skill might decrease to 0.

6 of one, half a dozen of the other.

Edited by tpw

Share this post


Link to post
Share on other sites

Yep that works as well. honestly I don't know what would be best for gameplay. On a somewhat related note...

I am trying to make it so the restoration of stance and skill occur separately. Ie. if I suppress an ai, he will restore back to full accuracy after only 3-5 second, but take longer to go back to normal stance. To do that I have tried making the equivalent of a "SupNextTime", called "SkillRegain". I am horrible at describing things so I'll just show it.

"7Rnd_45ACP_1911", 
"8Rnd_9x18_Makarov", 
"8Rnd_9x18_MakarovSD", 
"64Rnd_9x19_Bizon", 
"64Rnd_9x19_SD_Bizon", 
"13Rnd_9mm_SLP", 
"17Rnd_9x19_glock17", 
"6Rnd_45ACP", 
"30Rnd_9x19_UZI", 
"30Rnd_9x19_UZI_SD"]; 

//Main function 
tpw_sup =   
{  
   { 
   _unit = _x;
hint str (ai skill "aimingaccuracy");
       if (vehicle _x == _x) then  
       { 
       _SkillRegain = _unit getVariable ["SkillRegain", -1];  
       _SupNextTime = _unit getVariable ["SupNextTime", -1];  
       if (_SupNextTime == -1) then  
           {	
           _unit setVariable ["SupNextTime", diag_tickTime];
    _unit setvariable ["SkillRegain", diag_tickTime];  
           _unit setvariable ["SupSide", side _unit];  
           _unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}]; 

           //Saves original skills
    _originalaccuracy = _unit skill "aimingAccuracy";
           _unit setVariable ["originalaccuracy", _originalaccuracy]; 
    _originalshake = _unit skill "aimingshake"; 
           _unit setVariable ["originalshake", _originalshake];
    _originalcourage = _unit skill "courage";
    _unit setVariable ["originalcourage", _originalcourage]; 
    _general = _unit skill "general";
    _unit setVariable ["general", _general];
    //makes suppressed skills 
    _suppressedaccuracy = _originalaccuracy*_general*_originalcourage; 
    _unit setVariable ["suppressedaccuracy", _suppressedaccuracy];
    _suppressedshake = _originalshake* _general* _originalcourage; 
    _unit setVariable ["suppressedshake", _suppressedshake];	
    _suppressedcourage = _originalcourage*_general*_originalcourage;
    _unit setVariable ["suppressedcourage", _suppressedcourage];
    };


if ( diag_tickTime >= _SupNextTime) then  
           { 
              //restores original stance
              _unit setVariable ["SupShots", 0]; 
              _unit setunitpos "auto";
     };


------>if (diag_tickTime >= _SkillRegain) then                                           
------>			{                                                                            
------>	   	         //restores original skills
------>                       _originalaccuracy = _unit getVariable "originalaccuracy";   
------>           	         _originalshake = _unit getVariable "originalshake";            
------>   	    	         _originalcourage = _unit getVariable "originalcourage";      
------>	    	         _unit setskill ["aimingAccuracy",_originalaccuracy];            
------>            	         _unit setskill ["aimingAccuracy",_originalshake];                
------>   	    	         _unit setskill ["aimingAccuracy",_originalcourage];             
------>		         }:                                                                                    



       if !(isnull tpw_bullet) then  
           { 
           _bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]); 
           if (_bc > 0) then  
               { 
               if ((tpw_fired distance _unit) > 25) then  
                   { 
                   if !(tpw_mag in tpw_mags) then  
                       {
	        _unit setVariable ["SkillRegain", diag_tickTime + 5]; 
                       _unit setVariable ["SupNextTime", diag_tickTime + 10]; 
                       _shots = _unit getVariable "SupShots"; 
                       _unit setVariable ["SupShots", _shots + _bc]; 
                       _shots = _unit getVariable "SupShots";
	        _suppressedaccuracy = _unit getVariable "suppressedaccuracy";  
           	        _suppressedshake = _unit getVariable "suppressedshake";
  	    	        _suppressedcourage = _unit getVariable "suppressedcourage";                  
                       if (side tpw_fired != _unit getVariable "SupSide") then  
                           { 
                           if (_shots > 0) then {_unit setunitpos "middle";
		    _unit setskill ["aimingAccuracy",_suppressedaccuracy];  
          		    _unit setskill ["aimingAccuracy",_suppressedshake];
  	   		    _unit setskill ["aimingAccuracy",_suppressedcourage];
			}; 
                           if (_shots > 5) then {_unit setunitpos "down";
                             _unit setskill ["aimingAccuracy",_suppressedaccuracy];  
          		    _unit setskill ["aimingAccuracy",_suppressedshake];
  	   		    _unit setskill ["aimingAccuracy",_suppressedcourage];
                           }; 
                           }  
                           else 
                           { 
                           if (_shots > 0) then {_unit setunitpos "middle"}; 
                           }; 
                       }; 
                   }; 

               }; 
           }; 
       };  
   } forEach allunits; 
}; 

//Call function using per frame eventhandler so computer doesn't explode 
[tpw_sup,0] call cba_fnc_addPerFrameHandler;  

Problem is, when I implement this, the suppression effects cease to work. Actually it is the line indicated in particular that stop all suppression effects, whether stance or skill, from occurring. And I have absolutely no clue why they would do that. Can anyone point out my mistake? It would be much appreciated and would let me sleep alot better:)

Edited by -Coulum-

Share this post


Link to post
Share on other sites

Try this.

//Main function 
tpw_sup =   
{  
   { 
   _unit = _x;
   hint str (ai skill "aimingaccuracy");
       if ((vehicle _x == _x) and (alive _x)) then  
       { 
       _SkillRegain = _unit getVariable "SkillRegain";  
       _SupNextTime = _unit getVariable ["SupNextTime", -1];  
       if (_SupNextTime == -1) then  
           {    
           _unit setVariable ["SupNextTime", diag_tickTime];
		_unit setvariable ["SkillRegain", diag_tickTime];  
           _unit setvariable ["SupSide", side _unit];  
           _unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}]; 

           //Saves original skills
		_originalaccuracy = _unit skill "aimingAccuracy";
		_unit setVariable ["originalaccuracy", _originalaccuracy]; 
		_originalshake = _unit skill "aimingshake"; 
		_unit setVariable ["originalshake", _originalshake];
		_originalcourage = _unit skill "courage";
		_unit setVariable ["originalcourage", _originalcourage]; 
		_general = _unit skill "general";
		_unit setVariable ["general", _general];

		//makes suppressed skills 
		_suppressedaccuracy = _originalaccuracy*_general*_originalcourage; 
		_unit setVariable ["suppressedaccuracy", _suppressedaccuracy];
		_suppressedshake = _originalshake* _general* _originalcourage; 
		_unit setVariable ["suppressedshake", _suppressedshake];    
		_suppressedcourage = _originalcourage*_general*_originalcourage;
		_unit setVariable ["suppressedcourage", _suppressedcourage];
		};

	if ( diag_tickTime >= _SupNextTime) then  
           { 
           //restores original stance
           _unit setVariable ["SupShots", 0]; 
           _unit setunitpos "auto";
		};

	if (diag_tickTime >= _SkillRegain) then                                           
           {                                                                            
           //restores original skills
           _originalaccuracy = _unit getVariable "originalaccuracy";   
           _originalshake = _unit getVariable "originalshake";            
           _originalcourage = _unit getVariable "originalcourage";      
           _unit setskill ["aimingAccuracy",_originalaccuracy];            
           _unit setskill ["aimingshake",_originalshake];                
           _unit setskill ["courage",_originalcourage];             
           }:                                                                                    

       if !(isnull tpw_bullet) then  
           { 
           _bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]); 
           if (_bc > 0) then  
               { 
               if ((tpw_fired distance _unit) > 25) then  
                   { 
                   if !(tpw_mag in tpw_mags) then  
                       {
					_unit setVariable ["SkillRegain", diag_tickTime + 5]; 
                       _unit setVariable ["SupNextTime", diag_tickTime + 10]; 
                       _shots = _unit getVariable "SupShots"; 
                       _unit setVariable ["SupShots", _shots + _bc]; 
                       _shots = _unit getVariable "SupShots";
					_suppressedaccuracy = _unit getVariable "suppressedaccuracy";  
                       _suppressedshake = _unit getVariable "suppressedshake";
                       _suppressedcourage = _unit getVariable "suppressedcourage";                  
                       if (side tpw_fired != _unit getVariable "SupSide") then  
                           { 
						_unit setskill ["aimingAccuracy",_suppressedaccuracy];  
						_unit setskill ["aimingshake",_suppressedshake];
						_unit setskill ["courage",_suppressedcourage];
                           if (_shots > 0) then 
							{
							_unit setunitpos "middle";
							}; 
                           if (_shots > 5) then 
							{
							_unit setunitpos "down";
                               }; 
                           }  
                           else 
                           { 
                           if (_shots > 0) then 
							{
							_unit setunitpos "middle"
							}; 
                           }; 
                       }; 
                   }; 

               }; 
           }; 
       };  
   } forEach allunits; 
}; 

//Call function using per frame eventhandler so computer doesn't explode 
[tpw_sup,0] call cba_fnc_addPerFrameHandler;

There were few issues like this:

------>                     _unit setskill ["aimingAccuracy",_originalaccuracy];            
------>                         _unit setskill ["aimingAccuracy",_originalshake];                
------>                        _unit setskill ["aimingAccuracy",_originalcourage];  

where you were repeatedly setting the same variable. That might have caused problems.

Apart from that, it should work, but I can't test it until I get home.

Share this post


Link to post
Share on other sites

Thanks tpw. Your right, but it doesn't seem to be whats causing the problem. I actually replaced all that setskill stuff with a simple "hint "placeholder - skills are regained";" and still no go. What I found interesting though was that no matter how much I fired this hint was repeated every frame indicating that SkillRegain hadn't been set correctly when shots are fired... but once again, I don't see why it wouldn't be set right.Oh that hint was probably being constantly repeated for me, the player.

It seems to be the "if ( diag_tickTime >= _SkillRegain) then... " statement itself rather than what inside that is causing problems. But I am still lost as to why.

Edited by -Coulum-

Share this post


Link to post
Share on other sites

The only thing I can think of is to put the if ( diag_tickTime >= _SkillRegain) then block before the if ( diag_tickTime >= _SupNextTime) then block, since a unit should regain skills before regaining his stance.

Thanks tpw. Your right, but it doesn't seem to be whats causing the problem. I actually replaced all that setskill stuff with a simple "hint "placeholder - skills are regained";" and still no go. What I found interesting though was that no matter how much I fired this hint was repeated every frame indicating that SkillRegain hadn't been set correctly when shots are fired... but once again, I don't see why it wouldn't be set right.Oh that hint was probably being constantly repeated for me, the player.

It seems to be the "if ( diag_tickTime >= _SkillRegain) then... " statement itself rather than what inside that is causing problems. But I am still lost as to why.

Share this post


Link to post
Share on other sites

I've been tinkering the first version of coulom script that degenerate the skill. I think it serve the purpose quite nicely.

Here's my version:

// ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m 
// BULLETS FIRED FROM LESS THAN 25m ARE IGNORED  
// BULLETS FROM SMG AND PISTOLS ARE IGNORED 
// BULLETS FROM OWN SIDE CAUSE UNIT TO KNEEL/CROUCH 
// BULLETS FROM ENEMY SIDE CAUSE UNIT TO KNEEL/DROP, AND TEMPORARY DECREASE IN SKILL

// Original code idea by -Coulum- 
// TPW 20120621  

//Start hint 
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""}; 

private ["_supnextime","_unit","_bc","_shots","_skill"];  

//Pistol and SMG  ammo to ignore 
tpw_mags =["30rnd_9x19_MP5", 
"30rnd_9x19_MP5SD", 
"15Rnd_9x19_M9", 
"15Rnd_9x19_M9SD", 
"7Rnd_45ACP_1911", 
"8Rnd_9x18_Makarov", 
"8Rnd_9x18_MakarovSD", 
"64Rnd_9x19_Bizon", 
"64Rnd_9x19_SD_Bizon", 
"13Rnd_9mm_SLP", 
"17Rnd_9x19_glock17", 
"6Rnd_45ACP", 
"30Rnd_9x19_UZI", 
"30Rnd_9x19_UZI_SD"]; 

//Main function 
tpw_sup =  
{ 
   {
   if ((vehicle _x == _x) and (alive _x))then 
   {
       _unit = _x; 
   //hintsilent str (skill o1);
       _SupNextTime = _unit getVariable ["SupNextTime", -1]; 
       if (_SupNextTime == -1) then 
       {
           //_ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["SupBall",_ball];//debugging
           _unit setVariable ["SupNextTime", diag_tickTime];
           _unit setVariable ["SupSkill", skill _unit];
           _unit setvariable ["SupSide", side _unit]; 
           _unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}];
       };
       if (diag_tickTime >= _SupNextTime) then 
       {
           _unit setVariable ["SupShots", 0];
           _unit setunitpos "auto";
//REGAINING SKILL PART - slowly
		if(skill _unit >= _unit getvariable "SupSkill") then
		{
			_unit setskill (_unit getvariable "SupSkill");
			//_ball = _unit getvariable "SupBall"; _ball hideobject true; //debugging 
		}
		else
		{
			_unit setskill (((_unit getvariable "SupSkill")*0.001) + (skill _unit));
			//_unit allowFleeing (1 - (skill _unit));
		};   
       };
       if !(isnull tpw_bullet) then 
       {
           _bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]);
           if (_bc > 0) then 
           {
               if ((tpw_fired distance _unit) > 25) then 
               {
                   if !(tpw_mag in tpw_mags) then 
                   {
                       _unit setVariable ["SupNextTime", diag_tickTime + 3 + random 5];
                       _shots = _unit getVariable "SupShots";
                       _unit setVariable ["SupShots", _shots + _bc];
                       _shots = _unit getVariable "SupShots";
                       _skill = _unit getVariable "SupSkill";        
                       //_ball = _unit getvariable "SupBall";//debugging                    
                       if (side tpw_fired != _unit getVariable "SupSide") then 
                       { 
                           //_ball hideobject false;//debugging
                           if (_shots > 0) then {_unit setunitpos "middle";};
                           if (_shots > 5) then {_unit setunitpos "down";};
//LOSING SKILL part based on tpw math
                           _loss = _skill * _shots * 0.01; 
						if (_loss > _skill) then {_loss = _skill};
						_skill = _skill - _loss;
						_unit setskill _skill; 
						//_unit allowFleeing (1 - (skill _unit));						
					} 
                       else
                       {
                           if (_shots > 0) then {_unit setunitpos "middle"};
                       };
                   };
               };
           };
       };
   }; 
   } forEach allunits;
};

//Call function using per frame eventhandler so computer doesn't explode
[tpw_sup,0] call cba_fnc_addPerFrameHandler;  

Basically suppressed AI will lose skill overtime, and they will regain their skill slowly based on their original skill. The math maybe needed some work. But it serve the purpose. I think you can edit this script for your regaining stance coulom?

As for the commented allowFleeing, I try to make them flee overtime, but after they flee, they seems wont recover... maybe needed some more test

Share this post


Link to post
Share on other sites

I think it's not a good idea to use the overall setSkill command, I think that will make the AI more and more stupid overtime...

Share this post


Link to post
Share on other sites

Yeah i would rather go with changing only aimingAccuracy, aimingShake and maybe courage. The other AI abilities shouldn't suffer from being suppressed imao.

Share this post


Link to post
Share on other sites
Yeah i would rather go with changing only aimingAccuracy, aimingShake and maybe courage. The other AI abilities shouldn't suffer from being suppressed imao.

I agree, but overall skill is easier to work with when you're trying to establish a workable system. Once you have that then you make the skill stuff more granular. Professor -Coulum- is pretty close I think.

Given that the whole AI skill thing will never please everyone, I've got a feeling that in the end we'll release 2 versions of the system, one which changes skills under suppression, and one which only changes stance.

Share this post


Link to post
Share on other sites
Yeah i would rather go with changing only aimingAccuracy, aimingShake and maybe courage. The other AI abilities shouldn't suffer from being suppressed imao.

good because that's the only stats I changed. This script decreases individual skills, and further more, it decreases skills by an amount dependant on the number of shots coming in and that units other skills. So a courageous unit will suffer less of an aiming penalty, for a shorter amount of time. I've also used Centipede's idea of making skills regenerative, but at a rate that tapers off the closer it gets to the original skill. I am hoping this makes it so that suppression will have long term effects but will not make the ai too useless for more than a few seconds, unless under constant fire. This is a basic break down

When you shoot at an enemy is skill drops to about 1/2 (depends on his courage and general skill)

Every additional shot will subtract an addition few skill points (also depend on courage and general skill)

After a few seconds (part random, part skill dependant) the soldier starts regaining his skills. This is totally independant of his stance though. So a unit might still stay prone due suppression, but be at full accuracy, shake etc.

The regeneration will initially be very rapid but slow the closer the soldier's current skill gets to his original skill.

Courage regenerates at a constant rate but only starts to replenish when the soldier returns to auto stance.

So basically, if you keep up fire on a unit you will be able to keep their accuracy very low. A machinegunner will even be able to cut down a soldiers skills to absolute zero, if he focuses fire on it.

//SLEEP 20;

// ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m  
// BULLETS FIRED FROM LESS THAN 25m ARE IGNORED   
// ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m  
// BULLETS FIRED FROM LESS THAN 25m ARE IGNORED   
// BULLETS FROM SMG AND PISTOLS ARE IGNORED  
// BULLETS FROM OWN SIDE CAUSE UNIT TO KNEEL/CROUCH  
// BULLETS FROM ENEMY SIDE CAUSE UNIT TO KNEEL/DROP, AND TEMPORARY DECREASE IN SKILL 

// Original code idea by -Coulum-  
// TPW 20120621   

//Start hint  
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};  

private ["_supnextime","_Skillregain","_unit","_bc","_shots","_originalaccuracy","_originalshake","_originalcourage","_general"];   

//Pistol and SMG  ammo to ignore  
tpw_mags =["30rnd_9x19_MP5",  
"30rnd_9x19_MP5SD",  
"15Rnd_9x19_M9",  
"15Rnd_9x19_M9SD",  
"7Rnd_45ACP_1911",  
"7Rnd_45ACP_1911", 
"8Rnd_9x18_Makarov", 
"8Rnd_9x18_MakarovSD", 
"64Rnd_9x19_Bizon", 
"64Rnd_9x19_SD_Bizon", 
"13Rnd_9mm_SLP", 
"17Rnd_9x19_glock17", 
"6Rnd_45ACP", 
"30Rnd_9x19_UZI", 
"30Rnd_9x19_UZI_SD"]; 

//Main function 
tpw_sup =   
{  
//___________________________________Check if Script is Applicable, SetUp variables________________________________

{ 
_unit = _x;
//hint format["accuracy = %1, shake = %2, courage = %3, general = %4",(ai skill "aimingaccuracy"),(ai skill "aimingshake"),(ai skill "courage"),(ai skill "general")];
if (vehicle _x == _x) then  
       	{ 
       	_SkillRegain = _unit getVariable ["SkillRegain", -1];  
       	_SupNextTime = _unit getVariable ["SupNextTime", -1];

//_______________________________________Default Skills and settings - repeated Once_______________________________

       	if (_SupNextTime == -1) then  
           		{    
		_unit setVariable ["SupNextTime", diag_tickTime];
       		_unit setvariable ["SkillRegain", diag_tickTime];  
      			_unit setvariable ["SupSide", side _unit];  
       		_unit addeventhandler ["Fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}]; 

           		//Saves original skills
       		_originalaccuracy = _unit skill "aimingAccuracy";
       		_unit setVariable ["originalaccuracy", _originalaccuracy]; 
       		_originalshake = _unit skill "aimingshake"; 
       		_unit setVariable ["originalshake", _originalshake];
       		_originalcourage = _unit skill "courage";
       		_unit setVariable ["originalcourage", _originalcourage]; 
       		_general = _unit skill "general";
       		_unit setVariable ["general", _general];
       		};

//__________________________________Reapply Basic Stance and Skills If not Suppressed_______________________________      

   		if ( diag_tickTime >= _SupNextTime) then  
           		{ 
              		//restores original stance 
		_unit setVariable ["SupShots", 0]; 
              		_unit setunitpos "auto";
		_originalcourage = _unit getVariable "originalcourage";
		_general = _unit getVariable "general";  
		if((_unit skill "courage") < _originalcourage) then 
           			{ 
               		_unit setskill ["courage",(_unit skill "courage")+(_general)*(0.003)];  
                 		};
        		};

	if (diag_tickTime >= _skillregain) then 
		{
		_originalaccuracy = _unit getVariable "originalaccuracy";   
           		_originalshake = _unit getVariable "originalshake";            
           		_originalcourage = _unit getVariable "originalcourage";
		_general = _unit getVariable "general";      

		if((_unit skill "aimingaccuracy") < _originalaccuracy) then 
           			{ 
			_unit setskill ["aimingAccuracy",(_unit skill "aimingaccuracy")+((_originalaccuracy-(_unit skill "aimingaccuracy"))*.01)];  
                 		};
		if((_unit skill "aimingshake") < _originalshake) then 
           			{ 
               		_unit setskill ["aimingshake",(_unit skill "aimingshake")+((_originalshake-(_unit skill "aimingshake"))*.01)]; 
                 		};    
		};

//___________________________________Check for Suppressive Fire_____________________________________________________

       	if !(isnull tpw_bullet) then  
           		{ 
           		_bc = count ((getposatl _unit) nearobjects ["Bulletbase",10]); 
           		if (_bc > 0) then  
               		{ 
               		if ((tpw_fired distance _unit) > 25) then  
                   			{ 
                   			if !(tpw_mag in tpw_mags) then  
                       			{
               				_unit setVariable ["SkillRegain", diag_tickTime + (random 4)-((_unit getVariable "general")+(_unit getVariable "originalcourage"))];  
                       			_unit setVariable ["SupNextTime", diag_tickTime + 10]; 
                       			_shots = _unit getVariable "SupShots"; 
                       			_unit setVariable ["SupShots", _shots + _bc]; 
                       			_shots = _unit getVariable "SupShots";

//_____________________________________Transfer Suppressed Skills___________________________________________________

					_originalaccuracy = _unit getVariable "originalaccuracy";  
                       			_originalshake = _unit getVariable "originalshake";
                      				_originalcourage = _unit getVariable "originalcourage"; 
					_general = _unit getVariable "general";						   

//_______________________________________Apply Suppression Effects__________________________________________________

                       			if (side tpw_fired != _unit getVariable "SupSide") then  
                           				{ 
                           				if (_shots > 0) then 
							{_unit setunitpos "middle";
               						_unit setskill ["aimingAccuracy",_originalaccuracy*_originalcourage*_general-(_shots*(1-_general)*.003)]; 
                      						_unit setskill ["aimingShake",_originalshake*_originalcourage*_general-(_shots*(1-_general)*.003)];
                     						_unit setskill ["Courage",_originalcourage*_originalcourage*_general-(_shots*(1-_general)*.003)];
               						}; 
                           				if (_shots > 5) then 
							{
							_unit setunitpos "down";
                           					}; 
                           				}  
                           				else 
                           				{ 
                           				if (_shots > 0) then 
							{
							_unit setunitpos "middle"

//__________________________________________End a Shitload of Nested If's____________________________________________

							}; 
                           				}; 
                       			}; 
                   			}; 
               		}; 
           		}; 
       	};  
//___________________________________________Perform for Each Unit____________________________________________________

   	} forEach allunits; 
}; 

//____________________________________________Repeat Every Frame______________________________________________________

//Call function using per frame eventhandler so computer doesn't explode 
[tpw_sup,0] call cba_fnc_addPerFrameHandler;  

If you want to see a units skills changing dynamicly in-game, simply name him "ai" and uncomment this line ://hint format["accuracy = %1, shake = %2, courage = %3, general = %4",(ai skill "aimingaccuracy"),(ai skill "aimingshake"),(ai skill "courage"),(ai skill "general")];(its towards the top of the script)

Now with vanilla this isn't nearly as interesting as with asr ai skills. But if you plan to use it with asr, you'll have to let the script sleep for 20 seconds or so before having it activate, in order for asr skills to set in.

Feedback is very welcome.

Share this post


Link to post
Share on other sites

Beautiful! So how did you get it to work in the end? Probably just needs a few more small code cleanups and it's ready for packaging and sale! Well done -Coulum-, it's been great to be part of the process of bringing your excellent ideas to fruition.

Share this post


Link to post
Share on other sites

One thing: if you want to test with the hint, replace it by hintsilent. Or do not wear a headset. I almost died of a heart attack.

done one test so far, on lingor, with 100 units, asr, ACE, and stuff. Looks good. Will try it without ace and see if there isn't anything conflicting though.

Share this post


Link to post
Share on other sites
Beautiful! So how did you get it to work in the end? Probably just needs a few more small code cleanups and it's ready for packaging and sale!

Honestly... I have no fucking clue. I just rebooted the computer, and rewrote the whole script. It worked after that. I still haven't been able to find what was giving me trouble, probably some small seemingly unrelated error. And yes I think there are probably many refinements that could be made but I am off to a soccer game now, so that will have to wait until tomorrow. I also think there might be a bug where vehicle shots won't suppress soldiers - I didn't do a lot of testing though so I'm not positive.

Well done -Coulum-, it's been great to be part of the process of bringing your excellent ideas to fruition.

What do you mean "part of the process"? You practically were the process.:) Great job and many thanks tpw!

One thing: if you want to test with the hint, replace it by hintsilent. Or do not wear a headset. I almost died of a heart attack.

done one test so far, on lingor, with 100 units, asr, ACE, and stuff. Looks good. Will try it without ace and see if there isn't anything conflicting though.

When I was writing the script I was testing it with ace so hopefully it works fine. And be warned that having the hint on actually cuts 5 fps or so.

Share this post


Link to post
Share on other sites

That's cool cause i have a very nice fps rate here, even though i have quite a load of mods loaded, playing in the biggest city on lingor with around 200 units (and the hint). Means that your script doesn't cut that much into it! Well done to both of you!

And yeah, seems to be working just fine with ace.

Beeing an automatic rifleman finally means something in here. Seems that you can very quickly reduce the skills of an enemy group to zero if you keep laying down some proper suppressive fire!

What we need now is some MP testing/adjusting!

Share this post


Link to post
Share on other sites
I also think there might be a bug where vehicle shots won't suppress soldiers - I didn't do a lot of testing though so I'm not positive.

The whole system is set up to ignore shooters in vehicles at present (ie it only runs if vehicle _x == _x). So it's not a bug as such. The idea was that you don't want to be able to suppress a player in a vehicle (imagine being able to suppress a jet by shooting an assault rifle at it from the ground), but the side effect is that a player in a vehicle can't suppress a foot unit.

Will have to think about that one some more.

EDIT:

OK, did some thinking, here's the result:

/*
ALL INFANTRY UNITS ON MAP WILL REACT IF ANY BULLETS PASS WITHIN 10m   
BULLETS FIRED FROM LESS THAN 25m ARE IGNORED    
BULLETS FROM SMG AND PISTOLS ARE IGNORED   
BULLETS FROM OWN SIDE CAUSE UNIT TO KNEEL/CROUCH   
BULLETS FROM ENEMY SIDE CAUSE UNIT TO KNEEL/DROP, AND TEMPORARY DECREASE IN SKILL  
SKILLS WILL GRADUALLY RETURN ONCE UNIT IS NOT SUPPRESSED

Authors: TPW & -Coulum-
Last changed: 20120622    
*/

//Allow time for ASR AI skills to propagate
sleep 30;

//Start hint   
0 = [] spawn {sleep 3;hintsilent "AI suppress active"; sleep 3; hintsilent ""};   

private ["_stanceregain","_skillregain","_unit","_bc","_shots","_originalaccuracy","_originalshake","_originalcourage","_general"];    

//Pistol and SMG  ammo to ignore   
tpw_mags =["30rnd_9x19_MP5",   
"30rnd_9x19_MP5SD",   
"15Rnd_9x19_M9",   
"15Rnd_9x19_M9SD",   
"7Rnd_45ACP_1911",   
"7Rnd_45ACP_1911",  
"8Rnd_9x18_Makarov",  
"8Rnd_9x18_MakarovSD",  
"64Rnd_9x19_Bizon",  
"64Rnd_9x19_SD_Bizon",  
"13Rnd_9mm_SLP",  
"17Rnd_9x19_glock17",  
"6Rnd_45ACP",  
"30Rnd_9x19_UZI",  
"30Rnd_9x19_UZI_SD"];  

//Main function  
tpw_ai_sup =    
{   
{  
   //hint format["accuracy = %1, shake = %2, courage = %3, general = %4",(ai skill "aimingaccuracy"),(ai skill "aimingshake"),(ai skill "courage"),(ai skill "general")]; // Dsiplay skills for unit named "AI"
   if (alive _x) then   
	{
	_unit = _x; 	
	_skillregain = _unit getvariable ["skillregain", -1];   
	_stanceregain = _unit getvariable ["stanceregain", -1]; 

	if (_stanceregain == -1) then   
		 {     
		_unit setvariable ["stanceregain", diag_ticktime]; 
		_unit setvariable ["skillregain", diag_ticktime];   
		_unit addeventhandler ["fired",{tpw_fired = _this select 0;tpw_mag = _this select 5; tpw_bullet = _this select 6}];  
		_originalaccuracy = _unit skill "aimingaccuracy"; 
		_unit setvariable ["originalaccuracy", _originalaccuracy];  
		_originalshake = _unit skill "aimingshake";  
		_unit setvariable ["originalshake", _originalshake]; 
		_originalcourage = _unit skill "courage"; 
		_unit setvariable ["originalcourage", _originalcourage];  
		_general = _unit skill "general"; 
		_unit setvariable ["general", _general]; 
		}; 

	if ( diag_ticktime >= _stanceregain) then   
		{  
		_unit setvariable ["supshots", 0];  
		_unit setunitpos "auto"; 
		_originalcourage = _unit getvariable "originalcourage"; 
		_general = _unit getvariable "general";   
		if((_unit skill "courage") < _originalcourage) then  
			{  
			_unit setskill ["courage",(_unit skill "courage")+(_general)*(0.003)];   
			}; 
		}; 

	if (diag_ticktime >= _skillregain) then  
		{ 
		_originalaccuracy = _unit getvariable "originalaccuracy";    
		_originalshake = _unit getvariable "originalshake";             
		_originalcourage = _unit getvariable "originalcourage"; 
		_general = _unit getvariable "general";       
		if((_unit skill "aimingaccuracy") < _originalaccuracy) then  
			{  
			_unit setskill ["aimingaccuracy",(_unit skill "aimingaccuracy")+((_originalaccuracy-(_unit skill "aimingaccuracy"))*.01)];   
			}; 
		if((_unit skill "aimingshake") < _originalshake) then  
			{  
			_unit setskill ["aimingshake",(_unit skill "aimingshake")+((_originalshake-(_unit skill "aimingshake"))*.01)];  
			};     
		}; 

	if !(isnull tpw_bullet) then   
		{  
		_bc = count ((getposatl _unit) nearobjects ["bulletbase",10]);  
		if (_bc > 0) then   
			{  
			if ((tpw_fired distance _unit) > 25) then   
				{  
				if !(tpw_mag in tpw_mags) then   
					{ 
				_unit setvariable ["skillregain", diag_ticktime + (random 4)-((_unit getvariable "general")+(_unit getvariable "originalcourage"))];   
					_unit setvariable ["stanceregain", diag_ticktime + 10];  
					_shots = _unit getvariable "supshots";  
					_unit setvariable ["supshots", _shots + _bc];  
					_shots = _unit getvariable "supshots"; 
					_originalaccuracy = _unit getvariable "originalaccuracy";   
					_originalshake = _unit getvariable "originalshake"; 
					_originalcourage = _unit getvariable "originalcourage";  
					_general = _unit getvariable "general";
					_unit setunitpos "middle"; 									
					if ((side tpw_fired != side _unit) && (vehicle _unit == _unit)) then   
						{
						_unit setskill ["aimingaccuracy",_originalaccuracy*_originalcourage*_general-(_shots*(1-_general)*.003)];  
						_unit setskill ["aimingshake",_originalshake*_originalcourage*_general-(_shots*(1-_general)*.003)]; 
						_unit setskill ["courage",_originalcourage*_originalcourage*_general-(_shots*(1-_general)*.003)]; 		
						if (_shots > 5) then  
							{ 
							_unit setunitpos "down"; 
							};  
						};   
					};  
				};  
			};  
		};  
	};   
   } foreach allunits;  
};  

//Call function using per frame eventhandler so computer doesn't explode  
[tpw_ai_sup,0] call cba_fnc_addPerFrameHandler;   

Units should react to projectiles from any infantry or vehicle now, but the actual skill suppression is only applied if the unit is not in a vehicle. Can't test this at work...

I also took the liberty of a bit of code cleanup and removed all the comments from the actual function (might speed it up incrementally, who knows).

Edited by tpw

Share this post


Link to post
Share on other sites
imagine being able to suppress a jet by shooting an assault rifle at it from the ground

Would it go prone?

What if you'd go with something like:

if ((side tpw_fired != _unit getVariable "SupSide") && (vehicle _x == _x)) then 

i.e Checking that only when it comes to actually apply suppressive effects?

Share this post


Link to post
Share on other sites

Back in ARMA days, second's suppression script use bullet type to determine suppression effects. So an AA type weapon like the ZU-23 can have a bigger effect suppressing the infantry. Though I cant remember if it can suppress vehicle or not...

But overall I think it should in some ways able to suppress the vehicle/static weapon...

Share this post


Link to post
Share on other sites
Would it go prone?

What if you'd go with something like:

if ((side tpw_fired != _unit getVariable "SupSide") && (vehicle _x == _x)) then 

i.e Checking that only when it comes to actually apply suppressive effects?

Great minds think alike mate! Check my edit

Share this post


Link to post
Share on other sites

Perhaps something else to consider would be unit resistance to suppression (i.e. SF), but this may be moving too far into Robalo territory.

Share this post


Link to post
Share on other sites
Perhaps something else to consider would be unit resistance to suppression (i.e. SF), but this may be moving too far into Robalo territory.

That's my thought. We want all these addons to get along with each other.

Once we are at proper release time, I'll probably make a "lite" version that does only stance changes and no other skill or behavioural stuff, so that it really stays out of the way of other AI mods.

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  

×