Jump to content
Sign in to follow this  
warlord554

Accessory On/Off using script and addaction

Recommended Posts

How would I be able to turn on/off my custom made IR laser using scripts and addaction instead of just "L"?

Share this post


Link to post
Share on other sites
Player addAction ["Laser On",{
_target=(_this select 0);
_caller=(_this select 1);
_id=(_this select 2);

_caller enableIRLasers true

},[],2,false,true,"",""];

Player addAction ["Laser Off",{
_target=(_this select 0);
_caller=(_this select 1);
_id=(_this select 2);

_caller enableIRLasers false;

},[],2,false,true,"",""];

Share this post


Link to post
Share on other sites

You guys rock, thanx for the info :). Is there a way to make the actions only available once accessory is attached? I've researched and tried some things but no joy yet :confused:

I'm also trying to include a script set inside my weapon mod, and I have a init.sqf(in main mod folder) with

[] execVM "myscript.sqf";

But still not getting the addactions

Edited by WarLord554

Share this post


Link to post
Share on other sites

That may be so, but the actionmenu is a real pain and having a lot of entries there is much much worse than binding a few extra keys.

( besides, the Keybinding system in ArmA is pretty much the best one I know :D )

Share this post


Link to post
Share on other sites

This is true. However I'm testing various features of my WIP PEQ16A, which includes IR Laser/Flashlight/Visible Red Laser combo. Scripting through an action menu allows all three to be used in one unit

Share this post


Link to post
Share on other sites

Here is an old test script of mine for swapping muzzles via addactions. Not exactly what you want but might give you some ideas.

LARs_var_hasMuz = [nil, nil];
LARs_var_muzEquipped = [false, false];

LARs_fnc_checkMuzzles = {
{
	_weapon = [] call compile format ["%1weapon player", _x];
	_weaponSlot = _x;
	if (_weaponSlot == "primary") then {
		_weaponSlot = "primaryWeapon";
	};
	_index = _forEachIndex;
	if (_weapon != "") then {
		_silencer = [] call compile format ["(%1Items player) select 0", _weaponSlot];
		_compMuz = getArray (configfile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "MuzzleSlot" >> "compatibleItems");
		{ _compMuz set [_forEachIndex, (toLower _x)] }forEach _compMuz;
		if ( _silencer != "" && (toLower _silencer) in _compMuz ) then {
			LARs_var_hasMuz set [_index, _Silencer];
			LARs_var_muzEquipped set [_index, true];
		}else{
			LARs_var_hasMuz set [_index, nil];
			LARs_var_muzEquipped set [_index, false];
			{
				_itemType = ([_x] call bis_fnc_itemType) select 1;
				if ( _itemType == "AccessoryMuzzle" && (toLower _x) in _compMuz ) exitWith {
					LARs_var_hasMuz set [_index, _x];
					LARs_var_muzEquipped set [_index, false];
				};
			}forEach (items player);
		};
	}else{
		LARs_var_hasMuz set [_index, nil];
		LARs_var_muzEquipped set [_index, false];
	};
}forEach ["primary","handgun"];

};

LARs_fnc_equipMuz = {
_equip = _this;
{
	_weaponSlot = _x;
	_muzzle = LARs_var_hasMuz select _forEachIndex;
	_equipped = LARs_var_muzEquipped select _forEachIndex;
	if (_equip ) then {
		if ( !(isNil {_muzzle}) && !(_equipped) ) then {
			[] call compile format ["player add%1Item %2;",_weaponSlot, str _muzzle];
			player removeItem _muzzle;
		};
	}else{
		if ( (_equipped) ) then {
			[] call compile format ["player remove%1Item %2;", _weaponSlot, str _muzzle];
			player addItem _muzzle;
		};
	};
}forEach ["primaryWeapon","handgun"];
[] call LARs_fnc_checkMuzzles;
};



[] call LARs_fnc_checkMuzzles;


player addEventHandler ["TAKE", {
hintSilent format ["taken %1\n\naccessoryType\n%2", (_this select 2), ([(_this select 2)] call bis_fnc_itemType) select 1];
[] call LARs_fnc_checkMuzzles;
}];

player addEventHandler ["PUT", {
hintSilent format ["put %1\n\naccessoryType\n%2", (_this select 2), ([(_this select 2)] call bis_fnc_itemType) select 1];
[] call LARs_fnc_checkMuzzles;
}];


player addAction ["Go Silent", {true call LARs_fnc_equipMuz;}, [], -99, false, true, "", " !(isNil {(LARs_var_hasMuz select ([primaryWeapon player, handgunWeapon player] find (currentWeapon player)))}) && !(LARs_var_muzEquipped select ([primaryWeapon player, handgunWeapon player] find (currentWeapon player))) "];

player addAction ["Go Loud", {false call LARs_fnc_equipMuz;}, [], -99, false, true, "", " LARs_var_muzEquipped select ([primaryWeapon player, handgunWeapon player] find (currentWeapon player)) "];

Just paste that into the debug console and find yourself a silencer to get the actions to appear.

Share this post


Link to post
Share on other sites

Hey thanks buddy. There is actually a muzzle attach gesture I noticed looking through the configs

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  

×