From 01473e2c320ce44fbb1259f4cff411c6a37166e3 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Mon, 15 Apr 2024 22:16:58 +0200 Subject: [PATCH] Show civilian vehicles markers for killers from the start without requiring teleportation (#97) * Show vehicle markers without requiring teleportation * Make markers visible slightly longer * Prevent markers on damaged vehicles * Make markers smaller * Restart marker alpha if necessary * Fix marker decay allowing concurrent loops * Check if a marker exists to avoid recreating it --- .../fnc_createMarkersForNearbyVehicles.sqf | 14 +++++++++++--- addons/killers/functions/fnc_createTeleport.sqf | 1 + addons/markers/functions/fnc_markerDecay.sqf | 3 ++- addons/markers/functions/fnc_markerDecayLoop.sqf | 11 +++++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/addons/killers/functions/fnc_createMarkersForNearbyVehicles.sqf b/addons/killers/functions/fnc_createMarkersForNearbyVehicles.sqf index 3acb2e15..08127911 100644 --- a/addons/killers/functions/fnc_createMarkersForNearbyVehicles.sqf +++ b/addons/killers/functions/fnc_createMarkersForNearbyVehicles.sqf @@ -21,13 +21,21 @@ params ["_position", ["_radius", 1000]]; private _nearbyVehicles = _position nearEntities [["Air", "Car", "Motorcycle", "Tank"], _radius]; private _emptyVehicles = _nearbyVehicles select { - crew _x isEqualTo [] + damage _x isEqualTo 0 && + {crew _x isEqualTo []} }; { private _vehicle = _x; - private _marker = createMarkerLocal [format ["vehicle_%1", _vehicle], getPosATL _vehicle]; + private _markerName = format ["vehicle_%1", _vehicle]; + private _markerExists = getMarkerPos _markerName isNotEqualTo [0, 0, 0]; + if (_markerExists) then { continue }; + + private _marker = createMarkerLocal [_markerName, getPosATL _vehicle]; + if (_marker isEqualTo "") then { _marker = _markerName }; _marker setMarkerColorLocal "ColorCIVILIAN"; + _marker setMarkerSizeLocal [0.5, 0.5]; + _marker setMarkerAlphaLocal 1; // Force just in case marker already exists and should be fully-visible again _marker setMarkerTextLocal getText (configFile >> "CfgVehicles" >> (typeof _vehicle) >> "displayName"); private _markerType = if (_vehicle isKindOf "Air") then { @@ -35,7 +43,7 @@ private _emptyVehicles = _nearbyVehicles select { } else { "loc_car" }; _marker setMarkerTypeLocal _markerType; - [_marker, 2, true] call EFUNC(markers,markerDecay); + [_marker, 2.5, true] call EFUNC(markers,markerDecay); } forEach _emptyVehicles; nil diff --git a/addons/killers/functions/fnc_createTeleport.sqf b/addons/killers/functions/fnc_createTeleport.sqf index 94271b76..56702533 100644 --- a/addons/killers/functions/fnc_createTeleport.sqf +++ b/addons/killers/functions/fnc_createTeleport.sqf @@ -28,6 +28,7 @@ private _positionID = 0; [QGVAR(teleportedToStart), [_this select 0]] call CBA_fnc_localEvent; }, [_destinationPos]]; [_destinationPos, _destinationName] call FUNC(createStartPositionMarker); + [_destinationPos] call FUNC(createMarkersForNearbyVehicles); // Add for deletion after teleportation _teleportActionsIDs pushBack _teleportActionID; _positionID = _positionID + 1; diff --git a/addons/markers/functions/fnc_markerDecay.sqf b/addons/markers/functions/fnc_markerDecay.sqf index 879ecd62..407c775b 100644 --- a/addons/markers/functions/fnc_markerDecay.sqf +++ b/addons/markers/functions/fnc_markerDecay.sqf @@ -20,5 +20,6 @@ params ["_marker", ["_decayHalfTime", 10], ["_local", false]]; // How much decay will be applied every 15 seconds private _decayRate = 1/(_decayHalfTime * 4 * 2); +private _currentAlpha = markerAlpha _marker; -[_marker, _decayRate, _local] call FUNC(markerDecayLoop); +[_marker, _decayRate, _currentAlpha, _local] call FUNC(markerDecayLoop); diff --git a/addons/markers/functions/fnc_markerDecayLoop.sqf b/addons/markers/functions/fnc_markerDecayLoop.sqf index 285dc2b4..9ac096cc 100644 --- a/addons/markers/functions/fnc_markerDecayLoop.sqf +++ b/addons/markers/functions/fnc_markerDecayLoop.sqf @@ -16,16 +16,19 @@ * Public: No */ -params ["_marker", "_decayRate", ["_local", false]]; +params ["_marker", "_decayRate", ["_previousAlpha", -1], ["_local", false]]; private _currentAlpha = markerAlpha _marker; +if (_currentAlpha isNotEqualTo _previousAlpha && {_previousAlpha isNotEqualTo -1}) exitWith {}; if (_currentAlpha <= _decayRate) exitWith {deleteMarker _marker}; +private _newAlpha = (_currentAlpha - _decayRate); + if (_local) then { - _marker setMarkerAlphaLocal (_currentAlpha - _decayRate); + _marker setMarkerAlphaLocal _newAlpha; } else { - _marker setMarkerAlpha (_currentAlpha - _decayRate); + _marker setMarkerAlpha _newAlpha; }; -[FUNC(markerDecayLoop), [_marker, _decayRate, _local], 15] call CBA_fnc_waitAndExecute; +[FUNC(markerDecayLoop), [_marker, _decayRate, _newAlpha, _local], 15] call CBA_fnc_waitAndExecute;