Jump to content
Sign in to follow this  
vostov

Power outage

Recommended Posts

Is there a script/init line that will turn off all artificial lighting?

I want to simulate a power-outage after a satchel charge blows up a power plant..

Share this post


Link to post
Share on other sites

You can find the lights using this array

_objectArray = ["Lamps_Base_F", "PowerLines_base_F", "Land_PowerPoleWooden_F", "Land_LampHarbour_F", "Land_LampShabby_F", "Land_PowerPoleWooden_L_F", "Land_PowerPoleWooden_small_F", "Land_LampDecor_F", "Land_LampHalogen_F", "Land_LampSolar_F", "Land_LampStreet_small_F", "Land_LampStreet_F", "Land_LampAirport_F", "Land_PowerPoleWooden_L_F"];

You can turn off each light using:

_lightSource setDamage 0.95

Share this post


Link to post
Share on other sites

@Kushluk Are those the classnames for the lights in that array?

_objectArray = ["Lamps_Base_F", "PowerLines_base_F", "Land_PowerPoleWooden_F", "Land_LampHarbour_F", "Land_LampShabby_F", "Land_PowerPoleWooden_L_F", "Land_PowerPoleWooden_small_F", "Land_LampDecor_F", "Land_LampHalogen_F", "Land_LampSolar_F", "Land_LampStreet_small_F", "Land_LampStreet_F", "Land_LampAirport_F", "Land_PowerPoleWooden_L_F"];

_allLights = [];
{
_y = typeOf _x
_z = _x
{
	if (_x == configName(configFile >> "CfgVehicles" >> _y) then //maybe????? I couldn't find lamps in the config viewer.
	{
		//_allLights set [count _allLights, _z]; //derpy mistake. originally had set to _x instead of _y. double derpy mistake. created new variable so I could return the object.
		_allLights pushBack _z; //very very last edit
		exitWith{}; //end the loop early so you can't add object to array twice. not sure if any object can fall under 2 classnames.
		//if it's not possible then this is, and always was, for performance.
	};
}forEach _objectArray;
}forEach (allMisionObjects "");

This code is supposed to return all lights in the mission. Not sure if it will work. Also I found a few interesting things while searching for the answer to this (make sure you read notes too)

switchLight, setHit, and of course, you can always just setDamage if these commands don't work.

EDIT: edited with code that might actually work.

EDIT2: bunch of edits to the code, now it might really work.

EDIT3: added pushBack command instead of "array set []", again performance-related

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

_lightSource setDamage 0.95

Doesn't work because: ''Local variable in global space"

DreadedEntity, your code doesn't work either.

Any ideas? Thanks.

Share this post


Link to post
Share on other sites
[color="#FF8040"][color="#8B3E2F"][b]{[/b][/color]
[color="#000000"]_x[/color] [color="#191970"][b]setHit[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"light_1_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0.97[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#000000"]_x[/color] [color="#191970"][b]setHit[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"light_2_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0.97[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#000000"]_x[/color] [color="#191970"][b]setHit[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"light_3_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0.97[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#000000"]_x[/color] [color="#191970"][b]setHit[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"light_4_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0.97[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]forEach[/b][/color] [color="#191970"][b]nearestObjects[/b][/color] [color="#8B3E2F"][b][[/b][/color]thisTrigger[color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b][[/b][/color]
[color="#7A7A7A"]"Lamps_base_F"[/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"PowerLines_base_F"[/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"PowerLines_Small_base_F"[/color]
[color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]500[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Edited by Killzone_Kid

Share this post


Link to post
Share on other sites

KK's code works

The only problem is that the spotlights on the airfields actually have 4 lights so you should use something like this instead.

_objectArray = ["Lamps_Base_F", "PowerLines_base_F", "Land_PowerPoleWooden_F", "Land_LampHarbour_F", "Land_LampShabby_F", "Land_PowerPoleWooden_L_F", "Land_PowerPoleWooden_small_F", "Land_LampDecor_F", "Land_LampHalogen_F", "Land_LampSolar_F", "Land_LampStreet_small_F", "Land_LampStreet_F", "Land_LampAirport_F", "Land_PowerPoleWooden_L_F"];
{
_x setHit ["light_1_hitpoint", 0.97];
_x setHit ["light_2_hitpoint", 0.97];
_x setHit ["light_3_hitpoint", 0.97];
_x setHit ["light_4_hitpoint", 0.97];
} forEach nearestObjects [player, _objectArray, 500];

Also, there were a few errors in my code. And allMissionObjects didn't do what I thought it was going to do. allMissionObjects only returns objects that have been spawned in or placed during the editor, not default objects already in the map. Otherwise it would have worked with a little debugging, and it would have been spectacular.

Share this post


Link to post
Share on other sites

You don't need to iterate through all the classes, it is enough to search base classes. Land_LampSolar_F for example inherits from Lamps_Base_F, which is already incuded, etc. Thanks for pointing out 4th hitpoint.

Share this post


Link to post
Share on other sites

If Vostov is still having problems with KK's code, it might be because of trying to run the code from a trigger, in which case it should be "thisTrigger" instead of "this".

} forEach nearestObjects [thisTrigger, [ <- The part I mean.

Share this post


Link to post
Share on other sites
If Vostov is still having problems with KK's code, it might be because of trying to run the code from a trigger, in which case it should be "thisTrigger" instead of "this".

} forEach nearestObjects [thisTrigger, [ <- The part I mean.

You could be right, I thought he was trying unit init because of ''Local variable in global space", but you get same error with triggers too. Good spot.

Share this post


Link to post
Share on other sites

Hey sorry all. Thanks for your help thus far. Booting up Arma to try it out.

Magirot, I am going to run it from a trigger. (maybe that's why things haven't been working for me..

I suck at this scripting/syntax integrity/coding... (really, really, bad...)

---------- Post added at 09:07 PM ---------- Previous post was at 08:48 PM ----------

KK's code works

The only problem is that the spotlights on the airfields actually have 4 lights so you should use something like this instead.

_objectArray = ["Lamps_Base_F", "PowerLines_base_F", "Land_PowerPoleWooden_F", "Land_LampHarbour_F", "Land_LampShabby_F", "Land_PowerPoleWooden_L_F", "Land_PowerPoleWooden_small_F", "Land_LampDecor_F", "Land_LampHalogen_F", "Land_LampSolar_F", "Land_LampStreet_small_F", "Land_LampStreet_F", "Land_LampAirport_F", "Land_PowerPoleWooden_L_F"];
{
_x setHit ["light_1_hitpoint", 0.97];
_x setHit ["light_2_hitpoint", 0.97];
_x setHit ["light_3_hitpoint", 0.97];
_x setHit ["light_4_hitpoint", 0.97];
} forEach nearestObjects [player, _objectArray, 500];

Also, there were a few errors in my code. And allMissionObjects didn't do what I thought it was going to do. allMissionObjects only returns objects that have been spawned in or placed during the editor, not default objects already in the map. Otherwise it would have worked with a little debugging, and it would have been spectacular.

It just tells me:

"Local variable in global space"

So, no go.

Share this post


Link to post
Share on other sites

You need to put that code in an sqf file, lets call it powerOut.sqf, then call it in your trigger's onAct field as: nul = [] execVM "powerOut.sqf";

Share this post


Link to post
Share on other sites
You need to put that code in an sqf file, lets call it powerOut.sqf, then call it in your trigger's onAct field as: nul = [] execVM "powerOut.sqf";

I put this into the "On Act" field of a trigger designated ''Foxtrot'': nul = [] execVM "powerOut.sqf"

I also put:

_objectArray = ["Lamps_Base_F", "PowerLines_base_F", "Land_PowerPoleWooden_F", "Land_LampHarbour_F", "Land_LampShabby_F", "Land_PowerPoleWooden_L_F", "Land_PowerPoleWooden_small_F", "Land_LampDecor_F", "Land_LampHalogen_F", "Land_LampSolar_F", "Land_LampStreet_small_F", "Land_LampStreet_F", "Land_LampAirport_F", "Land_PowerPoleWooden_L_F"];

{

_x setHit ["light_1_hitpoint", 0.97];

_x setHit ["light_2_hitpoint", 0.97];

_x setHit ["light_3_hitpoint", 0.97];

_x setHit ["light_4_hitpoint", 0.97];

} forEach nearestObjects [thistrigger, _objectArray, 5000];

The bold sections are changes I made. (possibly causing the trigger not to work. I wanted the entire Stratis Island to be dark.) Also, the powerout.sqf is an ''.sqf'' file. Not a ''powerout.sqf.rtf'' ect. ect.

Any ideas?

Share this post


Link to post
Share on other sites

Any ideas?

Well, what is the problem exactly, you just said what you've done...

Share this post


Link to post
Share on other sites

Since you're using the trigger to run a script, you need to pass the variables to the script when you run it.

Take this:

null = [thisTrigger] execVM "powerOut.sqf"

And this:

_trigger = _this select 0;
_objectArray = ["Lamps_Base_F", "PowerLines_base_F", "Land_PowerPoleWooden_F", "Land_LampHarbour_F", "Land_LampShabby_F", "Land_PowerPoleWooden_L_F", "Land_PowerPoleWooden_small_F", "Land_LampDecor_F", "Land_LampHalogen_F", "Land_LampSolar_F", "Land_LampStreet_small_F", "Land_LampStreet_F", "Land_LampAirport_F", "Land_PowerPoleWooden_L_F"];
{ 
_x setHit ["light_1_hitpoint", 0.97]; 
_x setHit ["light_2_hitpoint", 0.97]; 
_x setHit ["light_3_hitpoint", 0.97]; 
_x setHit ["light_4_hitpoint", 0.97]; 
} forEach nearestObjects [getPos _trigger, _objectArray, 5000];

Come on JShock you knew the answer to that! :p

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Try it now, I had to do something similar in a different script I wrote. I had to look at that old script to see how I took the trigger position.

 forEach nearestObjects [_trigger, _objectArray, 5000];

        replace with

forEach nearestObjects [getPos _trigger, _objectArray, 5000];

It should work after this, I made a typo

Share this post


Link to post
Share on other sites
Come on JShock you knew the answer to that! :p

I have learned not to assume anything anymore....

Try just using a marker and name it powerOutMrk and place it somewhere near the center of the map:

_objectArray = ["Lamps_Base_F", "PowerLines_base_F", "Land_PowerPoleWooden_F", "Land_LampHarbour_F", "Land_LampShabby_F", "Land_PowerPoleWooden_L_F", "Land_PowerPoleWooden_small_F", "Land_LampDecor_F", "Land_LampHalogen_F", "Land_LampSolar_F", "Land_LampStreet_small_F", "Land_LampStreet_F", "Land_LampAirport_F", "Land_PowerPoleWooden_L_F"];
{ 
_x setHit ["light_1_hitpoint", 0.97]; 
_x setHit ["light_2_hitpoint", 0.97]; 
_x setHit ["light_3_hitpoint", 0.97]; 
_x setHit ["light_4_hitpoint", 0.97]; 
} forEach nearestObjects [(getMarkerPos "powerOutMrk"), _objectArray, 5000];  

Share this post


Link to post
Share on other sites

I must be missing something here. poweroutmrk is a sqf?

What am I doing here? Please do treat me like a noob. Because I am. All I do is make pretty lines with waypoints and insert delicious things into init lines like:

removeHeadgear this;

removeGoggles this;

removeallweapons this;

removeallassigneditems this;

removeallcontainers this;

this addUniform "U_B_CTRG_1";

this addheadgear "H_HelmetB_light";

this addvest "V_PlateCarrierH_CTRG";

this addmagazines ["30Rnd_65x39_caseless_mag", 11];

this addweapon "arifle_MX_black_F";

this addMagazines ["HandGrenade", 5];

this addmagazines ["11Rnd_45ACP_Mag", 2];

this addweapon "hgun_Pistol_heavy_01_F";

this addweapon "ItemCompass";

this addweapon "ItemMap";

this addweapon "ItemRadio";

this addweapon "ItemWatch";

this addItem "FirstAidKit";

this addPrimaryWeaponItem "optic_ACO";

this addPrimaryWeaponItem "acc_pointer_IR";

this addWeapon "NVGoggles";

this assignItem "NVGoggles";

this assignItem "Binocular";

So, I really don't know how to do anything complicated. I just think eliminating light sources makes sense in a wargame. (trust me... if a battle is going on near you... the lights are off...)

Share this post


Link to post
Share on other sites

powerOutMrk is the name of a marker you place in the editor (recommend the "empty" marker so it's invisible on the map) so when your in the marker menu on the right hand side you can see: "Name", "Text", and something else my brain is forgetting, but that doesn't matter. Now in the name field you will put powerOutMrk, click ok, and the drag that marker in the general vicinity of the middle of the map.

Now the code is in an sqf that is either called via a trigger's onAct field or through the init.sqf. Depending on if you want the effect to be situational (trigger) or there to start with(init.sqf), which dictates on where you are putting the call line to the powerOut.sqf which would be:

nul=[] execVM "powerOut.sqf";

So hopefully if all goes well with the script itself the radius around the marker (5000m) will "destroy" all the lamps/lights across the map.

Share this post


Link to post
Share on other sites

It might've been easier to use KK's code now that it has thisTrigger. I understood from post #9 that the long class array isn't needed, and since it doesn't require a separate script, it would've probably been easier to handle for someone not experienced with execVM.

To explain to some extent, what a "local variable" in "Local variable in global space" is referring to is the identifier with _ in front of it, in this case _objectArray. Variables with _ in front of them (local variables) can only be used in a script, since unlike variables defined in a global space (which includes everything defined in the editor), they aren't broadcast outside of the script, thus saving resources but preventing their use in triggers, which require that the data is available during a longer time period.

You could use this code too without a separate script, either by just removing the _'s from the fronts of the two _objectArray's, or by moving the contents of _objectArray's defination to the part where it's later referred to.

But as said, if the longer array of classnames isn't needed, you could just use what KK provided, and throw it into a trigger's onActivation:

[color="#FF8040"][color="#8B3E2F"][b]{[/b][/color]
[color="#000000"]_x[/color] [color="#191970"][b]setHit[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"light_1_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0.97[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#000000"]_x[/color] [color="#191970"][b]setHit[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"light_2_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0.97[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#000000"]_x[/color] [color="#191970"][b]setHit[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"light_3_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0.97[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#000000"]_x[/color] [color="#191970"][b]setHit[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"light_4_hitpoint"[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0.97[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color] [color="#191970"][b]forEach[/b][/color] [color="#191970"][b]nearestObjects[/b][/color] [color="#8B3E2F"][b][[/b][/color]thisTrigger[color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b][[/b][/color]
[color="#7A7A7A"]"Lamps_base_F"[/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"PowerLines_base_F"[/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"PowerLines_Small_base_F"[/color]
[color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]5000[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Then again, if you are using a script, AND using it in multiplayer, it would be a good idea to add

if (!isServer) exitWith {};

to the script's first line to prevent resources from being wasted needlessly.

Share this post


Link to post
Share on other sites

Guys, this thread got real complicated, real fast..

Remember .. K.I.S.S.

THE FOLLOWING METHOD DOES NOT REQUIRE A SCRIPT. (But can call one if required)

In the Editor place a trigger

Name:Transformer1

Axis A=0

Axis B=0

ANGLE=0

Activation = Once

Not Present.

Now in the CONDITION put this.

damage (nearestObject [getposATL thisTrigger,"Land_dp_transformer_F"]) >= 1;

And in the On ACT field put this

titletext[format["Small Transformer Destroyed."],"PLAIN"];blowlights = ["Lamps_base_F","PowerLines_base_F","PowerLines_Small_base_F"];{_x setHit ["light_1_hitpoint", 0.97];_x setHit ["light_2_hitpoint", 0.97];_x setHit ["light_3_hitpoint", 0.97];_x setHit ["light_4_hitpoint", 0.97];} forEach nearestObjects [thisTrigger, blowlights, 500];

See example.

Trigger.jpg

Now position the trigger exactly on top of the "Land_dp_transformer_F" in the editor and go in game and blow it up.

Note in my example above I am using "Land_dp_transformer_F":

Land_dp_transformer_F.jpg

If you really must use a script, then replace the above ON ACT: field with this, (but use the same CONDITION)

nul=[thistrigger] execVM "powerOut.sqf";

and use KK'd powerout.sqf

if (!hasInterface) exitWith {};
{
_x setHit ["light_1_hitpoint", 0.97];
_x setHit ["light_2_hitpoint", 0.97];
_x setHit ["light_3_hitpoint", 0.97];
_x setHit ["light_4_hitpoint", 0.97];
} forEach nearestObjects [_this, [
"Lamps_base_F",
"PowerLines_base_F",
"PowerLines_Small_base_F"
], 5000];

Simples!!

Edited by Beerkan
Updated with Killzone_Kid's " if (!hasInterface) exitWith {};" suggestion

Share this post


Link to post
Share on other sites
If you really must use a script, then replace the above ON ACT: field with this, (but use the same CONDITION)

nul=[] execVM "powerOut.sqf";

and use KK'd powerout.sqf

if (!isServer) exitWith {};
{
_x setHit ["light_1_hitpoint", 0.97];
_x setHit ["light_2_hitpoint", 0.97];
_x setHit ["light_3_hitpoint", 0.97];
_x setHit ["light_4_hitpoint", 0.97];
} forEach nearestObjects [thisTrigger, [
"Lamps_base_F",
"PowerLines_base_F",
"PowerLines_Small_base_F"
], 5000];

Simples!!

This is really biting at the sidelines, but thisTrigger obviously doesn't work inside the script. :)

nul = [b]thisTrigger[/b] execVM "powerOut.sqf";

if (!isServer) exitWith {};
{
_x setHit ["light_1_hitpoint", 0.97];
_x setHit ["light_2_hitpoint", 0.97];
_x setHit ["light_3_hitpoint", 0.97];
_x setHit ["light_4_hitpoint", 0.97];
} forEach nearestObjects [[b]_this[/b], [
"Lamps_base_F",
"PowerLines_base_F",
"PowerLines_Small_base_F"
], 5000];

I do agree that the trigger not requiring a script that you iterate first is the best way.

Share this post


Link to post
Share on other sites

You're right. I was concentrating on the trigger method that in my haste I cut and pasted the wrong powerOut.sqf. (Previous post now fixed.)

Edited by Beerkan
Fixed

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  

×