From 58b1c0f3a9a0f1199e2943f3f6f3098386c8a6d0 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Fri, 3 Jul 2015 13:13:02 +0100 Subject: [PATCH 1/2] Solve crashing caused by off map position and disableSimulation to stop underwater issues --- addons/spectator/XEH_preInit.sqf | 2 -- .../spectator/functions/fnc_setSpectator.sqf | 31 +++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index c4d1205776..b316161739 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -28,6 +28,4 @@ PREP(unitSide); PREP(unitVar); PREP(viewDistance); -GVAR(penPos) = [-10e5,-10e5,0]; - ADDON = true; diff --git a/addons/spectator/functions/fnc_setSpectator.sqf b/addons/spectator/functions/fnc_setSpectator.sqf index 424769b1a8..2bd4c61532 100644 --- a/addons/spectator/functions/fnc_setSpectator.sqf +++ b/addons/spectator/functions/fnc_setSpectator.sqf @@ -27,13 +27,16 @@ if (_set isEqualTo (_unit getVariable [QGVAR(isSpectator), false])) exitWith {}; // Spectators aren't physical entities (todo: this command has to be executed on the server) _unit hideObjectGlobal _set; -if (isClass (configFile >> "CfgPatches" >> "ace_hearing")) then {EGVAR(hearing,disableVolumeUpdate) = _set}; -if (isClass (configFile >> "CfgPatches" >> "acre_sys_radio")) then {[_set] call acre_api_fnc_setSpectator}; -if (isClass (configFile >> "CfgPatches" >> "task_force_radio")) then {[_unit, _set] call TFAR_fnc_forceSpectator}; +// Prevent player falling into water +_unit enableSimulation !_set; if (_set) then { // Move the player ASAP to avoid being seen - _unit setPosATL GVAR(penPos); + _unit setPosASL (getMarkerPos QGVAR(respawn)); + [_unit] joinSilent grpNull; + + // Dead men can't talk + [_unit, "isSpectator"] call EFUNC(common,muteUnit); if !(GVAR(modulePos)) then { if !(isNull _target) then { @@ -41,26 +44,22 @@ if (_set) then { }; }; - // Spectators shouldn't show in group UI - [_unit] joinSilent grpNull; - - // Prevent drowning and vision blur - if (surfaceisWater GVAR(penPos)) then { - _unit forceAddUniform "U_B_Wetsuit"; - _unit addVest "V_RebreatherB"; - }; - - // Dead men can't talk - [_unit, "isSpectator"] call EFUNC(common,muteUnit); - 0 fadeSound 0; 999999 cutText ["", "BLACK FADED", 0]; ["Init", [true]] call FUNC(camera); } else { // Code to exit spectator and "respawn" player goes here (WIP) ["Exit"] call FUNC(camera); + + // Living men can talk + [_unit, "isSpectator"] call EFUNC(common,unmuteUnit); }; +// Handle common addon audio +if (isClass (configFile >> "CfgPatches" >> "ace_hearing")) then {EGVAR(hearing,disableVolumeUpdate) = _set}; +if (isClass (configFile >> "CfgPatches" >> "acre_sys_radio")) then {[_set] call acre_api_fnc_setSpectator}; +if (isClass (configFile >> "CfgPatches" >> "task_force_radio")) then {[_unit, _set] call TFAR_fnc_forceSpectator}; + // Spectators ignore damage (vanilla and ace_medical) _unit allowDamage !_set; _unit setVariable ["ace_medical_allowDamage", !_set]; From a23f4016957534d35b63e6c2ef4acb723173aeb2 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Fri, 3 Jul 2015 19:07:10 +0100 Subject: [PATCH 2/2] Removing all references to penPos --- addons/spectator/XEH_postInit.sqf | 2 +- addons/spectator/functions/fnc_camera.sqf | 214 +++++++++--------- .../functions/fnc_canSpectateUnit.sqf | 11 +- addons/spectator/functions/fnc_map.sqf | 40 ++-- 4 files changed, 132 insertions(+), 135 deletions(-) diff --git a/addons/spectator/XEH_postInit.sqf b/addons/spectator/XEH_postInit.sqf index e59c4daf2e..d81be40640 100644 --- a/addons/spectator/XEH_postInit.sqf +++ b/addons/spectator/XEH_postInit.sqf @@ -18,7 +18,7 @@ if (GVAR(endMission) && isServer) then { [{ - if ({isPlayer _x && alive _x && (_x distance GVAR(penPos)) > 200} count playableUnits == 0) then { + if ({(isPlayer _x) && (alive _x) && !(_x getVariable [QGVAR(isSpectator), false])} count playableUnits == 0) then { [["endDeath", false], "BIS_fnc_endMission"] call BIS_fnc_MP; [_this select 1] call CBA_fnc_removePerFrameHandler; }; diff --git a/addons/spectator/functions/fnc_camera.sqf b/addons/spectator/functions/fnc_camera.sqf index bc4cea88cc..2b12c5fd6a 100644 --- a/addons/spectator/functions/fnc_camera.sqf +++ b/addons/spectator/functions/fnc_camera.sqf @@ -30,23 +30,21 @@ _this = _this select 1; switch _mode do { case "Init": { - + GVAR(noEscape) = if (count _this > 0) then {_this select 0} else {false}; - - call FUNC(penPos); _camPos = if (!isNil QGVAR(startingPos)) then { GVAR(startingPos) } else { getPos cameraOn }; - + _camDir = if (!isNil QGVAR(startingDir)) then { GVAR(startingDir) } else { 0 }; - + _camPos set [2, (_camPos select 2) + 2]; _cam = "camera" camCreate _camPos; _cam setDir _camDir; @@ -56,7 +54,7 @@ switch _mode do { showCinemaBorder false; cameraEffectEnableHUD true; setViewDistance 3000; - + //variables GVAR(cam) = _cam; GVAR(LMB) = false; @@ -74,27 +72,27 @@ switch _mode do { GVAR(markers) = 3; GVAR(accTime) = 1; GVAR(third) = false; - + //define only if doesn't exist (to preserve saved spots from a previous camera) if (isNil QGVAR(savedSpots)) then { GVAR(savedSpots) = []; for "_i" from 0 to 11 do {GVAR(savedSpots) set [_i, []]}; }; - + if (isNil QGVAR(savedUnits)) then { GVAR(savedUnits) = []; for "_i" from 0 to 9 do {GVAR(savedUnits) set [_i, objNull]}; }; - + GVAR(keys) = []; _DIKcodes = true call BIS_fnc_keyCode; _DIKlast = _DIKcodes select (count _DIKcodes - 1); for "_i" from 0 to (_DIKlast - 1) do { GVAR(keys) set [_i, false]; }; - + _display = findDisplay 46; - + GVAR(ehDraw3D) = addMissionEventhandler ["Draw3D", {['Draw3D', _this] call FUNC(draw3D)}]; addMissionEventHandler ["Ended", {if (!isNil QGVAR(cam)) then {["Exit"] call FUNC(camera)}}]; GVAR(ehKeyDown) = _display displayAddEventHandler ["keyDown", {['KeyDown', _this] call FUNC(camera)}]; @@ -117,40 +115,40 @@ switch _mode do { for "_i" from 1 to (count _layers - 1) step 2 do { (_layers select _i) cutText ["", "Plain"]; }; - + clearRadio; - + //crosshair _layer = [QGVAR(crosshair)] call BIS_fnc_rscLayer; _layer cutRsc [QGVAR(crosshair), "PLAIN", 2, true]; - + //compass _layer = [QGVAR(compass)] call BIS_fnc_rscLayer; _layer cutRsc [QGVAR(compass), "PLAIN", 2, true]; - + //status _layer = [QGVAR(status)] call BIS_fnc_rscLayer; _layer cutRsc [QGVAR(status), "PLAIN", 2, true]; - + //help _layer = [QGVAR(help)] call BIS_fnc_rscLayer; preloadTitleRsc [QGVAR(help), "PLAIN", 0, true]; - + if (isClass (configFile >> "CfgPatches" >> "ace_nametags")) then { GVAR(tags) = [EGVAR(nametags,showPlayerNames), EGVAR(nametags,showNamesForAI)]; EGVAR(nametags,showPlayerNames) = 0; EGVAR(nametags,showNamesForAI) = false; }; - + if (isClass (configFile >> "CfgPatches" >> "ace_interact_menu")) then { [QGVAR(interactCondition), {false}] call EFUNC(common,addCanInteractWithCondition); }; - + //add unit check, since if tracking were on it would already be present if !GVAR(tracking) then { [FUNC(checkUnits), 2] call CBA_fnc_addPerFrameHandler }; - + [FUNC(cameraIntro), 1] call CBA_fnc_addPerFrameHandler; }; @@ -158,7 +156,7 @@ switch _mode do { case "Mouse": { _mapOn = uiNamespace getVariable QGVAR(map); if (!isNull _mapOn) exitWith {}; - + _keys = GVAR(keys); _cam = GVAR(cam); _dir = GVAR(vector) select 0; @@ -166,7 +164,7 @@ switch _mode do { _bank = GVAR(vector) select 2; _camPos = getPosASL _cam; _coef = (GVAR(moveScale) * (((getPosATL _cam) select 2) / 2)) min 50 max 0.001; - + _move = { _inPos = _this; if !GVAR(cameraOn) exitWith {}; @@ -181,7 +179,7 @@ switch _mode do { _cam setPosASL _inPos; }; }; - + if (GVAR(LMB) || GVAR(RMB)) then { if GVAR(mouseBusy) exitWith {}; _mX = (_this select 1) * (GVAR(accTime) max 0.05); @@ -191,10 +189,10 @@ switch _mode do { _dX = _mX; _dY = -_mY; - + _camPos = [_camPos, _dY, getDir _cam] call BIS_fnc_relPos; _camPos = [_camPos, _dX, getDir _cam + 90] call BIS_fnc_relPos; - + _camPos call _move; } else { @@ -213,7 +211,7 @@ switch _mode do { GVAR(vector) = [_dir, _pitch, _bank]; [_cam, GVAR(vector)] call BIS_fnc_setObjectRotation; }; - }; + }; _camMove = { _dX = _this select 0; @@ -227,11 +225,11 @@ switch _mode do { (_pos select 2) + _dZ * _coef / 1.5 ]; //for some reason, at visual height = 0, cameras report 10cm higher than they actually are - _camPos set [2, (_camPos select 2) max (getTerrainHeightASL _camPos + 0.1)]; + _camPos set [2, (_camPos select 2) max (getTerrainHeightASL _camPos + 0.1)]; _camPos call _move; }; - + _camRotate = { if ((GVAR(lock) select 0) > -1) exitWith {}; _dX = (_this select 0) * GVAR(fov) * _rotMod; @@ -242,7 +240,7 @@ switch _mode do { GVAR(vector) = [_dir, _pitch, _bank]; [_cam, GVAR(vector)] call BIS_fnc_setObjectRotation; }; - + _camBank = { if ((GVAR(lock) select 0) > -1) exitWith {}; _dZ = (_this select 0) * _rotMod; @@ -252,7 +250,7 @@ switch _mode do { GVAR(vector) = [_dir, _pitch, _bank]; [_cam, GVAR(vector)] call BIS_fnc_setObjectRotation; }; - + _numPad0 = _keys select DIK_NUMPAD0; _numPadDel = _keys select DIK_DECIMAL; _rotMod = if (_numPad0 && !_numPadDel) then { @@ -290,13 +288,13 @@ switch _mode do { _cam camPrepareFOV GVAR(fov); _cam camCommitPrepared 0; }; - + if (_keys select DIK_NUMPADENTER) then { GVAR(fov) = 0.7; _cam camPrepareFOV GVAR(fov); _cam camCommitPrepared 0; }; - + if (_keys select DIK_MINUS) then { _cur = GVAR(focus) select 0; if (_cur < 0) then {_cur = 1}; @@ -305,7 +303,7 @@ switch _mode do { _cam camSetFocus GVAR(focus); _cam camCommit 0; }; - + if (_keys select DIK_EQUALS) then { _cur = GVAR(focus) select 0; if (_cur < 0) then {_cur = 1}; @@ -314,7 +312,7 @@ switch _mode do { _cam camSetFocus GVAR(focus); _cam camCommit 0; }; - + if (_keys select DIK_LBRACKET)then { if (!isMultiplayer) then { _cur = GVAR(accTime); @@ -323,7 +321,7 @@ switch _mode do { setAccTime GVAR(accTime); }; }; - + if (_keys select DIK_RBRACKET)then { if (!isMultiplayer) then { _cur = GVAR(accTime); @@ -356,7 +354,7 @@ switch _mode do { case "MouseButtonUp": { _mapOn = uiNamespace getVariable QGVAR(map); if (!isNull _mapOn) exitWith {}; - + _button = _this select 1; switch (_button) do { case 0: {GVAR(LMB) = false}; @@ -368,7 +366,7 @@ switch _mode do { case "MouseZChanged": { _mapOn = uiNamespace getVariable QGVAR(map); if (!isNull _mapOn) exitWith {}; - + _diff = _this select 1; if (_diff > 0) then { GVAR(moveScale) = GVAR(moveScale) + (GVAR(moveScale) / 10) min 1; @@ -393,7 +391,7 @@ switch _mode do { _lock = GVAR(lock) select 0; _camPos = [getPos _cam, GVAR(vector), GVAR(fov), GVAR(focus)]; - + _camSaveSpot = { _num = _this select 0; if (!isNull GVAR(attach)) then { @@ -402,9 +400,9 @@ switch _mode do { _vector set [0, _dir - (getDir GVAR(attach))]; _camPos set [1, _vector]; }; - GVAR(savedSpots) set [_num, _camPos]; + GVAR(savedSpots) set [_num, _camPos]; }; - + _camLoadSpot = { _num = _this select 0; _arr = GVAR(savedSpots) select _num; @@ -420,12 +418,12 @@ switch _mode do { _cam camPrepareFocus (_arr select 3); _cam camCommitPrepared 0; GVAR(vector) = _vector; - }; + }; }; - + _camSaveUnit = { _num = _this select 0; - + if (!isNull _unit) then { _alreadySaved = GVAR(savedUnits) find _unit; if (_alreadySaved > -1) then { @@ -434,7 +432,7 @@ switch _mode do { GVAR(savedUnits) set [_num, _unit] }; }; - + _camLoadUnit = { _num = _this select 0; _unit = GVAR(savedUnits) select _num; @@ -457,15 +455,15 @@ switch _mode do { ["Camera", ["SwitchUnit"]] call FUNC(camera); }; }; - }; + }; }; - + _detach = { if (!isNull GVAR(attach)) then { ["Camera", ["Attach"]] call FUNC(camera); }; }; - + switch (_key) do { case (DIK_F1): {if (_ctrl) then {[0] call _camSaveSpot} else {[0] call _camLoadSpot}; _return = true}; @@ -491,7 +489,7 @@ switch _mode do { case (DIK_8): {if (_ctrl) then {[7] call _camSaveUnit} else {[7] call _camLoadUnit}; _return = true}; case (DIK_9): {if (_ctrl) then {[8] call _camSaveUnit} else {[8] call _camLoadUnit}; _return = true}; case (DIK_0): {if (_ctrl) then {[9] call _camSaveUnit} else {[9] call _camLoadUnit}; _return = true}; - + case (DIK_NUMPAD5): { _dir = getDir _cam; if (!isNull GVAR(attach)) then {_dir = _dir - getDir GVAR(attach)}; @@ -501,13 +499,13 @@ switch _mode do { _cam camPrepareFOV GVAR(fov); _cam camCommitPrepared 0; }; - + case (DIK_NUMPADENTER): {_return = true}; - + case (DIK_NUMPAD0): {_return = true}; - + case (DIK_DECIMAL): {_return = true}; - + case (DIK_BACKSPACE): { GVAR(focus) = if (!_shift) then { [-1, 1]; @@ -518,16 +516,16 @@ switch _mode do { _cam camCommitPrepared 0; _return = true; }; - + case (DIK_BACKSLASH): { if (!isMultiplayer) then { GVAR(accTime) = 1; setAccTime GVAR(accTime); }; }; - + case (DIK_GRAVE): {_return = true}; - + case (DIK_SPACE): { if (!_camOn) exitWith {}; if (_ctrl) then { @@ -536,15 +534,15 @@ switch _mode do { ["Camera", ["Lock"]] call FUNC(camera); }; }; - + case (DIK_LEFT): { ["Camera", ["NewUnit", -1]] call FUNC(camera) }; - + case (DIK_RIGHT): { ["Camera", ["NewUnit", 1]] call FUNC(camera) }; - + case (DIK_UP): { if (isNull GVAR(unit)) exitWith {}; if (_lock > -1) then {["Camera", ["Lock"]] call FUNC(camera)}; @@ -557,7 +555,7 @@ switch _mode do { }; }; }; - + case (DIK_DOWN): { if (isNull GVAR(unit)) exitWith {}; if (_lock > -1) then {["Camera", ["Lock"]] call FUNC(camera)}; @@ -570,17 +568,17 @@ switch _mode do { }; }; }; - + case (DIK_T): { GVAR(markers) = GVAR(markers) + 1; if (GVAR(markers) > 3) then {GVAR(markers) = 0}; if (GVAR(markers) == 0) then {clearRadio}; }; - + case (DIK_U): { _map = uiNameSpace getVariable [QGVAR(map), findDisplay 12202]; if (!isNull _map) exitWith {}; - + _overlay = uiNamespace getVariable [QGVAR(overlay), findDisplay 12200]; if (isNull _overlay) then { createDialog QGVAR(overlay); @@ -588,7 +586,7 @@ switch _mode do { closeDialog 0; }; }; - + case (DIK_X): { _layer = [QGVAR(crosshair)] call BIS_fnc_rscLayer; _xhair = uiNamespace getVariable QGVAR(crosshair); @@ -599,7 +597,7 @@ switch _mode do { _layer cutText ["", "PLAIN"]; }; }; - + case (DIK_C): { _layer = [QGVAR(compass)] call BIS_fnc_rscLayer; if (isNull (uiNamespace getVariable QGVAR(compass))) then { @@ -607,7 +605,7 @@ switch _mode do { } else { _layer cutText ["", "PLAIN"]; }; - + _layer = [QGVAR(status)] call BIS_fnc_rscLayer; if (isNull (uiNamespace getVariable QGVAR(status))) then { _layer cutRsc [QGVAR(status), "PLAIN", 0, true]; @@ -615,7 +613,7 @@ switch _mode do { _layer cutText ["", "PLAIN"]; }; }; - + case (DIK_G): { _vd = uiNamespace getVariable [QGVAR(vd), findDisplay 12201]; if (isNull _vd) then { @@ -624,16 +622,16 @@ switch _mode do { closeDialog 0; } }; - + case (DIK_H): { _layer = [QGVAR(help)] call BIS_fnc_rscLayer; if (isNull (uiNamespace getVariable QGVAR(help))) then { _layer cutRsc [QGVAR(help), "PLAIN", 0, true]; } else { _layer cutText ["", "PLAIN"]; - }; + }; }; - + case (DIK_M): { _map = uiNameSpace getVariable [QGVAR(map), findDisplay 12202]; if (isNull _map) then { @@ -663,7 +661,7 @@ switch _mode do { camUseNVG false; true SetCamUseTi 1; }; - + case 4: { camUseNVG false; true SetCamUseTi 4; @@ -684,7 +682,7 @@ switch _mode do { }; default {}; }; - + _return }; @@ -695,16 +693,16 @@ switch _mode do { ////////////////////////////////////////// case "Camera": { - + _mode = _this select 0; - + _cam = GVAR(cam); _camOn = GVAR(cameraOn); _unit = GVAR(unit); _lock = GVAR(lock) select 0; - + _findTarget = { - + _ret = []; _screenPos = screenToWorld [0.5,0.5]; _camPosASL = getPosASL _cam; @@ -712,14 +710,14 @@ switch _mode do { _endPosASL = [_screenPos select 0, _screenPos select 1, getTerrainHeightASL _screenPos]; _endPosReal = if (surfaceIsWater _endPosASL) then {_endPosASL} else {ASLtoATL _endPosASL}; _objs = lineIntersectsWith [_camPosASL, _endPosASL, objNull, objNull, true]; - + if (count _objs > 0) then { //if vehicle/object found _obj = _objs select (count _objs - 1); _ret = _obj; } else { //check for units near endpoint instead _units = allUnits; if (count _units > 0) then { - _nearestUnit = _units select 0; + _nearestUnit = _units select 0; {if (_endPosReal distance _x < _endPosReal distance _nearestUnit) then {_nearestUnit = _x}} forEach _units; _intersect = [_nearestUnit, "FIRE"] intersect [_camPosReal, _endPosReal]; if (count (_intersect) > 0) then { @@ -734,13 +732,13 @@ switch _mode do { _ret = _endPosReal; }; }; - }; + }; }; _ret }; - + switch (_mode) do { - + case "Free": { GVAR(cameraOn) = true; GVAR(third) = false; @@ -755,7 +753,7 @@ switch _mode do { GVAR(vector) set [0, _dir]; [_cam, GVAR(vector)] call BIS_fnc_setObjectRotation; }; - + case "First": { if (_unit == player) exitWith {}; GVAR(cameraOn) = false; @@ -764,7 +762,7 @@ switch _mode do { _cam cameraEffect ["Terminate", "Back"]; vehicle _unit switchCamera "Internal"; }; - + case "Third": { if (_unit == player) exitWith {}; GVAR(third) = true; @@ -784,29 +782,29 @@ switch _mode do { vehicle _unit switchCamera "External"; }; }; - + case "NewUnit": { - + _increment = _this select 1; _units = []; { if (alive _x) then {_units pushBack _x}; } forEach GVAR(units); - + _count = count _units; - + if (_count > 0) then { _index = _units find _unit; _index = _index + _increment; if (_index < 0) then {_index = _count - 1}; if (_index > (_count - 1)) then {_index = 0}; - + GVAR(unit) = _units select _index; if (!_camOn) then {["Camera", ["SwitchUnit"]] call FUNC(camera)}; - }; + }; }; - + case "SwitchUnit": { if !GVAR(third) then { ["Camera", ["First"]] call FUNC(camera); @@ -814,12 +812,12 @@ switch _mode do { ["Camera", ["Third"]] call FUNC(camera); }; }; - + case "Lock": { if (_lock < 0) then { - + _target = call _findTarget; - + if (typeName _target == "OBJECT") then { GVAR(lock) = [1, _target]; } else { @@ -827,7 +825,7 @@ switch _mode do { GVAR(lock) = [1, _target]; }; }; - + _cam camPrepareTarget (GVAR(lock) select 1); _cam camCommitPrepared 0; call FUNC(crosshair); @@ -854,10 +852,10 @@ switch _mode do { }; GVAR(vector) = [_dir, _pitchBank select 0, 0]; [_cam, GVAR(vector)] call BIS_fnc_setObjectRotation; - call FUNC(crosshair); + call FUNC(crosshair); }; }; - + case "Attach": { _dir = getDir _cam; _pitchBank = _cam call BIS_fnc_getPitchBank; @@ -880,15 +878,15 @@ switch _mode do { [_cam, GVAR(vector)] call BIS_fnc_setObjectRotation; }; }; - + call FUNC(crosshair); }; - + ////////////////////////////////////////// case "Help": { - + _dialog = _this; - + _c1Action = parseText " Camera:

@@ -1002,26 +1000,26 @@ _add2 = parseText " _c2Action = composeText [_c2Action, _add1]; _c2Control = composeText [_c2Control, _add2]; }; - + (_dialog displayCtrl 1) ctrlSetStructuredText _c1Action; (_dialog displayCtrl 2) ctrlSetStructuredText _c1Control; (_dialog displayCtrl 3) ctrlSetStructuredText _c2Action; (_dialog displayCtrl 4) ctrlSetStructuredText _c2Control; }; - + ////////////////////////////////////////// case "Exit": { - + if (isClass (configFile >> "CfgPatches" >> "ace_nametags")) then { EGVAR(nametags,showPlayerNames) = GVAR(tags) select 0; EGVAR(nametags,showNamesForAI) = GVAR(tags) select 1; GVAR(tags) = nil; }; - + if (isClass (configFile >> "CfgPatches" >> "ace_hearing")) then { EGVAR(hearing,disableVolumeUpdate) = false; }; - + if (isClass (configFile >> "CfgPatches" >> "ace_interact_menu")) then { [QGVAR(interactCondition)] call EFUNC(common,removeCanInteractWithCondition); }; @@ -1031,7 +1029,7 @@ _add2 = parseText " false SetCamUseTi 0; camDestroy GVAR(cam); clearRadio; - + GVAR(noEscape) = nil; GVAR(cam) = nil; GVAR(LMB) = nil; @@ -1051,7 +1049,7 @@ _add2 = parseText " GVAR(accTime) = nil; _display = findDisplay 46; - + removeMissionEventHandler ["Draw3D", GVAR(ehDraw3D)]; _display displayRemoveEventHandler ["keyDown", GVAR(ehKeyDown)]; _display displayRemoveEventHandler ["keyUp", GVAR(ehKeyUp)]; @@ -1074,8 +1072,8 @@ _add2 = parseText " for "_i" from 1 to (count _layers - 1) step 2 do { (_layers select _i) cutText ["", "Plain"]; }; - + if (!isMultiplayer) then {setAccTime 1}; ACE_player switchCamera "Internal"; }; -}; \ No newline at end of file +}; diff --git a/addons/spectator/functions/fnc_canSpectateUnit.sqf b/addons/spectator/functions/fnc_canSpectateUnit.sqf index 1ce9f32d97..74da3cc5a4 100644 --- a/addons/spectator/functions/fnc_canSpectateUnit.sqf +++ b/addons/spectator/functions/fnc_canSpectateUnit.sqf @@ -22,9 +22,8 @@ _unit = _this select 0; -if (_unit distance GVAR(penPos) < 200) exitWith {false}; -if (_unit distance [0,0,0] < 100) exitWith {false}; -if (!GVAR(AI) && !isPlayer _unit) exitWith {false}; -if (GVAR(limitSide) && (([_unit] call FUNC(unitSide)) != GVAR(playerSide))) exitWith {false}; - -true \ No newline at end of file +(simulationEnabled _unit) && // Simulation enabled +//{!isObjectHidden _unit} && // Not hidden (currently dev branch only) +{!(_unit getVariable [QGVAR(isSpectator), false])} && // Who watches the watchmen? +{(GVAR(AI) || (isPlayer _unit))} && // Only allow AI when setting is enabled +{!GVAR(limitSide) || (([_unit] call FUNC(unitSide)) == GVAR(playerSide))} // Only allow units of same side when setting is enabled diff --git a/addons/spectator/functions/fnc_map.sqf b/addons/spectator/functions/fnc_map.sqf index b58fa8ce2b..c90bb4f226 100644 --- a/addons/spectator/functions/fnc_map.sqf +++ b/addons/spectator/functions/fnc_map.sqf @@ -26,12 +26,12 @@ _mode = _this select 0; _this = _this select 1; switch _mode do { - + case "Init": { _map = _this displayCtrl 1; if (isNil QGVAR(mapPos)) then { - GVAR(mapPos) = [(GVAR(penPos) select 0) / 4, (GVAR(penPos) select 1) / 4]; + GVAR(mapPos) = (getPosASL GVAR(cam)) select [0,2]; }; if (isNil QGVAR(mapZoom)) then { @@ -43,19 +43,19 @@ switch _mode do { setMousePosition [0.5, 0.5]; _map ctrlAddEventHandler ["Draw", {['Draw', _this] call FUNC(map)}]; - _map ctrlAddEventHandler ["MouseButtonDblClick", {['Click', _this] call FUNC(map)}]; + _map ctrlAddEventHandler ["MouseButtonDblClick", {['Click', _this] call FUNC(map)}]; }; - + case "Close": { _map = _this displayCtrl 1; GVAR(mapPos) = _map ctrlMapScreenToWorld [0.5,0.5]; GVAR(mapZoom) = ctrlMapScale _map; }; - + case "Draw": { _map = _this select 0; _zoom = ctrlMapScale _map; - + if (GVAR(markers) > 0) then { if ((GVAR(markers) > 2) && GVAR(tracking)) then { [_map, _zoom] call FUNC(drawTracks2D); @@ -63,7 +63,7 @@ switch _mode do { [_map, _zoom] call FUNC(drawMines2D); [_map, _zoom] call FUNC(drawUnits2D); }; - + if (GVAR(cameraOn)) then { _scale = 5 * safeZoneH / 100; _map drawIcon ["\A3\ui_f\data\gui\Rsc\RscDisplayMissionEditor\iconcamera_ca.paa", [1,1,1,1], getPos GVAR(cam), 500 * _scale, 500 * _scale, getDir GVAR(cam), "", 0, 0, "PuristaMedium"]; @@ -80,16 +80,16 @@ switch _mode do { if (GVAR(cameraOn)) then { _dir = [getPos GVAR(cam), _mapPos] call BIS_fnc_dirTo; GVAR(vector) set [0, _dir]; - [GVAR(cam), GVAR(vector)] call BIS_fnc_setObjectRotation; + [GVAR(cam), GVAR(vector)] call BIS_fnc_setObjectRotation; }; } else { - + _newUnit = objNull; - + _scale = ctrlMapScale _map; _radius = _scale * 250; _units = []; - + //find units near spot, ignoring height (necessary since nearestObjects takes height into account) { if (alive _x) then { @@ -100,7 +100,7 @@ switch _mode do { }; }; } forEach GVAR(units); - + //find closest unit to spot if (count _units > 0) then { _nearest = 0; @@ -111,14 +111,14 @@ switch _mode do { }; _newUnit = _units select _nearest; }; - + if (!isNull _newUnit) then { - + if (vehicle _newUnit != _newUnit) then { _crew = crew (vehicle _newUnit); _newUnit = _crew select 0; }; - + GVAR(unit) = _newUnit; if (GVAR(cameraOn)) then { ["Camera", ["Third"]] call FUNC(camera); @@ -130,7 +130,7 @@ switch _mode do { }; }; } else { - + if (!GVAR(cameraOn)) then { ["Camera", ["Free"]] call FUNC(camera); }; @@ -139,18 +139,18 @@ switch _mode do { }; }; }; - + case "KeyDown": { _key = _this select 1; _shift = _this select 2; _ctrl = _this select 3; _alt = _this select 4; _return = false; - + switch (_key) do { case (DIK_DELETE): {_return = true}; }; - + _return }; -}; \ No newline at end of file +};