Jump to content
RS30002

want to pass move command with onmapsingleclick

Recommended Posts

hint "Click on the map to select loiter area.";
openMap true;
target_zone = false;
onMapSingleClick "_this move _pos; target_zone = true; onMapSingleClick ''; true";
waitUntil {target_zone};
openMap false;

i want the drone (labeled above as _this) to move to target_zone.

 

Everything from the snippet happens, map opens, when you click it closes etc, but it doesnt pass map click as _pos or for some other reason the drone doesnt move.

 

Share this post


Link to post
Share on other sites

_this refers to parameter you pass to onMapSingleClick. In your case you used the main syntax instead of alternative syntax so _this doesn´t work.
Try it like this.

Drone onMapSingleClick "_this move _pos; target_zone = true; onMapSingleClick ''; true";

 

  • Like 1

Share this post


Link to post
Share on other sites
36 minutes ago, soldierXXXX said:

_this refers to parameter you pass to onMapSingleClick. In your case you used the main syntax instead of alternative syntax so _this doesn´t work.
Try it like this.


Drone onMapSingleClick "_this move _pos; target_zone = true; onMapSingleClick ''; true";

 

 

Hi, this looks like i have to name it "Drone"? 

 

I don't want to name it...is there another way maybe? 

 

 

Share this post


Link to post
Share on other sites

How are you calling this script? The drone needs to be referenced somehow.

 

Share this post


Link to post
Share on other sites

Yes, but it depends how you want your script to work.
If you perhaps creating vehicle you can simply refer to it like this in the same scope the code runs.
 

_veh = createVehicle ["B_UAV_02_dynamicLoadout_F", position player, [], 0, "FLY"];
_veh onMapSingleClick "_this move _pos; target_zone = true; onMapSingleClick ''; true";//must be in the same scope as the code to run this way

If you want to refer to already existing UAV you can return UAV vehicles with command allUnitsUAV and apply filter that suits your needs on them to return like for example the closest UAV.
 

_allUAVs = allUnitsUAV;
_allUAVs = _allUAVs select {side _x == west AND canMove _x};
_allUAVs = _allUAVs apply {[_x distance player, _x]}; 
_allUAVs sort TRUE;
_closestUAV = _allUAVs select 0 select 1;
_closestUAV onMapSingleClick "_this move _pos; target_zone = true; onMapSingleClick ''; true";

But of course, naming the UAV you want to use is the simplest way 🙂.

  • Like 1

Share this post


Link to post
Share on other sites
8 minutes ago, Harzach said:

How are you calling this script? The drone needs to be referenced somehow.

 

 

Hi..through radio menu nul = execVM "1234.sqf"

 

so i got it to work if i name the drone....but the thing is i want 20-30 drones and is there no better way than to name them all? 

and the script itself (drone swarm composition off steam) is full of references to _this throughout the whole script and idk how that'll behave when there's dozens.

 

(i am spawning them btw and i dont want them to go to a predefined marker as is with the composition but i want to signal where they go with map click.

 

 

Share this post


Link to post
Share on other sites
6 minutes ago, soldierXXXX said:

Yes, but it depends how you want your script to work.
If you perhaps creating vehicle you can simply refer to it like this in the same scope the code runs.
 


_veh = createVehicle ["B_UAV_02_dynamicLoadout_F", position player, [], 0, "FLY"];
_veh onMapSingleClick "_this move _pos; target_zone = true; onMapSingleClick ''; true";//must be in the same scope as the code to run this way


 

 

This means the second one will have to be marked as _veh2, the one after _veh3 etc etc right?

Share this post


Link to post
Share on other sites

I have a better solution for you. This will work if you have units already spawned.

_allUAVs = allUnitsUAV; 
_allUAVs = _allUAVs select {side _x == west AND canMove _x};
_allUAVs onMapSingleClick "{_x move _pos} forEach _this; target_zone = true; onMapSingleClick ''; true";

 

  • Like 1

Share this post


Link to post
Share on other sites

Alternatively, can i create a marker with onmapclick?

 

the script has inbuilt function that the drone goes to the marker anyway.

 

Somehow he got around multiple _this because he says he had 100, each one with the code thats in the drone init (full of _this zzzzz)

 

call{this spawn {     
_this addEventHandler ["killed", {
params ["_this"]; 
private _bomb = (typeOf bombWest) createVehicle position _this; 
_bomb setDamage 1; }];

while {!(triggerActivated westDroneTrigger)} do {sleep 1;};

_this setBehaviour "CARELESS";  
_this flyInHeight random[20,60,100];       
_this setSkill 1;        

[group _this, (getMarkerPos "westDroneMarker"), (((getMarkerSize "westDroneMarker") call BIS_fnc_arithmeticMean)/2)] call BIS_fnc_taskPatrol;

while {isNull(_this findNearestEnemy _this)} do {sleep 1;};         
private _target = _this findNearestEnemy _this;   
_this setSpeedMode "FULL"; 
for "_i" from count waypoints (group _this) - 1 to 0 step -1 do  
{  
 deleteWaypoint [(group _this), _i];  
};    

private _cutDistance = 0;    
while {(_this distance2D _target > _cutDistance) && (_this distance2D _target > 30)} do {    
_this DoMove (position _target);   
sleep 0.2;    
_temp = (2*9.81*(((getPosASL _this)select 2)-((getPosASL _target)select 2))); 
_temp = sqrt _temp;
_cutDistance = (((speed _this)*0.278)*_temp*0.102);     
};      
      
_this deleteVehicleCrew driver _this;      
};  }

 

Share this post


Link to post
Share on other sites
24 minutes ago, soldierXXXX said:

I have a better solution for you.


_allUAVs = allUnitsUAV; 
_allUAVs = _allUAVs select {side _x == west AND canMove _x};
_allUAVs onMapSingleClick "{_x move _pos} forEach _this; target_zone = true; onMapSingleClick ''; true";

 

 

 

ooof, looks like jackpot. tested it just with one tho...need a few

 

#edit: only the second one attacks 😕 probably because it is the last _this referenced and everything else referencing _this in the script goes to it and not both drones (tested with 2, they do move to _pos, so theres that)

 

idk, maybe ill have to name them all ...

 

if i do 

 

_allUAVs = allUnitsUAV; _allUAVs = _allUAVs select {side _x == west AND canMove _x}; _allUAVs onMapSingleClick "{_x move _pos} forEach _this; target_zone = true; onMapSingleClick ''; true";

 

 

after the spawning of the named drones...can i replace _this with _allUAVs in the main body of the script?

Share this post


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

Somehow he got around multiple _this because he says he had 100, each one with the code thats in the drone init (full of _this zzzzz)

 

_this is a local (and magic) variable. It refers to the argument(s) a script is called with:

call {this spawn				//  "this" is the argument, referring to the object in whose init field the call is placed
{_this addEventHandler ["killed", {		//  "_this" picks up the argument "this" for use in the EH
params ["_this"];				//  "_this" is picked up and privated for use in the EH's code

 

By itself, _this is entirely meaningless.

  • Like 1

Share this post


Link to post
Share on other sites
Quote

#edit: only the second one attacks 😕 probably because it is the last _this referenced and everything else referencing _this in the script goes to it and not both drones (tested with 2, they do move to _pos, so theres that)

Based on the provided script, these drones have their own specific behaviour writen in init field. They are not fully functional until the westDroneTrigger is activated. Then the script creates random waypoints inside marker named "westDroneMarker" and then drone seeks the enemy until it finds one. Maybe one drone knew about the target while other didn´t. Then the script deletes created waypoints and proceeds to target until it reaches 30 meters from the target. I´m not sure what _temp does. Probably some descent or something. After that the drone falls off which activates the bomb in killed EH.
_this has nothing to do with it. The script i provided just moves the drones to position you click on the map nothing else, because in your original question you asked: 

Quote

 want the drone (labeled above as _this) to move to target_zone.

Next

Quote

idk, maybe ill have to name them all ...


If i understand it right, naming would not help you in this case unless you want to control the drones different way (manually write code for each drone).
 

Quote

if i do 

 

_allUAVs = allUnitsUAV; _allUAVs = _allUAVs select {side _x == west AND canMove _x}; _allUAVs onMapSingleClick "{_x move _pos} forEach _this; target_zone = true; onMapSingleClick ''; true";

 

 

after the spawning of the named drones...can i replace _this with _allUAVs in the main body of the script?

Never try to combine two different scripts if you don´t know what you´re doing (practice first on easier scripts and try to learn what does what). If you did this, it would only create syntax errors because this and later _this in init fields of the drones refers to the drone itself while _allUAVs refers to array of all possible drones and it´s part of the other script. That means _allUAVs variable is not visible to other scripts.

  • Like 1

Share this post


Link to post
Share on other sites
24 minutes ago, soldierXXXX said:

Based on the provided script, these drones have their own specific behaviour writen in init field. They are not fully functional until the westDroneTrigger is activated.

 

I commented that line out. 

The 2nd drone knew about target, it was spawned 50 meters behind the first and there were 3 vehicles below its position. Script didn't activate, for sure, because i spawned 2 uav's in one instance of a script that was written for 1 uav.

 

ugh....i guess the only way seems to be a partial rewrite and naming them then? and writing 20 scripts? zzzzzzz

 

Is it possible to trick the script?

They are programmed to go to the marker yes. It's a prepositioned marker, placed by the script author.

But is it possible to create that marker where you want it (onmapsingleclick) and just name it whatever it's named in the script?

In effect, making it so that the drone code isn't even touched and avoiding all of _this (jk), just the marker to which they react gets manipulated.

Share this post


Link to post
Share on other sites

Alright i´ve put together a quick script which should be able to make what you described.
You don´t need anything else than marker called "eastDroneMarker". Script should operate with any drone on the map. If you want to be able to repeat the trigger it would need some adjusting for example to exclude already operating drones.
I´ve added also the possibility to spawn new drones if you´d wanted to use it.
Put this whole script to your 1234.sqf file and it should be able to run. Ideally separate it into Init.sqf and since "you can edit from here" to 1234.sqf but it´s not needed in case you  don´t wanna.
You shouldn´t use the original code in combination with this.

Spoiler

//declaration of the script in 1234.sqf or init.sqf
SuicideDroneScript = 
{
 params ["_drone"];
 _drone addEventHandler ["killed", {
					                params ["_drone"];
                                    private _bomb = "APERSMine_Range_Ammo" createVehicle position _drone;
                                    _bomb setDamage 1;
								   }
			            ];
_drone setBehaviour "CARELESS";
_drone flyInHeight random[20,60,100];     
_drone setSkill 1;
[group _drone, (getMarkerPos "eastDroneMarker"), (((getMarkerSize "eastDroneMarker") call BIS_fnc_arithmeticMean)/2)] call BIS_fnc_taskPatrol;
_target = objNull;
waitUntil {sleep 1;_target = (_drone findNearestEnemy _drone);!isNull _target OR !canMove _drone};
if (!canMove _drone) exitWith {};
//hint format ["target spotted!\n%1",_target];
_drone setSpeedMode "FULL"; 
for "_i" from count waypoints (group _drone) - 1 to 0 step -1 do  
{ 
 deleteWaypoint [(group _drone), _i];
};
private _cutDistance = 0;
while {(_drone distance2D _target > _cutDistance) && (_drone distance2D _target > 30) AND canMove _drone} do {
_drone doMove (position _target);
sleep 0.2;
_temp = (2*9.81*(((getPosASL _drone)select 2)-((getPosASL _target)select 2)));
_temp = sqrt _temp;
_cutDistance = (((speed _drone)*0.278)*_temp*0.102);
};
_drone deleteVehicleCrew driver _drone;
};

spawnDrones = 
{
 params [["_numberOfDrones",10],["_position",position player]];
 for "_i" from 0 to (_numberOfDrones -1) do
{
 private _veh = createVehicle ["O_UAV_01_F", _position, [], 50, "FLY"];
 createVehicleCrew _veh;
};
};
//=============================================================================================
//you can edit from here 1234.sqf
//this is example if you want to add behaviour to existing drones with possibility to spawn more
if (getMarkerColor "eastDroneMarker" == "") exitWith 
{
 hint "missing marker 'eastDroneMarker'"
};
hint "Click on the map to select loiter area.";
openMap true;
/*
private _spawnDronesScript = [] spawn spawnDrones;//this will call the spawnDrones function in case you want to use the radio to spawn drones also you can customize the number of drones and position like that:[20,[5629.17,2333.44,0]] spawn spawnDrones;
waitUntil {sleep 1;scriptDone _spawnDronesScript};//the script shall wait until new drones are created
sleep 0.1;
*/
target_zone = false;
_allUAVs = allUnitsUAV; 
_allUAVs = _allUAVs select {side _x == east AND canMove _x};
_allUAVs onMapSingleClick "'eastDroneMarker' setMarkerPos _pos;{_x spawn SuicideDroneScript} forEach _this; target_zone = true; onMapSingleClick ''; true";
waitUntil {sleep 0.5;target_zone};
openMap false;

 

  • Like 2

Share this post


Link to post
Share on other sites
6 hours ago, soldierXXXX said:

Alright i´ve put together a quick script which should be able to make what you described.
You don´t need anything else than marker called "eastDroneMarker". Script should operate with any drone on the map. If you want to be able to repeat the trigger it would need some adjusting for example to exclude already operating drones.
I´ve added also the possibility to spawn new drones if you´d wanted to use it.
Put this whole script to your 1234.sqf file and it should be able to run. Ideally separate it into Init.sqf and since "you can edit from here" to 1234.sqf but it´s not needed in case you  don´t wanna.
You shouldn´t use the original code in combination with this.

  Hide contents


//declaration of the script in 1234.sqf or init.sqf
SuicideDroneScript = 
{
 params ["_drone"];
 _drone addEventHandler ["killed", {
					                params ["_drone"];
                                    private _bomb = "APERSMine_Range_Ammo" createVehicle position _drone;
                                    _bomb setDamage 1;
								   }
			            ];
_drone setBehaviour "CARELESS";
_drone flyInHeight random[20,60,100];     
_drone setSkill 1;
[group _drone, (getMarkerPos "eastDroneMarker"), (((getMarkerSize "eastDroneMarker") call BIS_fnc_arithmeticMean)/2)] call BIS_fnc_taskPatrol;
_target = objNull;
waitUntil {sleep 1;_target = (_drone findNearestEnemy _drone);!isNull _target OR !canMove _drone};
if (!canMove _drone) exitWith {};
//hint format ["target spotted!\n%1",_target];
_drone setSpeedMode "FULL"; 
for "_i" from count waypoints (group _drone) - 1 to 0 step -1 do  
{ 
 deleteWaypoint [(group _drone), _i];
};
private _cutDistance = 0;
while {(_drone distance2D _target > _cutDistance) && (_drone distance2D _target > 30) AND canMove _drone} do {
_drone doMove (position _target);
sleep 0.2;
_temp = (2*9.81*(((getPosASL _drone)select 2)-((getPosASL _target)select 2)));
_temp = sqrt _temp;
_cutDistance = (((speed _drone)*0.278)*_temp*0.102);
};
_drone deleteVehicleCrew driver _drone;
};

spawnDrones = 
{
 params [["_numberOfDrones",10],["_position",position player]];
 for "_i" from 0 to (_numberOfDrones -1) do
{
 private _veh = createVehicle ["O_UAV_01_F", _position, [], 50, "FLY"];
 createVehicleCrew _veh;
};
};
//=============================================================================================
//you can edit from here 1234.sqf
//this is example if you want to add behaviour to existing drones with possibility to spawn more
if (getMarkerColor "eastDroneMarker" == "") exitWith 
{
 hint "missing marker 'eastDroneMarker'"
};
hint "Click on the map to select loiter area.";
openMap true;
/*
private _spawnDronesScript = [] spawn spawnDrones;//this will call the spawnDrones function in case you want to use the radio to spawn drones also you can customize the number of drones and position like that:[20,[5629.17,2333.44,0]] spawn spawnDrones;
waitUntil {sleep 1;scriptDone _spawnDronesScript};//the script shall wait until new drones are created
sleep 0.1;
*/
target_zone = false;
_allUAVs = allUnitsUAV; 
_allUAVs = _allUAVs select {side _x == east AND canMove _x};
_allUAVs onMapSingleClick "'eastDroneMarker' setMarkerPos _pos;{_x spawn SuicideDroneScript} forEach _this; target_zone = true; onMapSingleClick ''; true";
waitUntil {sleep 0.5;target_zone};
openMap false;

 

 

Havent been able to test yet, but thank you nevertheless. 

 

I need to move them with onmapsingleclick tho.....the marker is prepositioned by the script author, for the sakes of replayability i planned to spawn the actual target group with findsafepos, give task to player to find them and while he is searching, drones would be slowly spawning in, when player finds the targets,  click on map, drones move...... next "step" i planned to create a marker at that click for purposes of feedback to the player so he's aware of whats happening.

 

 

Am very sorry if this reads like moving the goalposts, should have been more clear from the start.

 

#edit: ugh...didnt read it well, early morning lol,  does this line 

 

_allUAVs onMapSingleClick "'eastDroneMarker' setMarkerPos _pos;

 

make it do the move marker thing?

Share this post


Link to post
Share on other sites
On 6/17/2022 at 1:32 AM, soldierXXXX said:

Alright i´ve put together a quick script which should be able to make what you described.
You don´t need anything else than marker called "eastDroneMarker". Script should operate with any drone on the map. If you want to be able to repeat the trigger it would need some adjusting for example to exclude already operating drones.
I´ve added also the possibility to spawn new drones if you´d wanted to use it.
Put this whole script to your 1234.sqf file and it should be able to run. Ideally separate it into Init.sqf and since "you can edit from here" to 1234.sqf but it´s not needed in case you  don´t wanna.
You shouldn´t use the original code in combination with this.

  Reveal hidden contents


//declaration of the script in 1234.sqf or init.sqf
SuicideDroneScript = 
{
 params ["_drone"];
 _drone addEventHandler ["killed", {
					                params ["_drone"];
                                    private _bomb = "APERSMine_Range_Ammo" createVehicle position _drone;
                                    _bomb setDamage 1;
								   }
			            ];
_drone setBehaviour "CARELESS";
_drone flyInHeight random[20,60,100];     
_drone setSkill 1;
[group _drone, (getMarkerPos "eastDroneMarker"), (((getMarkerSize "eastDroneMarker") call BIS_fnc_arithmeticMean)/2)] call BIS_fnc_taskPatrol;
_target = objNull;
waitUntil {sleep 1;_target = (_drone findNearestEnemy _drone);!isNull _target OR !canMove _drone};
if (!canMove _drone) exitWith {};
//hint format ["target spotted!\n%1",_target];
_drone setSpeedMode "FULL"; 
for "_i" from count waypoints (group _drone) - 1 to 0 step -1 do  
{ 
 deleteWaypoint [(group _drone), _i];
};
private _cutDistance = 0;
while {(_drone distance2D _target > _cutDistance) && (_drone distance2D _target > 30) AND canMove _drone} do {
_drone doMove (position _target);
sleep 0.2;
_temp = (2*9.81*(((getPosASL _drone)select 2)-((getPosASL _target)select 2)));
_temp = sqrt _temp;
_cutDistance = (((speed _drone)*0.278)*_temp*0.102);
};
_drone deleteVehicleCrew driver _drone;
};

spawnDrones = 
{
 params [["_numberOfDrones",10],["_position",position player]];
 for "_i" from 0 to (_numberOfDrones -1) do
{
 private _veh = createVehicle ["O_UAV_01_F", _position, [], 50, "FLY"];
 createVehicleCrew _veh;
};
};
//=============================================================================================
//you can edit from here 1234.sqf
//this is example if you want to add behaviour to existing drones with possibility to spawn more
if (getMarkerColor "eastDroneMarker" == "") exitWith 
{
 hint "missing marker 'eastDroneMarker'"
};
hint "Click on the map to select loiter area.";
openMap true;
/*
private _spawnDronesScript = [] spawn spawnDrones;//this will call the spawnDrones function in case you want to use the radio to spawn drones also you can customize the number of drones and position like that:[20,[5629.17,2333.44,0]] spawn spawnDrones;
waitUntil {sleep 1;scriptDone _spawnDronesScript};//the script shall wait until new drones are created
sleep 0.1;
*/
target_zone = false;
_allUAVs = allUnitsUAV; 
_allUAVs = _allUAVs select {side _x == east AND canMove _x};
_allUAVs onMapSingleClick "'eastDroneMarker' setMarkerPos _pos;{_x spawn SuicideDroneScript} forEach _this; target_zone = true; onMapSingleClick ''; true";
waitUntil {sleep 0.5;target_zone};
openMap false;

 

 

 

Had time to play around with it today. A wonderful solution good Sir! 👍 

Pretty much exactly what i wanted. Many thanks!  🍻

 

(Sorted out the marker by making it invisible at start and making it visible once clicked.)

Share this post


Link to post
Share on other sites

Thanks 🙂 I´m glad it´s working. In case you don´t need to repeat the radio action, i think we can consider this topic as closed 🙂.

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, soldierXXXX said:

Thanks 🙂 I´m glad it´s working. In case you don´t need to repeat the radio action, i think we can consider this topic as closed 🙂.

 

Have just one more question 😛

 

is there an easy way to spread the spawn among 3 locations? or alternatively making them retarget if original target is down already?

 

cuz what happens now is the majority out of a group of 15 go for the first APC that is physically the closest and ignore most of everything else that's behind it.

 

I can probably devise a workaround with positioning and maybe spawning some satchel in betweent he targets that'll go off, but if there's an easy way to do it through your script i think it would be best. (but only if easy, i hate to badger you further lol) 

Share this post


Link to post
Share on other sites

Okey. I´ve enhanced the script for all the possible usage 😄. It was a bit of work but now the script can do these things:

Script now can be repeated if needed.
Drones will now attack targets only if the target is not claimed by other drone. Drones wait until all drones that claimed target are destroyed or if they meanwhile find different target.
Drones now have optional parameter that will decide their usage-If they should reposition to new area or if they should stay at their current location. (when script is repeated)
I´ve added also example how to spawn drones at multiple locations heading for the same target area.
The script now doesn´t need anything prepared in the mission (i´ve removed the marker depandency)
The script is now also more optimized and should be separated into Init.sqf and 1234.sqf (memory operations optimization)
I´ve also added syntax comments so you know how you can use the scripts and what they need.

Init.sqf
 

Spoiler

//declaration of the script in Init.sqf (better optimization-functions are saved to memory no need to declare them again each time you call the script)
DroneTargets = [];//this array ensures multiple drones won´t attack single target at once (only one by one) don´t delete it !
/*
Syntax:
[
 <Object>,//drone itself
 <Array-Position3D>,//Optional-where should drone patrol-default position where drone is in time of spawning the script
 <Boolean>//Optional-if already patroling drones should reposition to newest location-default FALSE
] spawn SuicideDroneScript

//usage with onMapSingleClick gives variable _pos,_x is forEach magic variable 
//[_x,_pos,FALSE] spawn SuicideDroneScript-<Default> Only newly created drones will move to new location
//[_x,_pos,TRUE] spawn SuicideDroneScript-all drones will reposition to newest location
*/
SuicideDroneScript = 
{
 params ["_drone",["_droneAreaPos",[]],["_ReposPatrolingDrones",FALSE]];
 scriptName format ["SuicideDroneScript-drone:%1",_drone];
 if (_drone getVariable ["DronePatroling",FALSE]) exitWith
 {
  if (!(_ReposPatrolingDrones)) exitWith {};
   for "_i" from count waypoints (group _drone) - 1 to 0 step -1 do
   {
    deleteWaypoint [(group _drone), _i];
   };
   if (_droneAreaPos isEqualTo []) then {_droneAreaPos = position _drone};
   [group _drone, _droneAreaPos, 100] call BIS_fnc_taskPatrol;
 };
 _drone setVariable ["DronePatroling",TRUE];
 _drone addEventHandler ["killed", {
					                params ["_drone"];
                                    private _bomb = "APERSMine_Range_Ammo" createVehicle position _drone;
                                    _bomb setDamage 1;
								   }
			            ];
_drone setBehaviour "CARELESS";
_drone flyInHeight random[20,60,100];
_drone setSkill 1;
if (_droneAreaPos isEqualTo []) then {_droneAreaPos = position _drone};
[group _drone, _droneAreaPos, 100] call BIS_fnc_taskPatrol;
_target = objNull;
waitUntil {sleep 1;_target = (_drone findNearestEnemy _drone);(!isNull _target AND !(_target in DroneTargets)) OR {!canMove _drone}};
if (!canMove _drone) exitWith {};
//hint format ["target spotted!\n%1",_target];
//hint str DroneTargets;
DroneTargets pushBackUnique _target;
_drone setSpeedMode "FULL";
for "_i" from count waypoints (group _drone) - 1 to 0 step -1 do  
{
 deleteWaypoint [(group _drone), _i];
};
private _cutDistance = 0;
while {(_drone distance2D _target > _cutDistance) AND (_drone distance2D _target > 30) AND canMove _drone} do {
_drone doMove (position _target);
sleep 0.2;
_temp = (2*9.81*(((getPosASL _drone)select 2)-((getPosASL _target)select 2)));
_temp = sqrt _temp;
_cutDistance = (((speed _drone)*0.278)*_temp*0.102);
};
DroneTargets deleteAt (DroneTargets find _target);
_drone deleteVehicleCrew driver _drone;
};

/*
Syntax:
[
 <number>,//Optional-Number of drones you want to spawn-Default-10
 <Array-Position3D>//Optional-Position where should the drones spawn Default-position player 
] spawn spawnDrones;
*/
spawnDrones = 
{
 scriptName "spawnDrones";
 params [["_numberOfDrones",10],["_position",position player]];
 for "_i" from 0 to (_numberOfDrones -1) do
{
 private _veh = createVehicle ["O_UAV_01_F", _position, [], 50, "FLY"];
 createVehicleCrew _veh;
};
};

 


1234.sqf
 

Spoiler

//=============================================================================================
//you can edit from here-this is in 1234.sqf file
//this is example if you want to add behaviour to existing drones with possibility to spawn more
//Marker "eastDroneMarker" is now optional and does not have any connection to the drone script
scriptName "1234.sqf";
if (is3DENPreview AND getMarkerColor "eastDroneMarker" == "") then
{
 systemChat "Debug: missing marker 'eastDroneMarker'-This marker is no longer needed for the script function";
};

/*
private _spawnDronesScript = [10,[5793.88,2087.36,0]] spawn spawnDrones;//this will call the spawnDrones function in case you want to use the radio to spawn drones also you can customize the number of drones and position like that:[20,[5629.17,2333.44,0]] spawn spawnDrones;
waitUntil {sleep 0.2;scriptDone _spawnDronesScript};//the script shall wait until new drones are created
_spawnDronesScript = [5,[5686.62,2476.73,0]] spawn spawnDrones;//this is how you can do spawning from different positions
waitUntil {sleep 0.2;scriptDone _spawnDronesScript};
_spawnDronesScript = [5,[5536.96,2336.87,0]] spawn spawnDrones;
waitUntil {sleep 0.2;scriptDone _spawnDronesScript};
sleep 0.1;
*/

openMap true;
hint "Click on the map to select loiter area.";
target_zone = false;
_allUAVs = allUnitsUAV; 
_allUAVs = _allUAVs select {side _x == east AND canMove _x};
_allUAVs onMapSingleClick "{[_x,_pos,TRUE] spawn SuicideDroneScript} forEach _this; target_zone = true; onMapSingleClick ''; true";//'eastDroneMarker' setMarkerPos _pos;//this marker is now optional. If you want to see the clicked location, put it back in expression.
waitUntil {sleep 0.5;target_zone};
openMap false;

 


Try it out and let me know if that meets your expectations 😄

  • Like 2

Share this post


Link to post
Share on other sites
5 hours ago, soldierXXXX said:

Okey. I´ve enhanced the script for all the possible usage 😄. It was a bit of work but now the script can do these things:

Script now can be repeated if needed.
Drones will now attack targets only if the target is not claimed by other drone. Drones wait until all drones that claimed target are destroyed or if they meanwhile find different target.
Drones now have optional parameter that will decide their usage-If they should reposition to new area or if they should stay at their current location. (when script is repeated)
I´ve added also example how to spawn drones at multiple locations heading for the same target area.
The script now doesn´t need anything prepared in the mission (i´ve removed the marker depandency)
The script is now also more optimized and should be separated into Init.sqf and 1234.sqf (memory operations optimization)
I´ve also added syntax comments so you know how you can use the scripts and what they need.
Try it out and let me know if that meets your expectations 😄

 

Damn man, i will try it later on, but no matter how it turns out, thank you for your time and effort. 🍻

You've literally taken it out of the shackles it was created with and now there's options!

 

Anyhow, am making a pilot mission generator (it started as a project mainly for myself, but there's some really cool stuff in it by now, so i was thinking of releasing it.), this will be one of the missions (find enemy concentration, direct drones)...and as a token of gratitude if you have DM's open ill send it a bit ahead when it's done (a few tasks more to do, to make it 15), if not, just get it off Steam if you want (i will make a post on the forums too).

 

Many thanks again! 😀

 

 

  • Like 1

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

×