Jump to content

Recommended Posts

Hi guys!

 

I want to create a script where the player clicks on a marker on the map (taken from the array "availableBuildings") in order to confirm their "base location". They have to click the same marker location twice in order to confirm.

 

This is what I got so far:

	///////////////////////////////////////
	// Click on map to choose base location
	///////////////////////////////////////
	
	_blds = nearestObjects [[worldSize / 2, worldSize / 2, 0], ["Land_i_Shed_Ind_F"], 15000];
	missionNamespace setVariable ["availableBuildings", _blds, true];
	_markerArray = [];
	
	playSound "BIS_WL_Sector_WEST";
	
	{
	_markerName = format ["marker_%1", _forEachIndex];
	_markerstr = createMarker [_markerName, position _x];
	_markerstr setMarkerShape "ICON";
	_markerstr setMarkerText "";
	_markerstr setMarkerType "loc_Tourism";
	_markerstr setMarkerSize [0.85, 0.85];
	_markerstr setMarkerColor "ColorOrange";
	_markerArray pushBack _markerName;
	} forEach (missionNamespace getVariable "availableBuildings");

	markerstr = createMarker ["marker_confirmation", [0,0,0]];
	_handleMarker = ["marker_confirmation", 0, 1] spawn BIS_fnc_blinkMarker;
	markerstr setMarkerShape "ICON";
	markerstr setMarkerText " Selected Starting Zone - close map to confirm";
	markerstr setMarkerType "Select";
	markerstr setMarkerSize [1.8, 1.8];
	markerstr setMarkerColor "ColorBlue";
	markerstr setMarkerAlpha 0;

	addMissionEventHandler ["MapSingleClick", {
	
			params ["_units", "_pos", "_alt", "_shift"];
			
			_nearestMarker = [allMapMarkers, _pos] call BIS_fnc_nearestPosition;
			
			markerstr setMarkerPos (getMarkerPos _nearestMarker);
			markerstr setMarkerAlpha 1;
		
			if (isNil _nearestMarker) then {
			
				if (getMarkerPos _nearestMarker distance _pos >= 300) then {
					
					playSound "BIS_WL_Selected_WEST";
					markerstr setMarkerColor "ColorGreen";
					
					{ deleteMarker _x } forEach (missionNamespace getVariable "availableBuildings");
					
				};
			};
		
	}];

Obviously this isn't completely functional yet. I need help to make it fully functional. Can anyone please help?

 

Thanks for your time!

Share this post


Link to post
Share on other sites
14 minutes ago, killzone_kid said:

Why do you make availablebuldings array public?

 

I was using it in other scripts in my mission (this code is currently run in initServer.sqf)

Share this post


Link to post
Share on other sites

Right, my bad. I was indeed. Could either of you, or anyone else, help me figure out how to allow for a two-click verification of the choice that the player selects?

Share this post


Link to post
Share on other sites
14 minutes ago, daniel-davies said:

Right, my bad. I was indeed. Could either of you, or anyone else, help me figure out how to allow for a two-click verification of the choice that the player selects?

You could utilize onDoubleClick, works similar to onMapSingleClick, alternatively you could keep a timestamp for every single click and trigger your action if 2 timestamps happened within a certain timeframe to emulate a double click, quite a few ways actually.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
7 minutes ago, Grumpy Old Man said:

You could utilize onDoubleClick, works similar to onMapSingleClick, alternatively you could keep a timestamp for every single click and trigger your action if 2 timestamps happened within a certain timeframe to emulate a double click, quite a few ways actually.

 

Cheers

Sorry..this replay has nothing to do with the OP question, but I just wanna say how much I love your new thin-foil hat avatar Grumpy Old Man..... You're on, ma' man!!!

  • Like 1

Share this post


Link to post
Share on other sites

Just use a MouseButtonDblClicked EH on the map control.

Spoiler

h = [] spawn {
	
	_worldRadius = worldSize / 2;
	availableBuildings = [];
	
	//Create building markers
	{
		_markerName = format[ "marker_%1", _forEachIndex ];
		_marker = createMarkerLocal[ _markerName, position _x ];
		_marker setMarkerShapeLocal "ICON";
		_marker setMarkerTextLocal "";
		_marker setMarkerTypeLocal "loc_Tourism";
		_marker setMarkerSizeLocal[ 0.85, 0.85 ];
		_marker setMarkerColorLocal "ColorOrange";
		
		//Store building along with its marker
		private _nul = availableBuildings pushBack [ _x, _marker ];
	} forEach ( [ _worldRadius, _worldRadius, 0 ] nearObjects [ "Land_i_House_Small_03_V1_F", _worldRadius * 1.4142 ] );
	
	//Force open users map
	openMap[ true, true ];
  
	//Display user instruction
	hint "Double left click a marker to select base location";
	
	//Make sure map is open, before...
	waitUntil{ !isNull findDisplay 12 };
	
	//Add event to map ctrl for when DblClicked
	CEH_MBDC = findDisplay 12 displayCtrl 51 ctrlAddEventHandler [ "MouseButtonDblClick", {
		params[ "_map", "_button", "_mouseX", "_mouseY" ];
		
		//If left mouse button
		if ( _button isEqualTo 0 ) then {
			
			//Get a copy of availableBuildings
			_buildings = +( missionNamespace getVariable "availableBuildings" );
			
			//Change each array item to [ distance, building, marker ]
			//Where distance is from mouse click
			_buildings = _buildings apply{
				_x params[ "_building", "_marker" ];
				
				[
					_building distanceSqr ( _map ctrlMapScreenToWorld[ _mouseX, _mouseY ] ),
					_building,
					_marker
				]
			};
			
			//Re-order to nearest first
			_buildings sort true;
			
			//Get nearest buildings vars
			_buildings select 0 params[ "_dist", "_building", "_marker" ];
			
			//Set choosen as [ building, marker ]
			missionNamespace setVariable[ "choosenBuilding", [ _building, _marker ] ];
			
			//Set selected buildings marker as Green
			_marker setMarkerColorLocal "ColorGreen";
			
			playSound "BIS_WL_Selected_WEST";
						
			//Delete all other markers
			{
				_x params[ "", "", "_marker" ];
				deleteMarkerLocal _marker;
			} forEach ( _buildings select[ 1, count _buildings ] );
			
			//Remove this event
			_map ctrlRemoveEventHandler[ "MouseButtonDblClick", CEH_MBDC ];
		};
	}];
	
	//Wait for selection
	waitUntil { !isNil "choosenBuilding" };
	
	//Remove hint
	hint "";
	
	//Close map
	openMap[ false, false ];
};

 

 

  • Like 3

Share this post


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

Just use a MouseButtonDblClicked EH on the map control.

  Hide contents


h = [] spawn {
	
	_worldRadius = worldSize / 2;
	availableBuildings = [];
	
	//Create building markers
	{
		_markerName = format[ "marker_%1", _forEachIndex ];
		_marker = createMarkerLocal[ _markerName, position _x ];
		_marker setMarkerShapeLocal "ICON";
		_marker setMarkerTextLocal "";
		_marker setMarkerTypeLocal "loc_Tourism";
		_marker setMarkerSizeLocal[ 0.85, 0.85 ];
		_marker setMarkerColorLocal "ColorOrange";
		
		//Store building along with its marker
		private _nul = availableBuildings pushBack [ _x, _marker ];
	} forEach ( [ _worldRadius, _worldRadius, 0 ] nearObjects [ "Land_i_House_Small_03_V1_F", _worldRadius * 1.4142 ] );
	
	//Force open users map
	openMap[ true, true ];
  
	//Display user instruction
	hint "Double left click a marker to select base location";
	
	//Make sure map is open, before...
	waitUntil{ !isNull findDisplay 12 };
	
	//Add event to map ctrl for when DblClicked
	CEH_MBDC = findDisplay 12 displayCtrl 51 ctrlAddEventHandler [ "MouseButtonDblClick", {
		params[ "_map", "_button", "_mouseX", "_mouseY" ];
		
		//If left mouse button
		if ( _button isEqualTo 0 ) then {
			
			//Get a copy of availableBuildings
			_buildings = +( missionNamespace getVariable "availableBuildings" );
			
			//Change each array item to [ distance, building, marker ]
			//Where distance is from mouse click
			_buildings = _buildings apply{
				_x params[ "_building", "_marker" ];
				
				[
					_building distanceSqr ( _map ctrlMapScreenToWorld[ _mouseX, _mouseY ] ),
					_building,
					_marker
				]
			};
			
			//Re-order to nearest first
			_buildings sort true;
			
			//Get nearest buildings vars
			_buildings select 0 params[ "_dist", "_building", "_marker" ];
			
			//Set choosen as [ building, marker ]
			missionNamespace setVariable[ "choosenBuilding", [ _building, _marker ] ];
			
			//Set selected buildings marker as Green
			_marker setMarkerColorLocal "ColorGreen";
			
			playSound "BIS_WL_Selected_WEST";
						
			//Delete all other markers
			{
				_x params[ "", "", "_marker" ];
				deleteMarkerLocal _marker;
			} forEach ( _buildings select[ 1, count _buildings ] );
			
			//Remove this event
			_map ctrlRemoveEventHandler[ "MouseButtonDblClick", CEH_MBDC ];
		};
	}];
	
	//Wait for selection
	waitUntil { !isNil "choosenBuilding" };
	
	//Remove hint
	hint "";
	
	//Close map
	openMap[ false, false ];
};

 

 

 

I ended up figuring it out, but coming back to this topic and seeing Larrow once again being a godsend is so nice. Thank you so much Larrow!

Some of these scripting commands I didn't even realize existed actually haha

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

×