Jump to content
Sign in to follow this  
dragon zen

How to make AI artillery FireAtPosition BY Script in OA??Just like player's command

Recommended Posts

Hey friends:

Very simple question on artillery, but I didn't find out the solution because I don't need those complex script.

In OA, if you have Artillery in your squad, you can simply command that AI Fire At Position on map, right? Thanks BI, this is huge advance in comparison with AA2.

My question is, how to make an AI Fire At Position by the script I write? I can deal with all thing: mortar, AI, target and target position, doTarget or commandTarget, reveal and so on. But I just don't know how to let the AI Fire at that position, like player command. I think simple code is OK ,but don't know what is it.:o

Thanks a lot if any body could help me, :D

=================

Addition:

(1) I know how to use AA2's artillery module (http://community.bistudio.com/wiki/Artillery_Module), but in this way, Eventhandler "killed" can't return the name of mortar (just <object-Null>), that's why I need to artillery computer in OA.

(2) In that wiki page, it is said that "Do not load your static arty weapons with the magazines which have the "ARTY" prefix." and it is even unecessary to sync logic with mortar. However, nobody explain what is the script to use Artillery in OA ---- if I still use "BIS_ARTY_F_ExecuteTemplateMission", the ammo of mortar will become ARTY_ automatically. It is obvious that we should use other script, but what on earth is the script or code or variable for OA??

(3) In addtion to (2), the action "FireAtPositon" in menu, I don't know whether it is run in the same way as artillery module in AA2, or in a totally different way... In all, I'm quite confused here.......

Edited by Dragon Zen

Share this post


Link to post
Share on other sites

UP EVERYDAY...

I really need help with this issue, my mission just blocked here..............................

T_T

Share this post


Link to post
Share on other sites

You may want to look into onMapSingleClick, dotarget, DoFire & maybe even createvehicle :confused:

Share this post


Link to post
Share on other sites
UP EVERYDAY...

Don't recommend you do that. Not getting a reply in the day is usual. Plus that thing has been answered countless times.

Share this post


Link to post
Share on other sites
You may want to look into onMapSingleClick, dotarget, DoFire & maybe even createvehicle :confused:

Thanks for your answer, but I want to run it will script totally: without any command of player. I have target and mortar and so on, just need a code to fire.

---------- Post added at 09:13 AM ---------- Previous post was at 09:07 AM ----------

Don't recommend you do that. Not getting a reply in the day is usual. Plus that thing has been answered countless times.

Well, I'm sorry for that.

But are you sure this has been asked serveral times?? I searched the artillery issue but most of them use Artillery Module under AA2 (such as http://community.bistudio.com/wiki/Artillery_Module) or use very very complex script made by other gamers. Since in OA player's command is quite simple, I want to know how to make similar order with pure script.

However, By now, I really haven't found what I need. And I also concern whether it also need script just like old Artillery Module... So if u see the answer countless times, could you tell me some things about that? I'm really appreciated.

Share this post


Link to post
Share on other sites

If your not using the Arty modules then the following will make the AI fire the weapon.

gun1 action ["useweapon",gun1,gun1 turretUnit [0],0];

or

gl = gun1 fireAtTarget [target]

gl = game logic

gun1 = mortar

I don't think it will do what your expecting as AI in these units do not seem to be able to target an object even if you use dotarget.

They don't seem to have access to the Ballistic computer.

There may be a mod that enables this but I don't know what it was called.

In the past I would fire the weapon and then delete the shell using an Eventhandler and then just spawn the shell above the target.

Edited by F2k Sel

Share this post


Link to post
Share on other sites
If your not using the Arty modules then the following will make the AI fire the weapon.

Thanks bro, I try this code but AI didn't turn mortar and just shot a fire at default angle.

In fact, I can use Artillery Module. But in this way, EventHandler "killed" can't get the killer, reply a <object-Null> instead.

(http://community.bistudio.com/wiki/Artillery_Module) has pointed out that in OA, it is uneccesary to use Artillery Module with ARTY_ prefix ammo, but how to change the ammo?? If I use script in this page, the ammo will change to ARTY automatically.

So I just wondering how to use artillery computer with AI.

Share this post


Link to post
Share on other sites

Don't use a gamelogic as the target, use ArtilleryTargetE for a Blufor mortar (ArtilleryTargetW for Opfor).

Also they don't automatically change their fire mode, so if your taget is further than a few hundred meters, they'll miss. They'll still shoot with the "close" mode. You'll have to change them manually to medium or long rang range, and I'm not sure how to do that right now.

Share this post


Link to post
Share on other sites

The artillery computer for AI is the Artillery Module - that's the problem - it uses ARTY ammunition and it doesn't matter which ARTY mode you use - the gun doesn't fire a projectile from A to B. Both modes use spawning of the projectile. (either that or this isn't working properly, I tried both modes with tracking markers for the projectiles (addEventHandler Fired) and the shell seems to be deleted upon firing.)

http://community.bistudio.com/wiki/Artillery_Module#ARTY_Modes

Share this post


Link to post
Share on other sites

Possible solution here:

https://dev-heaven.net/issues/16071

Bug reporter found that an artillery magazine was not defined correctly so added a balistics table and registered the magazine with the Artillery Module. Not sure if this would work for non Arty ammo but it's worth a try. There is an example mission so it's possible to test it?

I get the same error when using:

["M119", "HE", "30Rnd_105mmHE_M119"] call BIS_ARTY_F_AddOrdnanceType;

Have fun lol.

Ballistics calculator which you may need to generate a correct table - location: \modules\ca\modules\ARTY\data

scriptName format ["%1ARTY\data\scripts\ARTY_calcBallistics.sqf (_this: %1)",_this];
// Ballistic table generator
// 
// Creates pre-rendered ballistic data for use with ARTY.


/*
//Run to get btab
_initSpeed = getNumber(configFile >> "cfgMagazines" >> "30Rnd_105mmHE_M119" >> "initSpeed");
_artilleryCharge = getNumber(configFile >> "cfgWeapons" >> "M119" >> "SINGLE3" >> "artilleryCharge");
if (_artilleryCharge > 0) then {_initSpeed = _initSpeed * _artilleryCharge};
_shell = getText(configFile >> "cfgMagazines" >> "30Rnd_105mmHE_M119" >> "ammo");
//_airFriction = -(getNumber(configFile >> "cfgAmmo" >> _shell >> "airFriction"));  //uncomment, comment below, get number, negative it
_airFriction = -0.00055;
_emin = 40;
_emax = 90;
_estep = 1;
_hmin = -1000;
_hmax = 1000;
_hstep = 200;

player globalChat format["%1 %2", _initSpeed, _airFriction];

mybtab = [_initSpeed, _airFriction, _emin, _emax, _estep, _hmin, _hmax, _hstep] call compile preprocessFileLineNumbers "bScripts\arty\calcBallistics.sqf";
mybtab = mybtab + [_hmin, _hmax, _hstep];

copyToClipboard str(mybtab);
hint "done";
*/


private ["_offsetTable", "_useOffsets", "_offsetIdx", "_useElevation", "_addTab", "_offsetEntry"];

_muzzle_velocity = _this select 0;
_airFriction = _this select 1;
_emin = _this select 2;
_emax = _this select 3;
_estep = _this select 4;
_hmin = _this select 5;
_hmax = _this select 6;
_hstep = _this select 7;

// Grab offset table if it exists. Offsets are used for calculating rocket artillery trajectories.
// The number of entries in the offset table must match the number of entries in the generated ballistic table,
// based on the elevation step value.

_useOffsets = false;
if (count _this >= 9) then
{
   _offsetTable = _this select 8;
   _offsetIdx = 0;
   _useOffsets = true;
};

_grav = -9.80665;                      // Gravity constant.
_fps = 60;                             // Frames per second for calculation.

// Stops
_minrange = 99999999;
_maxrange = 0;

// Initialize resultant set of data
_btab = [];
_elevation = 0;

for [{_elevation=_emin},{_elevation<=_emax},{_elevation=_elevation+_estep}] do {

	player globalChat format["_elevation: %1", _elevation];

       // Initial params
       _vgate = 0;
       _gaterng = 0;
       _x = 0;
       _y = 0.1;
       _vx = 0;
       _vy = 0;
       _ymax = 0;
       _xmax = 0;
       _vel = _muzzle_velocity;
       _fc = 0;
       _tof = 0;

       // Apply offsets and new elevation if they are being used.
       if (_useOffsets) then
       {
           _offsetEntry = _offsetTable select _offsetIdx;
           _x = _offsetEntry select 0;
           _y = _offsetEntry select 1;
           _useElevation = _offsetEntry select 2;
           _vel = _offsetEntry select 3;

           // Go to next table entry
           _offsetIdx = _offsetIdx + 1;
       } else // Otherwise just use the current elevation.
       {
           _useElevation = _elevation;
       };

       // Set t0 parameters
       _vx = _vel * cos(_useElevation);
       _vy = _vel * sin(_useElevation);
       _frame = 1 / _fps;

       _slices = [];
       _agate = _hmax;

       while {_y >= _hmin} do
       {

		//player globalChat format["_agate: %1", _agate];

           // Calculate next velocity frame
           _vx = _vx + (_vx * _vel * _airFriction * _frame);
           _vy = _vy + (_vy * _vel * _airFriction * _frame);
           _vy = _vy + (_grav * _frame);
           _vel = sqrt(_vx*_vx + _vy*_vy);

           // Increment positions
           _y = _y + (_vy * _frame);
           _x = _x + (_vx * _frame);

           // Record max altitude and range
           if (_y > _ymax) then
           {
               _ymax = _y;
           };
           if (_x > _xmax) then
           {
               _xmax = _x;
           };

           // Take slices

           if ((_y < _agate) && (_vy < 0) && (_agate >= _hmin)) then
           {
               while {_agate > _y} do {_agate = _agate - _hstep;};
               _slices = _slices + [[_x, _y, _fc*_frame]];
           };

           // Increment frame count.
           _fc = _fc + 1;
       };
       _xmax = _x;

       if (_xmax < _minrange) then
       {
               _minrange = _xmax;
       };
       if (_xmax > _maxrange) then
       {
               _maxrange = _xmax;
       };

       // Order slices lowest to highest
       _rSlices = [];
       for [{_a = count(_slices)-1;},{_a >= 0},{_a = _a - 1}] do
       {
           _rSlices = _rSlices + [_slices select _a];
       };

       // Put calculated rocket decay points into table if offsets are used.
       _addTab = [_elevation, _ymax, _rSlices];
       if (_useOffsets) then
       {
           _addTab set [3, _offsetEntry select 0]; // Rocket horizontal offset
           _addTab set [4, _offsetEntry select 1]; // Rocket vertical offset
           _addTab set [5, _offsetEntry select 2]; // Rocket elevation
           _addTab set [6, _offsetEntry select 3]; // Rocket velocity
       };

       _btab set [count _btab, _addTab];
};

[_btab, _minrange, _maxrange]

Edited by Mattar_Tharkari

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  

×