IRONFRONT FANS FORUM
Register Latest Topics
 
 
 


Reply
  Author   Comment  
Tayuk

Avatar / Picture

Admin
Registered:
Posts: 455
Reply with quote  #1 
Download AI Mortar script

Just looking through the scripts on Armaholic and I found this by Zonekiller and thought I'd give it a try on Ironfront, and its works, AI mortar teams now fire on spotted enemy. Only 1 problem noticed "How do you get close enough to take out the mortar team?, they are ruthless".

The package has 3 scripts needed all shown below and the functions module is required on the map.

This goes in the init field of the AI Mortar unit

Code:
 0 = this execVM "mortar.sqf";


Scripts are:-

Global_Guided_Code.sqf
Code:
// Script by Zonekiller -- http://zonekiller.ath.cx -- -- zonekiller@live.com.au --

_veh = _this select 0;
_missile = _this select 1;

if (!(local _veh) or (isplayer gunner _veh)) exitwith {};

_target = assignedTarget gunner _veh;

if ((isNull _target) or !(alive _target) or (isNull _missile) or (typeName _target != "OBJECT")) exitWith {};

waituntil {((((getpos _missile) select 2) > 90) or !(alive _missile))};


_homeMissile = {
private ["_velocityX", "_velocityY", "_velocityZ", "_target", "_missile", "_missileSpeed", "_travelTime"];

_missile = _this select 0;
_target = _this select 1;
_targetasl = _this select 2;
_missileSpeed = _this select 3;



if (_missile distance _target > (_missileSpeed / 20)) then
{
_travelTime = (_target distance _missile) / _missileSpeed;
_relDirHor = [_missile, _target] call BIS_fnc_DirTo;
_missile setDir _relDirHor;
_relDirVer = asin ((((getPosASL _missile) select 2) - (_targetasl select 2)) / (_target distance _missile));
_relDirVer = (_relDirVer * -1);
[_missile, _relDirVer, 0] call BIS_fnc_setPitchBank;

_velocityX = ((_targetasl select 0) - ((getPosASL _missile) select 0)) / _travelTime;
_velocityY = ((_targetasl select 1) - ((getPosASL _missile) select 1)) / _travelTime;
_velocityZ = ((_targetasl select 2) - ((getPosASL _missile) select 2)) / _travelTime;
};

[_velocityX, _velocityY, _velocityZ]
};


_posasl = ((getposASL _target) select 2);
_target1 = (gunner _veh) getHideFrom _target;
_targetasl = [_target1 select 0,_target1 select 1,_posasl];

_spd = 180;
_hgt = 50;

while {((alive _missile) && (_hgt > 5) && (alive _target))} do
{
_pos = position _missile;
_hgt = _pos select 2;

if ((alive _target) && (_hgt > 5) && (alive _missile)) then
{
_velocityForCheck = [_missile,_target1,_targetasl,_spd] call _homeMissile;
if ({(typeName _x) == (typeName 0)} count _velocityForCheck == 3) then {_missile setVelocity _velocityForCheck;};
};

sleep 1;
};


Global_Launch_Code.sqf
Code:
// Script by Zonekiller -- http://zonekiller.ath.cx -- -- zonekiller@live.com.au --


_veh = _this select 0;

if !(local _veh) exitwith {};

sleep 2;

while {canmove _veh} do
{

waituntil {((!isnull assignedTarget (gunner _veh)) && !(isplayer gunner _veh))};


_target = assignedTarget (gunner _veh);


//hint typeof _target;

sleep 1;
_delay = 2;
if ((alive _target) && (_target iskindof "LAND")) then {_veh fireAtTarget [_target];_delay = 7;};
sleep _delay;

_veh setVehicleAmmo 1;

};


Mortar.sqf
Code:
// Script by Zonekiller -- http://zonekiller.ath.cx -- -- zonekiller@live.com.au --

sleep 3;

_nil = [_this] execVM "Global_Launch_Code.sqf";
_this addEventHandler ["Fired", {_missile = nearestObject [_this select 0, _this select 4];[_this select 0,_missile] execVM "Global_Guided_Code.sqf"}];


gunner _this setUnitAbility 1;
gunner _this setskill 1;
gunner _this setSkill ["spotDistance", 1];
gunner _this setSkill ["spotTime", 1];

gunner _this setCombatMode "RED";
gunner _this setBehaviour "COMBAT";
0
Ringo

Private
Registered:
Posts: 10
Reply with quote  #2 
How do you use this Script?  When I try to use it is says mortar.sqf not found.
Do you have to combine all three parts into one file?  I made them into 3 different ones and added them to mission folder.
Put what you had for the init into the mortars' init line, and saved.  Started the mission and it gives me the error mortar.sqf not found if I did something wrong please let me know, thanx Ringo


P.S. I used a text document when I copied the scripts. don't know if that helps.  I also noticed people talking about some program that combines mission.sqm and the sqf's into one, do you have to do that?
0
Tayuk

Avatar / Picture

Admin
Registered:
Posts: 455
Reply with quote  #3 
The 3 files are separate files called Global_Guided_Code.sqf, Global_Launch_Code.sqf and Mortar.sqf and the all go in the same folder as your mission.sqm file so the very minimum your mission folder will have the above mentioned 4 files. But as mentioned previously the way scripts work in IF is exactly the same as it is in Arma2 so if your have done it in arma then just follow the same procedure and it will work.
Making the files with a text document is fine so long as the file name is the same as above and the file extension for the 3 scripts is .sqf and NOT .txt as a text document like notepad will do that as standard.
0
Ringo

Private
Registered:
Posts: 10
Reply with quote  #4 
Yeah figured it out man. Sorry dumbass moment!
As soon as I installed Arma edit and realized what I did I wanted to slap myself.  Thank you for the reply though.
0
Santa Six

Avatar / Picture

Colonel
Registered:
Posts: 360
Reply with quote  #5 
Will it work with a spotter leading the units?
0
Gunter Severloh

Avatar / Picture

Admin
Registered:
Posts: 2,749
Reply with quote  #6 
Now hosted on the MR
Download AI Mortar script


1st post updated with download.

__________________
0
Foxsch

Avatar / Picture

Colonel
Registered:
Posts: 454
Reply with quote  #7 
Would this work in A3?
__________________
Mission Repository - http://www.missionrepository.com

0
Gunter Severloh

Avatar / Picture

Admin
Registered:
Posts: 2,749
Reply with quote  #8 
Test it, but if anything ask Zonekiller on BIS forums, he could tell ya.
__________________
0
Foxsch

Avatar / Picture

Colonel
Registered:
Posts: 454
Reply with quote  #9 
I'll give it a shot (ignore the pun) and see if it works OK - I'll post back if it is working
__________________
Mission Repository - http://www.missionrepository.com

0
Foxsch

Avatar / Picture

Colonel
Registered:
Posts: 454
Reply with quote  #10 
That works just fine : -) 
__________________
Mission Repository - http://www.missionrepository.com

0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.