The function fn_artillery_plane has some issues with performance with the bomblauncher and
grenadelauncher. Now there is always some lag when such a projectile gets released from those pilons. The more you add the worst it gets. The reason is that for some reason somebody put a whole script in a waituntil evaluator. So when the plane fires all those events that got added fire. Suggestion for fix is move the eventhandler outside of the waituntil loop. I tried to upload a sqf or a txt file but that didn't work. So here is the code in a tag that also doesn't seem to work Example:
/*
File: custom_fn_artillery_plane.sqf
Author: Ethan Johnson
date: 2020-06-25
Last Update: 2022-01-31
Public: No
Description:
Spawns a plane with predetermined settings from the artillery module GUI
Parameter(s):
_i - Index of this plane's run [NUMBER]
_planeCfg - Plane config [CONFIG]
_vehicle_class - Plane className [STRING]
_start_pos - Start position for the run [ARRAY]
_end_pos - End position for the run [ARRAY]
_amount_index - Number of total runs [NUMBER]
_magazine - Array of magazines which will be fired from the vehicle [ARRAY]
_unit - Unit that called the artillery [OBJECT]
_illumination - Is the artillery run an illumination run [NUMBER]
Returns:
Function reached the end [BOOL]
Example(s):
[0, configfile >> "cfgvehicles" >> "aircraft_class", "aircraft_class", [0, 0, 0], [100, 100, 0], 0, ["rockets"], player, 0] call vn_fnc_artillery_plane
*/
params ["_i", "_planeCfg", "_vehicle_class", "_start_pos", "_end_pos", "_amount_index", "_magazine", "_unit", "_illumination"];
private _posATL = _start_pos;
private _pos = +_posATL;
_pos set [2, (_pos select 2) + getTerrainHeightASL _pos];
private _dir = _start_pos getDir _end_pos;
if (_start_pos distance2D _end_pos < 1) then {
_dir = 0
};
private _dis = 3000;
private _alt = 1000;
private _pitch = atan (_alt / _dis);
private _speed = 400 / 3.6;
private _duration = ([0, 0] distance [_dis, _alt]) / _speed;
// --- Create plane
private _planePos = [_pos, _dis, _dir + 180] call BIS_fnc_relPos;
_planePos set [2, (_pos select 2) + _alt];
private _planeSide = (getnumber (_planeCfg >> "side")) call BIS_fnc_sideType;
([_planePos, _dir, _vehicle_class, _planeSide] call bis_fnc_spawnVehicle) params ["_plane", "_planeCrew", "_planeGroup"];
_plane setPosASL _planePos;
_plane move ([_pos, _dis, _dir] call BIS_fnc_relPos);
_plane disableai "move";
_plane disableai "target";
_plane disableai "autotarget";
_plane setcombatmode "blue";
// make the AI captive if enabled
if (vn_artillery_captive) then {
{
_x setCaptive true
} forEach _planeCrew;
};
private _vectorDir = [_planePos, _pos] call BIS_fnc_vectorFromXToY;
private _velocity = [_vectorDir, _speed] call BIS_fnc_vectorMultiply;
_plane setVectorDir _vectorDir;
[_plane, -90 + atan (_dis / _alt), 0] call BIS_fnc_setPitchBank;
private _vectorUp = vectorUp _plane;
private _turret = allTurrets _plane;
{
private _turret = _x;
private _weapons = _plane weaponsTurret _turret;
{
private _weapon = _x;
if (_magazine findIf {
_x == _weapon
} <= -1) then
{
_plane removeWeaponTurret [_weapon, _turret];
};
} forEach _weapons;
} forEach _turret;
{
if (_foreachindex < count _magazine && {
(_magazine#_foreachindex) != ""
}) then
{
if (isClass (configfile >> "CfgMagazines" >> (_magazine#_foreachindex))) then {
_plane setPylonLoadout [_foreachindex + 1, _magazine#_foreachindex, true];
} else {
if (isClass (configfile >> "CfgWeapons" >> (_magazine#_foreachindex))) then {
private _magazines = getArray (configfile >> "CfgWeapons" >> (_magazine#_foreachindex) >> "magazines");
if (count _magazines >= 1) then {
_plane setPylonLoadout [_foreachindex + 1, _magazines#0, true];
} else {
_plane setPylonLoadout [_foreachindex + 1, "", true];
};
} else {
_plane setPylonLoadout [_foreachindex + 1, "", true];
};
};
} else {
_plane setPylonLoadout [_foreachindex + 1, "", true];
};
} forEach getPylonMagazines _plane;
{
// Passed through weapons will be added along with ammo
if (isClass (configfile >> "cfgWeapons" >> _x)) then {
private _turrets = allTurrets _plane;
if (count _turrets > 0) then {
_plane addWeaponTurret [_x, _turrets#0];
private _ammo = getArray (configfile >> "cfgWeapons" >> _x >> "magazines");
if (count _ammo > 0) then {
_plane addMagazineTurret [_ammo#0, _turrets#0];
};
};
};
} forEach _magazine;
private _target = createVehicle ["Land_HelipadEmpty_F", _start_pos, [], 0, "CAN_COLLIDE"];
_plane setVariable ["vn_target", _target];
// --- Approach
private _fire = [] spawn {
waitUntil {false}
};
private _fireNull = true;
private _time = time;
_plane addEventHandler ["Fired", {
params ["_plane", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
private _player = _plane getVariable ["vn_player", objNull];
if isMultiplayer then {
[_projectile, [_plane, _player]] remoteExecCall ["setShotParents", 2];
};
private _type = (_weapon call BIS_fnc_itemType)#1;
if (["bomblauncher", "grenadelauncher"] findIf { _x == _type } > -1) then {
[_projectile, _plane getVariable ["vn_target", objNull]] call vn_fnc_artillery_bomb_guide;
// [getPosASL _projectile,_projectile,_plane getVariable ["vn_target", objNull]] call BIS_fnc_EXP_camp_guidedProjectile;
};
}];
waitUntil{
private _fireProgress = _plane getvariable ["fireProgress", 0];
// --- set the plane approach vector
_plane setVelocityTransformation
[
_planePos, [_pos select 0, _pos select 1, (_pos select 2) + _fireProgress * 12],
_velocity, _velocity,
_vectorDir, _vectorDir,
_vectorUp, _vectorUp,
(time - _time) / _duration
];
_plane setVelocity velocity _plane;
_plane setVariable ["vn_player", _unit];
// --- fire!
if ((getPosASL _plane) distance _pos < 1000 && {
_fireNull && {
_illumination <= 0
}
}) then
{
_fireNull = false;
terminate _fire;
_fire = [_plane, _target, _illumination] spawn
{
params ["_plane", "_target", "_illumination"];
private _duration = 3;
private _time = time + _duration;
waitUntil
{
{
private _weapon = getText (configFile >> "CfgMagazines" >> _x >> "pylonWeapon");
private _type = (_weapon call BIS_fnc_itemType)#1;
if (["bomblauncher", "rocketlauncher", "grenadelauncher", "machinegun", "cannon"] findIf {
_x == _type
} > -1) then
{
// Non-aimed weapons use BIS_fnc_fire
[_plane, _weapon] call BIS_fnc_fire;
} else {
// Aimed weapons use fireAtTarget
_plane fireAtTarget [_target, _weapon];
};
} forEach getPylonMagazines _plane;
private _turret = allTurrets _plane;
{
private _turret = _x;
private _weapons = _plane weaponsTurret _turret;
{
private _type = (_x call BIS_fnc_itemType)#1;
if (["bomblauncher", "rocketlauncher", "grenadelauncher", "machinegun", "cannon"] findIf {
_x == _type
} > -1) then
{
// Non-aimed weapons use BIS_fnc_fire
[_plane, _x, _turret] call BIS_fnc_fire;
} else {
// Aimed weapons use fireAtTarget
_plane selectWeaponTurret [_x, _turret];
_plane fireAtTarget [_target, _x];
};
} forEach _weapons;
} forEach _turret;
_plane setvariable ["fireProgress", (1 - ((_time - time) / _duration)) max 0 min 1];
sleep 0.1;
time > _time || isNull _plane// --- Shoot only for specific period or only one bomb
};
sleep 1;
};
};
sleep 0.01;
scriptDone _fire || isNull _plane
};
_plane setVelocity velocity _plane;
_plane flyInHeight _alt;
if (_illumination > 0) then {
[_plane] spawn
{
params ["_plane"];
private _time = time + 10;
waitUntil {
time > _time
};
private _flare = createVehicle ["vn_flare_plane_med_w_ammo", getPosATL _plane, [], 0, "CAN_COLLIDE"];
_flare setVelocity [0, 0, -25];
};
};
deleteVehicle _target;
// --- fire CM
for "_u" from 0 to 1 do
{
driver _plane forceweaponfire ["CMFlareLauncher", "Burst"];
_time = time + 1.1;
waitUntil {
time > _time || isNull _plane
};
};
if (_i isEqualTo _amount_index) then {
["014", "Covey", _unit] call vn_fnc_artillery_message;
};
// prevent AI from engaging on it's own after the fire mission was completed
_planeGroup setBehaviour "CARELESS";
waitUntil {
_plane distance _pos > _dis || !alive _plane
};
// --- Delete plane
if (alive _plane) then {
private _group = group _plane;
private _crew = crew _plane;
deleteVehicle _plane;
{
deleteVehicle _x
} forEach _crew;
deleteGroup _group;
};
!<