Skip to content

Commit

Permalink
Show civilian vehicles markers for killers from the start without req…
Browse files Browse the repository at this point in the history
…uiring 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
  • Loading branch information
3Mydlo3 authored Apr 15, 2024
1 parent 4004b52 commit 01473e2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
14 changes: 11 additions & 3 deletions addons/killers/functions/fnc_createMarkersForNearbyVehicles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,29 @@ 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 {
if (_vehicle isKindOf "Plane") then { "loc_plane" } else { "loc_heli" }
} else { "loc_car" };
_marker setMarkerTypeLocal _markerType;

[_marker, 2, true] call EFUNC(markers,markerDecay);
[_marker, 2.5, true] call EFUNC(markers,markerDecay);
} forEach _emptyVehicles;

nil
1 change: 1 addition & 0 deletions addons/killers/functions/fnc_createTeleport.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion addons/markers/functions/fnc_markerDecay.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
11 changes: 7 additions & 4 deletions addons/markers/functions/fnc_markerDecayLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 01473e2

Please sign in to comment.