Jump to content

Recommended Posts

Hi guys, here's the skinny.

I've got an aircraft with 3 AI crew and one player crew in an MP environment on a dedicated server. That said the player is NOT grouped with the 3 AI crew for REASONS... What I'm trying to do is add an addiction to the aircraft to allow the player to select a position on the map and order the aircraft to Loiter with given radius and altitude.
Here's the code I have at the moment
 

Mother addaction ["Set Orbit",  {
	_this select 1;
	Orbit_set = true;
	hintsilent "Open your Map. Leftclick to set orbit center";
	onMapSingleClick "
	_wp1 = group MotheD addwaypoint [_pos, 0];
	[group MotherD, 1] setWaypointType ""LOITER"";
	_mk1 = createMarkerLocal [""OrbitCenter"", _pos];
	""OrbitCenter"" setMarkerType ""waypoint"";
	[group MotherD, 1] setWaypointPosition [_pos, 1];
	[group MotherD, 1] setWaypointLoiterRadius 2000;
	Mother flyInHeight 1500;
	Orbit_set = false;
	";
	waitUntil{!Orbit_set};
	onMapSingleClick "";
;}
];

So whats happening is, I select the action (as the player) and I receive the hint, however when I click on a position after opening the map nothing happens. I can go into Zeus and verify no waypoint has been created. However; when I alt click on the map the whole aircraft gets teleported to that position... what gives I don't have a getpos setpos anywhere in there I'm totally lost, I was reading something about an EH for this kind of thing but I'm not understanding that, It seems way more complicated than it needs to be.
Thanks!

Mother = the aircraft variable name
MotherD = the driver of Mother (Pilot)
 

Edited by Cockheaven
Clarified Variables

Share this post


Link to post
Share on other sites

Typo? group MotheD addwaypoint [_pos, 0];

 

On the other hand, you don't need to specify for driver. A simple group Mother  will do the trick.

Share this post


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

However; when I alt click on the map the whole aircraft gets teleported to that position

This is an editor preview feature. You can Alt  + LftClick to teleport about.

 

Spoiler


//initPlayerLocal.sqf

#include "\a3\ui_f\hpp\definedikcodes.inc"

Mother addAction ["Set Orbit", {
	params[ "_target", "_caller", "_ID", "_args" ];

	hintSilent "Leftclick to set orbit center. Or Spacebar to cancel";

	_h = [] spawn {

		//Wait for Map display
		waitUntil{ !isNull ( uiNamespace getVariable[ "RscDiary", displayNull ] ) };

		//Add key up EH to Map display so the user can cancel out of the forced map
		DEH_KU = uiNamespace getVariable "RscDiary" displayAddEventHandler [ "KeyUp", {
			params[ "_display", "_keyCode" ];

			//If the user presses Spacebar
			if ( _keyCode == DIK_SPACE ) then {
				//Remove MapSingleClick MEH
				removeMissionEventHandler[ "MapSingleClick", MEH_MSC ];
				//Remove this display key up EH
				_display displayRemoveEventHandler[ "KeyUp", DEH_KU ];

				//Close map
				openMap[ false, false ];
				//Remove hint
				hint "";
			};
		}];
	};

	//Add mission MapSingleClick EH
	MEH_MSC = addMissionEventHandler [ "MapSingleClick", {
		params[ "_units", "_pos", "_alt", "_shift" ];

		//Depending on helos altitude,
		//it will try to climb to this height before proceeding to follow Loiter WP
		Mother flyInHeight 1500;

		//Add Loiter waypoint
		_wp1 = group MotherD addWaypoint[ _pos, 0 ];
		_wp1 setWaypointType "LOITER";
		_wp1 setWaypointLoiterType "CIRCLE";
		_wp1 setWaypointLoiterRadius 2000;
		//Set WP as groups current WP
		group MotherD setCurrentWaypoint _wp1;

		//If marker OrbitCenter already exists
		if !( getMarkerPos "OrbitCenter" isEqualTo [0,0,0] ) then {
			//Move it
			"OrbitCenter" setMarkerPosLocal _pos;
		}else{
			//Create OribitCenter marker
			_mk1 = createMarkerLocal[ "OrbitCenter", _pos ];
			_mk1 setMarkerType "waypoint";
		};

		//Remove this MEH MapSingleClick
		removeMissionEventHandler[ "MapSingleClick", _thisEventHandler ];
		//Remove Map display key up EH
		uiNamespace getVariable "RscDiary" displayRemoveEventHandler[ "KeyUp", DEH_KU ];

		//Close map
		openMap[ false, false ];
		//Clear hint
		hint "";
	}];

	//Force open the map
	openMap[ true, true ];

}];

 

 

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

×