Jump to content
Alek10

AI shooting at training target

Recommended Posts

Hello. I know there is a lot of threads like this, but I can't find anyone that helps me.

What I want is some AI's standing and shooting at some training target. And I want them to keep doing it. So it needs to be in a loop and with infinite ammo.

And please tell me the full code, I suck at this...

Hope someone will help me :-)

Share this post


Link to post
Share on other sites

That only makes him target it. He don't shoot. Not even if I put "man2 doFire target2" after doTarget

Share this post


Link to post
Share on other sites

Yea that's what I was afraid of, the doFire command wiki does state that it does not work with objects, but the doTarget command does not state that. But at this point I'm not quite sure how to do what you need, hopefully someone else will pick it up from this point.

Share this post


Link to post
Share on other sites

name your target targ1,targ2,targ3

place this in the units init box

this addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}]; 
null=this spawn {
while {alive _this} do {
targ=[targ1,targ2,targ3] call BIS_fnc_selectRandom;
_this dotarget targ;
sleep 4;
_this fire (currentWeapon _this)};
};

Share this post


Link to post
Share on other sites
name your target targ1,targ2,targ3

place this in the units init box

this addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}]; 
null=this spawn {
while {alive _this} do {
targ=[targ1,targ2,targ3] call BIS_fnc_selectRandom;
_this dotarget targ;
sleep 4;
_this fire (currentWeapon _this)};
};

Thank you very much.. Is there a way to make them keep target the target if they only have one?

  • Like 1

Share this post


Link to post
Share on other sites

Hmm. never worked with popup targets. Idk if they have alive state or animations etc. Anyhow, this is what I've to contribute. A mere idea :p

_unit addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}]; 
_targetArray = allMissionObjects "TargetBase";

while {alive _unit} do {
_aliveArray = [];    
{
	if ( ( animationState _x ) == "") then {
		_aliveArray pushBack _x;
	};
} foreach _targetArray;

_rantarget = _aliveArray call BIS_fnc_selectRandom;
_unit dotarget _rantarget;
sleep 4;
_unit fire (currentWeapon _unit);
};

Share this post


Link to post
Share on other sites
Hmm. never worked with popup targets. Idk if they have alive state or animations etc.

I messed with them a while back. Don't remember 100% off hand but the animationPhase responsible for popping up and down is "terc", and yes they do have an alive state and damage values too.

Share this post


Link to post
Share on other sites
Hmm. never worked with popup targets. Idk if they have alive state or animations etc. Anyhow, this is what I've to contribute. A mere idea :p

_unit addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}]; 
_targetArray = allMissionObjects "TargetBase";

while {alive _unit} do {
_aliveArray = [];    
{
	if ( ( animationState _x ) == "") then {
		_aliveArray pushBack _x;
	};
} foreach _targetArray;

_rantarget = _aliveArray call BIS_fnc_selectRandom;
_unit dotarget _rantarget;
sleep 4;
_unit fire (currentWeapon _unit);
};

The code that F2k Sel wrote works fine with popup targets.. I would just like if they would keep target the target. Like always point the weapon at it so I can make them only have 1 sek sleep

Share this post


Link to post
Share on other sites

this addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}]; 
null=[this,targ1] spawn {
_unit = _this select 0;
while {alive _unit} do {
//targ=[targ1,targ2,targ3] call BIS_fnc_selectRandom;
_unit dotarget (_this select 1);
sleep 4;
_unit fire (currentWeapon _unit)};
}; 

you can replace [this,targ1] with unit name and the target name that so it can work for multiple units

Share this post


Link to post
Share on other sites
The code that F2k Sel wrote works fine with popup targets.. I would just like if they would keep target the target. Like always point the weapon at it so I can make them only have 1 sek sleep

Ahh okay. I thought you wanted the unit to only aim and shoot at valid targets. eg; ones that weren't already knocked over.

Edited by Iceman77

Share this post


Link to post
Share on other sites
this addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}]; 
null=[this,targ1] spawn {
_unit = _this select 0;
while {alive _unit} do {
//targ=[targ1,targ2,targ3] call BIS_fnc_selectRandom;
_unit dotarget (_this select 1);
sleep 4;
_unit fire (currentWeapon _unit)};
}; 

you can replace [this,targ1] with unit name and the target name that so it can work for multiple units

You mean like [man2,targ1] ? It dosn't work. I can't "save" the unit with that code in init. Not with [this,targ1] either ?

(The target is called targ1, 2, 3 etc

Share this post


Link to post
Share on other sites

this addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}]; 
null=[man2,targ1] spawn {
_unit = _this select 0;
while {alive _unit} do {
_unit dotarget (_this select 1);
sleep 4;
_unit fire (currentWeapon _unit)};
}; 

I removed //targ=[targ1,targ2,targ3] call BIS_fnc_selectRandom;

and it works for me.

Share this post


Link to post
Share on other sites
On 10/30/2014 at 5:00 AM, f2k sel said:

 


this addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}]; 
null=[man2,targ1] spawn {
_unit = _this select 0;
while {alive _unit} do {
_unit dotarget (_this select 1);
sleep 4;
_unit fire (currentWeapon _unit)};
}; 
 

 

Thanks it works for me

Share this post


Link to post
Share on other sites

Hi!

I've tried the code above on a squad at shooting range. Everything workes fine, then after a few minutes of shooting, they start waving all around. In the end they turn 360 degrees and shoot everything around at random.

I also added unit1 setDir 30; unit1 setFormDir 30;// needed for AI to keep the given direction

But it doesn't help.

Any ideas? I'm using Advanced AI Command, CBA_A3 and Vcom AI V3.0 - Could that be conflict? Or does the AI just behave like this?

 

Best regards

 

Share this post


Link to post
Share on other sites

No it's an issue with the game engine, it seems to get target overload.

At the time there was no efficient way to clear the targets from memory, we now have the forgettarget command which seems to help.

try placing it after the fire command.

_unit forgetTarget (_this select 1); 

 

They still can't hit the target very well though.

Share this post


Link to post
Share on other sites
16 hours ago, brynjard said:

Hi!

I've tried the code above on a squad at shooting range. Everything workes fine, then after a few minutes of shooting, they start waving all around. In the end they turn 360 degrees and shoot everything around at random.

I also added unit1 setDir 30; unit1 setFormDir 30;// needed for AI to keep the given direction

But it doesn't help.

Any ideas? I'm using Advanced AI Command, CBA_A3 and Vcom AI V3.0 - Could that be conflict? Or does the AI just behave like this?

 

Best regards

 

 

That's the reason why I added some lines to make the unit look at the target.

See this post.

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×