Jump to content
thecoolsideofthepillow

onMapSingleClick, openMap & inputAction conditions.

Recommended Posts

I am trying to write a script that will force open the map and set a variable so when the player clicks on the map, they are teleported to the clicked location.

 

I am having some trouble getting it to know when I have clicked, though. I started off with just simply making the map open and telling it to waitUntil the user clicks the mouse then just close the map; but it doesn't seem to register the clicks inside the map so it never closes.

 

If I can get THAT to work, I just need to know how./where I would set up the variable condition indicating the map is opened from the actionMenu and not just the player pressing M, so that when they click the map they are teleported to the map location based on onMapSingleClick. At first I tried having it all as a condition in a trigger, but that would just cause the map to close instantly seemingly bypassing the onMapSingleClick action.

 

This is the current script that runs from the addAction item on a whiteboard:

private _MapOpened = missionNamespace getVariable "Teleport_Map";
if (isNil "_MapOpened") then
{
    missionNamespace setVariable ["Teleport_Map",0];
    _MapOpened = 0;
};
openMap [true,true];
player setVariable ["Teleport_Map", 1];

[] spawn {
    waitUntil {inputaction "actionFreeLook" > 0};
    openMap [false,false];
};

Note: I have tried the waitUntil without a spawn and the inputAction as "fire" also which produced the same results. It's not because I am forcing the map opened, but not forcing it closed am I? I just don't want to have the player accidentally close the map while it waits for them to click on it and I assume forcing it closed won't allow them to open it manually again.

Share this post


Link to post
Share on other sites

You can use global boolean variable to allow onMapSingleClick handle rto teleport player to position and ignore it otherwise.

map_teleport_enabled = false;

map_click_handler =
[
	"map_teleport", "onMapSingleClick",
	{
		if (map_teleport_enabled) then {
			player setPos _pos; // _pos is predefined for onMapSingleClick
			systemChat format ["Teleported to map position; %1", _pos];
			map_teleport_enabled = false;
			openMap false;
		};
	},
	nil
] call BIS_fnc_addStackedEventHandler;

_id = _target addAction
[
	"Teleport to position on map",
	{
		map_teleport_enabled = true;
		if (!visibleMap) then {
			// will probably need to check if player has map, and use forceMap if he doesn't
			openMap true;
			waitUntil {visibleMap};
		};
		mapCenterOnCamera ((findDisplay 12) displayCtrl 51);
		waitUntil {!visibleMap};
		if (map_teleport_enabled) then {
			systemChat "Teleport to map position cancelled.";
		};
		map_teleport_enabled = false;
	},
	nil, 0.5, false, true
];

If teleport is allowed, then close the map from handler and forbid teleport. So when player opens map by pressing M he will not be teleported when clicked on map.

When action is activated, it allows handler to teleport player.

Notice that if user did not teleport and closed the map, action checks for this case and disables teleporting on its own.

Share this post


Link to post
Share on other sites
	_tpStart = openMap [true,true];
	hintc "Left click on the map where you want to be teleported";
	_plr = _this select 1;
	["teleportClick", "onMapSingleClick", 
	{	
		hint "";
		_this setPos _pos;
		openmap [false,false];
		["teleportClick", "onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
	},_plr] call BIS_fnc_addStackedEventHandler; 

called from addAction on object

 

Sorry pedeathtrian answered in between me clicking reply and me actually writing it :/

Share this post


Link to post
Share on other sites
	_tpStart = openMap [true,true];
	hintc "Left click on the map where you want to be teleported";
	_plr = _this select 1;
	["teleportClick", "onMapSingleClick", 
	{	
		hint "";
		_this setPos _pos;
		openmap [false,false];
		["teleportClick", "onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
	},_plr] call BIS_fnc_addStackedEventHandler; 

called from addAction on object

 

Sorry pedeathtrian answered in between me clicking reply and me actually writing it :/

 

 

I will say yours is a bit cleaner though. I appreciate both your help :)

Share this post


Link to post
Share on other sites

I will say yours is a bit cleaner though.

That's only because it does not allow cancelling teleport and uses forced map. Otherwise the concept is the same.

I also checked the openMap command both with one boolean argument and array (for forced) and forceMap command. All of them don't show map if player does not have one. Should be checked too.

  • 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

×