Skip to content

Commit

Permalink
Fix killer marker behaviour and prevent cops from seeing jail situati…
Browse files Browse the repository at this point in the history
…on from the map markers (#60)

* Fix killer marker not going back to red if he's armed

* Prevent cops from seeing "hidden" killer marker in jail and shortly after release

* Fix compilation

* Fix isHandcuffed returning nil every time

* Remove redundant empty line

* Remove cop/killer marker on death
  • Loading branch information
3Mydlo3 authored Feb 6, 2024
1 parent 3c274ae commit c75ce42
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 26 deletions.
1 change: 1 addition & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (isServer) then {
if (hasInterface) then {
/* Initial player loadout */
GVAR(playerLoadout) = getUnitLoadout player;
player setVariable [QGVAR(side), playerSide, true];

/* Spectator events */
[QGVAR(initializeSideSpectator), {
Expand Down
1 change: 1 addition & 0 deletions addons/jail/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ PREP(free);
PREP(freeAll);
PREP(getRandomJailPos);
PREP(imprison);
PREP(isHandcuffed);
PREP(jailMarker);
PREP(removeReleaseAction);
8 changes: 8 additions & 0 deletions addons/jail/functions/fnc_free.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ params ["_prisoner"];
GVAR(prisoners) deleteAt (GVAR(prisoners) findIf {_x isEqualTo _prisoner});
publicVariable QGVAR(prisoners);
_prisoner setVariable [QGVAR(isImprisoned), false, true];
_prisoner setVariable [QGVAR(wasImprisonedRecently), true, true];

[{[_this] call FUNC(isHandcuffed)}, {
// Ignore if he's a prisoner again
}, _prisoner, RECENTLY_FREED_TIMEOUT, {
// Clear the flag
_this setVariable [QGVAR(wasImprisonedRecently), false, true];
}] call CBA_fnc_waitUntilAndExecute;

// Terminate prisoner spectator
[QEGVAR(common,terminateSpectator), [], _prisoner] call CBA_fnc_targetEvent;
24 changes: 24 additions & 0 deletions addons/jail/functions/fnc_isHandcuffed.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function checks if a unit is handcuffed.
*
* Arguments:
* 0: Unit to check <UNIT>
*
* Return Value:
* True if unit is handcuffed (alive, but can't move on it's own) <BOOL>
*
* Example:
* [bob] call afsk_jail_fnc_isHandcuffed
*
* Public: No
*/

params ["_unit"];

if (EGVAR(common,ACE_Loaded)) then {
_unit getVariable [QACEGVAR(captives,isHandcuffed), false]
} else {
_unit getVariable [QEGVAR(jail,isImprisoned), false]
};
2 changes: 2 additions & 0 deletions addons/jail/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
#endif

#include "\z\afsk\addons\main\script_macros.hpp"

#define RECENTLY_FREED_TIMEOUT 60
18 changes: 5 additions & 13 deletions addons/killers/functions/fnc_anyKillerFree.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@
* Public: No
*/

if (EGVAR(common,ACE_Loaded)) then {
allPlayers findIf {
side _x isEqualTo EAST
&& {alive _x
&& {!(_x getVariable [QACEGVAR(captives,isHandcuffed), false])
}}}!= -1
} else {
allPlayers findIf {
side _x isEqualTo EAST
&& {alive _x
&& {!(_x getVariable [QEGVAR(jail,isImprisoned), false])
}}}!= -1
};
allPlayers findIf {
side _x isEqualTo EAST
&& {alive _x
&& {!([_x] call EFUNC(jail,isHandcuffed))
}}} != -1

1 change: 1 addition & 0 deletions addons/markers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PREP(createCivilianMarker);
PREP(createCopMarker);
PREP(createKillerMarker);
PREP(createOrUpdateKillerMarker);
PREP(deleteUnitMarker);
PREP(markerDecay);
PREP(markerDecayLoop);
Expand Down
8 changes: 8 additions & 0 deletions addons/markers/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ 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 Down
3 changes: 3 additions & 0 deletions addons/markers/functions/fnc_createKillerMarker.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ params ["_killer", ["_hidden", false]];
private _marker = format["killer_%1", name _killer];
createMarkerLocal [_marker, getPos _killer];
_marker setMarkerTypeLocal "mil_dot";

if (_hidden) then {
_marker setMarkerColorLocal "ColorGreen";
} else {
_marker setMarkerColorLocal "ColorEAST";
};

if (playerSide isEqualTo EAST) then {
_marker setMarkerSizeLocal [0.75, 0.75];
_marker setMarkerTextLocal (name _killer);
} else {
_marker setMarkerSizeLocal [0.5, 0.5];
};

_killer setVariable [QGVAR(marker), _marker];
33 changes: 33 additions & 0 deletions addons/markers/functions/fnc_createOrUpdateKillerMarker.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function creates or updates marker for given killer.
*
* Arguments:
* 0: Unit to create marker for <OBJECT>
* 1: Is it hide marker? <BOOL>
*
* Return Value:
* None
*
* Example:
* [player] call afsk_markers_fnc_createKillerMarker
*
* Public: No
*/

params ["_killer", ["_hidden", false]];

private _marker = _killer getVariable [QGVAR(marker), ""];

if (_marker isEqualTo "") then {
_marker = [_killer, _hidden] call FUNC(createKillerMarker);
} else {
_marker setMarkerPosLocal (position _killer);

if (_hidden) then {
_marker setMarkerColorLocal "ColorGreen";
} else {
_marker setMarkerColorLocal "ColorRed";
};
};
27 changes: 14 additions & 13 deletions addons/markers/functions/fnc_loop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@ if (playerSide isEqualTo WEST) then {
{
private _killer = _x;
private _hidden = !([_killer] call EFUNC(common,appearsArmed));
private _marker = _killer getVariable [QGVAR(marker), ""];

// Check if player should be able to see killer's marker
if (playerSide isEqualTo EAST || {_hidden}) then {
// Check if killer already has marker
if (_marker isEqualTo "") then {
_marker = [_killer, _hidden] call FUNC(createKillerMarker);
} else {
_marker setMarkerPosLocal (position _killer);
if (_hidden) then {
_marker setMarkerColorLocal "ColorGreen";
} else {
_marker setMarkerColorLocal "ColorRed";
};
};
// Player must:
// 1. either be EAST (other killer)
// 2a. or a killer must appear as unarmed
// 2b. and not be in prison, or recently freed from prison
if (playerSide isEqualTo EAST) then {
[_killer, _hidden] call FUNC(createOrUpdateKillerMarker);
} else {
private _isOrWasImprisoned = [_killer] call EFUNC(jail,isHandcuffed)
|| {_killer getVariable [QEGVAR(jail,wasImprisonedRecently), false]};

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

if !(_marker isEqualTo "") then {
[_killer] call FUNC(deleteUnitMarker);
};
Expand Down

0 comments on commit c75ce42

Please sign in to comment.