Sarge46 10 Posted June 11, 2012 (edited) Edit I have rewritten the part that turns on and off the siren. Sirens and lights turn on but do not turn off unless I get out of the car and wait for siren to finish. Then I can hop back in. I'm trying to use a script from all the Life missions to give police cars sirens outside of the Life missions. The script will say "Siren On" in the titletext, but no siren or lights will run. It will never say "Siren Off". I went into a life mission and placed a vehicle through the editor and the same problem occurred, but purchasing a vehicle it works perfectly. I then named the vehicle "vehicle_Cop1_78", keeping with the naming convention of car name variables. That did not work and the .rpt reporting any errors either. siren.sqf // [0,0,0,["activate"]] execVM "siren\siren.sqf"; _this = _this select 3; _art = _this select 0; _vcl = vehicle player; _playtime = 120; _lichtstaerke = 1; _shortDur = 0.71; _longDur = 4.86; if (_art == "activate") then { if (!(_vcl getVariable ["sirenon", false])) then { _vcl setVariable ["sirenon", true, true]; _siren = [0,0,0,["siren"]] execVM "siren\siren.sqf"; } else { _vcl setVariable ["sirenon", false, true]; terminate _siren; }; _sirenon = _vcl getVariable ["sirenon", false]; hint format ["%1", _sirenon]; }; if (_art == "siren") then { _driver = driver _vcl; _sirenon = _vcl getVariable ["sirenon", false]; _light1 = "#lightpoint" createVehicleLocal (getpos _vcl); _light1 setLightBrightness _lichtstaerke; _light1 setLightAmbient [0, 0, 0.3]; _light1 setLightColor [0, 0, 0.5]; _light2 = "#lightpoint" createVehicleLocal (getpos _vcl); _light2 setLightBrightness _lichtstaerke; _light2 setLightAmbient [0.3, 0, 0]; _light2 setLightColor [0.5, 0, 0]; _lightscript = [0,1,2,["light", _vcl, [_light1, _light2]]] execVM "siren\siren.sqf"; while {(_driver == driver _vcl) and (alive _vcl) and _sirenon} do { if (player distance _vcl < 500) then { if (speed _vcl == 0) then { sleep 1; } else { if (speed _vcl > 60) then { _vcl say ["Siren_Long", 1]; sleep _longDur; } else { _vcl say ["Siren_Short", 1]; sleep _shortDur; }; }; } else { sleep 5; }; if (!_sirenon) exitWith {}; }; terminate _lightscript; deleteVehicle _light1; deleteVehicle _light2; _vcl setvariable ["sirenon", false, true]; }; if (_art == "light") then { _vcl = _this select 1; _light1 = ((_this select 2) select 0); _light2 = ((_this select 2) select 1); while {true} do { if (player in _vcl) then { _light1 setLightBrightness (_lichtstaerke / 2); _light2 setLightBrightness (_lichtstaerke / 2); } else { _light1 setLightBrightness _lichtstaerke; _light2 setLightBrightness _lichtstaerke; }; _light1 lightAttachObject [_vcl, [0,0,0]]; sleep 0.15; LightDetachObject _light1; _light1 setpos [0,0,0]; sleep 0.075; _light2 lightAttachObject [_vcl, [0,0,0]]; sleep 0.15; LightDetachObject _light2; _light2 setpos [0,0,0]; sleep 0.075; _light1 lightAttachObject [_vcl, [0,0,0]]; sleep 0.15; LightDetachObject _light1; _light1 setpos [0,0,0]; sleep 0.5; _light2 lightAttachObject [_vcl, [0,0,0]]; sleep 0.15; LightDetachObject _light2; _light2 setpos [0,0,0]; sleep 0.5; }; }; Edited June 12, 2012 by Sarge46 Updated Script Share this post Link to post Share on other sites
=Odin= 0 Posted June 12, 2012 Heya Sarge, I may be a bit rusty at scripting, but in your 1st line of the siren.sqf _this = _this select 3; you are using one of the Magic Variables ==>http://community.bistudio.com/wiki/Magic_Variables, Maybe change that and all corrisponding references to a new name e.g. _sarge = _this select 3;[//CODE]Also a [color=#0000FF]select 3 [/color]should follow [color=#0000FF]select 0;[/color] it may not be law but I think it helps.Like I say I am a bit rusty but try that and see if it helps.Odin Share this post Link to post Share on other sites
Sarge46 10 Posted June 12, 2012 Thanks for taking a look. _this = _this select 3; _art = _this select 0; Those "_this"s are to look at the "activate" in the array. I rewrote the activation part to somewhat work but it wont turn off now. Share this post Link to post Share on other sites
cuel 25 Posted June 12, 2012 Unless I'm blind and this is the only way to turn them off except the timer; if (_art == "activate") then { if (!(_vcl getVariable ["sirenon", false])) then { _vcl setVariable ["sirenon", true, true]; _siren = [0,0,0,["siren"]] execVM "siren\siren.sqf"; } else { _vcl setVariable ["sirenon", false, true]; terminate _siren; }; _sirenon = _vcl getVariable ["sirenon", false]; }; Correct me if I'm wrong but "_siren" is nil for the else-clause I also don't see how a terminate command would remove the lights, tho I've never actually used that command. Wouldn't it be possible to assign a global variable for the vehicle lights, based on vehicle var name and then use that to name the lights so they can be deleted later I also do not see a reason why this script works recursively, to me it's just a mess. Share this post Link to post Share on other sites
Sarge46 10 Posted June 12, 2012 What I don't understand is why this While-Do loop doesn't stop when _sirenon is false. Line 26: _sirenon = _vcl getVariable ["sirenon", false]; Line 41: while {(_driver == driver _vcl) and (alive _vcl) and _sirenon} do { if (player distance _vcl < 500) then { if (speed _vcl == 0) then { sleep 1; } else { if (speed _vcl > 60) then { _vcl say ["Siren_Long", 1]; sleep _longDur; } else { _vcl say ["Siren_Short", 1]; sleep _shortDur; }; }; } else { sleep 5; }; if (!_sirenon) exitWith {}; }; Share this post Link to post Share on other sites
f2k sel 164 Posted June 12, 2012 (edited) It may be because _sirenon hasn't been declared outside the initial If statement. You can do that by placing the following in the script private ["_sirenon"]; You could also just set it to true or false where you've set up the other variables. _sirenon=true; example 1 If (alive player) then { _test=1; }; hint format ["%1",_test]; will return any example 2 private ["_test"]; If (alive player) then { _test=1; }; hint format ["%1",_test]; will return 1 Check to see if all variables are set up correctly. Edited June 12, 2012 by F2k Sel Share this post Link to post Share on other sites
Sarge46 10 Posted June 13, 2012 Thanks everyone but I simply put _sirenon = _vcl getVariable ["sirenon", false]; inside the while-do and the sirens turn off. Share this post Link to post Share on other sites
twirly 11 Posted June 13, 2012 (edited) Yeah... but that's not how you use getvariable..... so that's not why it's working! EDIT: Hmmmm.... I see they also show the use of the command like this.... object getVariable [name, defaultValue]. Maybe I'm wrong!! Edited June 13, 2012 by twirly Share this post Link to post Share on other sites
Sarge46 10 Posted June 13, 2012 The power of typing it one way, then copy paste. Share this post Link to post Share on other sites
cuel 25 Posted June 13, 2012 Yeah... but that's not how you use getvariable..... so that's not why it's working!EDIT: Hmmmm.... I see they also show the use of the command like this.... object getVariable [name, defaultValue]. Maybe I'm wrong!! Yeah you can define getVariable as an array with false/true at the end to return that value if the variable doesn't exist. Very useful. Share this post Link to post Share on other sites
twirly 11 Posted June 13, 2012 Yeah you can define getVariable as an array with false/true at the end to return that value if the variable doesn't exist. Very useful. Yep...it will be for sure. Just never knew it worked like that!! Share this post Link to post Share on other sites
ben_sherman 1 Posted November 27, 2012 Please tell me that some one got this to work. I have the original one but I don't get it to work at all. And this one is so great works perfectly besides that you can't turn the sirens off... Share this post Link to post Share on other sites