Jump to content
Blitzen88

Move a Marker to the Closest Sector

Recommended Posts

Im using UPS to have units attack/patrol a marker area. I want to move that marker area to the closest uncaptured sector or the closest enemy sector. As the sectors are captured the units will advance from sector to sector until they come into contact with the enemy. The units base should be used as the “reference point” when calculating which sector is closest. 

 

Does anyone have a script that does this?

 

 

TLDR

Can someone teach me how to move a marker to the closest uncaptured sector OR the closest enemy sector?

 

 

Share this post


Link to post
Share on other sites

Something like...

_basePos = #;//Your base position
_enemySide = east; //?
_marker = "someMarkerToMove";

_sectors = +BIS_fnc_moduleSector_sectors apply{ [ _x distanceSqr _basePos, _x ] };
_sectors sort true;

_index = _sectors findIf{
	_x params[ "", "_sector" ];
	
	_sectorOwner = _sector getVariable[ "owner", sideUnknown ];
	_sectorOwner isEqualTo sideUnknown || _sectorOwner isEqualTo _enemySide
};

if !( isNil "_index" ) then {
	_marker setMarkerPos getPos ( _sectors select _index select 1 );
};

 

Share this post


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

Something like...


_basePos = #;//Your base position
_enemySide = east; //?
_marker = "someMarkerToMove";

_sectors = +BIS_fnc_moduleSector_sectors apply{ [ _x distanceSqr _basePos, _x ] };
_sectors sort true;

_index = _sectors findIf{
	_x params[ "", "_sector" ];
	
	_sectorOwner = _sector getVariable[ "owner", sideUnknown ];
	_sectorOwner isEqualTo sideUnknown || _sectorOwner isEqualTo _enemySide
};

if !( isNil "_index" ) then {
	_marker setMarkerPos getPos ( _sectors select _index select 1 );
};

 

Thank you for doing this. I will try it out!

 

Will this auto-update? Ie will this continue to move the marker as sectors are captured?

Share this post


Link to post
Share on other sites

Played around with this a little this afternoon and couldnt get it to work....

 

I suppose my first issue is that I dont know how to call/execute it in game.  I was able to execute it via a Radio trigger and my marker moved to the closest uncontrolled sector area.  As soon as that sector was captured, the marker moved to the next sector.  Everything was work but eventually, I dont know why, the marker was moved to the sector's location and not the area/trigger location.  Is there any way to fix that?

 

Also, can I run this everytime a sector is captured via the expression tab on the sector?  I also get the following error: Invalid Number in Expression, Line 17

 

Thank you so much for your help!

 

 

Share this post


Link to post
Share on other sites
Spoiler

//initServer.sqf
	
TAG_fnc_findNearestSector = {
	_fnc_scriptName = if ( isNil "_fnc_scriptName" ) then {
		"TAG_fnc_findNearestSector"
	}else{
		_fnc_scriptName
	};
	
	if !( params[
		[ "_side", sideUnknown, [ sideUnknown ] ], 
		[ "_basePos", [], [ [], objNull ], [ 3 ] ], 
		[ "_marker", "", [ "" ] ]
	] ) exitWith {
		diag_log format[ "Side: %1, BasePos: %2, Marker: %3", _side, _basePos, _marker ];
		"incorrect params" call BIS_fnc_error;
	};
	
	//Error checking
	if ( getMarkerPos _marker isEqualTo [0,0,0] ) exitWith {
		format[ "marker does not exist - '%1'", _marker ] call BIS_fnc_error;
	};
	
	//BasePos as OBJECT
	if ( _basePos isEqualType objNull ) then {
		_basePos = getPosATL _basePos;
	};
	
	_current param[ 3, objNull ];
	_enemySides = ( _side call BIS_fnc_enemySides ) - [ sideEnemy ];
	
	//Get a list of all sectors
	_sectors = +BIS_fnc_moduleSector_sectors - [ _current ];
	
	//Get all the sectors that are either uncaptured or belong to the enemy
	_sectors = _sectors select{ _x getVariable[ "owner", sideUnknown ] in ( [ sideUnknown ] + _enemySides ) };
	
	//Set all sectors in the list to [ distance from base, sector ]
	_sectors = _sectors apply{ [ _x distanceSqr _basePos, _x ] };
	
	//Sort sectors to nearest first
	_sectors sort true;

	//Get nearest sector
	_nearestSector = _sectors select 0 select 1;
	
	//Get the nearest sectors trigger( capture area ) 
	_trigger = _nearestSector getVariable "areas" select 0;
	
	//Move marker to trigger
	_marker setMarkerPos getPosATL _trigger;

	//Unique identifier for this markers SEH	
	_SEH_ID_var = format[ "SEH_ID_%1", _marker ];
	
	//Code as STRING for SEH so we can format the needed variables into it
	_SEH_code = format[ "
		params[ '_sector', '_owner' ];
		
		_side = [ east, west, independent, civilian ] select %1;
		_enemySides = ( _side call BIS_fnc_enemySides ) - [ sideEnemy ];
		
		if !( _owner in ( [ sideUnknown ] + _enemySides ) ) then {
			[ _sector, 'ownerChanged', _sector getVariable '%4' ] call BIS_fnc_removeScriptedEventHandler;
			[ _side, %2, '%3', _sector ] call TAG_fnc_findNearestSector;
		};
	", _side call BIS_fnc_sideID, _basePos, _marker, _SEH_ID_var ];
	
	//Store on the sector a reference to...
	_nearestSector setVariable[ _SEH_ID_var,
		//Add a "ownerChanged" SEH( scriptedEventHandler ) to the sector
		//This is the same as the expression field in the editor
		[ _nearestSector, "ownerChanged", _SEH_code ] call BIS_fnc_addScriptedEventHandler
	];	
};
	
{
	//Find starting nearest sector
	[] call TAG_fnc_findNearestSector;
}forEach [
	//[ Side, sides basePos, sides markerToMove ] //NOTE!! it is now side not enemy side
	[ #, #, "" ],	//FILL THESE OUT AS NEEDED
	[ #, #, "" ]	//FILL THESE OUT AS NEEDED
];

 

Still Untested.

 

On 5/22/2019 at 11:43 PM, Blitzen88 said:

I suppose my first issue is that I dont know how to call/execute it in game.

Rewritten it as initServer.sqf

 

On 5/22/2019 at 11:43 PM, Blitzen88 said:

the marker was moved to the sector's location and not the area/trigger location.

I wrote to find the sector module not its capture trigger. Fixed in above code.

 

On 5/22/2019 at 11:43 PM, Blitzen88 said:

can I run this everytime a sector is captured via the expression tab on the sector?

Done in above code. The expression field is the same as a scripitedEventHandler of "ownerChanged" placed on the sector.

 

Share this post


Link to post
Share on other sites
16 hours ago, Larrow said:

Rewritten it as initServer.sqf

Thank you so much for helping me with this. I really appreciate it!

 

My goal is to have this script run for both the enemy side and the player’s side. I figure I can make two versions of this script: A West side and an East side...? How could I call those two versions of the script?

 

Also, Im getting an error message whenever a sector has been captured: Image

 

Tested some more and it seems like the scripts stops a sector, which has already been captured by the player's side, from being captured by the enemy side?

Share this post


Link to post
Share on other sites
13 hours ago, Blitzen88 said:

My goal is to have this script run for both the enemy side and the player’s side.

It would have been convenient to mention this in the first place. Always when posting make sure you write all relevant information.

 

Updated code in previous post and fixed a couple of errors.

See very bottom for the variables that need filling out //FILL THESE OUT AS NEEDED.

If you receive any errors please post relevant section from your RPT and the settings you filled in.

Share this post


Link to post
Share on other sites
10 hours ago, Larrow said:

It would have been convenient to mention this in the first place. Always when posting make sure you write all relevant information.

 

My apologies.  I didnt mention that at first because I thought that a script which included both sides would've been more difficult and time consuming to create.  I figured I could use two identical scripts and just switch the names.

 

I tried the new version and it gives the following message: [TAG_fnc_findNearestSector] incorrect params.

 

I filled in the following values:

    [ West, NatoMain, "Patrol" ],    //FILL THESE OUT AS NEEDED
    [ East, CsatMain, "Patrol2" ]    //FILL THESE OUT AS NEEDED

 

Share this post


Link to post
Share on other sites
48 minutes ago, Blitzen88 said:

NatoMain

48 minutes ago, Blitzen88 said:

CsatMain

 

I presume these are objects? Cannot tell without RPT output. If so put a getPos in front of them.

On 5/23/2019 at 5:37 AM, Larrow said:

//[ Side, sides basePos, sides markerToMove ]

 

Share this post


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

 

I presume these are objects? Cannot tell without RPT output. If so put a getPos in front of them.

 

Yes, they are objects. I will try the getpos

Share this post


Link to post
Share on other sites

Updated code to also except OBJECT as basePos.

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

×