Jump to content
BRPVP

Two primary Weapons with no mods

Recommended Posts

Hi,

I did two primary weapons with no mods:

 

 

In BRPVP the code saves on database and have other particularities, but i can do a stand alone version to be run on missions without database.

You just need to press 1 again to change between primary weapons A and B.

  • Like 3
  • Thanks 2

Share this post


Link to post
Share on other sites

This is the stand alone code, you just need to run that on any client that you want the feature.

When the player get killed, the weapon on the virtual slot goes to a box near the player.

 

Special: If you already have a "Killed" and/or "keyDown" event handler, you can integrate the code on those.

//FUNCTIONS
BRPVP_playerKeydown = {
	private _return = false;
	if (inputAction "SwitchPrimary" > 0) then {
		private _wep1Class = primaryWeapon player;
		private _currWep = currentWeapon player;
		private _wep4 = player getVariable ["brpvp_weapon_4",[]];
		if ((count _currWep > 0 && _currWep isEqualTo _wep1Class) || _wep1Class isEqualTo "") then {
			_return = true;
			private _wep1 = [];
			{if (_x select 0 isEqualTo _wep1Class) exitWith {_wep1 = _x;};} forEach weaponsItems player;
			player setVariable ["brpvp_weapon_4",_wep1];
			player removeWeapon _wep1Class;
			private _nPrimary = _wep4 deleteAt 0 call BIS_fnc_baseWeapon;
			if (_wep4 isEqualTo []) then {
				player action ["SwitchWeapon",player,player,100];
			} else {
				player addWeapon _nPrimary;
				{
					if (count _x > 0) then {
						if (_x isEqualType "") then {
							player addPrimaryWeaponItem _x;
						} else {
							player addWeaponItem [_nPrimary,_x,true];
						};
					};
				} forEach _wep4;
			};
			player selectWeapon _nPrimary;
			
		};
	};
	_return
};
BRPVP_playerKilled = {
	_wep4 = player getVariable ["brpvp_weapon_4",[]];
	if !(_wep4 isEqualTo []) then {
		_wpBox = createVehicle ["Box_Syndicate_Ammo_F",ASLToATL getPosASL player,[],0.5,"CAN_COLLIDE"];
		clearWeaponCargoGlobal _wpBox;
		clearMagazineCargoGlobal _wpBox;
		clearItemCargoGlobal _wpBox;
		clearBackpackCargoGlobal _wpBox;
		_wpBox allowDamage false;
		_wpBox addWeaponWithAttachmentsCargoGlobal [_wep4,1];
		player setVariable ["brpvp_weapon_4",[]];
	};
};

//EVENT HANDLERS
player addEventHandler ["Killed",{call BRPVP_playerKilled;}];
0 spawn {
	waitUntil {!isNull findDisplay 46};
	(findDisplay 46) displayAddEventHandler ["keyDown",{_this call BRPVP_playerKeydown}];
};

 

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites

I updated the code with those fixes:

1 - One magazine from gear dissapears after you change the weapon, this is because when you put the weapon on the player the engine auto move a magazine into the weapon.

2 - Bipod dupe.

 

The code get bigger... 😔

 

//FUNCTIONS
BRPVP_playerKeydown = {
	private _return = false;
	if (inputAction "SwitchPrimary" > 0) then {
		private _wep1Class = primaryWeapon player;
		private _currWep = currentWeapon player;
		private _wep4 = player getVariable ["brpvp_weapon_4",[]];
		if ((count _currWep > 0 && _currWep isEqualTo _wep1Class) || _wep1Class isEqualTo "") then {
			_return = true;
			private _wep1 = [];
			{if (_x select 0 isEqualTo _wep1Class) exitWith {_wep1 = _x;};} forEach weaponsItems player;
			player setVariable ["brpvp_weapon_4",_wep1];
			player removeWeapon _wep1Class;
			private _nPrimary = _wep4 deleteAt 0 call BIS_fnc_baseWeapon;
			if (_wep4 isEqualTo []) then {
				player action ["SwitchWeapon",player,player,100];
			} else {
				private _conts = [uniformContainer player,vestContainer player,backpackContainer player];
				private _mags = _conts apply {magazinesAmmoCargo _x};
				player addWeapon _nPrimary;
				{player removePrimaryWeaponItem _x;} forEach primaryWeaponItems player;
				{
					if (count _x > 0) then {
						if (_x isEqualType "") then {
							player addPrimaryWeaponItem _x;
						} else {
							player addWeaponItem [_nPrimary,_x,true];
						};
					};
				} forEach _wep4;
				private _magsAfter = _conts apply {magazinesAmmoCargo _x};
				{
					private _idx = _forEachIndex;
					{
						private _magsIdx = _mags select _idx;
						_magsIdx deleteAt (_magsIdx find _x);
					} forEach _x;
				} forEach _magsAfter;
				{
					_idx = _forEachIndex;
					{
						_conts select _idx addMagazineAmmoCargo [_x select 0,1,_x select 1];
					} forEach _x;
				} forEach _mags;
			};
			player selectWeapon _nPrimary;
			
		};
	};
	_return
};
BRPVP_playerKilled = {
	_wep4 = player getVariable ["brpvp_weapon_4",[]];
	if !(_wep4 isEqualTo []) then {
		_wpBox = createVehicle ["Box_Syndicate_Ammo_F",ASLToATL getPosASL player,[],0.5,"CAN_COLLIDE"];
		clearWeaponCargoGlobal _wpBox;
		clearMagazineCargoGlobal _wpBox;
		clearItemCargoGlobal _wpBox;
		clearBackpackCargoGlobal _wpBox;
		_wpBox allowDamage false;
		_wpBox addWeaponWithAttachmentsCargoGlobal [_wep4,1];
		player setVariable ["brpvp_weapon_4",[]];
	};
};

//EVENT HANDLERS
player addEventHandler ["Killed",{call BRPVP_playerKilled;}];
0 spawn {
	waitUntil {!isNull findDisplay 46};
	(findDisplay 46) displayAddEventHandler ["keyDown",{_this call BRPVP_playerKeydown}];
};

 

  • Thanks 5

Share this post


Link to post
Share on other sites

Hello from Russia, thanks for the great script!Can you please tell me how to save the weapon in the database via extbd3?
The script is the best I've seen so far. It would be cool to add a save to the database + a weapon pickup animation.

Share this post


Link to post
Share on other sites

I just came across the script I was wondering does it still work and where do I need to put the code to call it for the mission.  

Share this post


Link to post
Share on other sites

Hi  @BRPVP thank you so much for sharing this. But, please how can I use it. Regards.

Share this post


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

Hi  @BRPVP thank you so much for sharing this. But, please how can I use it. Regards.

Yeah, after reading this intro I've put your code to a file called TwoPrimWeas.sqf and then put this file in the mission folder, and then inside the mission (eden editor) I've executed the script file with debug console like this:

[] execVM "TwoPrimWeas.sqf";

Very useful in the battle to carry a long range weapon and an assault one at the same time!

Thank you so much! @BRPVP

Share this post


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

Yeah, after reading this intro I've put your code to a file called TwoPrimWeas.sqf and then put this file in the mission folder, and then inside the mission (eden editor) I've executed the script file with debug console like this:


[] execVM "TwoPrimWeas.sqf";

Very useful in the battle to carry a long range weapon and an assault one at the same time!

Thank you so much! @BRPVP


To make it more comfortable, and you don't have to write and execute from the console, when you edit the mission, paste that line in the player initialization (you open the soldier's properties in init, paste that line)

  • Thanks 1

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

×