From ec0ece059f69819dfcf6793c5e89332ecf057448 Mon Sep 17 00:00:00 2001 From: bux Date: Sun, 10 Jan 2016 20:58:54 +0100 Subject: [PATCH] use Killed event, fix missing public setVar add more text, don't delete dead unit --- .../switchunits/functions/fnc_initPlayer.sqf | 2 +- .../switchunits/functions/fnc_switchBack.sqf | 7 +++-- .../switchunits/functions/fnc_switchUnit.sqf | 30 ++++++++++++++----- addons/switchunits/stringtable.xml | 4 +++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/addons/switchunits/functions/fnc_initPlayer.sqf b/addons/switchunits/functions/fnc_initPlayer.sqf index 80388a9d2b..87873c349f 100644 --- a/addons/switchunits/functions/fnc_initPlayer.sqf +++ b/addons/switchunits/functions/fnc_initPlayer.sqf @@ -21,7 +21,7 @@ params ["_playerUnit", "_sides"]; if (vehicle _playerUnit == _playerUnit) then { [_sides] call FUNC(markAiOnMap); - _playerUnit setVariable [QGVAR(IsPlayerUnit), true]; + _playerUnit setVariable [QGVAR(IsPlayerUnit), true, true]; _playerUnit allowDamage false; GVAR(OriginalUnit) = _playerUnit; diff --git a/addons/switchunits/functions/fnc_switchBack.sqf b/addons/switchunits/functions/fnc_switchBack.sqf index b48414061c..4c3d05ae54 100644 --- a/addons/switchunits/functions/fnc_switchBack.sqf +++ b/addons/switchunits/functions/fnc_switchBack.sqf @@ -26,10 +26,11 @@ params ["_originalPlayerUnit"]; if (local _originalPlayerUnit) exitWith { selectPlayer _originalPlayerUnit; - deleteVehicle _currentUnit; - private _layer = "BIS_fnc_respawnCounter" call bis_fnc_rscLayer; - _layer cuttext ["","plain"]; + // deleteVehicle _currentUnit; + + // private _layer = "BIS_fnc_respawnCounter" call bis_fnc_rscLayer; + // _layer cuttext ["","plain"]; [_pfhId] call CBA_fnc_removePerFrameHandler; }; diff --git a/addons/switchunits/functions/fnc_switchUnit.sqf b/addons/switchunits/functions/fnc_switchUnit.sqf index cc95d478d7..903207652c 100644 --- a/addons/switchunits/functions/fnc_switchUnit.sqf +++ b/addons/switchunits/functions/fnc_switchUnit.sqf @@ -40,19 +40,28 @@ if (_leave) exitWith { // should switch locality // This doesn't work anymore, because one's now able to switch to units from a different side //[_unit] joinSilent group player; -[[_unit, player], QUOTE({(_this select 0) setVariable [ARR_3(QUOTE(QGVAR(OriginalOwner)), owner (_this select 0), true)]; (_this select 0) setOwner owner (_this select 1)}), 1] call EFUNC(common,execRemoteFnc); +[ + [_unit, player], + QUOTE({ + (_this select 0) setVariable [ARR_3(QUOTE(QGVAR(OriginalOwner)), owner (_this select 0), true)]; + (_this select 0) setOwner owner (_this select 1) + }), + 1 +] call EFUNC(common,execRemoteFnc); [{ params ["_args", "_pfhId"]; _args params ["_unit", "_oldUnit"]; + [localize LSTRING(TryingToSwitch)] call EFUNC(common,displayTextStructured); + if (local _unit) exitWith { _oldUnit setVariable [QGVAR(IsPlayerControlled), false, true]; _oldUnit setVariable [QGVAR(PlayerControlledName), "", true]; - private _respawnEhId = _unit getVariable [QGVAR(RespawnEhId), -1]; - if (_respawnEhId != -1) then { - _oldUnit removeEventHandler ["Respawn", _respawnEhId]; + private _killedEhId = _unit getVariable [QGVAR(KilledEhId), -1]; + if (_killedEhId != -1) then { + _oldUnit removeEventHandler ["Killed", _killedEhId]; }; selectPlayer _unit; @@ -60,15 +69,22 @@ if (_leave) exitWith { _unit setVariable [QGVAR(IsPlayerControlled), true, true]; _unit setVariable [QGVAR(PlayerControlledName), GVAR(OriginalName), true]; - _respawnEhId = _unit addEventHandler ["Respawn", { + + _killedEhId = _unit addEventHandler ["Killed", { [GVAR(OriginalUnit), _this select 0] call FUNC(switchBack); }]; - _unit setVariable [QGVAR(RespawnEhId), _respawnEhId, true]; + _unit setVariable [QGVAR(KilledEhId), _killedEhId, true]; + // set owner back to original owner private _oldOwner = _oldUnit getVariable[QGVAR(OriginalOwner), -1]; if (_oldOwner > -1) then { - [[_oldUnit, _oldOwner], QUOTE({(_this select 0) setOwner (_this select 1)}), 1] call EFUNC(common,execRemoteFnc); + [ + [_oldUnit, _oldOwner], + QUOTE({ + (_this select 0) setOwner (_this select 1) + }), 1 + ] call EFUNC(common,execRemoteFnc); }; [localize LSTRING(SwitchedUnit)] call EFUNC(common,displayTextStructured); diff --git a/addons/switchunits/stringtable.xml b/addons/switchunits/stringtable.xml index d38175b1da..9170bd63a2 100644 --- a/addons/switchunits/stringtable.xml +++ b/addons/switchunits/stringtable.xml @@ -13,6 +13,10 @@ Cambia unità Trocado de unidade + + Trying to switch + Versuche zu Wechseln + This unit is too close to the enemy. Diese Einheit ist zu nah am Feind.