BEAKSBY 11 Posted August 18, 2014 This worked for a similar script using createVehicle instead. for "_i" from 0 to 2 do { _center = createCenter sideLogic; _group = createGroup _center; _CAS = _group createUnit ["ModuleCAS_F",[(_pos select 0) + _i*(10* sin(_vehDir)), (_pos select 1) + _i*(10* cos(_vehDir)), 0], [], 0, ""]; _CAS setDir _vehDir; _CAS setSkill 1; _CAS setVariable ["vehicle",_vehType,true]; _CAS setVariable ["type", 2, true]; _vehKilledEH = _CAS addeventhandler ["killed",{_this spawn BEAKS_fnc_reward_veh}]; sleep 5; }; Share this post Link to post Share on other sites
bangabob 42 Posted August 18, 2014 This worked for a similar script using createVehicle instead. for "_i" from 0 to 2 do { _center = createCenter sideLogic; _group = createGroup _center; _CAS = _group createUnit ["ModuleCAS_F",[(_pos select 0) + _i*(10* sin(_vehDir)), (_pos select 1) + _i*(10* cos(_vehDir)), 0], [], 0, ""]; _CAS setDir _vehDir; _CAS setSkill 1; _CAS setVariable ["vehicle",_vehType,true]; _CAS setVariable ["type", 2, true]; _vehKilledEH = _CAS addeventhandler ["killed",{_this spawn BEAKS_fnc_reward_veh}]; sleep 5; }; "Killed" EH passes 2 arguments in the _this command. _vehKilledEH = _cas addEventHandler ["Killed",{ _unitKilled = _this select 0; _killer = _this select 1; _killer spawn BEAKS_fnc_reward_veh; }]; Share this post Link to post Share on other sites
BEAKSBY 11 Posted August 18, 2014 Thanks, but I thought _this passes both as an array and I do not need to define them. They are defined in the function. Share this post Link to post Share on other sites
SilentSpike 84 Posted August 18, 2014 It does do that. The only thing I can think of is a locality issue. Is this a MP mission? Share this post Link to post Share on other sites
Larrow 2821 Posted August 18, 2014 You are adding a Killed EH to a Logic not the plane the logic module spawns. Unfortunately the logic does not hold a reference to the plane it spawns, the closest it does is add a reference of the logic to the plane. _plane setvariable ["logic",_logic]; The nearest you are going to get is monitoring the area around the logic for an air vehicle of type _vehType that has a variable called "logic" that matches the reference of your module. Share this post Link to post Share on other sites
SilentSpike 84 Posted August 18, 2014 Oh wow, I didn't even notice that. Yeah, Larrow is correct. However, what you could do is take the code of the module itself and use that. Here's a function I turned it into for my own purposes: 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"]}; 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"); _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; _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}; waituntil { _fireProgress = _plane getvariable ["fireProgress",0]; //--- Set the 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; waituntil {_plane distance _pos > _dis}; //--- Delete plane if (alive _plane) then { _group = group _plane; _crew = crew _plane; deletevehicle _plane; {deletevehicle _x} foreach _crew; deletegroup _group; }; You can add the event handler to _plane Share this post Link to post Share on other sites
BEAKSBY 11 Posted August 19, 2014 OK, thanks for the function code and solving the problem folks. Do you know how to increase the gun fire so the strafe lasts longer? Do I simply need to increase the _duration? Share this post Link to post Share on other sites