Jump to content
Sign in to follow this  
Kydoimos

Scripted Tank Fire

Recommended Posts

Hi - I'm trying to script a tank shooting at a target. I can get it to work, but the trouble is, the tank's firing doesn't have any animation from the main gun! It works ok when the play fires as gunner, or when the tank fires at the AI. The UseWeapon command however, doesn't trigger any smoke from the gun - very strange. Any ideas for a workaround? I've tried the doTarget and doFire commands but I haven't had much luck...

Share this post


Link to post
Share on other sites

Thanks Tankbuster - sort of of use - but the animation for the MBT's gun doesn't function with that command! There's no smoke or muzzle flash.

Share this post


Link to post
Share on other sites

Did you say the animation is seen if there's an AI gunner, or not? Didn't quite understand what you said in the first post?

Share this post


Link to post
Share on other sites

Hm, I simply use Fire. It seems to work fine.

Something like:

tank doWatch (getPos target);
tank fire ((weapons tank) select 0);

That should fire the MBT's main gun. Tested something similar just with Scorcher though.

Share this post


Link to post
Share on other sites

Ah, thanks Pete - that should do the trick. Weird why I couldn't get the barrel animation with the other method though!

---------- Post added at 19:59 ---------- Previous post was at 18:17 ----------

Works like a charm - mate, you're a star!

Share this post


Link to post
Share on other sites
Hm, I simply use Fire. It seems to work fine.

Something like:

tank doWatch (getPos target);
tank fire ((weapons tank) select 0);

That should fire the MBT's main gun. Tested something similar just with Scorcher though.

Very good this work well but i have just one shoot, can you plz tell me how get it shooting lot of times blind.

Thanks.

Share this post


Link to post
Share on other sites

The snippet you refer to is from a little script I use for partly random ambient vehicle fire. So far, I just tested it with the scorcher. It should be working with other tanks too but it might require some fine tuning regarding the parameters.

So to use it, create the script file and copy teh following. "ambientVehicleFire.sqf":

/*
Name: ambientVehicleFire
Author: IndeedPete
Purpose: Fires main gun of vehicle at partly random positions.
----------
Parameters:
_vehicle - OBJECT: Vehicle that fires. - myLittleTank
_target - OBJECT (OPTIONAL): Object to roughly fire at. - myLittleTarget - DEFAULT: player
_radius - NUMBER (OPTIONAL): Radius around _target. - 50 - DEFAULT: 200
_altitude - NUMBER (OPTIONAL): Altitude above _target. - 50 - DEFAULT: 1000
_delay - NUMBER (OPTIONAL): Delay between shots. - 25 - DEFAULT: 1
_cond - CODE (OPTIONAL): While condition, script runs as long as satisfied (and vehicle is alive.) - {alive player} - DEFAULT: {true}
*/

_vehicle = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_target = [_this, 1, player, [objNull]] call BIS_fnc_param;
_radius = [_this, 2, 200, [0]] call BIS_fnc_param;
_altitude = [_this, 3, 1000, [0]] call BIS_fnc_param;
_delay = [_this, 4, 1, [0]] call BIS_fnc_param;
_cond = [_this, 5, {true}, [{}]] call BIS_fnc_param;
_weapon = (weapons _vehicle) select 0;

_pos = getPos _target;
_targetX = _pos select 0;
_targetY = _pos select 1;
_targetZ = _pos select 2;

_vehicle disableAI "Target";
_vehicle disableAI "AutoTarget";

while {(alive _vehicle) && {call _cond}} do {
_vehicle setVehicleAmmo 1;

_gap = random _radius;
_direction = random 360;

_x = _targetX + ((cos _direction) * _gap);
_y = _targetY + ((sin _direction) * _gap);
_z = _targetZ + _altitude - _radius + random (_radius * 2);

_vehicle doWatch [_x, _y, _z];
_shots = round (random 12);

sleep (random 3);

for "_i" from 1 to _shots do {
	sleep _delay;
	_vehicle fire _weapon;
	//hint format ["%1 %2", _vehicle, _weapon];
};
};

Then make a function from it. Place the following in your "init.sqf" (or set up your functions library and add it):

IP_fnc_ambientVehicleFire = compile(preprocessFileLineNumbers "ambientVehicleFire.sqf");

Then place your tank (maybe a Scorcher) and a target (e.g. a Heli H) somewhere and call it like "IP_Arty1" and "IP_ArtyTarget1". Put in the tank's init field or your "init.sqf":

nul = [iP_Arty1, IP_ArtyTarget1, 100, 1000, 3] spawn IP_fnc_ambientVehicleFire;

Finally, let the magic happen or adjust the parameters as you see fit. ;)

  • 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
Sign in to follow this  

×