From ddf329073fcda4d5856401400734e0cbde291fd7 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 20 Oct 2020 18:18:52 +0200 Subject: [PATCH] added spectrum device scripts --- functions/Spectrum/fn_findTarget.sqf | 66 ++++++++++++++++++++++++++++ includes/CfgFunctions.hpp | 1 + includes/Spectrum/CfgFunctions.hpp | 4 ++ 3 files changed, 71 insertions(+) create mode 100644 functions/Spectrum/fn_findTarget.sqf create mode 100644 includes/Spectrum/CfgFunctions.hpp diff --git a/functions/Spectrum/fn_findTarget.sqf b/functions/Spectrum/fn_findTarget.sqf new file mode 100644 index 0000000..807b28d --- /dev/null +++ b/functions/Spectrum/fn_findTarget.sqf @@ -0,0 +1,66 @@ +/* + Author: Djeeberjr + + Description: + Points the Sectrum device to a spesific object + + Parameter(s): + 0: OBJECT - target of the scan + 1: NUMBER - interval of update e.g. 0.3 + 2: NUMBER - Frequency to scan on (UI only) + 3: NUMBER - Cutoff signale after angle e.g. 90 + 4: NUMBER - Min distance to target befor device goes 100% + 5: NUMBER - Max distance the target can be detected. Signal strength relativ to max distance. + 6: OBJECT - receiver object most of the time the player +*/ + +_this spawn { + params ["_target","_interval","_scanFreq","_angleCutoff","_minDistance","_maxDistance",["_receiverObject",player]]; + + missionNamespace setVariable ["#EM_FMin", _scanFreq - 3]; + missionNamespace setVariable ["#EM_FMax", _scanFreq + 3]; + + missionNamespace setVariable ["#EM_SelMin", _scanFreq - 0.3]; + missionNamespace setVariable ["#EM_SelMax", _scanFreq + 0.3]; + + missionNamespace setVariable ["#EM_Progress", 0]; + + while {alive _receiverObject} do { + + // Get distance + _objectDistance = round (_receiverObject distance _target); + + // Get angle difference to target range from 0 to 180 + _objectRelativeDirection = round (_receiverObject getRelDir _target); + if (_objectRelativeDirection >= 180) then{ + _objectRelativeDirection = (360 - _objectRelativeDirection); + }else{ + _objectRelativeDirection = _objectRelativeDirection; + }; + + // Apply angle cutoff + if (_objectRelativeDirection > _angleCutoff) then { + _objectRelativeDirection = 180; // Set angle to max value + }; + + + _dirSignalStrength = 1 - linearConversion [0,_angleCutoff,_objectRelativeDirection,0,1,true]; + + _distSignalStrength = 1 - linearConversion [0,_maxDistance,_objectDistance,0,1,true]; + + _absSignalStrength = _dirSignalStrength * _distSignalStrength; + + if (_objectDistance < _minDistance) then { + _absSignalStrength = 1; + _distSignalStrength = 1; + }; + + missionNamespace setVariable ["#EM_Values", [ + _scanFreq, + linearConversion [0,1,_absSignalStrength,missionNamespace getVariable "#EM_SMin",missionNamespace getVariable "#EM_SMax"] + ]]; + missionNamespace setVariable ["#EM_Progress", _distSignalStrength]; + + sleep _interval; + }; +}; diff --git a/includes/CfgFunctions.hpp b/includes/CfgFunctions.hpp index 80f1fcf..f042e11 100644 --- a/includes/CfgFunctions.hpp +++ b/includes/CfgFunctions.hpp @@ -9,4 +9,5 @@ class DLib{ #include "Util\CfgFunctions.hpp" #include "Zeus\CfgFunctions.hpp" #include "Other\CfgFunctions.hpp" + #include "Spectrum\CfgFunctions.hpp" } \ No newline at end of file diff --git a/includes/Spectrum/CfgFunctions.hpp b/includes/Spectrum/CfgFunctions.hpp new file mode 100644 index 0000000..4678ece --- /dev/null +++ b/includes/Spectrum/CfgFunctions.hpp @@ -0,0 +1,4 @@ +class Spectrum{ + file="DLib\functions\Spectrum"; + class findTarget{}; +}; \ No newline at end of file