mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
AGM_SafeMode pre CBA
This commit is contained in:
9
addons/safemode/functions/fn_firstMode.sqf
Normal file
9
addons/safemode/functions/fn_firstMode.sqf
Normal file
@ -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")
|
65
addons/safemode/functions/fn_lockSafety.sqf
Normal file
65
addons/safemode/functions/fn_lockSafety.sqf
Normal file
@ -0,0 +1,65 @@
|
||||
// by commy2
|
||||
|
||||
private ["_unit", "_weapon", "_muzzle", "_safedWeapons"];
|
||||
|
||||
_unit = _this select 0;
|
||||
_weapon = _this select 1;
|
||||
_muzzle = _this select 2;
|
||||
|
||||
// don't immediately switch back
|
||||
if (inputAction "nextWeapon" > 0) exitWith {};
|
||||
|
||||
_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_SafeWeapon_actionID", -1] == -1) then {
|
||||
private ["_condition", "_statement", "_id"];
|
||||
|
||||
_condition = {
|
||||
if (
|
||||
[_this select 1] call AGM_Core_fnc_canUseWeapon
|
||||
&& {
|
||||
if (currentMuzzle (_this select 1) in ((_this select 1) getVariable ["AGM_SafeMode_safedWeapons", []])) then {
|
||||
if (inputAction "nextWeapon" > 0) exitWith {
|
||||
[_this select 1, currentWeapon (_this select 1), currentMuzzle (_this select 1)] call AGM_SafeMode_fnc_unlockSafety;
|
||||
false
|
||||
};
|
||||
true
|
||||
} else {false}
|
||||
}
|
||||
) then {
|
||||
// player hud
|
||||
[false] call AGM_SafeMode_fnc_setSafeModeVisual;
|
||||
true
|
||||
} else {
|
||||
// player hud
|
||||
[true] call AGM_SafeMode_fnc_setSafeModeVisual;
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
_statement = {
|
||||
[_this select 1, currentWeapon (_this select 1), currentMuzzle (_this select 1)] call AGM_SafeMode_fnc_unlockSafety;
|
||||
};
|
||||
|
||||
//_id = [_unit, format ["<t color=""#FFFF00"" >%1</t>", localize "STR_AGM_SafeMode_TakeOffSafety"], "DefaultAction", _condition, {}, {true}, _statement, 10] call AGM_Core_fnc_addActionMenuEventHandler;
|
||||
_id = [_unit, "DefaultAction", _condition, {}] call AGM_Core_fnc_addActionEventHandler;
|
||||
|
||||
_unit setVariable ["AGM_SafeWeapon_actionID", _id];
|
||||
};
|
||||
|
||||
_unit selectWeapon _muzzle;//_weapon
|
||||
|
||||
// play fire mode selector sound
|
||||
[_unit, _weapon, _muzzle] call AGM_SafeMode_fnc_playChangeFiremodeSound;
|
||||
|
||||
private "_picture";
|
||||
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
|
||||
[localize "STR_AGM_SafeMode_PutOnSafety", _picture] call AGM_Core_fnc_displayTextPicture;
|
34
addons/safemode/functions/fn_playChangeFiremodeSound.sqf
Normal file
34
addons/safemode/functions/fn_playChangeFiremodeSound.sqf
Normal file
@ -0,0 +1,34 @@
|
||||
// by commy2
|
||||
|
||||
private ["_unit", "_weapon", "_sound"];
|
||||
|
||||
_unit = _this select 0;
|
||||
_weapon = _this select 1;
|
||||
|
||||
_sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound");
|
||||
|
||||
if (count _sound == 0) exitWith {
|
||||
playSound "AGM_Sound_Click";
|
||||
};
|
||||
|
||||
// add file extension
|
||||
if call {
|
||||
{
|
||||
if (toLower (_sound select 0) find _x == count toArray (_sound select 0) - count toArray _x - 1) exitWith {false};
|
||||
true
|
||||
} forEach [".wav", ".ogg", ".wss"];
|
||||
} then {
|
||||
_sound set [0, (_sound select 0) + ".wss"];
|
||||
};
|
||||
|
||||
// add default volume, pitch and distance
|
||||
if (count _sound < 2) then {_sound pushBack 1};
|
||||
if (count _sound < 3) then {_sound pushBack 1};
|
||||
if (count _sound < 4) then {_sound pushBack 0};
|
||||
|
||||
private "_position";
|
||||
|
||||
_position = _unit modelToWorld (_unit selectionPosition "RightHand");
|
||||
_position set [2, (_position select 2) + ((getPosASLW _unit select 2) - (getPosATL _unit select 2) max 0)];
|
||||
|
||||
playSound3D [_sound select 0, objNull, false, _position, _sound select 1, _sound select 2, _sound select 3];
|
21
addons/safemode/functions/fn_setSafeModeVisual.sqf
Normal file
21
addons/safemode/functions/fn_setSafeModeVisual.sqf
Normal file
@ -0,0 +1,21 @@
|
||||
// by commy2
|
||||
|
||||
private ["_show", "_control"];
|
||||
|
||||
_show = _this select 0;
|
||||
|
||||
disableSerialization;
|
||||
_control = (uiNamespace getVariable ["AGM_dlgSoldier", displayNull]) displayCtrl 187;
|
||||
|
||||
if (isNull _control) exitWith {};
|
||||
|
||||
if (_show) then {
|
||||
private "_config";
|
||||
_config = configFile >> "RscInGameUI" >> "RscUnitInfoSoldier" >> "WeaponInfoControlsGroupLeft" >> "controls" >> "CA_ModeTexture";
|
||||
|
||||
_control ctrlSetPosition [getNumber (_config >> "x"), getNumber (_config >> "y"), getNumber (_config >> "w"), getNumber (_config >> "h")];
|
||||
_control ctrlCommit 0;
|
||||
} else {
|
||||
_control ctrlSetPosition [0, 0, 0, 0];
|
||||
_control ctrlCommit 0;
|
||||
};
|
64
addons/safemode/functions/fn_unlockSafety.sqf
Normal file
64
addons/safemode/functions/fn_unlockSafety.sqf
Normal file
@ -0,0 +1,64 @@
|
||||
// by commy2
|
||||
|
||||
private ["_unit", "_weapon", "_muzzle", "_safedWeapons"];
|
||||
|
||||
_unit = _this select 0;
|
||||
_weapon = _this select 1;
|
||||
_muzzle = _this select 2;
|
||||
|
||||
_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 "_id";
|
||||
_id = _unit getVariable ["AGM_SafeWeapon_actionID", -1];
|
||||
|
||||
//[_unit, "DefaultAction", _id] call AGM_Core_fnc_removeActionMenuEventHandler;
|
||||
[_unit, "DefaultAction", _id] call AGM_Core_fnc_removeActionEventHandler;
|
||||
_unit setVariable ["AGM_SafeWeapon_actionID", -1];
|
||||
};
|
||||
};
|
||||
|
||||
_unit selectWeapon _muzzle;
|
||||
|
||||
if (inputAction "nextWeapon" > 0) then {
|
||||
// switch to the last mode to roll over to first after the default nextWeapon action
|
||||
private ["_modes", "_mode", "_index"];
|
||||
|
||||
// get weapon modes
|
||||
_modes = [];
|
||||
{
|
||||
if (getNumber (configFile >> "CfgWeapons" >> _weapon >> _x >> "showToPlayer") == 1) then {
|
||||
_modes pushBack _x;
|
||||
};
|
||||
if (_x == "this") then {
|
||||
_modes pushBack _weapon;
|
||||
};
|
||||
} forEach getArray (configfile >> "CfgWeapons" >> _weapon >> "modes");
|
||||
|
||||
// select last mode
|
||||
_mode = _modes select (count _modes - 1);
|
||||
|
||||
// switch to last mode
|
||||
_index = 0;
|
||||
while {
|
||||
_index < 100 && {currentMuzzle _unit != _weapon || {currentWeaponMode _unit != _mode}}
|
||||
} do {
|
||||
_unit action ["SwitchWeapon", _unit, _unit, _index];
|
||||
_index = _index + 1;
|
||||
};
|
||||
} else {
|
||||
// play fire mode selector sound
|
||||
[_unit, _weapon, _muzzle] call AGM_SafeMode_fnc_playChangeFiremodeSound;
|
||||
};
|
||||
|
||||
// player hud
|
||||
[true] call AGM_SafeMode_fnc_setSafeModeVisual;
|
||||
|
||||
private "_picture";
|
||||
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
|
||||
[localize "STR_AGM_SafeMode_TookOffSafety", _picture] call AGM_Core_fnc_displayTextPicture;
|
Reference in New Issue
Block a user