Skip to content

Commit

Permalink
safe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
commy2 committed Nov 8, 2014
1 parent 34be078 commit d6a8f84
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 5 deletions.
3 changes: 2 additions & 1 deletion AGM_Aircraft/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ class CfgVehicles {
class Turrets: Turrets {
class CopilotTurret: MainTurret {};
};
class UserActions;
};
class Plane_Base_F;

Expand Down Expand Up @@ -859,7 +860,7 @@ class CfgVehicles {
class Turrets: Turrets {
class CopilotTurret: CopilotTurret {};
};
class UserActions {
class UserActions: UserActions {
class DoorL1_Open {
available = 1;
condition = "this animationPhase ""door_back_L"" < 0.5 AND Alive(this)";
Expand Down
6 changes: 5 additions & 1 deletion AGM_Overheating/functions/fn_clearJam.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// by commy2

private ["_unit", "_weapon", "_skipAnim", "_jammedWeapons", "_actionID", "_clearJamAction"];
private ["_unit", "_weapon", "_skipAnim", "_jammedWeapons"];

_unit = _this select 0;
_weapon = _this select 1;
Expand All @@ -14,13 +14,17 @@ if (_weapon in _jammedWeapons) then {
_unit setVariable ["AGM_Overheating_jammedWeapons", _jammedWeapons];

if (count _jammedWeapons == 0) then {
private "_actionID";

_actionID = _unit getVariable ["AGM_JammingActionID", -1];
//_unit removeAction _actionID;
[_unit, "DefaultAction", _actionID] call AGM_Core_fnc_removeActionEventHandler;
_unit setVariable ["AGM_JammingActionID", -1];
};

if !(_skipAnim) then {
private "_clearJamAction";

_clearJamAction = getText (configFile >> "CfgWeapons" >> _weapon >> "AGM_clearJamAction");

if (_clearJamAction == "") then {
Expand Down
9 changes: 6 additions & 3 deletions AGM_Overheating/functions/fn_jamWeapon.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// based on KK_fnc_playerWeaponMulfunction from KillzoneKid

private ["_unit", "_weapon", "_jammedWeapons", "_condition", "_statement", "_actionID"];
private ["_unit", "_weapon", "_jammedWeapons"];

_unit = _this select 0;
_weapon = _this select 1;
Expand Down Expand Up @@ -36,13 +36,16 @@ _unit setVariable ["AGM_Overheating_jammedWeapons", _jammedWeapons];
AGM_Overheating_knowAboutJam = false;

if (_unit getVariable ["AGM_JammingActionID", -1] == -1) then {
private ["_condition", "_statement", "_actionID"];

_condition = {
_this select 1 == vehicle (_this select 1)
&& {currentMuzzle (_this select 1) in ((_this select 1) getVariable ['AGM_Overheating_jammedWeapons', []])}
&& {currentMuzzle (_this select 1) in ((_this select 1) getVariable ["AGM_Overheating_jammedWeapons", []])}
&& {!(currentMuzzle (_this select 1) in ((_this select 1) getVariable ["AGM_SafeMode_safedWeapons", []]))}
};

_statement = {
playSound3D ['a3\sounds_f\weapons\Other\dry9.wss', _this select 0];
playSound3D ["a3\sounds_f\weapons\Other\dry9.wss", _this select 0];

if (!(missionNamespace getVariable ["AGM_Overheating_knowAboutJam", false]) && {(_this select 1) ammo currentWeapon (_this select 1) > 0}) then {
[localize "STR_AGM_Overheating_WeaponJammed"] call AGM_Core_fnc_displayTextStructured;
Expand Down
38 changes: 38 additions & 0 deletions AGM_SafeMode/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// PATCH CONFIG
class CfgPatches {
class AGM_SafeMode {
units[] = {};
weapons[] = {};
requiredVersion = 0.60;
requiredAddons[] = {AGM_Core};
version = "0.94.1";
versionStr = "0.94.1";
versionAr[] = {0,94,1};
author[] = {"commy2"};
authorUrl = "https://github.com/commy2/";
};
};

class CfgFunctions {
class AGM_SafeMode {
class AGM_SafeMode {
file = "AGM_SafeMode\functions";
class firstMode;
class lockSafety;
class unlockSafety;
};
};
};

class AGM_Core_Default_Keys {
class safeWeapon {
displayName = "$STR_AGM_SafeMode_SafeMode";
condition = "[_player] call AGM_Core_fnc_canUseWeapon";
statement = "[_player, currentWeapon _player] call AGM_SafeMode_fnc_lockSafety";
exceptions[] = {"AGM_Interaction_isNotEscorting"};
key = 41;
shift = 0;
control = 1;
alt = 0;
};
};
9 changes: 9 additions & 0 deletions AGM_SafeMode/functions/fn_firstMode.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// by commy2

private ["_weapon", "_mode"];

_weapon = _this select 0;

_mode = getArray (configFile >> "CfgWeapons" >> _weapon >> "modes") select 0;

[_mode, _weapon] select (_mode == "this")
40 changes: 40 additions & 0 deletions AGM_SafeMode/functions/fn_lockSafety.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// by commy2

private ["_unit", "_weapon", "_safedWeapons"];

_unit = _this select 0;
_weapon = _this select 1;

_safedWeapons = _unit getVariable ["AGM_SafeMode_safedWeapons", []];

if (_weapon in _safedWeapons) exitWith {
_this call AGM_SafeMode_fnc_unlockSafety;
};

_safedWeapons pushBack _weapon;

_unit setVariable ["AGM_SafeMode_safedWeapons", _safedWeapons];

if (_unit getVariable ["AGM_SafeWeaponActionIDs", [-1, -1]] select 0 == -1) then {
private ["_condition", "_statement", "_actionIDs"];

_condition = {
_this select 1 == vehicle (_this select 1)
&& {currentMuzzle (_this select 1) in ((_this select 1) getVariable ["AGM_SafeMode_safedWeapons", []])}
};

_statement = {
[_this select 1, currentWeapon (_this select 1)] call AGM_SafeMode_fnc_unlockSafety;
};

_actionIDs = [
[_unit, "DefaultAction", _condition, {}] call AGM_Core_fnc_addActionEventHandler,
[_unit, "nextWeapon", {true}, _statement] call AGM_Core_fnc_addActionEventHandler
];

_unit setVariable ["AGM_SafeWeaponActionIDs", _actionIDs];
};

_unit selectWeapon _weapon;

playSound "AGM_Sound_Click";
28 changes: 28 additions & 0 deletions AGM_SafeMode/functions/fn_unlockSafety.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// by commy2

private ["_unit", "_weapon", "_safedWeapons"];

_unit = _this select 0;
_weapon = _this select 1;

_safedWeapons = _unit getVariable ["AGM_SafeMode_safedWeapons", []];

if (_weapon in _safedWeapons) then {
_safedWeapons = _safedWeapons - [_weapon];

_unit setVariable ["AGM_SafeMode_safedWeapons", _safedWeapons];

if (count _safedWeapons == 0) then {
private "_actionIDs";

_actionIDs = _unit getVariable ["AGM_SafeWeaponActionIDs", [-1, -1]];
//_unit removeAction _actionID;
[_unit, "DefaultAction", _actionIDs select 0] call AGM_Core_fnc_removeActionEventHandler;
[_unit, "nextWeapon", _actionIDs select 1] call AGM_Core_fnc_removeActionEventHandler;
_unit setVariable ["AGM_SafeWeaponActionIDs", [-1, -1]];
};
};

_unit selectWeapon _weapon;

playSound "AGM_Sound_Click";
9 changes: 9 additions & 0 deletions AGM_SafeMode/stringtable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="AGM">
<Package name="SafeMode">
<Key ID="STR_AGM_SafeMode_SafeMode">
<English>Safe Mode</English>
<German>Waffe sichern</German>
</Key>
</Package>
</Project>
5 changes: 5 additions & 0 deletions AGM_WeaponSelect/functions/fn_selectWeaponMode.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ _weapon = _this select 1;

if (_weapon == "") exitWith {};

// unlock safety
if (_weapon in (_player getVariable ["AGM_SafeMode_safedWeapons", []])) exitWith {
_this call AGM_SafeMode_fnc_unlockSafety;
};

if (currentWeapon _player != _weapon) exitWith {
_player selectWeapon _weapon;
};
Expand Down
5 changes: 5 additions & 0 deletions AGM_WeaponSelect/functions/fn_selectWeaponMuzzle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ _weapon = _this select 1;

if (_weapon == "") exitWith {};

// unlock safety
if (_weapon in (_player getVariable ["AGM_SafeMode_safedWeapons", []])) exitWith {
_this call AGM_SafeMode_fnc_unlockSafety;
};

_muzzles = [_weapon] call AGM_WeaponSelect_fnc_getWeaponMuzzles;

if (currentWeapon _player != _weapon) exitWith {
Expand Down

0 comments on commit d6a8f84

Please sign in to comment.