Home   Help Search Login Register  

Author Topic: seven's Runway Lights (updated to version 1.7 beta) (ACCEPTED)  (Read 10945 times)

0 Members and 1 Guest are viewing this topic.

Offline [seven]

  • Members
  • *
Dynamically detects or creates runway edgelights for any airport on any map and lights them up brightly.



Version 1.7 beta uploaded.

Whats new?

Strobes replaced with static lighting for constant visibility.

Now added script for placing PAPI lights in addition to edgelights.

Possible to customize which parts of the runway you want to light up.

Limitations: Arma can only have so many lightsources in a particular area.

OFPEC DOWNLOAD
« Last Edit: 10 Aug 2009, 19:54:33 by hoz »

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: seven's Runway Lights
« Reply #1 on: 05 Oct 2007, 16:49:40 »
hey Seven,

Looks interesting,

1) Can you put all the files into the same folder?  The readme and function are separate from the mission and init.sqs and i had to put them together.

2) Are you using a new top notch PC?  Mine is sadly 4 years old, and the game froze about 5 seconds into the mission as i approached the landing lights. I'm wondering if these functions eat up a lot of horsepower?

3) but its a cool idea thanks (could be just old PC's like mine that have issues)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: seven's Runway Lights
« Reply #2 on: 05 Oct 2007, 17:43:03 »
You could vastly shorten the script file (to about 5% of current length) and improve maintainability by doing this (I didn't use the correct IDs in this example, or actually run a test):
Code: (runwayLights.sqf) [Select]
// Get the input parameters here...

// List of IDs for all the lights.
_lightIDs = [
    [471455, 471633],
    [471451, 471628],
    [471499, 471695],
    // Rest of values here...
];

while {true} do
{
    {
        _ids = _x; // Pair of object ids.

        _lights = []; // List of light objects created.

        // Create the light objects.
        {
            _lightpos = _lightmark nearestObject _x;
            _light = "#lightpoint" createVehiclelocal _lightmark;
            _light setLightBrightness _brightness;
            _light setLightAmbient[_ar,_ag,_ab];
            _light setLightColor[_r,_g,_b];
            _light lightAttachObject [_lightpos, [_x,_y,_z]];
            _lights = _lights + [_light];
       } forEach _ids;

        sleep _timer;

        // Delete the light objects.
        {
            deletevehicle _x;
        } forEach _lights;
    } foreach _lightIDs;
};

To reduce lag, allow the mission-maker to configure the maximum range that the lights can be seen from. Check the range from player to airstrip every loop and if the player is outside that range, then just sleep for a few seconds instead. This won't help LeeHunt, but I'm not sure why he should be having problems (the script really doesn't do much at all so shouldn't slow anyone up noticeably ).

Hmm, in a part of the script that is never reached, it runs the script "runwaylightsx.sqf" (not included in the download). Not sure why that is done, but I assume it isn't supposed to still be there.
« Last Edit: 05 Oct 2007, 18:04:55 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: seven's Runway Lights
« Reply #3 on: 05 Oct 2007, 18:04:31 »
Why to create and then delete and then create ....
why not just create the lights, and then simply play with setLightBrightness?

BTW, for MP the script must be run on every client.

Offline Pergite

  • Members
  • *
Re: seven's Runway Lights
« Reply #4 on: 05 Oct 2007, 23:30:21 »
This would be a nice addon for a airfield raid I am working on.

BTW, for MP the script must be run on every client.

If anyone could tell me exactly how I should execute the script on all clients, I would be really greatfull. (What commmand, when and where?)
I have been trying to read up on the subject but havent gotten it to work yet...  :dunno:

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: seven's Runway Lights
« Reply #5 on: 05 Oct 2007, 23:58:41 »
just run it in the init.sqs or init.sqf file. If you want to make sure there is a player there, then wait first for the condition alive player or local player.

Offline [seven]

  • Members
  • *
Re: seven's Runway Lights (updated to version 1.1)
« Reply #6 on: 07 Oct 2007, 03:55:54 »
Script updated to version 1.1

What is new?

No longer creates then deletes lights, now simply changes brightness to create the same effect as per mandoble's suggestion.

Now includes a minimum distance check to as per spooner's suggestion.

Includes detailed readme exlplaining all arguments and how performance can be tweaked.

Includes two examples showing different performance.


@ LeeHunt
 I'm using an agp vid card and an old 2.8 GHz P4, same age as yours, so most people should be fine I think.

@ Mandoble and Spooner
Thanks for the excellent suggestions.  :good:
« Last Edit: 07 Oct 2007, 04:38:08 by [seven] »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: seven's Runway Lights (updated to version 1.1)
« Reply #7 on: 07 Oct 2007, 11:46:33 »
The end result is quite good  :good: But the script is extremely limited as it will work only with a single airfield of a single island: Sara.

Here is what I propose you to do:
1 - Check OFPEC ILS (ofpec_AirportEvents.sqf) to see how to get all the available airfields in an Island reading the config.
2 - For each airfield, get "ilsPosition" and "ilsDirection" class members. islDirection is in format [x,angle,y] so you only need to use x and y to know the runway angle: _rang = (ilsdirection select 0) atan2 (ilsdirection select 2);
3 - Now you have the starting position of the runway and the direction. So it is time to create the lights (use a light array  per airfield instead of individual variables per each light. lights[airfield number, light number] = createVehicle [x,y,0].
4 - To calculate the x and y use the ilsposition as origin reference and an increasing radius which will point each time to the center of the runway side-to-side. From this point you need to place a light to the left and a light to the right (_ang + 90) using a general value as half of runway width, and then increase the radius the desired delta and proceed with the next pair of lights.
5 - Repeat 3 and 4 for each airfield.
6 - when all your lights are correctly placed, check how close is the player vehicle to each airfield and activate the light animation for the closer one.

This way you will have a universal airfield lights script for any airfield and any island.

EDIT:
I would go even further to have only a single pair of lights per airfield, One at each side of the runway. As the player aproaches, the pair lights are moved forward (seposed) till certain distance, back to origin and move forward again (following the angle of the runway). To create that animation you really dont need more than a pair of lights. The practical effec for the pilots would be the same and the hit in performance would be minimal.

EDIT2:
Additionaly, this is what I get in arma.RPT file when running these example missions:

"Performance warning: Search for 51f2f718# 471613: runway_edgelight.p3d was very large (520 m)
Performance warning: Search for 51f2f398# 471614: runway_edgelight.p3d was very large (520 m)
"

Many messages like the above ones.
« Last Edit: 07 Oct 2007, 13:57:27 by Mandoble »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: seven's Runway Lights (updated to version 1.1)
« Reply #8 on: 07 Oct 2007, 14:02:14 »
Good to see that you've improved the script.

Just to cause trouble again, I realised that if you have multiple instances of the script running, to have multiple pairs of light illuminated at the same time, then they will eventually go out of synchronisation since using sleep commands in multiple scripts isn't precise. It would certainly be possible to have multiple pairs of lights in a single script, but you need to worry first about either getting the light IDs/objects into an array (as in my earlier example) or implementing Mandoble's last suggestion for a generic script. If you need any help with using arrays and iteration through them, then just shout.

@Mandoble
Although this effect would look great for pilots, anyone on the ground wouldn't see the lights appearing or disappearing where the actual runway lights are. Would it not be possible to use a generic script such as you suggest to find the positions of the map-placed runway light objects for visual consistency?
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: seven's Runway Lights (updated to version 1.1)
« Reply #9 on: 07 Oct 2007, 14:09:45 »
Nope, because most airfields in an Island do not have any map-placed runway light objects.

Offline [seven]

  • Members
  • *
Re: seven's Runway Lights (updated to version 1.1)
« Reply #10 on: 08 Oct 2007, 13:05:24 »
The dynamic airport lights thing sounds cool, but the aesthetics would be ruined without actual light fixtures to have the lights appear from.  So we'd have to add the option to add light fixtures fixtures and so we don't unnecessarily create fixtures for more airports than we have to the mission maker would need to insert an argument with an array of the airport id's he wants to be lit up.

As for the the lighting system you described, where the lights move forward as the player approaches, a pilot needs to see as much of the runway ahead as possible.  If a pilot truly needs the lights to land and they are not just being used to look pretty then we must assume he has no night vision, so with that in mind how can a pilot who is on final approach make the decision to land, do a touch and go, perform a go around, or execute a missed approach when he has no visual representation of where the boundaries of the runway ahead are?  Suppose there is a burned out plane wreck or other vehicle sitting in the middle of the runway 400m in front where you are touching down, by the time you saw it you would be going to slow to pull up and too fast to stop.  With the lights going from end to end you can see any obstruction that might cause an accident well in advance.


Spooner, I'm having trouble adjusting your template to create the lights first then use the while loop to illuminate them.  What I'd like to do for the double lights is illuminate two rows at once and then move on to the next two.  So row 1 and 2 would be lit then sleep then row 3 and 4.  Using this two row method we can cut the time it takes for the lights to reach the end from nearly three seconds to just over one thereby helping the pilot by refreshing his visual reference at a faster pace (it also looks amazing like this, feels more like a real airport lighting system), or we can increase performance by upping the sleep time by two fold.  Similarly, we could use an odds and evens scheme for a single light configuration where the odds were lit up until the lights reached the end and then the lights start over using the even rows, again this would make for faster pace and better performance.

This is the array I've been using to play with your template:

Quote
_lightIDs = [
    [471613],
    [471614],
    [471397, 471572],
    [471399, 471573],
    [471404, 471579],
    [471405, 471581],
    [471408, 471585],
    [471411, 471590],
    [471412, 471592],
    [471413, 471595],
    [471416, 471599],
    [471423, 471605],
    [471427, 471608],
    [471434],
    [471437],
    [471438],
    [471439],
    [471443],
    [471447],
    [471450, 471620],
    [471451, 471628],
    [471455, 471633],
    [471456, 471634],
    [471461, 471638],
    [471463, 471644],
    [471467, 471647],
    [471471, 471651],
    [471473, 471654],
    [471477, 471661],
    [471487, 471664],
    [471490, 471665],
    [471495, 471666],
    [471499, 471667],
    [471500, 471668],
    [471503, 471670],
    [471504, 471675],
    [471505, 471676],
    [471506, 471678],
    [471511, 471686],
    [471515],
    [471517],
    [471518],
    [471521, 471700],
    [471522, 471701],
    [471527, 471706],
    [471528, 471710],
    [471532, 471715],
    [471534, 471717],
    [471539, 471722],
    [471540, 471725],
    [471541, 471726],
    [471546, 471729],
    [471553, 471732],
    [471557, 471733],
    [471561, 471734],
    [471568, 471736],
    [471570]
];
« Last Edit: 08 Oct 2007, 17:29:29 by [seven] »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: seven's Runway Lights (updated to version 1.1)
« Reply #11 on: 08 Oct 2007, 17:48:54 »
I think that there is both a place for a simple, but "perfect", solution for just one airstrip (as I think you want to do) and a complex, generic solution for any airport that Mandoble is suggesting. Maybe, once you have the simple version working, you can think about working out the slightly more complex script/mathematics required for the generic version.

I'm not sure how much you want guidance and how much you want me to fix the code. I'll try to explain it first in pseudo-code for you to implement if, before I write the code straight out and spoil the learning experience for you ;P

First problem you'll be having is that you didn't close the array properly at the end, which will cause an immediate error. May just have been a copy-and-paste error though:
Code: [Select]
_lightIDs = [
    [471613],
    [471614],
    ...others...
    [471568, 471736],
    [471570]
];

Next thing to do is to construct a new list, containing light objects in the same positions as the ids you already have, and iterate though them, lighting and darkening the rows as you go:
Code: [Select]
_lightObjects = [];

// For each row of light IDs
// - create an empty array, _row.
// - insert one or two light objects into _row, created at locations based on the ID numbers in the current row.
// - insert _row into _lightObjects (Use: _lightObjects = _lightObjects + [_row])

// You should then have an array like this (don't type this in, I am just intending to show you that the new object array is structured the same as the ID one):
// [
//     [light object],
//     [light object],
//     ...others...
//     [light object, light object],
//     [light object]
// ];

// Repeat this for ever, while you are close to the airstrip:
for "_i" from 0 to ((count _lightObjects) - 1) do
{
    // Turn OFF the lights in row _i and row (_i + 1).
    // Turn ON the lights in row (_i + 2) and row (_i + 3).
    // Sleep.
};

You should notice that this will work fine until you get to the end of the list of light object, when (_i + 3) is actually asking for a row beyond the end of the array. To fix this, you can use the mod command to wrap each of these numbers around when they get over the end of the array. Although this algorithm will light two rows at once and flip to the next two rows, I'd probably just decrease the sleep time and allow for "sliding" rows which uses about the same amount of CPU (2 rows change lighting at a time instead of 4 rows, but it happens twice as fast) for a slightly improved visual effect:
Code: [Select]
for "_i" from 0 to ((count _lightObjects) - 1) do
{
    // Turn OFF the lights in row _i
    // Turn ON the lights in row (_i + 2).
    // Sleep.
};

This algorithm has two rows always lit, except for the fraction of a second before the very first "slide" occurs (which noone will care about).

**EDIT**
Made a mistake, I suggested to use "_lightObjects = _lightObjects + _row" when I meant "_lightObjects = _lightObjects + [_row]" (corrected in pseudocode, above)
« Last Edit: 09 Oct 2007, 11:16:06 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline [seven]

  • Members
  • *
Re: seven's Runway Lights (updated to version 1.1)
« Reply #12 on: 09 Oct 2007, 22:23:07 »
Can't quite get it to work but so far I have something like this:
Quote
_lightObjects = [];

{
   _ids = _x;
   _row = [];
   {
      _lightpos = _lightmark nearestObject _x;
      _light = "#lightpoint" createVehiclelocal _lightmark;
      _light setLightBrightness 0;
      _light setLightAmbient[_ar,_ag,_ab];
      _light setLightColor[_r,_g,_b];
      _light lightAttachObject [_lightpos, [_x,_y,_z]];
      _row = _row + [_light];
   } forEach _ids;
   _lightObjects = _lightObjects + [_row];
} forEach _lightIDs;

while {(_unit distance _lightmark) < _mindist} do
{
   for "_i" from 0 to ((count _lightObjects) - 1) do
   {
      {
      _x setlightbrightness 0;
      } forEach (_lightObjects select _i);

      {
      _x setlightbrightness 0;
      } forEach (_lightObjects select (_i + 1));

      {
      _x setlightbrightness _brightness;
      } forEach (_lightObjects select (_i + 2));

      {
      _x setlightbrightness _brightness;
      } forEach (_lightObjects select (_i + 3));
      sleep _timer;
   };
};

Where am I going wrong?  :dunno:
Also I looked up the mod command in the Biki but I'm still confused as to how to use it so if you could include an example, that would help.  :D

[Edit]: Typos in the quote fixed.
« Last Edit: 09 Oct 2007, 23:43:18 by [seven] »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: seven's Runway Lights (updated to version 1.1)
« Reply #13 on: 09 Oct 2007, 23:03:12 »
Since the values in the IDs array are numbers, you won't get any joy from:
Code: [Select]
_lightpos = _lightmark nearestObject "_x";
which should be:
Code: [Select]
_lightpos = _lightmark nearestObject _x;

I was being a bit vague about mod, which was obviously too vague :whistle: The problem with the script as is, is that when _i + 3 is greater than the number of rows, then there will be an error. What we need to do is make the row number wrap around if it is too big.

Before the while loop:
Code: [Select]
_numRows = count _lightObjects;

For each of the rows that you are affecting, you need to mod the value:
Code: [Select]
      {
          _x setlightbrighness 0;
      } forEach (_lightObjects select ((_i + 1) mod _numRows));

You also need a while {true} wrapped around the while loop you already have, or you'll only light the lights once.

It can be easier to attach the demo mission to the post rather than copy-and-paste sections of the code. Prevents errors and makes other people's lives easier since they can run the mission rather than imagining how the code would run (I know I'm probably making mistakes because I'm just reading/writing this code in the forum, not in a mission).

**EDIT**
I'm also not entirely sure I am helping you a great deal by trying to get you to write the script in the way I would, but I am trying to get you to learn how to do it rather than just be given the "correct" version of the script. *shrugs*
« Last Edit: 09 Oct 2007, 23:13:04 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline [seven]

  • Members
  • *
Re: seven's Runway Lights (updated to version 1.1)
« Reply #14 on: 10 Oct 2007, 00:35:24 »
The way you've been nudging me along so far is just fine, I'm not assuming you want me to write it in any particular way. 

Anyhow, it seems like I'm almost where I want to be but it isn't quite right yet.  I get no errors but no lights either.  File attached.

[Edit] I figured out the problem!  :good:

The argument _x was conflicting with the index value _x in the forEach loop that creates the lights.  So I renamed the argument _x to _xpos and it works.  Now we can maybe add some interesting features.   :scratch:
Thanks a bunch Spooner, you've really gone out your way to help out!  ;)  The file is updated.

[Edit 2] It seems the extra math involved in using an array degrades performace considerably.  I've updated the archive once more, this time there is also a script inside called runwaylightsv1_1quad.sqf that is written in the rudimentary style I orignally was writing in.  It uses the same arguments and also lights up two rows at a time but it noticeably outperforms the array based script I just wrote.  Using the array, the lights look slow and jittery on my old pc, using the old method it's smooth as butter.  Is there any way to keep the script compact and still have decent performace?
« Last Edit: 10 Oct 2007, 17:43:29 by [seven] »