Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
cklymowsky

HOW to designate multiple laser guided bombs to multiple LaserTargets?

Recommended Posts

HI All,

 

I have 3 planes flying in and releasing 4 laser guided bombs each, and I have created a laser target for each bomb spread apart, but only the first two bombs hits their laser target while the remain 10 seem to just drop too early and ignore any of the other laser targets?

 

Any ideas on how I can make the bombs guide towards the string of laserTargets?

 

 

 

Quote

// Get variables from vehicle selected

private ["_planeClass","_planeCfg","_weaponTypesID","_weaponTypes","_weapons","_modes","_mode","_posATL","_pos","_dir","_dis","_pitch","_speed",
"_duration","_planePos","_planeSide","_planeArray","_plane","_vectorDir","_velocity","_vectorUp","_currentWeapons","_fire","_fireNull","_time",
"_offset","_fireProgress","_crew"];

	/*
	Parameters:
	0 - Position to be hit
	1 - Direction of approach
	2 - Type of plane (Options: "B_Plane_CAS_01_F", "O_Plane_CAS_02_F", "I_Plane_Fighter_03_CAS_F")
	3 - Weapon type (0 = Guns, 1 = Missles, 2 = Both)
	*/

_planeClass = _this select 2;
_planeCfg = configfile >> "cfgvehicles" >> _planeClass;


//--- Detect gun
_weaponTypesID = _this select 3;
_weaponTypes = switch _weaponTypesID do {
    case 0: {["machinegun"]};
    case 1: {["missilelauncher"]};
    //case 2: {["machinegun","missilelauncher","rocketlauncher","bomblauncher","magazine"]};
	case 2: {["bomblauncher"]};
    default {[]};
};
_weapons = [];
{
    if (tolower ((_x call bis_fnc_itemType) select 1) in _weaponTypes) then {
        _modes = getarray (configfile >> "cfgweapons" >> _x >> "modes");
        if (count _modes > 0) then {
            _mode = _modes select 0;
            if (_mode == "this") then {_mode = _x;};
            _weapons set [count _weapons,[_x,_mode]];
        };
    };
} foreach getarray (_planeCfg >> "weapons");

//hint format ["_weaponTypes \n %1 \n \n getarray (_planeCfg >> ""weapons"") \n %2 \n \n _weapons \n %3",_weaponTypes, getarray (_planeCfg >> "weapons"), _weapons];

_posATL = _this select 0;
_pos = +_posATL;
_pos set [2,(_pos select 2) + getterrainheightasl _pos];
_dir = _this select 1;


_dis = 3000;
_alt = 1000;
_pitch = atan (_alt / _dis);
_speed = 400 / 3.6;
_duration = ([0,0] distance [_dis,_alt]) / _speed;


//--- Create plane
_planePos = [_pos,_dis,_dir + 180] call bis_fnc_relpos;
_planePos set [2,(_pos select 2) + _alt];
_planeSide = (getnumber (_planeCfg >> "side")) call bis_fnc_sideType;
_planeArray = [_planePos,_dir,_planeClass,_planeSide] call bis_fnc_spawnVehicle;
_plane = _planeArray select 0;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// assign correct value to each object in veh list for RepairRearmFlip
{
	__x =_x;    
	{
		if  (( typeof _x) in __x ) then {_x setvariable ["value",(__x select 0),true];};  
	} foreach  allunits+vehicles+allUnitsUAV;  
} foreach veh; 

_vehKilledEH = _plane addeventhandler ["killed",{_this spawn BEAKS_fnc_reward_veh}];
{
	_pilotKilledEH = _plane addeventhandler ["killed",{_this spawn BEAKS_fnc_reward_inf}];
}forEach crew _plane;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

_plane setposasl _planePos;
_plane move ([_pos,_dis,_dir] call bis_fnc_relpos);
_plane disableai "move";
_plane disableai "target";
_plane disableai "autotarget";
_plane setcombatmode "blue";


_vectorDir = [_planePos,_pos] call bis_fnc_vectorFromXtoY;
_velocity = [_vectorDir,_speed] call bis_fnc_vectorMultiply;
_plane setvectordir _vectorDir;
[_plane,-90 + atan (_dis / _alt),0] call bis_fnc_setpitchbank;
_vectorUp = vectorup _plane;


//--- Remove all other weapons
/*
_currentWeapons = weapons _plane;
{
    if !(tolower ((_x call bis_fnc_itemType) select 1) in (_weaponTypes + ["countermeasureslauncher"])) then {
        _plane removeweapon _x;
    };
} foreach _currentWeapons;
*/

//--- Approach
_fire = [] spawn {waituntil {false}};
_fireNull = true;
_time = time;
_offset = if ({_x == "missilelauncher"} count _weaponTypes > 0) then {20} else {0};

//--- Create laserTargets
_laserSideType = "";
_laser = objNull;	
_arrow = objNull;
_laserArray = [];
_arrowArray = [];
if (playerSide == WEST) then {_laserSideType = "LaserTargetW"} else {_laserSideType = "LaserTargetE"};
for "_i" from 0 to 3 do {
	_laser = _laserSideType createVehicle [(_pos select 0)+(sin _dir)*_i*5,(_pos select 1)+(cos _dir)*_i*5,(_pos select 2)];	//LaserTargetE
	_arrow = "Sign_Arrow_F" createVehicle [(_pos select 0)+(sin _dir)*_i*5,(_pos select 1)+(cos _dir)*_i*5,(_pos select 2)];	
	_laserArray pushBack _laser;
	_arrowArray pushBack _arrow;
};

waituntil {
    _fireProgress = _plane getvariable ["fireProgress",0];


    //--- set [5,_Total]he plane approach vector
    _plane setVelocityTransformation [
        _planePos, [_pos select 0,_pos select 1,(_pos select 2) + _offset + _fireProgress * 12],
        _velocity, _velocity,
        _vectorDir,_vectorDir,
        _vectorUp, _vectorUp,
        (time - _time) / _duration
    ];
    _plane setvelocity velocity _plane;

    //--- Fire!
    if ((getposasl _plane) distance _pos < 1000 && _fireNull) then {
        _fireNull = false;
        terminate _fire;
        _fire = [_plane,_weapons] spawn {
            private ["_plane","_planeDriver","_weapons","_duration","_time"];
            _plane = _this select 0;
            _planeDriver = driver _plane;
            _weapons = _this select 1;
            _duration = 3;
            _time = time + _duration;
            waituntil {
                {
                    _planeDriver forceweaponfire _x;
                } foreach _weapons;
                _plane setvariable ["fireProgress",(1 - ((_time - time) / _duration)) max 0 min 1];
                sleep 0.1;
                time > _time || isnull _plane
            };
            sleep 1;
        };
    };

    sleep 0.01;
    scriptdone _fire || isnull _plane
};
_plane setvelocity velocity _plane;
_plane flyinheight _alt;

// LEAVE the battlefield
waitUntil{
  // exit loop if the unit gets deleted
	if (isNull _plane) exitWith {true};  // has to return true to continue	
	sleep 60;
	{deletevehicle _x}forEach _laserArray+_arrowArray;

	//--- Delete plane
		//while {(count (waypoints _grp)) > 0} do { deleteWaypoint ((waypoints _grp) select 0)};
		{deletevehicle _x} foreach crew _plane;		
		deletevehicle _plane;
		//deletegroup _grp;
		//hint format ["DELETE PLANE \n _plane:%1 \n crew:%2", _plane, crew _plane];
	sleep 5;
  !(alive _plane);
};

 

 

Share this post


Link to post
Share on other sites
Sign in to follow this  

×