cleanup SwitchUnits

This commit is contained in:
bux
2016-01-10 19:08:28 +01:00
parent 0397b3f9f4
commit 09e4a6a76e
10 changed files with 74 additions and 84 deletions

View File

@ -15,19 +15,17 @@
*/
#include "script_component.hpp"
private ["_nearestEnemyPlayers", "_allNearestPlayers", "_oldUnit", "_leave"];
params ["_unit"];
// don't switch to original player units
if (!([_unit] call FUNC(isValidAi))) exitWith {};
// exit var
_leave = false;
private _leave = false;
if (GVAR(EnableSafeZone)) then {
_allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers);
_nearestEnemyPlayers = [_allNearestPlayers, {((side GVAR(OriginalGroup)) getFriend (side _this) < 0.6) && !(_this getVariable [QGVAR(IsPlayerControlled), false])}] call EFUNC(common,filter);
private _allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers);
private _nearestEnemyPlayers = [_allNearestPlayers, {((side GVAR(OriginalGroup)) getFriend (side _this) < 0.6) && !(_this getVariable [QGVAR(IsPlayerControlled), false])}] call EFUNC(common,filter);
if (count _nearestEnemyPlayers > 0) exitWith {
_leave = true;
@ -45,7 +43,6 @@ if (_leave) exitWith {
[[_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);
[{
private ["_respawnEhId", "_oldOwner"];
params ["_args", "_pfhId"];
_args params ["_unit", "_oldUnit"];
@ -53,7 +50,7 @@ if (_leave) exitWith {
_oldUnit setVariable [QGVAR(IsPlayerControlled), false, true];
_oldUnit setVariable [QGVAR(PlayerControlledName), "", true];
_respawnEhId = _unit getVariable [QGVAR(RespawnEhId), -1];
private _respawnEhId = _unit getVariable [QGVAR(RespawnEhId), -1];
if (_respawnEhId != -1) then {
_oldUnit removeEventHandler ["Respawn", _respawnEhId];
};
@ -69,7 +66,7 @@ if (_leave) exitWith {
_unit setVariable [QGVAR(RespawnEhId), _respawnEhId, true];
// set owner back to original owner
_oldOwner = _oldUnit getVariable[QGVAR(OriginalOwner), -1];
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);
};