Jump to content
Sign in to follow this  
lax

Make AI Fire Weapon

Recommended Posts

Ok this is really starting to bug me. I am making a short movie using Camera.sqs in arma 2. The biggest problem I have is that I cant get the AI (a US army ranger with a thermal scoped .50 cal) to fire his weapon. I have used dotarget and dofire endlessly but nothing works. The closest i got was getting the AI to shoot a specific unit but when i activate the trigger, he crawls for about 10 minutes to "get into a better position" then fires while crawling like a complete idiot. I dont even need the ai to be shooting at anything I just need him to lay prone where I place him and fire the damn rifle. Anybody have any ideas? I think its pretty absurd that I cant get this dude to simply pull the trigger of his gun without crawling around and acting like a fool.

Share this post


Link to post
Share on other sites


Put the following in a radio trigger.
gameLogicName action ["useWeapon", vehicle unit1, unit1, 0];

http://community.bistudio.com/wiki/ArmA_2:_Actions#UseWeapon

You need a named game logic on the map (object type) and a sniper named unit1. Give the sniper a waypoint, type stealth to make him prone. If he moves about try a doStop this; in the snipers init.

Edited by PELHAM

Share this post


Link to post
Share on other sites

Put the following in a radio trigger.
gameLogicName action ["useWeapon", vehicle unit1, unit1, 0];

http://community.bistudio.com/wiki/ArmA_2:_Actions#UseWeapon

You need a named game logic on the map (object type) and a sniper named unit1. Give the sniper a waypoint, type stealth to make him prone. If he moves about try a doStop this; in the snipers init.

PERFECT. Absolutely perfect. thanks!

Share this post


Link to post
Share on other sites

Or a little easier...

In the unit's init:

doStop this; this setUnitPos "Down"; this doTarget [i]TARGETNAME[/i]; this doFire [i]TARGETNAME[/i]

;)

Share this post


Link to post
Share on other sites
Or a little easier...

In the unit's init:

doStop this; this setUnitPos "Down"; this doTarget [i]TARGETNAME[/i]; this doFire [i]TARGETNAME[/i]

;)

He is making a film and wants the unit to fire on que so that isn't the best method.

Share this post


Link to post
Share on other sites

Put the following in a radio trigger.
gameLogicName action ["useWeapon", vehicle unit1, unit1, 0];

http://community.bistudio.com/wiki/ArmA_2:_Actions#UseWeapon

You need a named game logic on the map (object type) and a sniper named unit1. Give the sniper a waypoint, type stealth to make him prone. If he moves about try a doStop this; in the snipers init.

This is very interesting but i cannot understand the code. I mean I need a M119 to shoot in a determinated position without stopping. How to do that? and I cannot understand the syntax.. what's "useWeapon" for? and unit1, unit1,0? And I'm obliged to use a radio trigger?

Share this post


Link to post
Share on other sites

Dofire targetname or this doTarget TARGETNAME;

was a command i remember in OFP, that still work?, haven't tried since OFP days.

replace useWeapon with the classname of the weapon your using, and then the vehicle unit1, unit1, are the targets which you need a name for.

the full wiki example:

UseWeapon

unitOne ["UseWeapon", <target vehicle>, <target unit>, <weapon index>]

Soldier 'unitOne' will play the action animation. Target unit will fire the specified unit's position in the target vehicle's (can be the unit itself) weapon mode index.

The indexes seem to be based upon the order in which weapons are added to the unit/vehicle, with each weapon's muzzle's fire mode having an unique index.

Weapons can be fired in this way from a not-readied position (eg, firing a rifle on a soldiers back). Pistols will fire from the current weapon's proxy.

It can also be used to sound the horn on AI controlled vehicles.

Examples: gameLogic action ["useWeapon",unit1,unit1,16] gameLogic action ["useWeapon",vehicle unit1,unit1,0] gameLogic action ["useWeapon",myTank,gunner myTank,1] gameLogic action ["useWeapon",myTank,commander myTank,0]

Try a script instead, might be easier for you.

heres a good one:

Artillery Support System Package - script version

http://www.armaholic.com/page.php?id=6783

or

Advanced Artillery Request System

http://www.armaholic.com/page.php?id=9056&highlight=ARTILLERY

or

ARTY - another simple artillery script

http://www.armaholic.com/page.php?id=15520&highlight=ARTILLERY

theres many of them, pick which one suite what your trying to do.

Edited by Gnter Severloh

Share this post


Link to post
Share on other sites

Ye thanks but I already know how to make an artillery support, But I need the M119 to shoot randomly for a scene of my mission :D

Anyway your two commands seem to don't work :(

Share this post


Link to post
Share on other sites
This is very interesting but i cannot understand the code. I mean I need a M119 to shoot in a determinated position without stopping. How to do that? and I cannot understand the syntax.. what's "useWeapon" for? and unit1, unit1,0? And I'm obliged to use a radio trigger?

Tested and working, radio trigger on Act:

parameters are: <target vehicle> action ["UseWeapon", <target vehicle>, <target unit>, <weapon index>]

http://community.bistudio.com/wiki/ArmA_2:_Actions#UseWeapon

man1 = gunner gun1; gun1 action ["useWeapon", gun1, man1, 0];

edit: better example:

gun1 action ["useWeapon", gun1, gunner gun1, 0];

For a battery of 3 guns (named gun1,gun2,gun3) try this - you need an Object H near them called target1:

parameters: nul = [targetName,[gunName1,gunName2,gunName3]] execVM "battery.sqf";

example: nul = [target1,[gun1,gun2,gun3]] execVM "battery.sqf";

_target = _this select 0;
_guns = _this select 1;
_target setPosATL [getPosATL _target select 0, getPosATL _target select 1, + 100];
{_x doWatch _target} foreach _guns;

sleep 4;
while {true} do {
{_x doWatch _target} foreach _guns;
{_x action ["useWeapon", _x, gunner _x, 0]; sleep 1;} foreach _guns;
};

Edited by PELHAM

Share this post


Link to post
Share on other sites

So I have to make a battery.sqf with the code that you typed? I cannot do that IG?

Share this post


Link to post
Share on other sites
So I have to make a battery.sqf with the code that you typed? I cannot do that IG?

I would use the script - it gives you much more control. Easy to do just put it in a text file renamed to battery.sqf and put:

nul = [target1,[gun1,gun2,gun3]] execVM "battery.sqf";

in a radio trigger or in a file called init.sqf

all the above gore in the mission folder.

Share this post


Link to post
Share on other sites

this is my battery.sqf in which target1 is the gamelogic object that I wanna use and gunner1 the name of the unit, then i changed the "_guns" with gun1 ( and to be honest I don't really know why).. it only aims to the target without shooting. Sorry I'm not good in scripting, I've just started to learn. What's the error here?

target1 = _this select 0;

gun1 = _this select 1;

target1 setPosATL [getPosATL target1 select 0, getPosATL target1 select 1, + 100];

{gunner1 doWatch target1} foreach gun1;

sleep 4;

while {true} do {

{gunner1 doWatch target1} foreach gun1;

{gunner1 action ["useWeapon", gunner1, gunner target1, 0]; sleep 1;} foreach gun1;

};

Share this post


Link to post
Share on other sites

This is what I use for ambient arty...Fatty's Ambient Artillery Tool. Guns fire live ammo!

Copy and paste this code into a file called faat.sqf and put it in your mission folder. See below for parameters.

You'll also need a target for the arty to shoot at. I use an invisible helipad approx 100m from the gun and using setPos have it hover about 300m in the air.

/*

fatty's ambient artillery tool (faat) version 1.0

by fatty


Forces an AI gun (e.g. cannon or rocket artillery) to fire at regular intervals at a defined target. Gunners will persist until out of ammo or dead.

CAUTION: the guns fire live ammo, so be careful where you aim!

Required Parameters:
Artillery Piece (object) - object to begin firing.
Target (object) - target at which the artillery piece will fire. Suggested target is an invisible H setPos'd several hundred metres above the gun.

Optional Parameters:
Delay (number) - delay between shots in seconds (default is 10 seconds).
Disable aiming AI (boolean) - prevents AI gunners from engaging other targets (default is true).
Enable auto-rearm (boolean) - enables automatic rearming of gun after every shot (default is false).

Examples:
nul = [big_gun, gun_target] execVM "faat.sqf";
nul = [rocket_artillery, house, 20, false, true] execVM "faat.sqf";
*/

if !(isServer) exitWith {};

private ["_gun","_target","_delay","_disableaim","_autorearm"];

_gun = _this select 0;
_target = _this select 1;
_delay = if (count _this > 2) then {_this select 2} else {10};
_disableaim = if (count _this > 3) then {_this select 3} else {true};
_autorearm = if (count _this > 4) then {_this select 4} else {false};


if (_disableaim) then {
{_gun disableAI "_x";} foreach [move,target,autotarget,anim];
_gun setCombatMode "BLUE";
};

(gunner _gun) lookAt _target;

_gun addEventHandler ["fired",{faatAmmoType = _this select 4;deleteVehicle (nearestObject [_this select 0, _this select 4]);}];

While {alive (gunner _gun)} do
{
sleep _delay;
_gun say "gerFire";
sleep 2;
_gun fire (weapons _gun select 0);
if (_autorearm) then {
	_gun setVehicleAmmo 1
};

};

_gun removeAllEventHandlers "fired";

Edited by SavageCDN

Share this post


Link to post
Share on other sites

THe problem is that I copy and paste the scripts but i don't understand what to change... I don't understand where to put an eventual unit name and other stuff like this one

Share this post


Link to post
Share on other sites
THe problem is that I copy and paste the scripts but i don't understand what to change... I don't understand where to put an eventual unit name and other stuff like this one

Using the faat.sqf script I posted (you shouldn't need to change anything within the script itself.. just add the editor units and their init lines as well as the targets):

Place an arty unit in editor

Put this code into the artillery unit's init line in the editor (and call the unit gun1)

nul = [gun1, target1, 20, true, true] execVM "faat.sqf";

gun1 = units name in editor

target1 = arty targets name in editor (for ambient arty I use an invisible Helipad object and set it's height at 300m).. this can be any object I think as long as you name it

20 = seconds between firing

1st true = prevents gunner from engaging other targets

2nd true = enables auto-rearming (ie: unlimited ammo)

Make sure the faat.sqf file is in your mission folder.

Share this post


Link to post
Share on other sites

I'll try and I'll let you know, many thanks, it seems more clear to me right now :D

---------- Post added at 21:04 ---------- Previous post was at 20:48 ----------

It doesn't work yet :( omg i'm getting crazy.. it asked for battery.sqf, i put it and now it still not working

Share this post


Link to post
Share on other sites

The instructions I posted are for the faat.sqf file, not the one you created called battery.sqf. What is the error you are getting?

You can try the faat.sqf script out in a new, clean mission with just the arty and stuff.. to see if it works.

Share this post


Link to post
Share on other sites
this is my battery.sqf in which target1 is the gamelogic object that I wanna use and gunner1 the name of the unit, then i changed the "_guns" with gun1 ( and to be honest I don't really know why).. it only aims to the target without shooting. Sorry I'm not good in scripting, I've just started to learn. What's the error here?

There are many mistakes in that which is why it doesn't work - I posted code for 1 gun in my 1st reply. (probably confused you with parameters for the action - target in that means target for the action code not the gun!)

Corrected it:

nul = [target1,gun1] execVM "battery.sqf";

_target = _this select 0;
_gun = _this select 1;
_target setPosATL [getPosATL _target select 0, getPosATL _target select 1, + 100];
_gun doWatch _target;
sleep 4;
while {true} do {
_gun doWatch _target;
_gun action ["useWeapon", _gun, gunner _gun, 0]; 
sleep 1;
};

Edited by PELHAM

Share this post


Link to post
Share on other sites
The instructions I posted are for the faat.sqf file, not the one you created called battery.sqf. What is the error you are getting?

You can try the faat.sqf script out in a new, clean mission with just the arty and stuff.. to see if it works.

It says "sound gerfire not found after about 10 seconds... and the cannon doesn't shoot :( I made a paste and copy of the code and I renamed the target "target1"( i didn't put it 300 meters above the ground, it is not a problem right?) and the m119 unit "gun1" and I put the code in the init field that you gave me.. but nothing happens

Share this post


Link to post
Share on other sites

I'm sorry my bad.. I grabbed that copy from an I44 mission which has custom german voices.

_gun say "gerFire";

sleep 2;

^ Remove these two lines or replace gerfire with a stock arma voice clip (this line is just for the crew to yell 'fire' before actually firing)

Share this post


Link to post
Share on other sites

It works!! Thanks god!!!! Thank you guys lol

Share this post


Link to post
Share on other sites

You're welcome. I'm not too sure if the target height actually matters.. I guess if your M119 is firing 'direct' at it rather than indirect you may have to set a height. I've only used this script for I44 stuff (mortars, flak guns)

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  

×