Jump to content
Sign in to follow this  
bearbison

Digital Compass Script

Recommended Posts

Digital Compass Bearing script



This adds the ability to have a digital compass heading (bearing) in either a hint box or the original text mode which can be toggled on or off.

Note: The k (default compass) key is the toggle key

Thumbnails:

Old text style:

th_BEARB_CHoldstyle.jpg

New hint style:

​th_BEARB_CHnewstyle.jpg

Enabling the script:

To use this script in a mission, copy the following code lines into your init.sqf file.

/* Compass bearing */
call compile preprocessFile "scripts\BEARB_heading.sqf";

Then copy the scripts folder into your mission.

Changing the display style:

To change from the new hint method of display to the older text method, open the file scripts\BEARB_heading.sqf and edit the value for BEARB_compassheading_old from false to true.

/*
Determines if the old (text) or the new (hint) display method is used for the digital compass bearing
false = new style (in hint message)
true = old style (in text on screen)
*/
BEARB_compassheading_old = false;

Download:

news_download_a3_3.png

Changelog:

v2

  • Added the option to choose between the old text style or the new hint style display.
  • Fixed the toggle option
  • Tidied the code

v1

  • Initial release

Note:

A mod version for use in all missions is available here

Edited by BearBison
Added mirror

Share this post


Link to post
Share on other sites

Digital Compass Bearing script



A mod version for use in all missions is available here

Is there a script version of available? The link provided does not work.

Share this post


Link to post
Share on other sites

Made a slightly modified version of it to use on my server. Very useful, thanks BearBison. I'm so dumb when speaking of display.

/*
This script creates a hint by default that displays the players bearing when toggled on.
Toggle key is the "k" key
created by [RIP]BearBison
*/
if (isDedicated) exitwith {};

/* Private variables */
private ["_key", "_bearing","_text"];

/* Set the initial toggle state */
BEARB_compassheading_on = false;

/*
Determines if the old (text) or the new (hint) display method is used for the digital compass bearing
false = new style (in hint message)
true = old style (in text on screen)
*/
BEARB_compassheading_old = if (isNil {_this select 0}) then {false} else {_this select 0};

/* Sets what happens when the toggle is pressed */
BEARB_compassheading_down =
{
   _key = _this select 1;
   if (_key == 37) then 
   {
       if (!BEARB_compassheading_on) then {BEARB_compassheading_on = true;};
   };
};

/* Sets what happens when the toggle is released */
BEARB_compassheading_up =
{
   _key = _this select 1;
   if (_key == 37) then
   {
       if (BEARB_compassheading_on) then 
       {
           BEARB_compassheading_on = false;
           if (!BEARB_compassheading_old) then {hintsilent "";};
       };
   };
};
/* Ensures the primary display is found */
waitUntil {!isNull(findDisplay 46)};

/* Adds the eventhandlers to detect the toggle key press */
(findDisplay 46) displayAddEventHandler ["keyDown", "_this call BEARB_compassheading_down"];
(findDisplay 46) displayAddEventHandler ["keyUp", "_this call BEARB_compassheading_up"];

/* What happens when the toggle is true */
while {true} do
{
   if (BEARB_compassheading_on && {"ItemCompass" in assignedItems Player}) then
   {
       _bearing = getdir player;
       _bearing = round (_bearing);
       if (BEARB_compassheading_old) then
       {
           titleText [("                                                BEARING: " + str _bearing), "PLAIN DOWN", 0.02];
       }
       else
       {
           _text = "BEARING: ";
           hintsilent parseText (_text + str _bearing);
       };
   };
   sleep 0.1; // no need to be on a urge
};

So I can use this line in my init to get the old style:

[true] spawn compile preprocessFile "scripts\BEARB_heading.sqf";

Take it if you find it useful.

Regards,

Holo.

Edited by holo89
replaced call by spawn

Share this post


Link to post
Share on other sites

So I can use this line in my init to get the old style:

[true] call compile preprocessFile "scripts\BEARB_heading.sqf";

Take it if you find it useful.

Regards,

Holo.

I appreciate the work and the share.

Thank you Holo

Hajimoto

Share this post


Link to post
Share on other sites

I tried a call, but it should be a spawn if you don't want your Init.sqf to jam at this place... ;-)

[true] spawn compile preprocessFile "scripts\BEARB_heading.sqf";

Share this post


Link to post
Share on other sites

You might wanna remove that while loop and put it into the oneachFrame. The whily loop can theoretically run many times as second where it only has to run once per frame (or for that matter 10 times a second would probably do it).

So I suggest either putting a sleep 0.1 or use this:

waitUntil {!isNil {player}};
waitUntil {!isNull player};
addMissionEventHandler ["Draw3D", 
{
       if (BEARB_compassheading_on && "ItemCompass" in assignedItems Player) then
{
	_bearing = getdir player;
	_bearing = round (_bearing);
	if (BEARB_compassheading_old) then
	{
		titleText [("                                                BEARING: " + str _bearing), "PLAIN DOWN", 0.02];
	}
	else
	{
		_text = "BEARING: ";
		hintSilent parseText (_text + str _bearing);
	};
};
}];

Only you might wanna use hintSilent because the new hint makes this lovely sound.

Edit: This function would also prevent the init from stopping if you use a call instead of a spawn.

Share this post


Link to post
Share on other sites

@mindstorm, good idea the draw3d. everying else was already in the modif I posted.

I wonder if putting the script in a gamelogic with that draw3d would work. It may be an alternative to people that don't yet make script files. It would be 100% editor compatible. Some people just don't want to mess with init.sqf, and I think that is why BIS is putting efforts in modules.

regards,

Holo

edit: ouff, looking at the code, I think it would not be easy. adding displayeventhandler in a scriptlogic not sure how to wait for display 46 to be available in editor init of an object?

Edited by holo89
second tought

Share this post


Link to post
Share on other sites

Cheers guys, this was made before they added they sound back to silent, updated the mod version but don't really use this any more since the compass is readable :)

Thanks for the updates and suggestions holo and mindstorm, need to have a look at the draw3d as not played with it yet but sounds interesting.

Share this post


Link to post
Share on other sites

I just discovered it. I still find it useful, I find the compass numbers too small (playing on a 720p) and it has the advantage of showing bearing even when in optics of my sniper without quitting the enemy while pressing K

regards,

Holo

Share this post


Link to post
Share on other sites
@mindstorm, good idea the draw3d. everying else was already in the modif I posted.

I wonder if putting the script in a gamelogic with that draw3d would work. It may be an alternative to people that don't yet make script files. It would be 100% editor compatible. Some people just don't want to mess with init.sqf, and I think that is why BIS is putting efforts in modules.

regards,

Holo

edit: ouff, looking at the code, I think it would not be easy. adding displayeventhandler in a scriptlogic not sure how to wait for display 46 to be available in editor init of an object?

It shouldn't be a problem, although not best practice. You will have to paste the whole code of script tho and not only my posted part.

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
Sign in to follow this  

×