Fix switching non-local portable light on (#6522)

This commit is contained in:
Dystopian 2018-08-17 04:52:13 +03:00 committed by PabstMirror
parent 48b459240d
commit d8b54a8ef0
5 changed files with 24 additions and 51 deletions

View File

@ -665,14 +665,14 @@ class CfgVehicles {
class GVAR(TurnOn) {
displayName = CSTRING(TurnOn);
icon = "\A3\Ui_f\data\IGUI\Cfg\VehicleToggles\LightsIconOn_ca.paa";
condition = QUOTE(alive _target && !(_target getVariable [ARR_2('ACE_lampOn',true)]));
statement = QUOTE(_target call DFUNC(switchLamp));
condition = QUOTE(alive _target && !(_target getVariable [ARR_2(QQGVAR(isLightOn),true)]));
statement = QUOTE([ARR_3(QQGVAR(setLight),[ARR_2(_target,true)],_target)] call CBA_fnc_targetEvent);
};
class GVAR(TurnOff) {
displayName = CSTRING(TurnOff);
icon = "\A3\ui_f\data\igui\cfg\actions\ico_cpt_land_OFF_ca.paa";
condition = QUOTE(alive _target && _target getVariable [ARR_2('ACE_lampOn',true)]);
statement = QUOTE(_target call DFUNC(switchLamp));
condition = QUOTE(alive _target && _target getVariable [ARR_2(QQGVAR(isLightOn),true)]);
statement = QUOTE([ARR_3(QQGVAR(setLight),[ARR_2(_target,false)],_target)] call CBA_fnc_targetEvent);
};
};
};

View File

@ -43,4 +43,3 @@ PREP(canPush);
PREP(push);
PREP(canFlip);
PREP(switchLamp);

View File

@ -18,17 +18,6 @@ ACE_Modifier = 0;
_unit doMove _position;
}] call CBA_fnc_addEventHandler;
[QGVAR(setLampOn), {
params ["_lamp", "_hitPointsDamage", "_disabledLampDMG"];
{if((_x select 1) == _disabledLampDMG) then {_lamp setHit [_x select 0, 0];};nil} count _hitPointsDamage;
}] call CBA_fnc_addEventHandler;
[QGVAR(setLampOff), {
params ["_lamp", "_hitPointsDamage", "_disabledLampDMG"];
{_lamp setHit [_x select 0, (_x select 1) max _disabledLampDMG];nil} count _hitPointsDamage;
}] call CBA_fnc_addEventHandler;
[QGVAR(flip), {
params ["_vehicle"];
private _position = getPosATL _vehicle;
@ -36,6 +25,24 @@ ACE_Modifier = 0;
_vehicle setPosATL _position;
}] call CBA_fnc_addEventHandler;
[QGVAR(setLight), {
params ["_lamp", "_state"];
private _hitpoints = _lamp call EFUNC(common,getReflectorsWithSelections) select 1;
{
private _damage = _lamp getHit _x;
if (_state) then {
if (_damage == DISABLED_LAMP_DAMAGE) then {
_lamp setHit [_x, 0];
};
} else {
if (_damage < DISABLED_LAMP_DAMAGE) then {
_lamp setHit [_x, DISABLED_LAMP_DAMAGE];
};
};
} forEach _hitpoints;
_lamp setVariable [QGVAR(isLightOn), _state, true];
}] call CBA_fnc_addEventHandler;
[QGVAR(setCollisionLight), {
(_this select 0) setCollisionLight (_this select 1);
}] call CBA_fnc_addEventHandler;

View File

@ -1,35 +0,0 @@
/*
* Author: SzwedzikPL
* Turn on/off lamp
*
* Arguments:
* 0: Lamp <OBJECT>
*
* Return Value:
* None
*
* Example:
* lamp call ace_interaction_fnc_switchLamp
*
* Public: No
*/
#include "script_component.hpp"
#define DISABLED_LAMP_DMG 0.95
params ["_lamp"];
_isOn = _lamp getVariable ["ACE_lampOn", true];
private _reflectors = "true" configClasses (configfile >> "CfgVehicles" >> (typeof _lamp) >> "Reflectors");
private _hitPointsDamage = [];
{
private _hitPoint = getText (_x >> "hitpoint");
_hitPointsDamage pushback [_hitPoint, _lamp getHit _hitPoint];
nil
} count _reflectors;
//if lamp is on turn it off
private _eventName = [QGVAR(setLampOn), QGVAR(setLampOff)] select _isOn;
[_eventName, [_lamp, _hitPointsDamage, DISABLED_LAMP_DMG], [_lamp]] call CBA_fnc_targetEvent;
_lamp setVariable ["ACE_lampOn", !_isOn, true];

View File

@ -17,3 +17,5 @@
#include "\z\ace\addons\main\script_macros.hpp"
#define MACRO_DOOR_REACH_DISTANCE (AGLToASL positionCameraToWorld [0,0,0] vectorDistance AGLToASL (ACE_player modelToWorld (ACE_player selectionPosition "Head"))) + 2
#define DISABLED_LAMP_DAMAGE 0.95