Home   Help Search Login Register  

Author Topic: Is the player using his NVG’s?  (Read 3114 times)

0 Members and 1 Guest are viewing this topic.

Offline CH

  • Members
  • *
Is the player using his NVG’s?
« on: 19 Jun 2009, 00:32:10 »
I'm trying to create an IR beacon for a mission by placing a blinking light that only can be seen thru NVG's. To do this I need two things, a light that goes on and off, and some way of detecting if the player has turned on or off his NVG's, and it is the detection part I need help with. I've had a couple of ideas but none of them worked. Maybe I'm in way over my head? ???

Offline i0n0s

  • Former Staff
  • ****
Re: Is the player using his NVG’s?
« Reply #1 on: 19 Jun 2009, 01:06:02 »
The NVG detection ain't possible without ArmALib since:
  • The mission/an addon could activate the night vision itself
  • The player put the key for nightvision on a joystick or mouse button.
You can only try and hope that the issues above won't happen.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Is the player using his NVG’s?
« Reply #2 on: 19 Jun 2009, 04:23:22 »
Would it not be possible to create a light so dim you wouldn't see it unless you were amplifying the light with NVG? Not sure that would work, but worth a try, perhaps? Main issue would be that a lot of people seem to gamma up the night so much they don't need NVG and they'd be able to see it, I suppose, but can't do anything about them. About the best I can imagine without the magic of Armalib though.

Making a blinking light is easy enough though (been discussed plenty of times before, surely).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline CH

  • Members
  • *
Re: Is the player using his NVG’s?
« Reply #3 on: 19 Jun 2009, 12:21:13 »
Thank you both for the quick and very helpful replies!  :good:

The NVG detection ain't possible without ArmALib

Have you any experience using ArmALib. Would you recommend it?
BTW I found some very interesting things when I read about it that is not related to the question.

The mission/an addon could activate the night vision itself

That's not a problem since there are currently no addons in this mission and the mission itself won't turn on or off the NVG's

The player put the key for nightvision on a joystick or mouse button.

Would it be possible if the player only could control the NVG's with the keyboard?
This might be good enough since I guess most players don't use mouse or joystick to control NVG's.

Would it not be possible to create a light so dim you wouldn't see it unless you were amplifying the light with NVG?

The mission puts you in the role of a helo pilot that is looking for some friendly units that has marked an LZ with an IR beacon, so the beacon must visible at long range to be of any help. I got inspired by the movie "Black Hawk Down" where they use an IR beacon to mark some targets before an air strike.

Making a blinking light is easy enough though (been discussed plenty of times before, surely).

I know, I was just trying explain way I wanted to detect NVG usage.


Offline i0n0s

  • Former Staff
  • ****
Re: Is the player using his NVG’s?
« Reply #4 on: 19 Jun 2009, 15:40:52 »
Use actionKeys "NightVision" to get all keys that are assigned to start the night vision.

Offline CH

  • Members
  • *
Re: Is the player using his NVG’s?
« Reply #5 on: 24 Jun 2009, 13:16:02 »
I'm having trouble understanding the "ctrlSetEventHandler" command. This is what I've got so far:

Init.sqf
Code: [Select]
[irBeacon1] execVM "functions\irBeacon.sqf";
[] execVM "functions\nvg_on_or_off.sqf";

irBeacon.sqf
Code: [Select]
irBeacon_brightness = 0.05;

_object = _this select 0;
_light = "#lightpoint" createVehicle position _object;
_light setLightColor [2, 2, 2];
_light setLightAmbient [0.9, 0.9, 0.9];
_light setLightBrightness (irBeacon_brightness);

while {true} do
{
   _light setLightBrightness (irBeacon_brightness);                   
   sleep 0.2;
   _light setLightBrightness (0.0);
   sleep 0.6;
};

nvg_on_or_off.sqf
Code: [Select]
functionName_keyDown =
{
   private["_dikCode"];
   _dikCode = _this select 1;
   _handled = false;
   if (_dikCode in (actionKeys "nightVision")) then
   {
      if (irBeacon_brightness == 0.05) then
      {
      irBeacon_brightness = 0.00;
      }
      else
      {
      irBeacon_brightness = 0.05;
      };
      _handled = true;
   };
   _handled;
};

_ctrl ctrlSetEventHandler ["keyDown", "_this call functionName_keyDown"];

Any help would be appreciated...

Offline i0n0s

  • Former Staff
  • ****
Re: Is the player using his NVG’s?
« Reply #6 on: 24 Jun 2009, 15:11:26 »
You need to use displaySetEventHandler or better s_holes or Spooners displayEventhandler.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Is the player using his NVG’s?
« Reply #7 on: 24 Jun 2009, 15:22:39 »
Yes, use SPON Core along with:
Code: [Select]
functionName_keyDown =
{
      irBeacon_brightness = (irBeacon_brightness == 0) ? 0.05 : 0;

      false; // Must return false, otherwise other handlers won't be informed of the event.
};

{
      ["Down", _keyCode, functionName_keyDown] call SPON_addKeyEventHandler;
} forEach actionKeys "nightVision";

Bit simpler, but more importantly allows your system to be compatible with other people's. I am still not convinced this will be very effective though.

Note:
* Breaks if you enter a dialog with N pressed down.
* Breaks if disableUserInput ever used.
* Breaks if using something like SPON Kits or adjustable NV addon, that automatically enable/disable NVG.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline CH

  • Members
  • *
Re: Is the player using his NVG’s?
« Reply #8 on: 25 Jun 2009, 23:25:19 »
Once again quick replies!  :good:

This is what I did:

1.) Downloaded Spoon Core
2.) Opened the readme
3.) Followed the  "Installation (mission-script version)"
4.) Changed the nvg_on_or_off.sqf
5.) Tried the mission
6.) Got this error message

Code: [Select]
‘... brightness = (irBeacon_brightness == 0) I#I ? 0.05 : 0;

      false; // Must return false, otherwise other handlers won't be informed of the event.
};

{
      ["Down", _key...'

Error missing ;
File C:\Users (and so on)
line 3

7.) Double checked the  "Installation (mission-script version)" and  found nothing

8.) Replaced this line

Code: [Select]
irBeacon_brightness = (irBeacon_brightness == 0) ? 0.05 : 0;
with this

Code: [Select]
hint "test";
9.) Tried to get the hint displayed by pressing the NVG key but didn't see it



Note:
* Breaks if you enter a dialog with N pressed down.
* Breaks if disableUserInput ever used.
* Breaks if using something like SPON Kits or adjustable NV addon, that automatically enable/disable NVG.

Ok, but all those things are controlled by the mission author, right?
 :dunno:

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Is the player using his NVG’s?
« Reply #9 on: 27 Jun 2009, 20:34:39 »
Quote
Ok, but all those things are controlled by the mission author, right?
Only if the mission is never run with any addons (well, OK, SPON Kits, for example, is a mission-script so yes, that is under the control of the mission maker). Any of which could mess you up ;)

Oh, just remembered that when you press any button, you continually get DOWN events being called. Like I said, really telling if the NVG is on or off this way is more complex than it appears and is pretty much guaranteed to fail as soon as the average player tries to use it (players always find the best way to break anything, even if, as a dev you would never think of it)!

Sorry, had a brain fart moment originally (And wasn't writing in SQF or remembering what the hell I was doing!):
Code: [Select]
nightvision_keyDown =
{
      // Either key up has been lost in a disableKeyEvents/dialog entry or the
      // key has been recorded as released properly via up event.
      if ((time - irBeacon_downAt) > 1) then
      {
          irBeacon_brightness = if (irBeacon_brightness == 0) then { 0.05 } else { 0 };
      };

      irBeacon_downAt = time;

      false; // Must return false, otherwise other handlers won't be informed of the event.
};

nightvision_keyUp =
{
      irBeacon_downAt = 0; // Key has been released, so record presses again.

      false; // Must return false, otherwise other handlers won't be informed of the event.
};

{
      ["Down", _x, nightvision_keyDown] call SPON_addKeyEventHandler;
      ["Up", _x, nightvision_keyUp] call SPON_addKeyEventHandler;
} forEach actionKeys "nightVision";

Still, you'll have critical problems with, for example, the popular manual NVG addon.
« Last Edit: 30 Jun 2009, 04:04:35 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline CH

  • Members
  • *
Re: Is the player using his NVG’s?
« Reply #10 on: 30 Jun 2009, 01:25:08 »
It works! Thank you very much!  :clap:

Only if the mission is never run with any addons (well, OK, SPON Kits, for example, is a mission-script so yes, that is under the control of the mission maker). Any of which could mess you up ;)

Still, you'll have critical problems with, for example, the popular manual NVG addon.

I think I get it now. I thought that the mission maker/author could control the usage of addons by changing the mission.sqm file, but if I understand you correctly, this only specifies min. requirement.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Is the player using his NVG’s?
« Reply #11 on: 30 Jun 2009, 04:05:14 »
Absolutely! You can set requirements, but not make prohibitions.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)