Jump to content

Recommended Posts

Hi guys so i was watching dislexy video on yt and i noticed that he has a line on GPS for refrence  go to 1:49 seconds you can see that(

) where basicly points in where waypoints is but i cant find anything like that online that is finished.
So i tried to recreate it and this is what i have but it gives me error and i cant figure it what actually is:

onMapSingleClick "

	(findDisplay 12 displayCtrl 51) ctrlAddEventHandler ['Draw','
		(_this select 0) drawLine[getpos player,_pos,[1,1,1,1]];
	'];
	true;
";

I have error 0 elements provided expeted 3 and error type Number expeted bool. Anyhelp would be awsome ty.
 

Share this post


Link to post
Share on other sites

The problem is _pos isn't accessible in the control event handler scope. If you replace it with [0,0,0] it will work as you think it does. So, you can save _pos into a variable that is independent of scope, like a namespace variable, then recall it in the control Event Handler to get it working. But there are more problems than just that. The way you've set this up, you will be adding a new event handler every time you click on the map, which you don't want to do, so adding the control event handler needs to be taken out of the OnClick event. Another problem is you are using onMapSingleClick, which is the old way of doing this and could be overwritten, when you should be using the mission event handler for this. Lastly, you are passing your code as strings, this isn't a huge problem, it just makes everything generally harder and offers no benefits (that I know of)

 

So here is what I would use, with the above problems fixed:

addMissionEventHandler ["MapSingleClick", {
	player setVariable ["ClickedMapPos", _this # 1];
}];

((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw",{
	_pos = player getVariable "ClickedMapPos";
	if (!isNil "_pos") then {
		(_this select 0) drawLine [getpos player, _pos, [1,1,1,1]];
	};
}];

 

  • Like 2

Share this post


Link to post
Share on other sites

Ty very mutch for takeing your time explaning and providing the code but i have another questions as well. 1st How would i be able to display this line in GPS and how would i make like a number at the end of the line that tells the distance between 2 points ?

Edit: I think i actually manage to make it work to show on GPS as well here is the code now all i need is to figure how to show distance between 2 points.
 

addMissionEventHandler ["MapSingleClick", {
	player setVariable ["ClickedMapPos", _this # 1];
}];

// Wait for display
private _display = uiNamespace getVariable ["RscCustomInfoMiniMap", displayNull];

private _miniMapControlGroup = _display displayCtrl 13301;
private _miniMap = _miniMapControlGroup controlsGroupCtrl 101;


((findDisplay 12) displayCtrl 51) ctrlAddEventHandler ["Draw",{
	_pos = player getVariable "ClickedMapPos";
	if (!isNil "_pos") then {
		(_this select 0) drawLine [getpos player, _pos, [1,1,1,1]];
	};
}];


_miniMap ctrlAddEventHandler ["Draw",{
	_pos = player getVariable "ClickedMapPos";
	if (!isNil "_pos") then {
		(_this select 0) drawLine [getpos player, _pos, [1,1,1,1]];
	};
}];

 

Share this post


Link to post
Share on other sites
2 hours ago, Stormmy1950 said:

show distance between 2 points

 

That's the easy part! I just folded the code I was working on into yours:

addMissionEventHandler ["MapSingleClick", { 
	params ["_units", "_pos", "_alt", "_shift"]; 
	if (_shift) then { 
	player setVariable ["ClickedMapPos", _pos]; 
}}]; 

// Wait for display
private _display = uiNamespace getVariable ["RscCustomInfoMiniMap", displayNull];
private _miniMapControlGroup = _display displayCtrl 13301;
private _miniMap = _miniMapControlGroup controlsGroupCtrl 101;
private _map = findDisplay 12 displayCtrl 51; 

_map ctrlAddEventHandler ["Draw", {
	_pos = player getVariable "ClickedMapPos";
	_dist = (player distance2d _pos) / 1000 toFixed 1; 
	if (!isNil "_pos") then {
		_this#0 drawLine [getpos player, _pos, [1,1,1,1]];
		_this#0 drawIcon  
		[ 
			"IconControlPoint", [0,0.75,0,1], _pos, 24, 24, 45, format ["%1 km", _dist], 1, 0.03, "TahomaB", "right" 
		]; 
	};
}];


_miniMap ctrlAddEventHandler ["Draw",{
	_pos = player getVariable "ClickedMapPos";
	_dist = (player distance2d _pos) / 1000 toFixed 1;
	if (!isNil "_pos") then {
		_this#0 drawLine [getpos player, _pos, [1,1,1,1]];
		_this#0 drawIcon  
		[ 
			"IconControlPoint", [0,0.75,0,1], _pos, 24, 24, 45, format ["%1 km", _dist], 1, 0.03, "TahomaB", "right" 
		]; 
	};
}];

 

I added a _shift check, as D's system follows his shift+click waypoint. Not sure if it's via a mapclick EH like we're doing here, or if he's somehow detecting and finding the pos of the user's custom waypoint marker.

 

I am also, as in D's system, returning distance as kilometers to the first decimal. If you want a higher resolution, change these lines

_dist = (player distance2d _pos) / 1000 toFixed 1;

to (for example)

_dist = (player distance2d _pos) / 1000 toFixed 2;  // will now show two decimal places e.g. "4.75 km"

or, if you just want it in meters with no decimal places

_dist = round (player distance2d _pos);  //  e.g. "4752 meters"

//don't forget to change drawIcon's 7th param e.g. 

format ["%1 m", _dist]


 

Now, I can't for the life of me figure out how to draw any of the "selected" cursors or group icons like D is using, much less get them to rotate.

 

  • Like 2

Share this post


Link to post
Share on other sites

Ty very mutch. This is awsome. Now the only problem that i have is when player enters in vehicle and opens GPS in vehicle the line dosent show. Is the GSP display in vehicle diffrent display then on foot display and if so how can i find the idd of GSP display that is in vehicle ? (Also i am using ace idk if ace has something to do with that.)

 

Share this post


Link to post
Share on other sites

Ty very mutch. This is awsome. Now the only problem that i have is when player enters in vehicle and opens GPS in vehicle the line dosent show. Is the GSP display in vehicle diffrent display then on foot display and if so how can i find the idd of GSP display that is in vehicle ? (Also i am using ace idk if ace has something to do with that.)

9 hours ago, Harzach said:

Now, I can't for the life of me figure out how to draw any of the "selected" cursors or group icons like D is using, much less get them to rotate. 

  

I think he has custom icon in drawIcon and he just spawns it where he click on the map and then has a  fnc that rotates that picture. At least that would be my aproach 😄
EDIT: sry didnt mean double post dont know what actually happend.

Share this post


Link to post
Share on other sites

Working fine in vanilla and ACE here, though I haven't tried every vehicle.

 

49 minutes ago, Stormmy1950 said:

I think he has

 

Yeah, I was trying to do it without having to make an addon. The rotation isn't that big of a problem, but I gave up after failing to draw the right icon...

Share this post


Link to post
Share on other sites
2 minutes ago, Harzach said:

Working fine in vanilla and ACE here, though I haven't tried every vehicle.

Its a Air vehicle like a humming bird i was using. Also how would i execute this code so playes have it in multiplayer is it in InitPlayerLocal ? I was using Console to execute code so far.

Share this post


Link to post
Share on other sites
35 minutes ago, Stormmy1950 said:

InitPlayerLocal

 

Should work.

 

35 minutes ago, Stormmy1950 said:

Its a Air vehicle

 

OK, this is really odd. Regardless of vanilla/ACE/whatever:

  • If I place a rifleman with GPS, it works.
  • If I add a ground vehicle (with or without integrated GPS), it works.
  • If I add an air vehicle, the rifleman's GPS doesn't work, but the air vehicle's does.
  • If I add both a ground and air vehicle, again, only the air vehicle's works.

So, the map always works, but not the GPS.

Share this post


Link to post
Share on other sites
15 minutes ago, Harzach said:

Should work.

Also i tryied executing from InitPlayerLocal and the script fires but it dose not make line when its click on the map or anything else.

Share this post


Link to post
Share on other sites

Ok so i think i have manage to get it working here is the final product of this script:
 

/*
First of i wonna give big tanks to:
-Dslyecxi - for idea.
-dreadedentity
-Harzach
-Leopard20
and me L3gion (old name Stormmy1950)

without them this wouldn't be possible at least for me :) 

To execute this you need to create 2 files in your mission directory.
1.InitPlayerLocal.sqf
2. [somename].sqf

in InitPlayerLocal.sqf put this line of code:

null = [] execVM "[somename].sqf";

and in [somename].sqf copy all of this and paste it and it should work

Note: its tested on singleplayer and hosted server not tested in Dedicated server.
Note2: if you copyied this from BI Forums they may be hidden characters so double check to make shure there is no hidden characters.

*/

//EH that gets where player Shift + Left Click on the map
addMissionEventHandler ["MapSingleClick", { 
	params ["_units", "_pos", "_alt", "_shift"]; 
	if (_shift) then { 
	player setVariable ["ClickedMapPos", _pos];
}}]; 


private _map = findDisplay 12 displayCtrl 51;
//small wait becouse we are calling this script from InitPlayerLocal.sqf so it get initiliazes
while {isNull _map} do {
  uiSleep 0.1;
  _map = findDisplay 12 displayCtrl 51;
};

//EH Draw witch draws Line and pointers and distance text.
_map ctrlAddEventHandler ["Draw", {
	_pos = player getVariable "ClickedMapPos";
	_dist = (player distance2d _pos) / 1000 toFixed 1; //_dist = (player distance2d _pos) / 1000 toFixed 2;  - will now show two decimal places e.g. "4.75 km"
	/*
	if you just want it in meters with no decimal places

		_dist = round (player distance2d _pos);  //  e.g. "4752 meters"

		//don't forget to change drawIcon's 7th param e.g. 

		format ["%1 m", _dist]
	*/
	if (!isNil "_pos") then {
		_this#0 drawLine [getpos player, _pos, [1,1,1,1]];
		_this#0 drawIcon  
		[ 
			"IconControlPoint", [0,0,0,1], _pos, 24, 24, 45, format ["%1 km", _dist], 1, 0.03, "TahomaB", "right" 
		]; 
	};
}];

//These lines of code eneables to show on GPS regadlers are you in vehicle or not.
private _displays = uiNameSpace getVariable ["igui_displays", []];
{
  private _ctrl = _x displayCtrl 101;

  if (!isNull _ctrl && ctrlType _ctrl == 101) then {

		_ctrl ctrlAddEventHandler ["Draw", {
		_pos = player getVariable "ClickedMapPos";
		_dist = (player distance2d _pos) / 1000 toFixed 1;
		if (!isNil "_pos") then {
			_this#0 drawLine [getpos player, _pos, [1,1,1,1]];
			_this#0 drawIcon  
			[ 
				"IconControlPoint", [0,0,0,1], _pos, 24, 24, 45, format ["%1 km", _dist], 1, 0.03, "TahomaB", "right" 
			]; 
		};
		}];
  };
} forEach _displays;

 

  • Like 1

Share this post


Link to post
Share on other sites
On 4/26/2022 at 6:09 PM, Stormmy1950 said:

Ok so i think i have manage to get it working here is the final product of this script:
 


/*
First of i wonna give big tanks to:
-Dslyecxi - for idea.
-dreadedentity
-Harzach
-Leopard20
and me L3gion (old name Stormmy1950)

without them this wouldn't be possible at least for me :) 

To execute this you need to create 2 files in your mission directory.
1.InitPlayerLocal.sqf
2. [somename].sqf

in InitPlayerLocal.sqf put this line of code:

null = [] execVM "[somename].sqf";

and in [somename].sqf copy all of this and paste it and it should work

Note: its tested on singleplayer and hosted server not tested in Dedicated server.
Note2: if you copyied this from BI Forums they may be hidden characters so double check to make shure there is no hidden characters.

*/

//EH that gets where player Shift + Left Click on the map
addMissionEventHandler ["MapSingleClick", { 
	params ["_units", "_pos", "_alt", "_shift"]; 
	if (_shift) then { 
	player setVariable ["ClickedMapPos", _pos];
}}]; 


private _map = findDisplay 12 displayCtrl 51;
//small wait becouse we are calling this script from InitPlayerLocal.sqf so it get initiliazes
while {isNull _map} do {
  uiSleep 0.1;
  _map = findDisplay 12 displayCtrl 51;
};

//EH Draw witch draws Line and pointers and distance text.
_map ctrlAddEventHandler ["Draw", {
	_pos = player getVariable "ClickedMapPos";
	_dist = (player distance2d _pos) / 1000 toFixed 1; //_dist = (player distance2d _pos) / 1000 toFixed 2;  - will now show two decimal places e.g. "4.75 km"
	/*
	if you just want it in meters with no decimal places

		_dist = round (player distance2d _pos);  //  e.g. "4752 meters"

		//don't forget to change drawIcon's 7th param e.g. 

		format ["%1 m", _dist]
	*/
	if (!isNil "_pos") then {
		_this#0 drawLine [getpos player, _pos, [1,1,1,1]];
		_this#0 drawIcon  
		[ 
			"IconControlPoint", [0,0,0,1], _pos, 24, 24, 45, format ["%1 km", _dist], 1, 0.03, "TahomaB", "right" 
		]; 
	};
}];

//These lines of code eneables to show on GPS regadlers are you in vehicle or not.
private _displays = uiNameSpace getVariable ["igui_displays", []];
{
  private _ctrl = _x displayCtrl 101;

  if (!isNull _ctrl && ctrlType _ctrl == 101) then {

		_ctrl ctrlAddEventHandler ["Draw", {
		_pos = player getVariable "ClickedMapPos";
		_dist = (player distance2d _pos) / 1000 toFixed 1;
		if (!isNil "_pos") then {
			_this#0 drawLine [getpos player, _pos, [1,1,1,1]];
			_this#0 drawIcon  
			[ 
				"IconControlPoint", [0,0,0,1], _pos, 24, 24, 45, format ["%1 km", _dist], 1, 0.03, "TahomaB", "right" 
			]; 
		};
		}];
  };
} forEach _displays;

 

I managed to get this to work in one instance but not work in another. It's confounding!

In some_1.sqf the following works:
  

 private _displays = uiNameSpace getVariable ["igui_displays", []];
    {
        private _ctrl = _x displayCtrl 101;

        if (!isNull _ctrl && ctrlType _ctrl == 101) then {
        _ctrl ctrlAddEventHandler ["Draw", 
            {
                _this#0 drawIcon [getMissionPath "\images\attack.paa", [1,1,1,1], (getMarkerPos "BZMarker"), 30, 30, 0, "", 1, 0.03, "TahomaB", "right"];
            }];
    };
} forEach _displays;

In some_2.sqf:
 

//This works and displays an icon on the player map
findDisplay 12 displayCtrl 51 ctrlAddEventHandler ["Draw", 
{ 
    _ALP_towers = ALP_mainZone getVariable "ALP_triggerTowers";
    {
        _this select 0 drawIcon [getMissionPath format ["\images\tower%1_ca.paa", (_forEachIndex + 1)], [1,1,1,1], (getPos (_x select 0)), 24, 24, 0, "", 1, 0.03, "TahomaB", "right"];
    } forEach _ALP_towers;
}];
//This does NOT work, but doesn't throw any errors!
private _displays = uiNameSpace getVariable ["igui_displays", []];
{
    private _ctrl = _x displayCtrl 101;
    _ALP_towers = ALP_mainZone getVariable "ALP_triggerTowers";
    if (!isNull _ctrl && ctrlType _ctrl == 101) then {
        {
            _ctrl ctrlAddEventHandler ["Draw", 
                       
            {
               _this#0 drawIcon [getMissionPath format ["\images\tower%1_ca.paa", (_forEachIndex + 1)], [1,1,1,1], (getPos (_x select 0)), 24, 24, 0, "", 1, 0.03, "TahomaB", "right"];
            }];
        } forEach _ALP_towers;
    };
} forEach _displays;

 

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

×