#49 - targetEvent for flashbang

This commit is contained in:
PabstMirror 2015-01-17 00:39:46 -06:00
parent 853dfba86a
commit 1783bf4db6
3 changed files with 70 additions and 69 deletions

View File

@ -6,4 +6,4 @@ PREP(flashbangThrownFuze);
PREP(nextMode); PREP(nextMode);
PREP(throwGrenade); PREP(throwGrenade);
[QGVAR(flashbangExplosionEvent), { _this call DFUNC(flashbangExplosionEH) }] call EFUNC(common,addEventHandler); ["flashbangExplosion", { _this call DFUNC(flashbangExplosionEH) }] call EFUNC(common,addEventHandler);

View File

@ -1,82 +1,85 @@
/* /*
* Author: KoffeinFlummi * Author: KoffeinFlummi
* *
* Creates the flashbang effect locally/knocks out AI units. * Creates the flashbang effect and knock out AI units.
* *
* Arguments: * Arguments:
* 0: The unit (Object) * 0: The grenade (Object)
* 1: The grenade (Object) *
* * Return Value:
* Return Value: * None
* None */
*/
#include "script_component.hpp" #include "script_component.hpp"
_unit = _this select 0; private ["_grenade", "_affected", "_strength", "_posGrenade", "_posUnit", "_angleGrenade", "_angleView", "_angleDiff", "_light"];
_grenade = _this select 1;
if (!local _unit) exitWith {}; _grenade = _this select 0;
if (!alive _unit) exitWith {};
if (damage _unit >= 1) exitWith {};
_strength = 1 - ((_unit distance _grenade) min 15) / 15; _affected = _grenade nearEntities ["CAManBase", 50];
if (_unit != ACE_player) exitWith { {
//must be AI if ((local _x) && {alive _x}) then {
_unit disableAI "MOVE";
_unit disableAI "ANIM";
_unit disableAI "AUTOTARGET";
_unit disableAI "TARGET";
_unit disableAI "FSM";
_unit setSkill (skill _unit / 50);
[FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_RESETAI, (time + (7 * _strength)), _unit]] call CBA_fnc_addPerFrameHandler; _strength = 1 - ((_x distance _grenade) min 15) / 15;
};
// is there line of sight to the grenade? if (_x != ACE_player) then {
_posGrenade = getPosASL _grenade; //must be AI
_posGrenade set [2, (_posGrenade select 2) + 0.2]; // compensate for grenade glitching into ground _x disableAI "MOVE";
if (lineIntersects [_posGrenade, getPosASL _unit, _grenade, _unit]) then { _x disableAI "ANIM";
_strength = _strength / 10; _x disableAI "AUTOTARGET";
}; _x disableAI "TARGET";
_x disableAI "FSM";
_x setSkill ((skill _x) / 50);
// beeeeeeeeeeeeeeeeeeeeeeeeeeeeep [FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_RESETAI, (time + (7 * _strength)), _x]] call CBA_fnc_addPerFrameHandler;
if (isClass (configFile >> "CfgPatches" >> "ACE_Hearing") and _strength > 0) then { } else {
[_unit, 0.5 + (_strength / 2)] call EFUNC(hearing,earRinging); //Do effects for player
}; // is there line of sight to the grenade?
_posGrenade = getPosASL _grenade;
_posGrenade set [2, (_posGrenade select 2) + 0.2]; // compensate for grenade glitching into ground
if (lineIntersects [_posGrenade, getPosASL _x, _grenade, _x]) then {
_strength = _strength / 10;
};
// account for people looking away by slightly // beeeeeeeeeeeeeeeeeeeeeeeeeeeeep
// reducing the effect for visual effects. if (isClass (configFile >> "CfgPatches" >> "ACE_Hearing") and _strength > 0) then {
_posUnit = getPos _unit; [_x, 0.5 + (_strength / 2)] call EFUNC(hearing,earRinging);
_posGrenade = getPos _grenade; };
_angleGrenade = ((_posGrenade select 0) - (_posUnit select 0)) atan2 ((_posGrenade select 1) - (_posUnit select 1));
_angleGrenade = (_angleGrenade + 360) % 360;
_angleView = (eyeDirection player select 0) atan2 (eyeDirection player select 1); // account for people looking away by slightly
_angleView = (_angleView + 360) % 360; // reducing the effect for visual effects.
_posUnit = getPos _x;
_posGrenade = getPos _grenade;
_angleGrenade = ((_posGrenade select 0) - (_posUnit select 0)) atan2 ((_posGrenade select 1) - (_posUnit select 1));
_angleGrenade = (_angleGrenade + 360) % 360;
_angleDiff = 180 - abs (abs (_angleGrenade - _angleView) - 180); _angleView = (eyeDirection player select 0) atan2 (eyeDirection player select 1);
_angleDiff = ((_angleDiff - 45) max 0); _angleView = (_angleView + 360) % 360;
_strength = _strength - _strength * (_angleDiff / 135); _angleDiff = 180 - abs (abs (_angleGrenade - _angleView) - 180);
_angleDiff = ((_angleDiff - 45) max 0);
// create flash to illuminate environment _strength = _strength - _strength * (_angleDiff / 135);
_light = "#lightpoint" createVehicleLocal getPos _grenade;
_light setLightBrightness 200;
_light setLightAmbient [1,1,1];
_light setLightColor [1,1,1];
_light setLightDayLight true;
[FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_DELETELIGHT, (time + (0.1)), _light]] call CBA_fnc_addPerFrameHandler; // create flash to illuminate environment
_light = "#lightpoint" createVehicleLocal getPos _grenade;
_light setLightBrightness 200;
_light setLightAmbient [1,1,1];
_light setLightColor [1,1,1];
_light setLightDayLight true;
[FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_DELETELIGHT, (time + (0.1)), _light]] call CBA_fnc_addPerFrameHandler;
// blind player // blind player
if (_strength > 0.1) then { if (_strength > 0.1) then {
GVAR(flashbangPPEffectCC) ppEffectEnable true; GVAR(flashbangPPEffectCC) ppEffectEnable true;
GVAR(flashbangPPEffectCC) ppEffectAdjust [1,1,(0.8 + _strength) min 1,[1,1,1,0],[0,0,0,1],[0,0,0,0]]; GVAR(flashbangPPEffectCC) ppEffectAdjust [1,1,(0.8 + _strength) min 1,[1,1,1,0],[0,0,0,1],[0,0,0,0]];
GVAR(flashbangPPEffectCC) ppEffectCommit 0.01; GVAR(flashbangPPEffectCC) ppEffectCommit 0.01;
[FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_PARTIALRECOVERY, (time + (7 * _strength)), _strength]] call CBA_fnc_addPerFrameHandler; [FUNC(flashbangEffectStages), 0, [EFFECT_STAGE_PARTIALRECOVERY, (time + (7 * _strength)), _strength]] call CBA_fnc_addPerFrameHandler;
[FUNC(flashbangEffectStages), 0, [ EFFECT_STAGE_FULLRECOVERY, (time + (17 * _strength))]] call CBA_fnc_addPerFrameHandler; [FUNC(flashbangEffectStages), 0, [ EFFECT_STAGE_FULLRECOVERY, (time + (17 * _strength))]] call CBA_fnc_addPerFrameHandler;
}; };
};
};
} forEach _affected;

View File

@ -12,9 +12,7 @@ if (_waitUntilTime > time) exitWith {};
if (alive _projectile) then { if (alive _projectile) then {
playSound3D ["A3\Sounds_F\weapons\Explosion\explosion_mine_1.wss", _projectile, false, getPosASL _projectile, 5, 1.2, 400]; playSound3D ["A3\Sounds_F\weapons\Explosion\explosion_mine_1.wss", _projectile, false, getPosASL _projectile, 5, 1.2, 400];
_affected = _projectile nearEntities ["CAManBase", 50]; _affected = _projectile nearEntities ["CAManBase", 50];
{ ["flashbangExplosion", _affected, [_projectile]] call EFUNC(common,targetEvent);
[QGVAR(flashbangExplosionEvent), [_x], [_x, _projectile]] call EFUNC(common,targetEvent);
} forEach _affected;
}; };