ACE3/addons/laser/functions/fnc_keyLaserCodeChange.sqf
Dedmen Miller e2ac18a05d [WIP] Fix script errors reporting wrong line numbers (#6407)
* advanced_ballistics

* advanced_fatigue

* advanced_throwing

* ai

* aircraft

* arsenal

* atragmx

* attach

* backpacks

* ballistics

* captives

* cargo

* chemlights

* common

* concertina_wire

* cookoff

* dagr

* disarming

* disposable

* dogtags

* dragging

* explosives

* fastroping

* fcs

* finger

* frag

* gestures

* gforces

* goggles

* grenades

* gunbag

* hearing

* hitreactions

* huntir

* interact_menu

* interaction

* inventory

* kestrel4500

* laser

* laserpointer

* logistics_uavbattery

* logistics_wirecutter

* magazinerepack

* map

* map_gestures

* maptools

* markers

* medical

* medical_ai

* medical_blood

* medical_menu

* microdagr

* minedetector

* missileguidance

* missionmodules

* mk6mortar

* modules

* movement

* nametags

* nightvision

* nlaw

* optics

* optionsmenu

* overheating

* overpressure

* parachute

* pylons

* quickmount

* rangecard

* rearm

* recoil

* refuel

* reload

* reloadlaunchers

* repair

* respawn

* safemode

* sandbag

* scopes

* slideshow

* spectator

* spottingscope

* switchunits

* tacticalladder

* tagging

* trenches

* tripod

* ui

* vector

* vehiclelock

* vehicles

* viewdistance

* weaponselect

* weather

* winddeflection

* yardage450

* zeus

* arsenal defines.hpp

* optionals

* DEBUG_MODE_FULL 1

* DEBUG_MODE_FULL 2

* Manual fixes

* Add SQF Validator check for #include after block comment

* explosives fnc_openTimerUI

* fix uniqueItems
2018-09-17 14:19:29 -05:00

67 lines
2.2 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: PabstMirror
* Change the laser key code (both seeker and transmitter)
*
* Argument:
* 0: Change in code <NUMBER>
*
* Return Value:
* Key Handled <BOOL>
* Example:
* [1] call ace_laser_fnc_keyLaserCodeChange;
*
* Public: No
*/
params [["_codeChange", 0, [0]]];
TRACE_1("params",_codeChange);
if ((!alive ACE_player) || {!([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith))}) exitWith {false};
private _currentShooter = objNull;
private _currentWeapon = "";
if (isNull (ACE_controlledUAV param [0, objNull])) then {
if (ACE_player call CBA_fnc_canUseWeapon) then {
_currentShooter = ACE_player;
_currentWeapon = currentWeapon ACE_player;
} else {
_currentShooter = vehicle ACE_player;
private _turretPath = if (ACE_player == (driver _currentShooter)) then {[-1]} else {ACE_player call CBA_fnc_turretPath};
_currentWeapon = _currentShooter currentWeaponTurret _turretPath;
};
} else {
_currentShooter = ACE_controlledUAV select 0;
private _turretPath = ACE_controlledUAV select 2;
_currentWeapon = _currentShooter currentWeaponTurret _turretPath;
};
TRACE_2("",_currentShooter,_currentWeapon);
if (((getNumber (configFile >> "CfgWeapons" >> _currentWeapon >> "laser")) == 0) &&
{(getNumber (configFile >> "CfgWeapons" >> _currentWeapon >> QGVAR(canSelect))) == 0}) exitWith {false};
private _oldLaserCode = _currentShooter getVariable [QGVAR(code), ACE_DEFAULT_LASER_CODE];
private _newLaserCode = _oldLaserCode;
// "Four-digit code equipment settings range from 1111 to 1788"
// While there is a 0 or 9 in code, keep adding change
if (((_codeChange < 0) && {_oldLaserCode > ACE_DEFAULT_LASER_CODE}) || {(_codeChange > 0) && {_oldLaserCode < 1788}}) then {
_newLaserCode = _oldLaserCode + _codeChange;
while {(((str _newLaserCode) find "0") >= 0) || {((str _newLaserCode) find "9") >= 0}} do {
_newLaserCode = _newLaserCode + _codeChange;
};
};
TRACE_2("",_oldLaserCode,_newLaserCode);
if (_oldLaserCode != _newLaserCode) then {
_currentShooter setVariable [QGVAR(code), _newLaserCode, true];
};
[format ["%1: %2", localize LSTRING(laserCode), _newLaserCode]] call EFUNC(common,displayTextStructured);
true