Jump to content
iV - Ghost

clear area after task done

Recommended Posts

I wanna clear the area of operations after the tasks are done.

But the script should waitUntil no players in the area.

 

 

This is my code:

/*
 *
 * Filename: fn_clearAO.sqf
 * Author: [iV] Ghost
 * Description: Delete units and mines in the ao plus all empty groups. Then delete taskmarker and pushBack file into array.
 *
 * Example: ["M_TaskHR", 500, "scripts\taskmanager\tasks\TaskHR.sqf", iV_Tasks] call iV_fnc_clearAO;
 *
 */



// RUN ON DEDICATED SERVER OR PLAYER HOST
if (!isServer) exitWith {};



// VARIABLES
params ["_markerName", "_radius", "_file", "_array"];
private _pos = getMarkerPos _markerName;
private _players = allPlayers - entities "HeadlessClient_F";
private _allObjects = _pos nearEntities ["Man", _radius + 50];
private _allMines = _pos nearEntities ["MineMine", _radius + 50];



// WAIT UNTIL
waitUntil {

    sleep 10;
    (_players distance _pos) > _radius + 100;  // Doesn't work (Only wait 10 seconds)
	
};



// CLEAR AREA, DELETE TASKMARKER & PUSHBACK FILE
if ((_players distance _pos) > _radius + 100) exitWith {

    {deleteVehicle _x} forEach _allObjects;  // Works
    {deleteVehicle _x} forEach _allMines;  // Not tested
	
	
    // REMOVE EMPTY GROUPS
    {

        if ((count (units _x)) == 0) then {
	
            deleteGroup _x;
            _x = grpNull;
            _x = nil;
		
        };
	
    } foreach allGroups;
	
	
    // TIMEOUT
    sleep 5;
	
	
    // DELETE TASKMARKER
    deleteMarker _markerName;  // Works
	
	
    // PUSHBACK INTO ARRAY
    _array pushBack _file;  // Doesn't work
    publicVariable str _array;
	
};

 

 

 

But now I have 2 problems:

 

1. The script don't waitUntil no players in the area.

2. My _file doesn't pushBack into my _array.

Share this post


Link to post
Share on other sites

Well...

 

According BIKI, distance command doesn't accept ARRAYS (except coordinates). But _players is array. So, you need to check distance to EACH unit something like this:

_nooneHere = ({(_x distance _pos) <= (_radius + 100)} count _players) == 0;

 

It's absolutely senselessly to do this:

_x = grpNull;
_x = nil;

 

According BIKI, publicVariable command accepts variable NAME, not VALUE. But "str _array" returns string representation of _array.

Possible resolution:

myPubVar = _array;

publicVariable "myPubVar";

 

General advice: read BIKI first.

  • Thanks 1

Share this post


Link to post
Share on other sites

@stanhope:

_file is a string with my taskpath (E.G. "scripts\taskmanager\tasks\TaskHR.sqf"). After a task is selected, the path is deleted so that it is not used twice.

And when a task is completed (canceled, succeeded, failed) the _file should be pushed back in the array.

 

 

@Schatten:

Works now. Thanks for help. Sometimes I can't see the problem. Always use google and the BIKI first.

And if I can't find the problem (oftenly a few weeks later) I'm asking for help in the forum.

 

...
private _area = _radius + 100;
private _players = allPlayers - entities "HeadlessClient_F";
...


// WAIT UNTIL
waitUntil {

    sleep 10;
    {_x distance _pos < _area} count _players == 0;
	
};



// CLEAR AREA, DELETE TASKMARKER & PUSHBACK FILE
if ({_x distance _pos < _area} count _players == 0) exitWith {

    ...
	
    // PUSHBACK INTO ARRAY
    _array pushBack _file;
    publicVariable str _array;
	
};

 

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

×