Jump to content
LSValmont

Alien Like Motion Scanner using the GPS minimap

Recommended Posts

I was wondering two things regarding this script/fnc I made:

 

Question 1: any way to open the mini map display via script commands?

 

Question 1: The minimap radius is based on the speed of the player, any way to manually control that?... since I check a range of 50 I would like the mini GPS to reflect that regarding of the player speed.

 

Also, Any suggestions?

 

The script in fnc form, spawned by a custom UI: (Special thanks to @Leopard20 who's insights made this posible)

 

vMotionScanner = {
    params [
        ["_unit", objNull, [objNull]],
        ["_motionScannerDistance", 60, [60]],
        ["_detectAllEnemies", false, [false]],
        ["_detectEnemyUnits", false, [false]],
        ["_detectEnemyVehicles", false, [false]],
        ["_detectEnemyAgents", true, [true]]
    ];
    
    if (isDedicated OR !hasInterface) exitWith {};
    
    if ( !("ItemGPS" in (assignedItems player)) || !(alive player) || (vehicle player isNotEqualTo player) ) exitWith {vMotionScannerRunning = false; systemChat "MOTION SCANNER not available";};
    
    vMotionScannerRunning = true;
    systemChat format ["MOTION SCANNER enabled by: %1, use the keys Control + M to toggle the screen.", name player];
    showGPS true;
    private _nearObjects = [];
    private _motionMarkersArray = [];
    private _maxMotionMarkers = 10;
    
    while { vMotionScannerRunning } do {
        if (visibleGPS) then {
            switch (true) do {
                case (_detectAllEnemies)    : { _nearObjects = (player nearEntities [["Man", "Air", "LandVehicle", "Ship"], _motionScannerDistance]) select {side group _x isNotEqualTo side group player && abs speed _x >= 3}; };
                case (_detectEnemyUnits)    : { _nearObjects = (player nearEntities [["Man"], _motionScannerDistance]) select {side group _x isNotEqualTo side group player && abs speed _x >= 3}; };
                case (_detectEnemyVehicles)    : { _nearObjects = (player nearEntities [["Air", "LandVehicle", "Ship"], _motionScannerDistance]) select {side group _x isNotEqualTo side group player && abs speed _x >= 3}; };
                case (_detectEnemyAgents)    : { _nearObjects = agents select {agent _x distance player < _motionScannerDistance}; };
            };
            if (_nearObjects isNotEqualTo []) then {
                private _sortedContacts = [];
                if (_detectEnemyAgents) then {
                    _sortedContacts = [_nearObjects, [], {(player distance2d agent _x)}, "ASCEND"] call BIS_fnc_sortBy;
                } else {
                    _sortedContacts = [_nearObjects, [], {(player distance2d _x)}, "ASCEND"] call BIS_fnc_sortBy;
                };
                private _closestContact = objNull;
                _closestContact = _sortedContacts select 0;
                private _closestContactDis = 999;
                if (_detectEnemyAgents) then {_closestContactDis = agent _closestContact distance2d player;} else {_closestContactDis = _closestContact distance2d player;};
                systemChat format ["MOTION SCANNER contact: %1 meters", _closestContactDis];
//                call {
//                    if (_closestContactDis < 10) exitWith { playSound3D [getMissionPath "vScripts\vSounds\motion10b.ogg", player] };
//                    if (_closestContactDis < 20) exitWith { playSound3D [getMissionPath "vScripts\vSounds\motion10.ogg", player] };
//                    if (_closestContactDis < 30) exitWith { playSound3D [getMissionPath "vScripts\vSounds\motion10.ogg", player] };
//                    if (_closestContactDis < 40) exitWith { playSound3D [getMissionPath "vScripts\vSounds\motion20.ogg", player] };
//                    if (_closestContactDis < 50) exitWith { playSound3D [getMissionPath "vScripts\vSounds\motion20.ogg", player] };
//                    if (_closestContactDis < 60) exitWith { playSound3D [getMissionPath "vScripts\vSounds\motion30.ogg", player] };
//                };
                call {
                    if (_closestContactDis < 10) exitWith { playSound "motion10b" };
                    if (_closestContactDis < 20) exitWith { playSound "motion10" };
                    if (_closestContactDis < 30) exitWith { playSound "motion10" };
                    if (_closestContactDis < 40) exitWith { playSound "motion20" };
                    if (_closestContactDis < 50) exitWith { playSound "motion20" };
                    if (_closestContactDis < 60) exitWith { playSound "motion30" };
                };                
                private _displayedMotionMarkers = 0;
                {
                    if (_displayedMotionMarkers < _maxMotionMarkers) then {
                        private _contactName = random 9999;
                        private _marker = "";
                        if (_detectEnemyAgents) then {
                            _contactName = str agent _x;
                            _marker = createMarkerLocal [_contactName, getPosWorld agent _x];
                        } else {
                            playerSide reveal _x;
                            _contactName = str _x;
                            _marker = createMarkerLocal [_contactName, getPosWorld _x];
                        };
                        _marker setMarkerShapeLocal "ICON";
                        _marker setMarkerTypeLocal "hd_dot";
                        _marker setMarkerColorLocal "ColorGrey";
                        _marker setMarkerAlphaLocal 0.85;
                        _marker setMarkerSizeLocal [0.5, 0.5];
                        [vAnimatedMarker_1_Fnc, _marker, 0.3] call CBA_fnc_waitAndExecute;
                        [vAnimatedMarker_2_Fnc, _marker, 0.6] call CBA_fnc_waitAndExecute;
                        [vdeleteMarkerLocalFnc, _marker, 0.9] call CBA_fnc_waitAndExecute;
                        _displayedMotionMarkers = _displayedMotionMarkers + 1;
                    };    
                } forEach _sortedContacts;                
            };
        };
    sleep 1;    
    if ( !("ItemGPS" in (assignedItems player)) || !(alive player) || (vehicle player isNotEqualTo player) ) exitWith { vMotionScannerRunning = false; systemChat "MOTION SCANNER disabled"; };
    };
};

  • Like 1

Share this post


Link to post
Share on other sites
38 minutes ago, LSValmont said:

I was wondering two things regarding this script/fnc I made:

 

Question 1: Is it ok that I use a "for "_i" from 1 to _maxMotionMarkers do" inside a forEach?

 

Question 2: The minimap radius is based on the speed of the player, any way to manually control that?... since I check a range of 50 I would like the mini GPS to reflect that regarding of the player speed.

 

Also, Any suggestions?

 

The script in fnc form, spawned by a custom UI:

 

vMotionScanner = {
    params [
        ["_unit", objNull, [objNull]],
        ["_motionScannerDistance", 60, [60]],
        ["_detectAllEnemies", false, [false]],
        ["_detectEnemyUnits", false, [false]],
        ["_detectEnemyVehicles", false, [false]],
        ["_detectEnemyAgents", true, [true]]
    ];
    
    if (isDedicated OR !hasInterface) exitWith {};
    
    if(!("ItemGPS" in assignedItems player) || !alive player || !(vehicle player == player)) exitWith {vMotionScannerRunning = false; cutText ["", "PLAIN"]};
    
    vMotionScannerRunning = true;
    private _nearObjects = [];
    private _motionMarkersArray = [];
    private _maxMotionMarkers = 10;
    
    if (_detectAllEnemies) then {
        while { vMotionScannerRunning } do {
            if (visibleGPS /*&& "ItemGPS" in (assignedItems player + items player*/)) then {
                private _nearObjects = (player nearEntities [["Man", "Air", "LandVehicle", "Ship"], _motionScannerDistance]);
                _nearObjects = _nearObjects select {side group _x isNotEqualTo side group player && abs speed _x >= 3};
                if (_nearObjects isNotEqualTo []) then {
                    private _sortedContacts = [];
                    private _closestContact = objNull;
                    _sortedContacts = [_nearObjects, [], { player distance _x }, "ASCEND"] call BIS_fnc_sortBy;
                    _closestContact = _sortedContacts select 0;
                    if (_closestContact distance2d player > (_motionScannerDistance*0.84)) then {
                        playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound.ogg", player];
                    } else {
                        [_closestContact] call {
                            params ["_closestContact"];
                            private _closestContactDis = _closestContact distance2d player;
                            switch (true) do {
                                case (_closestContactDis > 40 && _closestContactDis < 50): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_1.ogg", player] };
                                case (_closestContactDis > 30 && _closestContactDis < 40): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_2.ogg", player] };
                                case (_closestContactDis > 20 && _closestContactDis < 30): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_3.ogg", player] };
                                case (_closestContactDis > 10 && _closestContactDis < 20): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_4.ogg", player] };
                                case (_closestContactDis > 0  && _closestContactDis < 10): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_5.ogg", player] };
                            };
                        };
                    };
                    
                    {
                        for "_i" from 1 to _maxMotionMarkers do {
                            if((player isNotEqualTo _x) && (vehicle _x isEqualTo _x)) then {
                                if(abs speed _x >= 3) then {
                                    playerSide reveal _x;
                                    private _xName = name _x;
                                    private _marker = createMarkerLocal [_xName, position _x];
                                    _marker setMarkerShapeLocal "ICON";
                                    _marker setMarkerTypeLocal "DOT";
                                    _marker setMarkerColorLocal "ColorGUER";
                                    _marker setMarkerAlphaLocal 0.85;
                                    _marker setMarkerSizeLocal [0.5, 0.5];
                                    sleep 0.3;
                                    _marker setMarkerAlphaLocal 0.70;
                                    _marker setMarkerSizeLocal [1, 1];
                                    sleep 0.3;
                                    _marker setMarkerAlphaLocal 0.55;
                                    _marker setMarkerSizeLocal [1.4, 1.4];
                                    sleep 0.3;
                                    deleteMarkerLocal _marker;
                                };
                            };
                        };    
                    } forEach _sortedContacts;
                };
            };    
        sleep 0.8;
        };
    };

};

 

I don't know about your second question

But your for loop doesn't do what you want it to do

Let's say I have 10 contacts
Your for loop runs for 10 iterations
During each iteration it sleeps ~1 second, during which nothing else updates. Your marker "beeps" only for one target.
So it takes 100 seconds for the while loop to go around again

  • Thanks 1

Share this post


Link to post
Share on other sites
19 minutes ago, Leopard20 said:

I don't know about your second question

But your for loop doesn't do what you want it to do

Let's say I have 10 contacts
Your for loop runs for 10 iterations
During each iteration it sleeps ~1 second, during which nothing else updates. Your marker "beeps" only for one target.
So it takes 100 seconds for the while loop to go around again

 

Thanks for the input! I believe this will do the trick...

 

vMotionScanner = {
    params [
        ["_unit", objNull, [objNull]],
        ["_motionScannerDistance", 60, [60]],
        ["_detectAllEnemies", false, [false]],
        ["_detectEnemyUnits", false, [false]],
        ["_detectEnemyVehicles", false, [false]],
        ["_detectEnemyAgents", true, [true]]
    ];
    
    if (isDedicated OR !hasInterface) exitWith {};
    
    if(!("ItemGPS" in assignedItems player) || !alive player || !(vehicle player == player)) exitWith {vMotionScannerRunning = false; cutText ["", "PLAIN"]};
    
    vMotionScannerRunning = true;
    private _nearObjects = [];
    private _motionMarkersArray = [];
    private _maxMotionMarkers = 10;
    
    if (_detectAllEnemies) then {
        while { vMotionScannerRunning } do {
            if (visibleGPS /*&& "ItemGPS" in (assignedItems player + items player*/)) then {
                private _nearObjects = (player nearEntities [["Man", "Air", "LandVehicle", "Ship"], _motionScannerDistance]);
                _nearObjects = _nearObjects select {side group _x isNotEqualTo side group player && abs speed _x >= 3};
                if (_nearObjects isNotEqualTo []) then {
                    private _sortedContacts = [];
                    private _closestContact = objNull;
                    _sortedContacts = [_nearObjects, [], { player distance _x }, "ASCEND"] call BIS_fnc_sortBy;
                    _closestContact = _sortedContacts select 0;
                    if (_closestContact distance2d player > (_motionScannerDistance*0.84)) then {
                        playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound.ogg", player];
                    } else {
                        [_closestContact] call {
                            params ["_closestContact"];
                            private _closestContactDis = _closestContact distance2d player;
                            switch (true) do {
                                case (_closestContactDis > 40 && _closestContactDis < 50): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_1.ogg", player] };
                                case (_closestContactDis > 30 && _closestContactDis < 40): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_2.ogg", player] };
                                case (_closestContactDis > 20 && _closestContactDis < 30): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_3.ogg", player] };
                                case (_closestContactDis > 10 && _closestContactDis < 20): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_4.ogg", player] };
                                case (_closestContactDis > 0  && _closestContactDis < 10): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_5.ogg", player] };
                            };
                        };
                    };
                    private _displayedMotionMarkers = 0;
                    {
                        if((player isNotEqualTo _x) && (vehicle _x isEqualTo _x)) then {
                            _displayedMotionMarkers = _displayedMotionMarkers + 1;
                            if (_displayedMotionMarkers < _maxMotionMarkers) then {
                                [_x] spawn {
                                    params ["_motionTrackerContact"];
                                    if(abs speed _motionTrackerContact >= 3) then {
                                        playerSide reveal _motionTrackerContact;
                                        private _xName = name _motionTrackerContact;
                                        private _marker = createMarkerLocal [_xName, position _motionTrackerContact];
                                        _marker setMarkerShapeLocal "ICON";
                                        _marker setMarkerTypeLocal "DOT";
                                        _marker setMarkerColorLocal "ColorGUER";
                                        _marker setMarkerAlphaLocal 0.85;
                                        _marker setMarkerSizeLocal [0.5, 0.5];
                                        sleep 0.3;
                                        _marker setMarkerAlphaLocal 0.70;
                                        _marker setMarkerSizeLocal [1, 1];
                                        sleep 0.3;
                                        _marker setMarkerAlphaLocal 0.55;
                                        _marker setMarkerSizeLocal [1.4, 1.4];
                                        sleep 0.3;
                                        deleteMarkerLocal _marker;
                                    };
                                };
                            };    
                        };
                        sleep 0.1;
                    } forEach _sortedContacts;
                };
            };    
        sleep 0.5;
        if(!("ItemGPS" in assignedItems player) || !alive player || !(vehicle player == player)) exitWith {vMotionScannerRunning = false;};
        };
    };

};

 

I have lowered the sleeps because it has to look like this:

 

Share this post


Link to post
Share on other sites

Still not good

Spawning too many codes slows down other scripts (both those created by other mods and your own). Basically a code that can be done using a single thread is hogging the scheduler queue.
Even if not that, your code has timer overlapping problems
I absolutely don't recommend it.
Use the timer you use for while to apply the effect. No need to spawn any other code

  • Thanks 1

Share this post


Link to post
Share on other sites
4 hours ago, Leopard20 said:

Still not good

Spawning too many codes slows down other scripts (both those created by other mods and your own). Basically a code that can be done using a single thread is hogging the scheduler queue.
Even if not that, your code has timer overlapping problems
I absolutely don't recommend it.
Use the timer you use for while to apply the effect. No need to spawn any other code

 

Ok but if I want to show all the dots for the contacts almost simultaneously I need to remove the sleeps and if I remove the sleeps I loose the marker blinking effect (Marker going from smaller to bigger over 0.9 seconds).

 

Perhaps that effect alone is not worth it and I should just show a normal marker that doesn't grow in size and get it done with.

 

Thank you for all you feedback. I didn't know that spawns that last less than a second could still hog the scheduler.

Share this post


Link to post
Share on other sites
11 hours ago, LSValmont said:

 

Ok but if I want to show all the dots for the contacts almost simultaneously I need to remove the sleeps and if I remove the sleeps I loose the marker blinking effect (Marker going from smaller to bigger over 0.9 seconds).

 

Perhaps that effect alone is not worth it and I should just show a normal marker that doesn't grow in size and get it done with.

 

Thank you for all you feedback. I didn't know that spawns that last less than a second could still hog the scheduler.

yes, no need for those sleeps either.
Again, just use the sleep you use for while.

 

11 hours ago, LSValmont said:

I didn't know that spawns that last less than a second could still hog the scheduler. 

At low FPS and/or if the scheduler is "busy" (lots of spawns in the queue), your spawns may stay in there for a longer time than normal.
But the main reason I said that was timer overlap.
Let's assume an ideal execution (no delay in execution, which is not true, especially at low FPS). Each "beep" takes 0.9 seconds to complete, but you're spawning the codes every 0.1 seconds. So within that 0.9 seconds, you have spawned 90 codes for 10 contacts.

If FPS was low or scheduler was "busy", your spawned codes could keep growing before any of the old spawns are complete.

See the issue now?

Share this post


Link to post
Share on other sites
3 hours ago, Leopard20 said:

yes, no need for those sleeps either.
Again, just use the sleep you use for while.

 

At low FPS and/or if the scheduler is "busy" (lots of spawns in the queue), your spawns may stay in there for a longer time than normal.
But the main reason I said that was timer overlap.
Let's assume an ideal execution (no delay in execution, which is not true, especially at low FPS). Each "beep" takes 0.9 seconds to complete, but you're spawning the codes every 0.1 seconds. So within that 0.9 seconds, you have spawned 90 codes for 10 contacts.

If FPS was low or scheduler was "busy", your spawned codes could keep growing before any of the old spawns are complete.

See the issue now?

 

Yes @Leopard20 I do! Thank you!

 

I think I fixed all issues with this iteration of the script, what do you think?

 

vMotionScanner = {
    params [
        ["_unit", objNull, [objNull]],
        ["_motionScannerDistance", 60, [60]],
        ["_detectAllEnemies", false, [false]],
        ["_detectEnemyUnits", false, [false]],
        ["_detectEnemyVehicles", false, [false]],
        ["_detectEnemyAgents", true, [true]]
    ];
    
    if (isDedicated OR !hasInterface) exitWith {};
    
    if(!("ItemGPS" in assignedItems player) || !alive player || !(vehicle player == player)) exitWith {vMotionScannerRunning = false; cutText ["", "PLAIN"]};
    
    vMotionScannerRunning = true;
    private _nearObjects = [];
    private _motionMarkersArray = [];
    private _maxMotionMarkers = 10;
    
    switch (true) do {
        case (_detectAllEnemies)    : { _nearObjects = (player nearEntities [["Man", "Air", "LandVehicle", "Ship"], _motionScannerDistance]); };
        case (_detectEnemyUnits)    : { _nearObjects = (player nearEntities [["Man"], _motionScannerDistance]); };
        case (_detectEnemyVehicles)    : { _nearObjects = (player nearEntities [["Air", "LandVehicle", "Ship"], _motionScannerDistance]); };
        case (_detectEnemyAgents)    : { _nearObjects = agents select {agent _x distance player < _motionScannerDistance}; };
    };
    
    while { vMotionScannerRunning } do {
        if (visibleGPS) then {
            _nearObjects = _nearObjects select {side group _x isNotEqualTo side group player && abs speed _x >= 3};
            if (_nearObjects isNotEqualTo []) then {
                private _sortedContacts = [];
                _sortedContacts = [_nearObjects, [], { player distance _x }, "ASCEND"] call BIS_fnc_sortBy;
                private _closestContact = objNull;
                _closestContact = _sortedContacts select 0;
                switch (true) do {
                    case (_closestContactDis > 40 && _closestContactDis < 50): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_1.ogg", player] };
                    case (_closestContactDis > 30 && _closestContactDis < 40): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_2.ogg", player] };
                    case (_closestContactDis > 20 && _closestContactDis < 30): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_3.ogg", player] };
                    case (_closestContactDis > 10 && _closestContactDis < 20): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_4.ogg", player] };
                    case (_closestContactDis > 0  && _closestContactDis < 10): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_5.ogg", player] };
                };
                private _displayedMotionMarkers = 0;
                {
                    if (_displayedMotionMarkers < _maxMotionMarkers) then {                
                        playerSide reveal _motionTrackerContact;
                        private _xName = name _motionTrackerContact;
                        private _marker = createMarkerLocal [_xName, position _motionTrackerContact];
                        _marker setMarkerShapeLocal "ICON";
                        _marker setMarkerTypeLocal "DOT";
                        _marker setMarkerColorLocal "ColorGUER";
                        _marker setMarkerAlphaLocal 0.85;
                        _marker setMarkerSizeLocal [0.5, 0.5];
                        [vAnimatedMarker_1_Fnc, _marker, 0.3] call CBA_fnc_waitAndExecute;
                        [vAnimatedMarker_2_Fnc, _marker, 0.6] call CBA_fnc_waitAndExecute;
                        [vdeleteMarkerLocalFnc, _marker, 1] call CBA_fnc_waitAndExecute;
                        _displayedMotionMarkers = _displayedMotionMarkers + 1;
                    };    
                } forEach _sortedContacts;                
            };    
        };
    sleep 0.5;    
    };
};
    
vAnimatedMarker_1_Fnc = {
    params ["_marker"];
    _marker setMarkerAlphaLocal 0.70;
    _marker setMarkerSizeLocal [1, 1];
};

vAnimatedMarker_2_Fnc = {
    params ["_marker"];
    _marker setMarkerAlphaLocal 0.55;
    _marker setMarkerSizeLocal [1.4, 1.4];
};

vdeleteMarkerLocalFnc = {
    params ["_marker"];
    deleteMarkerLocal _marker;
};

Share this post


Link to post
Share on other sites

What I don't know if that latest iteration will draw the 10 markers closer to the player (due to using the sortedContacts in the forEach)? I assume so...

Share this post


Link to post
Share on other sites
7 minutes ago, LSValmont said:

 

Yes @Leopard20 I do! Thank you!

 

I think I fixed all issues with this iteration of the script, what do you think?

 

vMotionScanner = {
    params [
        ["_unit", objNull, [objNull]],
        ["_motionScannerDistance", 60, [60]],
        ["_detectAllEnemies", false, [false]],
        ["_detectEnemyUnits", false, [false]],
        ["_detectEnemyVehicles", false, [false]],
        ["_detectEnemyAgents", true, [true]]
    ];
    
    if (isDedicated OR !hasInterface) exitWith {};
    
    if(!("ItemGPS" in assignedItems player) || !alive player || !(vehicle player == player)) exitWith {vMotionScannerRunning = false; cutText ["", "PLAIN"]};
    
    vMotionScannerRunning = true;
    private _nearObjects = [];
    private _motionMarkersArray = [];
    private _maxMotionMarkers = 10;
    
    switch (true) do {
        case (_detectAllEnemies)    : { _nearObjects = (player nearEntities [["Man", "Air", "LandVehicle", "Ship"], _motionScannerDistance]); };
        case (_detectEnemyUnits)    : { _nearObjects = (player nearEntities [["Man"], _motionScannerDistance]); };
        case (_detectEnemyVehicles)    : { _nearObjects = (player nearEntities [["Air", "LandVehicle", "Ship"], _motionScannerDistance]); };
        case (_detectEnemyAgents)    : { _nearObjects = agents select {agent _x distance player < _motionScannerDistance}; };
    };
    
    while { vMotionScannerRunning } do {
        if (visibleGPS) then {
            _nearObjects = _nearObjects select {side group _x isNotEqualTo side group player && abs speed _x >= 3};
            if (_nearObjects isNotEqualTo []) then {
                private _sortedContacts = [];
                _sortedContacts = [_nearObjects, [], { player distance _x }, "ASCEND"] call BIS_fnc_sortBy;
                private _closestContact = objNull;
                _closestContact = _sortedContacts select 0;
                switch (true) do {
                    case (_closestContactDis > 40 && _closestContactDis < 50): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_1.ogg", player] };
                    case (_closestContactDis > 30 && _closestContactDis < 40): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_2.ogg", player] };
                    case (_closestContactDis > 20 && _closestContactDis < 30): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_3.ogg", player] };
                    case (_closestContactDis > 10 && _closestContactDis < 20): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_4.ogg", player] };
                    case (_closestContactDis > 0  && _closestContactDis < 10): { playSound3D [getMissionPath "vScripts\vSounds\MotionDetectorSound_5.ogg", player] };
                };
                private _displayedMotionMarkers = 0;
                {
                    if (_displayedMotionMarkers < _maxMotionMarkers) then {                
                        playerSide reveal _motionTrackerContact;
                        private _xName = name _motionTrackerContact;
                        private _marker = createMarkerLocal [_xName, position _motionTrackerContact];
                        _marker setMarkerShapeLocal "ICON";
                        _marker setMarkerTypeLocal "DOT";
                        _marker setMarkerColorLocal "ColorGUER";
                        _marker setMarkerAlphaLocal 0.85;
                        _marker setMarkerSizeLocal [0.5, 0.5];
                        [vAnimatedMarker_1_Fnc, _marker, 0.3] call CBA_fnc_waitAndExecute;
                        [vAnimatedMarker_2_Fnc, _marker, 0.6] call CBA_fnc_waitAndExecute;
                        [vdeleteMarkerLocalFnc, _marker, 1] call CBA_fnc_waitAndExecute;
                        _displayedMotionMarkers = _displayedMotionMarkers + 1;
                    };    
                } forEach _sortedContacts;                
            };    
        };
    sleep 0.5;    
    };
};
    
vAnimatedMarker_1_Fnc = {
    params ["_marker"];
    _marker setMarkerAlphaLocal 0.70;
    _marker setMarkerSizeLocal [1, 1];
};

vAnimatedMarker_2_Fnc = {
    params ["_marker"];
    _marker setMarkerAlphaLocal 0.55;
    _marker setMarkerSizeLocal [1.4, 1.4];
};

vdeleteMarkerLocalFnc = {
    params ["_marker"];
    deleteMarkerLocal _marker;
};

I think the main problem is that you don't pay attention to the overlaps:
 

while {true} do {
...
sleep 0.5;
}

now look at the timers here:

[vAnimatedMarker_1_Fnc, _marker, 0.3] call CBA_fnc_waitAndExecute;
[vAnimatedMarker_2_Fnc, _marker, 0.6] call CBA_fnc_waitAndExecute;
[vdeleteMarkerLocalFnc, _marker, 1] call CBA_fnc_waitAndExecute;


 

Share this post


Link to post
Share on other sites
4 minutes ago, Leopard20 said:

I think the main problem is that you don't pay attention to the overlaps:
 


while {true} do {
...
sleep 0.5;
}

now look at the timers here:


[vAnimatedMarker_1_Fnc, _marker, 0.3] call CBA_fnc_waitAndExecute;
[vAnimatedMarker_2_Fnc, _marker, 0.6] call CBA_fnc_waitAndExecute;
[vdeleteMarkerLocalFnc, _marker, 1] call CBA_fnc_waitAndExecute;


 

 

Good point, I will be tweaking those seconds of the CBA_fnc_waitAndExecute to never last longer than the while sleep. It was just a template I haven't been able to properly test the script until I am on my home PC.

 

Your imput has been invaluable! Thank you!

 

Also, besides those overlaps, are you more or less content with the script or you would do something/everything differently?

 

I am still looking for ways to:

1) Force the GPS mini map open with script commands.

2) Handle the area that the miniGPS displays. Currently based on speed, perhaps one of the devs will know this one...

Share this post


Link to post
Share on other sites
3 minutes ago, LSValmont said:

Also, besides those overlaps, are you more or less content with the script or you would do something/everything differently?

Your switch-case has "overlapping" conditions (some conditions are duplicates). Replace it with call-exitWith. example:
 

call {
	if (_a < 1) exitWith {}; //code for a < 1
	if (_a < 2) exitWith {}; //code for a>= 1 && a < 2
	if (_a < 3) exitWith {}; //code for a>= 2 && a < 3
	//code for a >= 3
};

Also, don't use position/getPos. They're slow, and they're very specialized commands for really advanced applications (you see people arbitrarily using them because they don't know that) . You can use getPosWorld for example.
Review these:
https://community.bistudio.com/wiki/Position
https://community.bistudio.com/wiki/Code_Optimisation#getPos.2A_and_setPos.2A

  • Like 1

Share this post


Link to post
Share on other sites
27 minutes ago, Leopard20 said:

Your switch-case has "overlapping" conditions (some conditions are duplicates). Replace it with call-exitWith. example:

 

Got it!: Optimized position with getPosWorld.

 

About the switch, your are referring to the first one or the second one or both?

Share this post


Link to post
Share on other sites
7 minutes ago, LSValmont said:

 

Got it!: Optimized position with getPosWorld.

 

About the switch, your are referring to the first one or the second one or both?

second one

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Leopard20 said:

second one

 

Final iteration of the script on the first post.

 

Thank you!

 

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×