Skip to content

Commit

Permalink
Add decaying markers for vehicles after killer is teleported (#56)
Browse files Browse the repository at this point in the history
* Add decaying markers for vehicles after killer is teleported

* Add local version of marker decay

* Fix radius parameter unused

* Create markers only for empty vehicles

* Fix markers still visible for everyone
  • Loading branch information
3Mydlo3 authored Jan 26, 2024
1 parent da7baec commit f38abee
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
1 change: 1 addition & 0 deletions addons/killers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PREP(addItemToStash);
PREP(createMarkersForNearbyVehicles);
PREP(createStartPositionMarker);
PREP(createTeleport);
PREP(deleteStartPositionsMarkers);
Expand Down
13 changes: 13 additions & 0 deletions addons/killers/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,16 @@ if (hasInterface) then {
}] call CBA_fnc_waitUntilAndExecute;
}] call CBA_fnc_addClassEventHandler;
};

[QGVAR(teleport), {
params ["_killer", "_destination"];

if (_destination isEqualType objNull) then {
_destination = getPos _destination;
};

// Mark nearest vehicles for first couple minutes
[_destination] call FUNC(createMarkersForNearbyVehicles);

[QEGVAR(common,teleport), [_killer, _destination]] call CBA_fnc_localEvent;
}] call CBA_fnc_addEventHandler;
41 changes: 41 additions & 0 deletions addons/killers/functions/fnc_createMarkersForNearbyVehicles.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Searches for vehicles in given radius near given position.
* Creates a decaying marker for each vehicle.
*
* Arguments:
* 0: Search position <POSITION>
* 1: Search radius <NUMBER>
*
* Return Value:
* None
*
* Example:
* [getPos bob, 500] call afsk_killers_fnc_createMarkersForNearbyVehicles
*
* Public: No
*/

params ["_position", ["_radius", 1000]];

private _nearbyVehicles = _position nearEntities [["Air", "Car", "Motorcycle", "Tank"], _radius];
private _emptyVehicles = _nearbyVehicles select {
crew _x isEqualTo []
};

{
private _vehicle = _x;
private _marker = createMarkerLocal [format ["vehicle_%1", _vehicle], getPos _vehicle];
_marker setMarkerColorLocal "ColorCIVILIAN";
_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);
} forEach _emptyVehicles;

nil
2 changes: 1 addition & 1 deletion addons/killers/functions/fnc_createTeleport.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private _positionID = 0;
private _destinationName = format ["%1 - %2", _positionID, _x];
private _destinationPos = GVAR(startPositions) getVariable _x;
private _teleportActionID = _flag addAction [_destinationName, {
[QEGVAR(common,teleport), [_this select 1, _this select 3 select 0]] call CBA_fnc_serverEvent;
[QEGVAR(killers,teleport), [_this select 1, _this select 3 select 0]] call CBA_fnc_localEvent;
// Delete all teleport actions and markers
call FUNC(deleteStartPositionsMarkers);
private _teleportActionsIDs = (_this select 0) getVariable [QGVAR(teleportActionsIDs), []];
Expand Down
4 changes: 2 additions & 2 deletions addons/markers/functions/fnc_markerDecay.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* Public: No
*/

params ["_marker", ["_decayHalfTime", 10]];
params ["_marker", ["_decayHalfTime", 10], ["_local", false]];

// How much decay will be applied every 15 seconds
private _decayRate = 1/(_decayHalfTime * 4 * 2);

[_marker, _decayRate] call FUNC(markerDecayLoop);
[_marker, _decayRate, _local] call FUNC(markerDecayLoop);
10 changes: 7 additions & 3 deletions addons/markers/functions/fnc_markerDecayLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
* Public: No
*/

params ["_marker", "_decayRate"];
params ["_marker", "_decayRate", ["_local", false]];

private _currentAlpha = markerAlpha _marker;

if (_currentAlpha <= _decayRate) exitWith {deleteMarker _marker};

_marker setMarkerAlpha (_currentAlpha - _decayRate);
if (_local) then {
_marker setMarkerAlphaLocal (_currentAlpha - _decayRate);
} else {
_marker setMarkerAlpha (_currentAlpha - _decayRate);
};

[FUNC(markerDecayLoop), [_marker, _decayRate], 15] call CBA_fnc_waitAndExecute;
[FUNC(markerDecayLoop), [_marker, _decayRate, _local], 15] call CBA_fnc_waitAndExecute;

0 comments on commit f38abee

Please sign in to comment.