dragonsyr 21 Posted December 23, 2017 i have this script //init of the pad [h2,4,hlight1] execVM "Lightstime.sqf"; if (!isServer) exitWith {}; while {true} do { _var = _this select 2; if (daytime >= 17.5 || daytime < 6.5) then { if (isNil "_var") then { _var = []; _target_pos = getPos (_this select 0); _point = _this select 0; _light1 = "#lightpoint" createVehicle position _point; _light2 = "Land_runway_edgelight" createVehicle position _point; _light1 setLightBrightness 0.4; _light1 setLightAmbient[0.99, 0.99, 0.74]; _light1 setLightColor[0.0, 0.0, 0.0]; _light1 lightAttachObject [_point, [0,0,0]]; _var set [(count _var), "_light1,_light2"]; if(true) exitWith{}; }; } else{ if ( !(isNil "_var") ) then { { hint "light out"; deleteVehicle _x; }forEach _var; _var = nil; }; }; uiSleep 30; }; the code working for the spawn part (daytime from/to) edit: (when the time comes the lights is spawned.) but my problem is that i cant delete the lights . edit: (when the time pass , the lights is not deleted) i have made many tests with many code changes , but i have no luck yet. i think that the variable i want to set is not working . (hlight1 in this example) how can i check it? i want this script because i want to use it on many pads with unique variable on each one because i want to delete the lights on each pad on demand from another script (without the daytime command) thanks Share this post Link to post Share on other sites
gc8 977 Posted December 23, 2017 I think the problem is in this line: _var = _this select 2; since you are setting the _var there the light creation code wont trigger... also it wont delete the light in _var because it's not array... maybe you meant to set the _var only once before the while loop? also this line does nothing: if(true) exitWith{}; Share this post Link to post Share on other sites
dragonsyr 21 Posted December 24, 2017 with manual entry of the variable , the script is working Spoiler //[h2] execVM "test4.sqf"; if (!isServer) exitWith {}; hlight = nil; while {true} do { if (daytime >= 17.5 || daytime < 6.5) then {_helitarget = _this select 0; _target_pos = getPos (_helitarget); _lightType = "Chemlight_green"; if (isNil "hlight") then { hlight = []; _light1 = "#lightpoint" createVehicle position _helitarget; _light1 setLightBrightness 0.4; _light1 setLightAmbient[0.99, 0.99, 0.74]; _light1 setLightColor[0.0, 0.0, 0.0]; _light1 lightAttachObject [_helitarget, [0,0,0]]; _circles = [ [6.3, 4, "Land_runway_edgelight_blue_F"], [0, 1, "Land_runway_edgelight"] ]; { _rad = _x select 0; _bcount = _x select 1; _lightClass = _x select 2; _inc = 360/_bcount; for "_ang" from 1 to 360 step _inc do { _a = (_target_pos select 0)+(sin(_ang)*_rad); _b = (_target_pos select 1)+(cos(_ang)*_rad); _pos = [_a,_b,_target_pos select 2]; _light = _lightClass createVehicle _pos; _light setPos _pos; hlight set [(count hlight), "_light, _light1"]; }; }forEach _circles; _centerLight = _lightType createVehicle [getPos _helitarget select 0, getPos _helitarget select 1,1]; hlight set [(count hlight), _centerLight]; };}else {if ( !(isNil "hlight") ) then { { deleteVehicle _x; }forEach hlight; hlight = nil; }; }; uiSleep 30; }; but when i replace the name to _var , then i get error Spoiler //[h2,hlight] execVM "test5.sqf"; // init of the pad if (!isServer) exitWith {}; _var = _this select 1; _var = nil; while {true} do { if (daytime >= 17.5 || daytime < 6.5) then {_var = _this select 1; _helitarget = _this select 0; _target_pos = getPos (_helitarget); _lightType = "Chemlight_green"; if (isNil "_var") then { _var = []; _light1 = "#lightpoint" createVehicle position _helitarget; _light1 setLightBrightness 0.4; _light1 setLightAmbient[0.99, 0.99, 0.74]; _light1 setLightColor[0.0, 0.0, 0.0]; _light1 lightAttachObject [_helitarget, [0,0,0]]; _circles = [ [6.3, 4, "Land_runway_edgelight_blue_F"], [0, 1, "Land_runway_edgelight"] ]; { _rad = _x select 0; _bcount = _x select 1; _lightClass = _x select 2; _inc = 360/_bcount; for "_ang" from 1 to 360 step _inc do { _a = (_target_pos select 0)+(sin(_ang)*_rad); _b = (_target_pos select 1)+(cos(_ang)*_rad); _pos = [_a,_b,_target_pos select 2]; _light = _lightClass createVehicle _pos; _light setPos _pos; _var set [(count _var), "_light, _light1"]; }; }forEach _circles; _centerLight = _lightType createVehicle [getPos _helitarget select 0, getPos _helitarget select 1,1]; _var set [(count _var), _centerLight]; }; uiSleep 30;}else {if ( !(isNil "_var") ) then { _var = _this select 1; { deleteVehicle _x; }forEach _var; _var = nil; uiSleep 30; };};}; Error position: <_var; Error Undefined variable in expression: _var line 45 what can i do to get this working Share this post Link to post Share on other sites
dragonsyr 21 Posted December 24, 2017 Update: Yesterday the 1st script worked. Today not. What is going on with this... i dont understand . why when i insert the code in a while loop is not working? Share this post Link to post Share on other sites
gc8 977 Posted December 24, 2017 Can you be precise on what you'r trying to accomplish? that way it's easier to help you. Share this post Link to post Share on other sites
dragonsyr 21 Posted December 24, 2017 1st , i need the lights that is spawned in this script to more than one helipad in specific range of time and when the time comes light spawn and when the time pass i want the lights to be deleted. 2nd i need also the same script edited (without the time loop) on more than one pad , with the ability to delete the lights on each pad on demand. thats why i need unique mission namespace value for each pad Share this post Link to post Share on other sites
gc8 977 Posted December 24, 2017 Do you place any light objects in the editor or are all created via script? what is h2 & hlight1 ? Share this post Link to post Share on other sites
dragonsyr 21 Posted December 24, 2017 all created from this script . h2 is the name of the pad and the hlight1 is the namespace i want to be selected for the namespace (ignore the hlight1 ,is for my testings for _var = _this select 1; ) edit: if you see the first commented line of each script , is the init of the pad edit2 : the script that worked yesterday is the 1st script in the 1st spoiler on post #3....not the #1st post edit3: this is the original script (working) Share this post Link to post Share on other sites
gc8 977 Posted December 24, 2017 (edited) Here I wrote the script for you that adds/removes the lights for each helipad placed in the editor: helipads = [h1,h2]; // helipads placed in the editor #define LIGHTS_DISTANCE_MUL 0.75 while { true } do { { _helipad = _x; _lights = _helipad getVariable ["lights", []]; // Store lights here for each helipad _lamps = _helipad getVariable ["lamps", []]; // lamps are stored in here _isNight = (daytime >= 17.5 || daytime < 6.5); if(count _lights == 0) then // No lights yet placed? { //player sideChat "Creating lights"; // Get corners of the helipad for the lights to be placed _bbr = boundingBoxReal _helipad; _p1 = _bbr select 0; _p2 = _bbr select 1; _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); _maxLength = abs ((_p2 select 1) - (_p1 select 1)); _lampsCreated = false; if(count _lamps > 0) then { _lampsCreated = true; }; // Loop all four corners { _loffset = _x; // Count light position at the corners of the helipad _lightPos = (getpos _helipad) vectorAdd [(_loffset select 0) * (_maxWidth / 2) * LIGHTS_DISTANCE_MUL, (_loffset select 1) * (_maxLength / 2) * LIGHTS_DISTANCE_MUL, 0 ]; if (_isNight) then { _light1 = "#lightpoint" createVehicle _lightPos; _light1 setLightBrightness 0.4; _light1 setLightAmbient[0.99, 0.99, 0.74]; _light1 setLightColor[0.0, 0.0, 0.0]; // Save the lights in array so that they can be deleted when day _lights pushBack _light1; }; // save the lamps in array so that they are created only once if(!_lampsCreated) then { _lamp = "Land_runway_edgelight" createVehicle _lightPos; _lamps pushBack _lamp; }; } forEach [[-1,-1],[1,-1],[1,1],[-1,1]]; // offset for lights to be placed at (corners of the helipad) _helipad setVariable ["lights", _lights]; if(!_lampsCreated) then // lamps are set only once in here { _helipad setVariable ["lamps", _lamps]; }; } else { if(!_isNight) then { //player sideChat "Deleting lights"; // Delete all helipad lights { _l = _x; deleteVehicle _l; } forEach _lights; _helipad setVariable ["lights", []]; // reset the variable to empty array }; }; } forEach helipads; sleep 5; }; I hope that is what you are looking for. You can use the skipTime command in the debug console to see that the light's are turning on/off. But note there's 5 second delay for the code to fire. (I made it so that lamps are created at start of the mission but the lights are created at night) Have fun :) Edited December 24, 2017 by gc8 updated code Share this post Link to post Share on other sites
dragonsyr 21 Posted December 24, 2017 thank you. i ll try that Share this post Link to post Share on other sites
dragonsyr 21 Posted December 24, 2017 as i see the lights created (too far from helipad ....how can i move the lights closer ? ) then when time pass i see the deleting lights hint and then i see creating lights hint and loop forever . the lights is still there. and how can i delete only the h1 or h2 pad lights? (when i remove the while time) Share this post Link to post Share on other sites
gc8 977 Posted December 24, 2017 8 minutes ago, dragonsyr said: as i see the lights created (too far from helipad ....how can i move the lights closer ? I updated the code with LIGHTS_DISTANCE_MUL define. tweak that for desired distance between the lights and the helipad. 8 minutes ago, dragonsyr said: then when time pass i see the deleting lights hint and then i see creating lights hint and loop forever . the lights is still there. Ignore the sidechat messages they are bit misleading, I just had them there to see that the code works. removed them now. 8 minutes ago, dragonsyr said: and how can i delete only the h1 or h2 pad lights? (when i remove the while time) so you want a way to remove the lights even at night? by what, a trigger? Share this post Link to post Share on other sites
dragonsyr 21 Posted December 24, 2017 yet , lights is not deleted , for the on demand delete , my thought was to make a copy of the working script without the time loop and then use of the delete part of the code on each pad. if i can delete the lights even at night with this script running , then would be nice. if you try my code in a square pad and in a circle pad you will see what i need for lighting. Spoiler //[h2] execVM "test.sqf"; _helitarget = _this select 0; _target_pos = getPos (_helitarget); _lightType = "Chemlight_green"; if (isNil "hlight") then { hlight = []; _light1 = "#lightpoint" createVehicle position _helitarget; _light1 setLightBrightness 0.4; _light1 setLightAmbient[0.99, 0.99, 0.74]; _light1 setLightColor[0.0, 0.0, 0.0]; _light1 lightAttachObject [_helitarget, [0,0,0]]; _circles = [ [6.3, 4, "Land_runway_edgelight_blue_F"], [0, 1, "Land_runway_edgelight"] ]; { _rad = _x select 0; _bcount = _x select 1; _lightClass = _x select 2; _inc = 360/_bcount; for "_ang" from 1 to 360 step _inc do { _a = (_target_pos select 0)+(sin(_ang)*_rad); _b = (_target_pos select 1)+(cos(_ang)*_rad); _pos = [_a,_b,_target_pos select 2]; _light = _lightClass createVehicle _pos; _light setPos _pos; hlight set [(count hlight), "_light, _light1"]; }; }forEach _circles; _centerLight = _lightType createVehicle [getPos _helitarget select 0, getPos _helitarget select 1,1]; hlight set [(count hlight), _centerLight]; }; /* //delete if ( !(isNil "hlight") ) then { { deleteVehicle _x; }forEach hlight; hlight = nil; };*/ put a circle heli pad and a square pad in editor name :h1 and h2 and in init [h2] execVM "test.sqf"; test it one at the time because of the namespace . for delete just run in debug console this if ( !(isNil "hlight") ) then { { deleteVehicle _x; }forEach hlight; hlight = nil; i need it like this because i can easy change , add or move the lights as i want , also i can add other objects as well, the problem is that when i put this code in a while loop i cant delete the lights. if you can fix this would be nice, now if you can make it for multi pads would be perfect, and if you can make the delete on demand even at night then would be awesome!!! all this if you have the time to do it . i dont want to bother anyone from his work for my testings .... thanks Share this post Link to post Share on other sites
gc8 977 Posted December 24, 2017 (edited) yet , lights is not deleted , you mean the lamps right? That's a feature , only the lights are deleted at day, not the lamps :) So you want a circle of lights? I could make my code do that... But here is my new code that allows the individual helipad lights to be turned on/off: helipads = [h1,h2]; // helipads placed in the editor #define LIGHTS_DISTANCE_MUL 0.75 toggleHelipadLights = { params ["_helipad","_lightsOn"]; _helipad setVariable ["lightsOn", _lightsOn]; }; while { true } do { { _helipad = _x; _lights = _helipad getVariable ["lights", []]; // Store lights here for each helipad _lamps = _helipad getVariable ["lamps", []]; // lamps are stored in here _lightsOn = _helipad getVariable ["lightsOn", true]; _isNight = (daytime >= 17.5 || daytime < 6.5); if(count _lights == 0) then // No lights yet placed? { //player sideChat "Creating lights"; // Get corners of the helipad for the lights to be placed _bbr = boundingBoxReal _helipad; _p1 = _bbr select 0; _p2 = _bbr select 1; _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); _maxLength = abs ((_p2 select 1) - (_p1 select 1)); _lampsCreated = false; if(count _lamps > 0) then { _lampsCreated = true; }; // Loop all four corners { _loffset = _x; // Count light position at the corners of the helipad _lightPos = (getpos _helipad) vectorAdd [(_loffset select 0) * (_maxWidth / 2) * LIGHTS_DISTANCE_MUL, (_loffset select 1) * (_maxLength / 2) * LIGHTS_DISTANCE_MUL, 0 ]; if (_isNight && _lightsOn) then { _light1 = "#lightpoint" createVehicle _lightPos; _light1 setLightBrightness 0.4; _light1 setLightAmbient[0.99, 0.99, 0.74]; _light1 setLightColor[0.0, 0.0, 0.0]; // Save the lights in array so that they can be deleted when day _lights pushBack _light1; }; // save the lamps in array so that they are created only once if(!_lampsCreated) then { _lamp = "Land_runway_edgelight" createVehicle _lightPos; _lamps pushBack _lamp; }; } forEach [[-1,-1],[1,-1],[1,1],[-1,1]]; // offset for lights to be placed at (corners of the helipad) _helipad setVariable ["lights", _lights]; if(!_lampsCreated) then // lamps are set only once in here { _helipad setVariable ["lamps", _lamps]; }; } else { if(!_isNight || !_lightsOn) then { //player sideChat "Deleting lights"; // Delete all helipad lights { _l = _x; deleteVehicle _l; } forEach _lights; _helipad setVariable ["lights", []]; // reset the variable to empty array }; }; } forEach helipads; sleep 5; }; just call: [h1,false] call toggleHelipadLights; to turn the light off at night. and to turn it back on use: [h1,true] call toggleHelipadLights; Edited December 24, 2017 by gc8 quote/answer Share this post Link to post Share on other sites