Skip to content

Commit

Permalink
Fix freeing from jail not working at all (#68)
Browse files Browse the repository at this point in the history
* Add logging for debugging what's happening

* Fix freeing from prison

* Log that killer was killed

* Possibly fix being unable to properly free from prison

* Fix cs_grad

* Mark that killer has respawned

* Extract release actions stuff to separate functions
  • Loading branch information
3Mydlo3 authored Mar 6, 2024
1 parent 8ff00a2 commit 94969a6
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 38 deletions.
3 changes: 3 additions & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ if (hasInterface) then {

/* Spectator events */
[QGVAR(initializeSideSpectator), {
INFO("Starting side spectator");
["Initialize", [player, [playerSide], false, true, true, true, true, true, true, true]] call BIS_fnc_EGSpectator;
}] call CBA_fnc_addEventHandler;

[QGVAR(initializeSpectator), {
INFO("Starting spectator");
["Initialize", [player, [], false, true, true, true, true, true, true, true]] call BIS_fnc_EGSpectator;
}] call CBA_fnc_addEventHandler;

[QGVAR(terminateSpectator), {
["Terminate"] call BIS_fnc_EGSpectator;
INFO("Terminated spectator");
}] call CBA_fnc_addEventHandler;

/* Sidechat msg event */
Expand Down
3 changes: 3 additions & 0 deletions addons/jail/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ PREP(free);
PREP(freeAll);
PREP(getRandomJailPos);
PREP(imprison);
PREP(initAceHandcuffed);
PREP(initReleaseAction);
PREP(initReleaseEventHandler);
PREP(isHandcuffed);
PREP(jailMarker);
PREP(removeReleaseAction);
36 changes: 1 addition & 35 deletions addons/jail/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,7 @@ if (isServer) then {

if (hasInterface) then {
if (playerSide isEqualTo EAST) then {
// Add/remove prisoner release action EH for EAST only
[QGVAR(addReleaseAction), {
_this call FUNC(addReleaseAction);
}] call CBA_fnc_addEventHandler;
[QGVAR(removeReleaseAction), {
_this call FUNC(removeReleaseAction);
}] call CBA_fnc_addEventHandler;

// Add local EH for release from prison. Supports ACE captives tie/untie.
if (EGVAR(common,ACE_Loaded)) then {
// Add ACE EH for handcuffing
[QACEGVAR(captives,setHandcuffed), {
params ["_unit", "_isHandcuffed"];
if !(_unit isEqualTo player) exitWith {};
if (_isHandcuffed) exitWith {
[QEGVAR(killers,killerHandcuffed), [_unit]] call CBA_fnc_serverEvent;
};
if (_unit getVariable [QGVAR(isImprisoned), false]) then {
[QGVAR(free), [player]] call CBA_fnc_serverEvent;
};
}] call CBA_fnc_addEventHandler;
} else {
// Add own EH for release
[QGVAR(released), {
params ["_unit"];
if (!(_unit isEqualTo player)) exitWith {};
if (_unit getVariable [QGVAR(isImprisoned), false]) then {
[QGVAR(free), [player]] call CBA_fnc_serverEvent;
};
}] call CBA_fnc_addEventHandler;
};

// JIP compatibility for own release action
{
[QGVAR(addReleaseAction), [_x]] call CBA_fnc_localEvent;
} forEach GVAR(prisoners);
call FUNC(initReleaseEventHandler);
};
};
17 changes: 17 additions & 0 deletions addons/jail/functions/fnc_free.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

params ["_prisoner"];

if (!(_prisoner getVariable [QGVAR(isImprisoned), false])) exitWith {
WARNING_1("Killer %1 is not in prison and can't be freed!",name _prisoner);
};

// Remove prisoner from prisoners list and remove assigned variable
GVAR(prisoners) deleteAt (GVAR(prisoners) findIf {_x isEqualTo _prisoner});
publicVariable QGVAR(prisoners);
Expand All @@ -28,7 +32,20 @@ _prisoner setVariable [QGVAR(wasImprisonedRecently), true, true];
}, _prisoner, RECENTLY_FREED_TIMEOUT, {
// Clear the flag
_this setVariable [QGVAR(wasImprisonedRecently), false, true];
INFO_1("Killer %1 is no longer considered as recently imprisoned.",name _prisoner);
}] call CBA_fnc_waitUntilAndExecute;

// Release prisoner. Supports ACE Captives untie.
if (EGVAR(common,ACE_Loaded)) then {
// Untie the prisoner.
[QACEGVAR(captives,setHandcuffed), [_prisoner, false], _prisoner] call CBA_fnc_targetEvent;
} else {
// Own implementation
[QGVAR(released), [_target], _target] call CBA_fnc_targetEvent;
[QGVAR(removeReleaseAction)] call CBA_fnc_globalEvent;
};

// Terminate prisoner spectator
[QEGVAR(common,terminateSpectator), [], _prisoner] call CBA_fnc_targetEvent;

INFO_1("Killer %1 is now free",name _prisoner);
3 changes: 1 addition & 2 deletions addons/jail/functions/fnc_freeAll.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ GVAR(prisoners) = [];
};
} forEach _prisoners;

private _msg = format ["Prisoners have been released from the prison!"];
[QEGVAR(common,showSideChatMsg), [WEST, _msg]] call CBA_fnc_globalEvent;
[QEGVAR(common,showSideChatMsg), [WEST, LLSTRING(Prisoners_Released)]] call CBA_fnc_globalEvent;
2 changes: 2 additions & 0 deletions addons/jail/functions/fnc_imprison.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ if (EGVAR(common,ACE_Loaded)) then {
// Add own release action to prisoner.
[QGVAR(addReleaseAction), [_unit]] call CBA_fnc_globalEvent;
};

INFO_1("Killer %1 is now imprisoned",name _unit);
31 changes: 31 additions & 0 deletions addons/jail/functions/fnc_initAceHandcuffed.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function initializes event handler on ACE Handcuffed event.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* call afsk_jail_fnc_initAceHandcuffed
*
* Public: No
*/

[QACEGVAR(captives,setHandcuffed), {
params ["_unit", "_isHandcuffed"];
if !(_unit isEqualTo player) exitWith {};

// Unit was handcuffed (arrested)
if (_isHandcuffed) exitWith {
[QEGVAR(killers,killerHandcuffed), [_unit]] call CBA_fnc_serverEvent;
};

// If a unit was imprisoned, free it
if (_unit getVariable [QGVAR(isImprisoned), false]) then {
[QGVAR(free), [player]] call CBA_fnc_serverEvent;
};
}] call CBA_fnc_addEventHandler;
38 changes: 38 additions & 0 deletions addons/jail/functions/fnc_initReleaseAction.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function initializes own implementation of release action.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* call afsk_jail_fnc_initReleaseAction
*
* Public: No
*/

// Add/remove prisoner release action EH for EAST only
[QGVAR(addReleaseAction), {
_this call FUNC(addReleaseAction);
}] call CBA_fnc_addEventHandler;
[QGVAR(removeReleaseAction), {
_this call FUNC(removeReleaseAction);
}] call CBA_fnc_addEventHandler;

// Add own EH for release
[QGVAR(released), {
params ["_unit"];
if (!(_unit isEqualTo player)) exitWith {};
if (_unit getVariable [QGVAR(isImprisoned), false]) then {
[QGVAR(free), [player]] call CBA_fnc_serverEvent;
};
}] call CBA_fnc_addEventHandler;

// JIP compatibility for own release action
{
[QGVAR(addReleaseAction), [_x]] call CBA_fnc_localEvent;
} forEach GVAR(prisoners);
23 changes: 23 additions & 0 deletions addons/jail/functions/fnc_initReleaseEventHandler.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function initializes release event handler(s).
* Exact implementation is selected depending on ACE being loaded.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* call afsk_jail_fnc_initReleaseEventHandler
*
* Public: No
*/

if (EGVAR(common,ACE_Loaded)) then {
call FUNC(initAceHandcuffed);
} else {
call FUNC(initReleaseAction);
};
4 changes: 4 additions & 0 deletions addons/jail/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
<English>Release prisoner</English>
<Polish>Uwolnij więźnia</Polish>
</Key>
<Key ID="STR_AFSK_Jail_Prisoners_Released">
<English>Prisoners have been released from the prison!</English>
<Polish>Więźniowie zostali uwolnieni z więzienia!</Polish>
</Key>
</Package>
</Project>
7 changes: 6 additions & 1 deletion addons/killers/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ if (hasInterface) then {
}] call CBA_fnc_addEventHandler;

// Killer killed EH
["C_man_p_fugitive_F", "killed", {
[KILLER_UNIT_CLASS, "killed", {
INFO("Killer was killed");
if (!(local (_this select 0))) exitWith {};
INFO("Killer player was killed");

[QGVAR(killerKilled), _this] call CBA_fnc_serverEvent;

[{alive player}, {
INFO("Killer player has respawned");
[QGVAR(killerRespawned), [player]] call CBA_fnc_serverEvent;
}] call CBA_fnc_waitUntilAndExecute;
}] call CBA_fnc_addClassEventHandler;
Expand Down
2 changes: 2 additions & 0 deletions addons/killers/functions/fnc_killerKilled.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ params ["_unit", "_killer"];

if !(isServer) exitWith {};

INFO_1("Killer %1 was killed",name _unit);

// Create spectator for killer so he won't get bored when he's dead or imprisoned.
[QEGVAR(common,initializeSpectator), [], _unit] call CBA_fnc_targetEvent;
4 changes: 4 additions & 0 deletions addons/killers/functions/fnc_killerRespawned.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@

params ["_unit"];

INFO_1("Killer %1 has respawned",name _unit);

_unit setVariable [QGVAR(alreadyKilled), false];

[QEGVAR(jail,imprison), [_unit]] call CBA_fnc_serverEvent;
2 changes: 2 additions & 0 deletions addons/killers/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 KILLER_UNIT_CLASS "C_man_p_fugitive_F"

0 comments on commit 94969a6

Please sign in to comment.