Jump to content

Recommended Posts

Hello,

 

I am looking for a solution to an issue which troubles me greatly - AI going prone on contact. I guess all of us have experienced it before and know that once the AI changes combat mode, it instantly goes to the ground which is not always realistic, nor is it good for the players.

 

I have searched for a solution for some time now and most of the solutions suggested forcing AI to one specific stance, either by Zeus or by setUnitPos. Unfortunately, none of the solutions considered allowing the AI to either STAND or KNEEL, which is what I'm hoping for. Maybe there is a way to add an eventhandler of some sort which could override the PRONE stance with KNEEL, if possible. Otherwise, maybe it could just disable prone itself, leaving kneel and stand for the AI to choose normally.

 

I did find a semi-solution to this, which is using trigger areas and modules, which force the stance change of the AI within a trigger to whatever I set, however that's a) fixed to one stance, and b) always in zones that have been predefined by me, not dynamic in any way.

 

I lack enough experience to write something like this on my own, but I do feel like forbidding AIs PRONE stance only is possible - I just don't know exactly how to do it.

 

Will be grateful for any help!

Adam

  • Like 1

Share this post


Link to post
Share on other sites

I do this and it works ok, might be a better way though:
 

_unit addEventHandler ["AnimStateChanged",
{
	params ["_unit", "_anim"];
	if (canStand _unit && (behaviour _unit in ["AWARE","COMBAT"])) then {
	_unit setUnitPos "MIDDLE";
	};
}];

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

I think it should be better to disable prone only inside buildings.

 

NOT Tested !

//________________	Thanks to Killzone Kid for his tutorials	________________
//	http://killzonekid.com/category/tutorials/

KK_fnc_inHouse = {
    private ["_house"];
    _house = "";
	lineIntersectsSurfaces [
		getPosWorld _this, 
		getPosWorld _this vectorAdd [0, 0, 50], 
		_this, objNull, true, 1, "GEOM", "NONE"
	] select 0 params ["","","","_house"];
	if (_house isKindOf "House") exitWith {true};
	false
};
//	onEachFrame {hintSilent str (player call KK_fnc_inHouse)};


GF_Force_UnitPos = {
	
	while {true} do {
		
	if (
	(alive _this) 
	&& (!(underwater _this) or ((getPosASLW _this select 2) > -1.5))
	) then {	
					
		//________________	_inHouse	________________
			
		_inHouse = _this call KK_fnc_inHouse;
			
		if (_inHouse) then {
		
		if (canStand _this && (behaviour _this in ["AWARE","COMBAT"])) then {
		_this setUnitPos "MIDDLE";
		};
		
		sleep 3;
		}else{

		
		//________________	COMBAT	________________
		//	you can also add different cases ex:
          
		if((!(_inHouse)) && (behaviour _this == "COMBAT")) then {
			//	code 
			sleep 3;
			};
		
		};
			
		}else{
		_this setUnitPos "UP";
		sleep 10;	
		};
	};
};

//________________	spawn	_____________

[] spawn {
	while {true} do {
    _time = diag_tickTime + 15;	//	% sec
    _i = 0;
    waitUntil {
        _i = _i + 1;		
        diag_tickTime >= _time
    };
	   //	hint format ["Code executed %1 times per second", _i];	
	{	
		if (
		((alive _x))
		&& (!(_x getVariable ["Var_GF_Force_UnitPos",false]))		
		&& (!isPlayer _x)
		
		/*
		//________________	You can filter the side here	________________	
		&& {((side group _x) == west || 
			(side group _x) == east || 
			(side group _x) == independent || 
			(side group _x) == civilian || 
			(side group _x) == sideUnknown)}
		
		//	&& (side _x == playerSide)	// only for the Player side
		*/
				
		) then {
		//________________	You can filter here	________________

		_x spawn GF_Force_UnitPos;
		};								
		_x setVariable ["Var_GF_Force_UnitPos",true];

		{waitUntil {!alive _x};
		_x setVariable ["Var_GF_Force_UnitPos",false];
		};
	}forEach allUnits;
	};
};

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

George your solution is better and more elaborate but I think triggering it via the animchanged EH rather than having it in a loop would be better for optimization.

  • Thanks 1

Share this post


Link to post
Share on other sites
16 minutes ago, Mr H. said:

triggering it via the animchanged EH rather than having it in a loop would be better for optimization.

 

It's always better using the EH ,

but generally if you want to apply this to the spawned units then , so else it needs the script to loop.

If not then , sure the wise choice is to use off course the EH.

Share this post


Link to post
Share on other sites

Wow, thanks for so many responses guys! I took a look at all of them and I indeed needed something that would work for spawned units as well, so I could not just assign a scirpt to a specific group.

The solution from @.kju works flawlessly - I made a small local mod out of it and works like a charm!

 

I may try out @GEORGE FLOROS GR's solution too, as in some missions I actualy may want the AI to lie down except for buildings - thanks for sharing the script man!

 

Thanks all for your help - that's a big thing!

  • Thanks 1

Share this post


Link to post
Share on other sites
16 minutes ago, Dj Rolnik said:

The solution from @.kju works flawlessly -

 

The 1st one or the second ?

would you like to upload this?

Thanks Dj Rolnik !

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, GEORGE FLOROS GR said:

 

The 1st one or the second ?

would you like to upload this?

Thanks Dj Rolnik !

 

They're basically the same things, just one is a big discussion on the BI Forums and the other is a repost on Reddit. Sure, I can share this, no problem. Unfortunately I am not sure how to attach files to posts, so had to generate a link, sorry for that... I left out the raw folder just for ease of modification :)

 

https://www68.zippyshare.com/v/HdEQcsCw/file.html - it's a whopping 866 bytes so shows as 0 MB ^^

 

Otherwise, it's just a config.cpp containing the below code from @.kju's first link - packed into a PBO.

class CfgSurfaces {
	class Default {
		AIAvoidStance = 2;
	};
};

Thanks again!

  • Like 3

Share this post


Link to post
Share on other sites
1 minute ago, Dj Rolnik said:

Thanks again!

 

Thank you very much Dj Rolnik !  :thumb:

  • Like 1

Share this post


Link to post
Share on other sites

I was checking , what is the default action indoors and they don't seem to pnone .

Basically i remember when i was playing , some time ago ( because now i don't ! ) that the ai were doing this , but i didn't notice anything now.

Might this changed ?

 

Here is also a pic:

ZOeQeZI.png

Share this post


Link to post
Share on other sites

I have no idea if you ask me - it may well be the case that it was just fixed somewhere on the way : )

  • Haha 1

Share this post


Link to post
Share on other sites
On 10/1/2019 at 11:36 AM, GEORGE FLOROS GR said:

Can someone confirm this ?

Thanks !

Spoiler
On 10/1/2019 at 2:49 AM, GEORGE FLOROS GR said:

I was checking , what is the default action indoors and they don't seem to pnone .

Basically i remember when i was playing , some time ago ( because now i don't ! ) that the ai were doing this , but i didn't notice anything now.

Might this changed ?

 

Here is also a pic:

ZOeQeZI.png

@.kju

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

×