Skip to content

Commit

Permalink
Improve initialization order for police stuff and allow saving loadou…
Browse files Browse the repository at this point in the history
…t for respawn (#69)

* Add action to save equipment for respawn

* Move all vehicle spawn actions to the top of action menu

* Add message after loadout is saved for respawn

* Drop unused param
  • Loading branch information
3Mydlo3 authored Feb 15, 2024
1 parent 5bfe82a commit 5230e37
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 2 deletions.
2 changes: 2 additions & 0 deletions addons/police/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PREP(createTeleport);
PREP(equipmentScoreCheck);
PREP(initPoliceStation);
PREP(initSpawner);
PREP(initPoliceStationClient);
PREP(initSaveEquipmentAction);
PREP(policeStationAlarm);
PREP(policeStationMarker);
PREP(removeVehiclesFromSpawner);
Expand Down
8 changes: 8 additions & 0 deletions addons/police/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ if (isServer) then {
// Initialize respawn for given police station
[WEST, _x] call BIS_fnc_addRespawnPosition;
} forEach EGVAR(modules,policeStations);

publicVariable QGVAR(arsenals);
}] call CBA_fnc_execNextFrame;
}] call CBA_fnc_waitUntilAndExecute;

Expand Down Expand Up @@ -59,6 +61,12 @@ if (isServer) then {

if (hasInterface) then {
if !(playerSide isEqualTo WEST) exitWith {};

// Fill arsenal with starting items
[{GVAR(arsenals) isNotEqualTo []}, {
call FUNC(initPoliceStationClient);
}] call CBA_fnc_waitUntilAndExecute;

player addEventHandler ["Killed", {
[QGVAR(copKilled), _this] call CBA_fnc_serverEvent;
}];
Expand Down
2 changes: 1 addition & 1 deletion addons/police/functions/fnc_addVehiclesToSpawner.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private _vehicleActions = _spawner getVariable QGVAR(vehicleActions);
private _vehicleName = getText (configFile >> "CfgVehicles" >> _x >> "displayName");
private _vehicleRequiredScore = [_x] call EFUNC(equipment,getRequiredScoreForItem);
private _actionText = format ["(%1) %2", _vehicleRequiredScore, _vehicleName];
private _actionID = _spawner addAction [_actionText, {[QGVAR(spawnVehicle), _this select 3] call CBA_fnc_serverEvent}, [_x, _spawner], _vehicleRequiredScore, true, true, "", "true", 3];
private _actionID = _spawner addAction [_actionText, {[QGVAR(spawnVehicle), _this select 3] call CBA_fnc_serverEvent}, [_x, _spawner], _vehicleRequiredScore + 10, true, true, "", "true", 3];

// Assign to namespace
_vehicleActions setVariable [_x, _actionID];
Expand Down
1 change: 0 additions & 1 deletion addons/police/functions/fnc_initPoliceStation.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ _logic setVariable ["Arsenal", _box, true];
_box setVariable ["policeStation", _logic, true];
[_box] call EFUNC(common,createArsenal);
GVAR(arsenals) pushBack _box;
publicVariable QGVAR(arsenals);

// Init vehicle spawner
[_box] call FUNC(initSpawner);
Expand Down
22 changes: 22 additions & 0 deletions addons/police/functions/fnc_initPoliceStationClient.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function initializes police station for client. Creates vehicle spawners, teleporters and arsenals.
*
* Arguments:
* 0: Police Station Module <LOGIC>
*
* Return Value:
* None
*
* Example:
* None
*
* Public: No
*/

{
[_x] call FUNC(initSaveEquipmentAction);
} forEach GVAR(arsenals);

call FUNC(equipmentScoreCheck);
44 changes: 44 additions & 0 deletions addons/police/functions/fnc_initSaveEquipmentAction.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function initializes action to save equipment for respawn on given object.
*
* Arguments:
* 0: Object which should allow saving equipment <OBJECT>
*
* Return Value:
* None
*
* Example:
* None
*
* Public: No
*/

params ["_object"];

private _condition = {side player isEqualTo WEST};

private _action = [
QGVAR(saveEquipment),
LLSTRING(SaveEquipmentForRespawn),
"",
{
EGVAR(common,playerLoadout) = getUnitLoadout player;
private _primaryWeapon = primaryWeapon player;
private _launcherWeapon = secondaryWeapon player;
private _handgun = handgunWeapon player;

private _msg = format [LLSTRING(SavedEquipment), _primaryWeapon, _handgun, _launcherWeapon];
[QGVAR(showMessage), [_msg]] call CBA_fnc_localEvent;
},
_condition,
{}, [], "", 4, [false, false, false, false, false], {}
] call ace_interact_menu_fnc_createAction;

[
_object,
0,
["ACE_MainActions"],
_action
] call ACEFUNC(interact_menu,addActionToObject);
8 changes: 8 additions & 0 deletions addons/police/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@
<English>Cop was killed at %1 near %2!</English>
<Polish>Policjant został zabity o godzinie %1 w pobliżu %2!</Polish>
</Key>
<Key ID="STR_AFSK_Police_SaveEquipmentForRespawn">
<English>Save equipment for respawn</English>
<Polish>Zapisz ekwipunek do odrodzenia</Polish>
</Key>
<Key ID="STR_AFSK_Police_SavedEquipment">
<English>Saved equipment for respawn. Primary weapon: %1 Handgun: %2 Launcher: %3</English>
<Polish>Zapisano ekwipunek do odrodzenia. Broń podstawowa: %1 Pistolet: %2 Wyrzutnia: %3</Polish>
</Key>
</Package>
</Project>

0 comments on commit 5230e37

Please sign in to comment.