Skip to content

Commit

Permalink
Markers loop improvements + decaying markers after death
Browse files Browse the repository at this point in the history
  • Loading branch information
3Mydlo3 committed Apr 15, 2024
1 parent 01473e2 commit 56110c4
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 24 deletions.
1 change: 1 addition & 0 deletions addons/killers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PREP(initConfig);
PREP(initKillersBase);
PREP(initKillersStashes);
PREP(initStartPositions);
PREP(isKiller);
PREP(killerHandcuffed);
PREP(killerKilled);
PREP(killerRespawned);
2 changes: 1 addition & 1 deletion addons/killers/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if (hasInterface) then {
if (!(local (_this select 0))) exitWith {};
INFO("Killer player was killed");

[QGVAR(killerKilled), _this] call CBA_fnc_serverEvent;
[QGVAR(killerKilled), _this] call CBA_fnc_globalEvent;

[{alive player}, {
INFO("Killer player has respawned");
Expand Down
20 changes: 20 additions & 0 deletions addons/killers/functions/fnc_isKiller.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function checks if given unit is a killer.
*
* Arguments:
* 0: Unit to check if it's a killer <OBJECT>
*
* Return Value:
* True if unit is a killer <BOOL>
*
* Example:
* [player] call afsk_killers_fnc_isKiller
*
* Public: No
*/

params ["_unit"];

_unit getVariable [QEGVAR(common,side), side _unit] isEqualTo EAST
24 changes: 16 additions & 8 deletions addons/markers/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ if (isServer) then {
};
};

[QEGVAR(killers,killerKilled), {
_this call FUNC(deleteUnitMarker);
}] call CBA_fnc_addEventHandler;

[QEGVAR(police,copKilled), {
_this call FUNC(deleteUnitMarker);
}] call CBA_fnc_addEventHandler;

[QGVAR(playerDisconnected), {
params ["_unit", "_id", "_uid", "_name"];
[_unit] call FUNC(deleteUnitMarker);
Expand All @@ -35,4 +27,20 @@ if (isServer) then {

if (hasInterface) then {
call FUNC(loop);

if (playerSide isEqualTo WEST) exitWith {
[QEGVAR(killers,killerKilled), {
[QGVAR(deleteUnitMarker), [_this select 0]] call CBA_fnc_localEvent;
}] call CBA_fnc_addEventHandler;

[QEGVAR(police,copKilled), {
[_this select 0] call FUNC(markerDecay);
}] call CBA_fnc_addEventHandler;
};

if (playerSide isEqualTo EAST) exitWith {
[QEGVAR(killers,killerKilled), {
[_this select 0] call FUNC(markerDecay);
}] call CBA_fnc_addEventHandler;
};
};
2 changes: 2 additions & 0 deletions addons/markers/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ ADDON = false;
// Killswitch
if (!EGVAR(common,enabled)) exitWith {};

GVAR(markersToDelete) = [];

ADDON = true;
5 changes: 3 additions & 2 deletions addons/markers/functions/fnc_deleteUnitMarker.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function deletes unit marker.
* Function schedules deletion of the unit marker.
* This is done in that way to avoid leaking information via disappearing markers outside of refresh frame.
*
* Arguments:
* 0: Unit to remove it's marker <OBJECT>
Expand All @@ -18,5 +19,5 @@
params ["_unit"];

private _marker = _unit getVariable [QGVAR(marker), ""];
deleteMarkerLocal _marker;
GVAR(markersToDelete) pushBack _marker;
_unit setVariable [QGVAR(marker), nil];
21 changes: 13 additions & 8 deletions addons/markers/functions/fnc_loop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
* Public: No
*/

{
deleteMarkerLocal _x;
} forEach GVAR(markersToDelete);
GVAR(markersToDelete) = [];

// Move marker for every civilian
{
private _civilian = _x;
Expand Down Expand Up @@ -43,13 +48,16 @@ if (playerSide isEqualTo WEST) then {
} else {
_marker setMarkerPosLocal (position _cop);
};
} forEach (allPlayers select {side _x isEqualTo WEST});
} forEach (allPlayers select {[_x] call EFUNC(police,isCop)});
};

// Move marker for every killer
{
private _killer = _x;
private _hidden = !([_killer] call EFUNC(common,appearsArmed));
private _isInPrison = [_killer] call EFUNC(jail,isHandcuffed);

if (_isInPrison) exitWith {};

// Check if player should be able to see killer's marker
// Player must:
Expand All @@ -59,18 +67,15 @@ if (playerSide isEqualTo WEST) then {
if (playerSide isEqualTo EAST) then {
[_killer, _hidden] call FUNC(createOrUpdateKillerMarker);
} else {
private _isOrWasImprisoned = [_killer] call EFUNC(jail,isHandcuffed)
|| {_killer getVariable [QEGVAR(jail,wasImprisonedRecently), false]};
private _recentlyReleasedFromPrison = _killer getVariable [QEGVAR(jail,wasImprisonedRecently), false];

if (_hidden && {!_isOrWasImprisoned}) exitWith {
if (_hidden && {!_recentlyReleasedFromPrison}) exitWith {
[_killer, _hidden] call FUNC(createOrUpdateKillerMarker);
};

if !(_marker isEqualTo "") then {
[_killer] call FUNC(deleteUnitMarker);
};
[_killer] call FUNC(deleteUnitMarker);
};
} forEach (allPlayers select {side _x isEqualTo EAST});
} forEach (allPlayers select {[_x] call EFUNC(killers,isKiller)});

// Schedule next loop
[FUNC(loop), [], GVAR(refreshRate)] call CBA_fnc_waitAndExecute;
13 changes: 11 additions & 2 deletions addons/markers/functions/fnc_markerDecay.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
/*
* Author: 3Mydlo3
* Function starts marker decay loop with given time (in minutes) to decay by half.
* If an object is passed, it's assigned marker is retrieved.
*
* Arguments:
* 0: Marker <STRING>
* 0: Object or marker <OBJECT/STRING>
* 1: Time to decay by half (in minutes) <NUMBER>
*
* Return Value:
Expand All @@ -16,10 +17,18 @@
* Public: No
*/

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

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

private _marker = if (_unitOrMarker isEqualType objNull) then {
_unitOrMarker getVariable [QGVAR(marker), ""]
} else {
_unitOrMarker
};

if (_marker isEqualTo "") exitWith {};

[_marker, _decayRate, _currentAlpha, _local] call FUNC(markerDecayLoop);
2 changes: 1 addition & 1 deletion addons/police/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if (hasInterface) then {
}] call CBA_fnc_waitUntilAndExecute;

player addEventHandler ["Killed", {
[QGVAR(copKilled), _this] call CBA_fnc_serverEvent;
[QGVAR(copKilled), _this] call CBA_fnc_globalEvent;
}];
player addEventHandler ["Respawn", {
player setUnitLoadout EGVAR(common,playerLoadout);
Expand Down
4 changes: 2 additions & 2 deletions addons/police/functions/fnc_isCop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Function checks whether given unit is a cop.
*
* Arguments:
* 0: Unit <OBJECT>
* 0: Unit to check if it's a cop <OBJECT>
*
* Return Value:
* True if unit is a cop <BOOL>
Expand All @@ -19,4 +19,4 @@ params ["_unit"];

if (isNull _unit) exitWith { false };

_unit getVariable [QEGVAR(common,side), CIVILIAN] isEqualTo WEST
_unit getVariable [QEGVAR(common,side), side _unit] isEqualTo WEST

0 comments on commit 56110c4

Please sign in to comment.