Jump to content
Sign in to follow this  
-Coulum-

Ai suppression script help

Recommended Posts

@DeltaFiveOne: the last PBO's work very well if you don't want to mess with the latest scripts in the editor; I'm sure that there will be updates to the PBOs soon. As for PBOing for your own use, that's within the forum rules AIUI - as long as you don't distribute them without author permission.

Thank you Orcinus! Where can I get the PBO at, I've searched and searched but haven't found them yet? I only see script spoilers on the OP's first post?

---------- Post added at 03:26 PM ---------- Previous post was at 03:16 PM ----------

Nvm, had to dig deeper into the spoilers. Got it.

Share this post


Link to post
Share on other sites
Thank you Orcinus! Where can I get the PBO at, I've searched and searched but haven't found them yet? I only see script spoilers on the OP's first post?

---------- Post added at 03:26 PM ---------- Previous post was at 03:16 PM ----------

Nvm, had to dig deeper into the spoilers. Got it.

Great.

For anyone else, here are the links I used:

http://www.gamefront.com/files/21867464 - distance-based

http://www.gamefront.com/files/21867465/%40TPWC_AI_SUPPRESS_S.zip - side-based

Share this post


Link to post
Share on other sites

So I'm about an hour away from a full configurable PBO version. In the mean time, what I've done is consolidate everything into a single script, which can be set to run either basic, light or full -coulum- kitchen sink suppression. As a bonus, it's now easily configurable. For the PBO I will move the configuration out to an hpp file in userconfig.

And, I've unilaterally (and unimaginatively) christened it TPWC AI SUPPRESSION

Script:

/*
TPWC AI SUPPRESSION

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

////////////
//VARIABLES
///////////

//Suppression type. 1 = basic , 2 = light, 3 = full  
tpwc_ai_sup_type = 3;  

//Delay before suppression functions start. Allows time for other AI mods to set unit skills
tpwc_ai_sup_sleep = 25;

//Debugging. Will display red balls over any suppressed units. Set to 1 for debugging
tpwc_ai_sup_debug = 0;

//Bullet detection radius (m). Bullets must pass within this distance of unit to suppress them. If set much below 10m, bullets may not be detected
tpwc_ai_sup_br = 10;

//Bullet ignore radius (m). Bullets from a shooter closer than this will not suppress. 
tpwc_ai_sup_ir = 25;

//Shot threshold. More shots than this will cause unit to drop/crawl
tpwc_ai_sup_st = 5;

//Pistol and SMG ammo to ignore. Add custom ammo (eg suppressed) or change to taste    
tpwc_ai_sup_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"];  

//////////
// SET UP
//////////

//Declare private variables
private ["_stanceregain","_skillregain","_unit","_bc","_shots","_originalaccuracy","_originalshake","_originalcourage","_general","_ball"]; 

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

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


//////////////////
// MAIN FUNCTIONS 
////////////////// 

//Basic version
tpwc_ai_sup_basic =    
{  
   {  
   if (alive _x) then   
       {
       _unit = _x;     
       _stanceregain = _unit getvariable ["stanceregain", -1]; 

       if (_stanceregain == -1) then   
           {     
           _unit setvariable ["stanceregain", diag_ticktime]; 
           _unit addeventhandler ["fired",{tpwc_ai_sup_fired = _this select 0;tpwc_ai_sup_bullet = _this select 6}];  
           _ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["supball",_ball];
		}; 

       if ( diag_ticktime >= _stanceregain) then   
           { 
		_ball = _unit getvariable "supball"; _ball hideobject true; 		
           _unit setvariable ["supshots", 0];  
           _unit setunitpos "auto"; 
           }; 

       if !(isnull tpwc_ai_sup_bullet) then   
           {  
           _bc = count ((getposatl _unit) nearobjects ["bulletbase",tpwc_ai_sup_br]);  
           if (_bc > 0) then   
               { 
               if ((tpwc_ai_sup_fired distance _unit) > tpwc_ai_sup_ir) then   
                   {  
                  	_unit setvariable ["stanceregain", diag_ticktime + 10];  
				_shots = _unit getvariable "supshots";  
				_unit setvariable ["supshots", _shots + _bc];  
				_shots = _unit getvariable "supshots"; 
				_unit setunitpos "middle";
				if (tpwc_ai_sup_debug == 1) then 
					{
					_ball = _unit getvariable "supball";_ball hideobject false;
					};			
				if (_shots > tpwc_ai_sup_st) then  
					{ 
					_unit setunitpos "down"; 
					};  
                   };  
               };  
           };  
       };   
   } foreach allunits;  
};  

//Lite version
tpwc_ai_sup_ai_sup_lite =    
{   
   {  
   if (alive _x) then   
       {
       _unit = _x;     
       _stanceregain = _unit getvariable ["stanceregain", -1]; 

       if (_stanceregain == -1) then   
           {     
           _unit setvariable ["stanceregain", diag_ticktime]; 
           _unit addeventhandler ["fired",{tpwc_ai_sup_fired = _this select 0;tpwc_ai_sup_mag = _this select 5; tpwc_ai_sup_bullet = _this select 6}];  
           _ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["supball",_ball];
		}; 

       if ( diag_ticktime >= _stanceregain) then   
           { 
		_ball = _unit getvariable "supball"; _ball hideobject true; 			
           _unit setvariable ["supshots", 0];  
           _unit setunitpos "auto"; 
           }; 

       if !(isnull tpwc_ai_sup_bullet) then   
           {  
           _bc = count ((getposatl _unit) nearobjects ["bulletbase",tpwc_ai_sup_br]);  
           if (_bc > 0) then   
               { 
               if ((tpwc_ai_sup_fired distance _unit) > tpwc_ai_sup_ir) then   
                   {  
                   if !(tpwc_ai_sup_mag in tpwc_ai_sup_mags) then   
                       { 
					_unit setvariable ["stanceregain", diag_ticktime + 10];  
                       _shots = _unit getvariable "supshots";  
                       _unit setvariable ["supshots", _shots + _bc];  
                       _shots = _unit getvariable "supshots"; 
                       _unit setunitpos "middle";                                     
                       if ((side tpwc_ai_sup_fired != side _unit) && (vehicle _unit == _unit)) then   
                           {
						if (tpwc_ai_sup_debug == 1) then 
							{
							_ball = _unit getvariable "supball";_ball hideobject false;
							};
                           if (_shots > tpwc_ai_sup_st) then  
                               { 
                               _unit setunitpos "down"; 
                               };  
                           };   
                       };  
                   };  
               };  
           };  
       };   
   } foreach allunits;  
};  

//Full version
tpwc_ai_sup_full =    
{   
   {  
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",{tpwc_ai_sup_fired = _this select 0;tpwc_ai_sup_mag = _this select 5; tpwc_ai_sup_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]; 
           _ball = "Sign_sphere25cm_EP1" createvehicle getposatl _unit;_ball attachTo [_unit,[0,0,2]]; _unit setvariable ["supball",_ball];
		}; 

       if ( diag_ticktime >= _stanceregain) then   
           { 
		_ball = _unit getvariable "supball"; _ball hideobject true;		
           _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 tpwc_ai_sup_bullet) then   
           {  
           _bc = count ((getposatl _unit) nearobjects ["bulletbase",tpwc_ai_sup_br]);  
           if (_bc > 0) then   
               { 
               if ((tpwc_ai_sup_fired distance _unit) > tpwc_ai_sup_ir) then   
                   {  
                   if !(tpwc_ai_sup_mag in tpwc_ai_sup_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 tpwc_ai_sup_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 (tpwc_ai_sup_debug == 1) then 
							{
							_ball = _unit getvariable "supball";_ball hideobject false;
							};						
                           if (_shots > tpwc_ai_sup_st) then  
                               { 
                               _unit setunitpos "down"; 
                               };  
                           };   
                       };  
                   };  
               };  
           };  
       };   
   } foreach allunits;  
};  

//CALL APPROPRIATE FUNCTION USING PER FRAME EVENTHANDLER SO COMPUTER DOESN'T EXPLODE  
if (tpwc_ai_sup_type == 1) then {[tpwc_ai_sup_basic,0] call cba_fnc_addPerFrameHandler};  
if (tpwc_ai_sup_type == 2) then {[tpwc_ai_sup_lite,0] call cba_fnc_addPerFrameHandler}; 
if (tpwc_ai_sup_type == 3) then {[tpwc_ai_sup_full,0] call cba_fnc_addPerFrameHandler};

Share this post


Link to post
Share on other sites
So I'm about an hour away from a full configurable PBO version. In the mean time, what I've done is consolidate everything into a single script, which can be set to run either basic, light or full -coulum- kitchen sink suppression. As a bonus, it's now easily configurable. For the PBO I will move the configuration out to an hpp file in userconfig.

And, I've unilaterally (and unimaginatively) christened it TPWC AI SUPPRESSION

So is the addon going to be one pbo with many options that you can set via userconfig - kinda like asr? That would be really great.

I finally got the chance to actually give this script a test in a mission, along with asr and the line of sight mod, and I must say, ai battles are a much better experience. more responsive fighting, less micromanaging stances, longer firefights and higher skilled units are much better fighters than lower skilled ones, yet are still unable to "insta headshot" their enemies. One thing I found particularly awesome is that there is flow to combat. If you start to lose fire-superiority enemy fire will start to zero in on your position and casualties will start racking up - but if you keep up the suppressive fire you have a pretty good chance of being safe. There is also no excuse for "the ai is too accurate!". If they are too accurate it means you aren't suppressing them properly.

I know things always look shiny when they're new, but I am very impressed so far. Great job tpw.

Share this post


Link to post
Share on other sites

Absolutely epic Coulum. If you ever need a tester, especially for a dedicated server or mixing it with other scripts/mods (like ASR, Zeus) then I'm all for it.

Share this post


Link to post
Share on other sites

@-Coulum-

+1, concur with everything you said. Combat has never been this good (& I haven't even added the LOS yet :) )

Excellent job by both of you.

Share this post


Link to post
Share on other sites

Slightly off-topic but quite useful for the code writers out here: updated notepad++ syntax high lighting

http://forums.bistudio.com/showthread.php?91939-Notepad-SQF-syntax-highlight&p=2181113&viewfull=1#post2181113

(hmm sorry for cross-post - was supposed to be in other thread but won't harm here either)

Edited by Ollem

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  

×