Jump to content
truerun

How do I use the transfer switch

Recommended Posts

Hey folks, so I need some help figuring out what I'm doing wrong here. I'm ultimately trying to make a switch that allows me to turn off and on lights, but specified lights, like light 1, 2, 3, and 4. more specifically I've been trying to use the transfer switch.

I've been using this script:

 

DistanceToReach = 300;
this addAction
[  
    "Turn Off",  
    {  
        params ["_target", "_caller", "_actionId", "_arguments"];  
  {  
  [_x, "OFF"] remoteExec ["switchLight",0,true];  
  } forEach (nearestObjects [_caller, [], DistanceToReach]);
  light1 switchLight "OFF";
  _target animateSource ["switchposition",1];  
  _target animateSource ["light",0];  
  _target setDamage 0;  
    },  
    [],  
    1.5,  
    true,  
    true,  
    "",  
    "alive _target",  
    3,  
    false,  
    "",  
    ""  
];
 
this addAction  
[  
    "Turn On",  
    {  
        params ["_target", "_caller", "_actionId", "_arguments"];  
  {  
  [_x, "ON"] remoteExec ["switchLight",0,true];  
  } forEach (nearestObjects [_caller, [], DistanceToReach]);
  Light1 switchlight "ON";
  _target animateSource ["switchposition",-1];  
  _target animateSource ["light",1];  
  _target setDamage 0;  
    },  
    [],  
    1.5,  
    true,  
    true,  
    "",  
    "!alive _target",  
    3,  
    false,  
    "",  
    ""  
];

 

What happens: when I plug in this script and test it out, it only turns off the light and I get no option to turn it on.
what I want: for the light to be able to turn on and off. In addition only turn "light1" on and off then add more lights to that.
please ask questions if you don't understand. Thanks.

Share this post


Link to post
Share on other sites

_target setDamage 0.95; // (or 1, not tested)

should work for the turn off addAction.

Share this post


Link to post
Share on other sites

In your "Turn on" addAction you have the condition "!alive _target", but in the turn off action code you setDamage 0. You should setDamage 1 and then I think the light should be "dead" and the action will show

Share this post


Link to post
Share on other sites

I see, but when I set it to 0 it destroys the light which is not what I want because it falls over. im using the double light stand

Share this post


Link to post
Share on other sites

For just "Light1":

 

this addAction
[
	"Turn Off",
	{
		params ["_target", "_caller", "_actionId", "_arguments"];
		light1 switchLight "OFF";
		_target animateSource ["switchposition",1];
		_target animateSource ["light",1];
	},
    [],
    1.5,
    true,
    true,
    "",
    "lightIsOn light1 == 'ON'",
    3,
    false,
    "",
    ""
];

this addAction
[
	"Turn On",
	{
		params ["_target", "_caller", "_actionId", "_arguments"];
		Light1 switchlight "ON";
		_target animateSource ["switchposition",-1];
		_target animateSource ["light",0];
	},
    [],
    1.5,
    true,
    true,
    "",
    "lightIsOn light1 == 'OFF'",
    3,
    false,
    "",
    ""
];

Pretty sure the lights on the box itself (red and green indicators) are accessed via "switchLight" and not "light," but I can only get the red one to turn on.

Share this post


Link to post
Share on other sites
19 hours ago, truerun said:

im using the double light stand

What lights? Portable lighs double (Land_PortableLight_double_F) or the rugged ones ie Land_PortableLight_02_double_black_F.

 

Spoiler

this setVariable[ "LightActionID",
	this addAction[ "Light Off", {
			params [ "_target", "_caller", "_id", "_args" ];
			
			_objectName = if ( vehicleVarName _target == "" ) then {
				_target call BIS_fnc_objectVar;
			};
			
			_info = if ( lightIsOn _target == "ON" ) then {
				[ "OFF", "Light On" ]
			}else{
				[ "ON", "Light Off" ]
			};
			
			_info params[ "_switch", "_text" ];
			[ _target, _switch ] remoteExec[ "switchLight", 0, format[ "%1_lightState", _objectName ] ];
			[ [ _target, _text ], { params[ "_target", "_text" ]; _target setUserActionText[ _target getVariable "LightActionID", _text ] } ] remoteExec[ "BIS_fnc_call", 0, format[ "%1_actionState", _objectName ] ];
		},
		[],
		1,
		true,
		false
	]
];

 

 

  • Like 1

Share this post


Link to post
Share on other sites

yeah the portable lights double (Land_PortableLight_double_F). So what im trying to achieve is to have the switch turn on the double portable lights and off simple on and off switch for them specifically

Share this post


Link to post
Share on other sites
2 hours ago, Larrow said:

What lights? Portable lighs double (Land_PortableLight_double_F) or the rugged ones ie Land_PortableLight_02_double_black_F.

 

  Reveal hidden contents


this setVariable[ "LightActionID",
	this addAction[ "Light Off", {
			params [ "_target", "_caller", "_id", "_args" ];
			
			_objectName = if ( vehicleVarName _target == "" ) then {
				_target call BIS_fnc_objectVar;
			};
			
			_info = if ( lightIsOn _target == "ON" ) then {
				[ "OFF", "Light On" ]
			}else{
				[ "ON", "Light Off" ]
			};
			
			_info params[ "_switch", "_text" ];
			[ _target, _switch ] remoteExec[ "switchLight", 0, format[ "%1_lightState", _objectName ] ];
			[ [ _target, _text ], { params[ "_target", "_text" ]; _target setUserActionText[ _target getVariable "LightActionID", _text ] } ] remoteExec[ "BIS_fnc_call", 0, format[ "%1_actionState", _objectName ] ];
		},
		[],
		1,
		true,
		false
	]
];

 

 

yeah the portable lights double (Land_PortableLight_double_F). So what im trying to achieve is to have the switch turn on the double portable lights and off simple on and off switch for them specifically, sorry im new to using this form and scripting in general lol.

Share this post


Link to post
Share on other sites

Something like this?

Example_Mission

 

Spoiler

/*****
******
	Original file: switchLights.sqf
	Written by Larrow
	Thursday, 28 April 2022
	Originally posted @: https://forums.bohemia.net/forums/topic/238442-how-do-i-use-the-transfer-switch/
******
	Description: MP compatible script used on a gamelogic that has a Land_TransferSwitch_01_F
	and any number of Land_PortableLight_double_F synchronised to it.
	Applies action to switch to operate the lights.
	Designed as is to be placed in the gameLogics init.
******

******
******/


_objs = synchronizedObjects this;
_switch = _objs select{ _x isKindOf "Land_TransferSwitch_01_F" } select 0;
_lights = _objs select{ _x isKindOf "Land_PortableLight_double_F" };

TAG_fnc_lightsState = {
	params[ "_lights", "_lightState" ];

	{
		_x switchLight _lightState;
	}forEach _lights;
};

_switch setVariable[ "LightActionID",
	_switch addAction[ "Light Off", {
			params [ "_target", "_caller", "_id", "_args" ];
			_args params[ "_lights" ];

			_info = if ( _target animationSourcePhase "SwitchPosition" == 0 ) then {
				[ "OFF", "Light On", 1, 0 ]
			}else{
				[ "ON", "Light Off", 0, 1 ]
			};

			_info params[ "_lightState", "_actionText", "_switchPosition", "_switchLight" ];
			_target animateSource[ "SwitchPosition", _switchPosition ];
			_target animateSource[ "SwitchLight", _switchLight ];
			[ [ _target, _actionText ], { params[ "_target", "_actionText" ]; _target setUserActionText[ _target getVariable "LightActionID", _actionText ] } ] remoteExec[ "BIS_fnc_call", 0, format[ "%1_actionState", _target call BIS_fnc_objectVar ] ];
			[ _lights, _lightState ] remoteExec[ "TAG_fnc_lightsState", 0, format[ "%1_lightState", _target call BIS_fnc_objectVar ] ];
		},
		[ _lights ],
		1,
		true,
		false
	]
];

 

 

  • Like 3

Share this post


Link to post
Share on other sites
4 hours ago, Larrow said:

Something like this?

Example_Mission

 

  Reveal hidden contents


/*****
******
	Original file: switchLights.sqf
	Written by Larrow
	Thursday, 28 April 2022
	Originally posted @: https://forums.bohemia.net/forums/topic/238442-how-do-i-use-the-transfer-switch/
******
	Description: MP compatible script used on a gamelogic that has a Land_TransferSwitch_01_F
	and any number of Land_PortableLight_double_F synchronised to it.
	Applies action to switch to operate the lights.
	Designed as is to be placed in the gameLogics init.
******

******
******/


_objs = synchronizedObjects this;
_switch = _objs select{ _x isKindOf "Land_TransferSwitch_01_F" } select 0;
_lights = _objs select{ _x isKindOf "Land_PortableLight_double_F" };

TAG_fnc_lightsState = {
	params[ "_lights", "_lightState" ];

	{
		_x switchLight _lightState;
	}forEach _lights;
};

_switch setVariable[ "LightActionID",
	_switch addAction[ "Light Off", {
			params [ "_target", "_caller", "_id", "_args" ];
			_args params[ "_lights" ];

			_info = if ( _target animationSourcePhase "SwitchPosition" == 0 ) then {
				[ "OFF", "Light On", 1, 0 ]
			}else{
				[ "ON", "Light Off", 0, 1 ]
			};

			_info params[ "_lightState", "_actionText", "_switchPosition", "_switchLight" ];
			_target animateSource[ "SwitchPosition", _switchPosition ];
			_target animateSource[ "SwitchLight", _switchLight ];
			[ [ _target, _actionText ], { params[ "_target", "_actionText" ]; _target setUserActionText[ _target getVariable "LightActionID", _actionText ] } ] remoteExec[ "BIS_fnc_call", 0, format[ "%1_actionState", _target call BIS_fnc_objectVar ] ];
			[ _lights, _lightState ] remoteExec[ "TAG_fnc_lightsState", 0, format[ "%1_lightState", _target call BIS_fnc_objectVar ] ];
		},
		[ _lights ],
		1,
		true,
		false
	]
];

 

 

This is great. It worked like I wanted it to, what do you mean by look at game logic, I dont know how to see the game logic.

Share this post


Link to post
Share on other sites

I think he means there is a module in the editor called gameLogic. The logic has an init field where code can be placed. Someone else should confirm.

Share this post


Link to post
Share on other sites
21 minutes ago, major-stiffy said:

I think he means there is a module in the editor called gameLogic. The logic has an init field where code can be placed. Someone else should confirm.

 

Yes, it is essentially an "empty" module. It's kind of a relic from the old days, but it still has its uses.

Share this post


Link to post
Share on other sites
16 hours ago, truerun said:

what do you mean by look at game logic, I dont know how to see the game logic.

This is a gameLogic...

switchLights_gamelogic.png?raw=1

... the white flag on a blue background. Double click on it to open it like any other entity and you will see it has an init area for code.

 

You can find them in the editor under Systems(F5) > Logic Entities > Objects.

Editor_gameLogics.png?raw=1

Some info

 

16 hours ago, Harzach said:

Yes, it is essentially an "empty" module. It's kind of a relic from the old days,

Meh relic is a little disingenuous, makes it sound like they are deprecated.

TBH I'd describe it differently saying, a module is a gameLogic that automatically runs predefined code. Modules inherit from Logic the configName for a gameLogic. pedantic but true 😄

  • Like 2
  • Haha 1

Share this post


Link to post
Share on other sites
3 hours ago, Larrow said:

Meh relic is a little disingenuous

 

How DARE you, sir!

 

I did qualify it with "kind of"...

  • Haha 2

Share this post


Link to post
Share on other sites
On 4/29/2022 at 7:36 AM, Larrow said:

This is a gameLogic...

switchLights_gamelogic.png?raw=1

... the white flag on a blue background. Double click on it to open it like any other entity and you will see it has an init area for code.

 

You can find them in the editor under Systems(F5) > Logic Entities > Objects.

Editor_gameLogics.png?raw=1

Some info

 

Meh relic is a little disingenuous, makes it sound like they are deprecated.

TBH I'd describe it differently saying, a module is a gameLogic that automatically runs predefined code. Modules inherit from Logic the configName for a gameLogic. pedantic but true 😄

Thanks for the help dude.

  • Like 2

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

×