Jump to content
beno_83au

Pistols & playActionNow "grabDrag"

Recommended Posts

Hi, I'm writing my own casualty drag and for the most part it's all working well. Where I'm coming unstuck though, is when it comes to dragging a casualty when you have a pistol. I'm using:

player playActionNow "grabDrag";

Nothing crazy, and it works as it should when the player has a primary weapon equipped. But when I have a pistol equipped and begin the action, the action still places the primary weapon where it would be if I had that equipped instead:

75INP07.jpg

 

So as you can see, I'm still holding (and firing) the pistol, but the primary weapon has been "superimposed" over the pistol. Is there a proper way around this, or will I have to write a work-around (and hit the feedback tracker up)? Unfortunately, in any of the other dragging-related scripts I've looked at I haven't seen this issue tackled.

Share this post


Link to post
Share on other sites
On 6/18/2020 at 5:29 AM, beno_83au said:

Hi, I'm writing my own casualty drag and for the most part it's all working well. Where I'm coming unstuck though, is when it comes to dragging a casualty when you have a pistol. I'm using:


player playActionNow "grabDrag";

Nothing crazy, and it works as it should when the player has a primary weapon equipped. But when I have a pistol equipped and begin the action, the action still places the primary weapon where it would be if I had that equipped instead:

 

 

So as you can see, I'm still holding (and firing) the pistol, but the primary weapon has been "superimposed" over the pistol. Is there a proper way around this, or will I have to write a work-around (and hit the feedback tracker up)? Unfortunately, in any of the other dragging-related scripts I've looked at I haven't seen this issue tackled.

 

Can you post your whole dragging script so we can test different solutions?

Edited by Dedmen
Removed images. Rule 14

Share this post


Link to post
Share on other sites

You probably need a workaround:  Get the primary weapon type and # of rounds in it, remove primaryWeapon when start dragging animation, then add it back with same # of rounds when dragging ends.  Just one of a million workarounds we do for realism.  Arggh.

 

Let's see a video of this sucker!  Can you shoot while dragging?

Share this post


Link to post
Share on other sites

Thanks @LSValmont I will when I get home.  

 

And @johnnyboy yeah you can shoot, you just can't reload or change weapons (although you can change fire modes). I've got it working for unarmed, handgun only, and if a secondary is equipped it'll be changed for a primary or handgun. I wrote out the steps to the work around in the OP before going to bed so if I have to, I should be able to get it going. 

  • Like 2

Share this post


Link to post
Share on other sites

Ahh so @LSValmont, sorry but I forgot I was going away for the weekend. Common mistake. Anyway, using just that single line of code will cause the problem if you have a handgun and primary weapon. However, here is what I have been using:

 

An addAction on the player uses [player,cursorObject] as the params for dragUnconscious.sqf.

dragUnconscious.sqf

params ["_player","_casualty"];

private _weapon = primaryWeapon player;
private _workAround = [false,[]];
switch true do {
	case ((currentWeapon player) == ""): {systemChat "Not needed - Empty";};
	case ((currentWeapon player) == primaryWeapon player): {systemChat "Not needed - Primary";};
	case ((currentWeapon player) == secondaryWeapon player): {
		systemChat "Secondary";
		if ((primaryWeapon player) == "") then {
			_weapon = handgunWeapon player;
			player selectWeapon _weapon;
			waitUntil {([animationState player,16,19] call BIS_fnc_trimString) == "wpst"};
		};
	};
	case ((currentWeapon player) == handgunWeapon player): {
		systemChat "Handgun";
		if ((primaryWeapon player) != "") then {
			private _primaryWeapon = primaryWeapon player;
			private _primaryWeaponItems = primaryWeaponItems player;
			private _primaryWeaponMagazine = primaryWeaponMagazine player;
			_workAround = [true,[_primaryWeapon,_primaryWeaponItems,_primaryWeaponMagazine]];
			
			//remove weapon
			//create groundWeaponHolder
			//add weapon to holder
			//attach holder to player
		};
	};
};

nul = [_workAround] execVM "dragging\restrictions.sqf";

[_casualty,"AinjPpneMrunSnonWnonDb_grab"] remoteExec ["switchMove",_casualty];
_player playActionNow "grabDrag";

_casualty attachTo [_player,[0.1,0.9,-0.02]];
_casualty setDir 180;

At the moment, I'm only using a "Fired" EH in dragging\restrictions.sqf to prevent "Throw" and "Put" weapons being used.

dragging\restrictions.sqf

params ["_workAround"];

private _ehIndex = player addEventHandler ["Fired",{
	params ["_unit","_weapon","","","","_magazine","_projectile"];
	if (({_weapon == _x} count ["Put","Throw"]) > 0) then {
		deleteVehicle _projectile;
		_unit addMagazine _magazine;
	};
}];

The work around was barely started before I went away and I've only just got back on, and I'll playing some SupCom so I'll probably do up something tomorrow.

  • Thanks 1

Share this post


Link to post
Share on other sites

Well, I kind of went down the rabbit hole on this one..... Surely there has to be a better way to do this? But anyway, here's what I ended up with, and the only part that blew out was trying to account for the player having a handgun equipped, with a primary on their back that happens to have more than 1 muzzle (grenade launcher attachments, or perhaps shotgun attachments even). Then that was even more difficult if any of those primary weapons mags weren't full. So to summarise, to prevent the primary weapon from glitching over the handgun (in the OP), I save the primary weapon's info, remove it, spawn a new one and attach it to the player's back, then give them the same weapon back in the same configuration it was after they finish dragging the casualty.

 

addActions:

Spoiler

player setVariable ["MIL_playerIsDragging",[false,objNull]];

_idDrag = player addAction [
	"<t color='#C6E32E'>Drag unconscious player</t>",
	{
		private _casualty = cursorObject;
		player setVariable ["MIL_playerIsDragging",[true,_casualty]];
		player setVariable ["#rev_enabled",false];
		nul = [_casualty] execVM "dragging\dragUnconscious.sqf";
	},
	nil,
	10,
	true,
	false,
	"",
	"((cursorObject distance _this) < 2) && (lifeState cursorObject == 'INCAPACITATED') && (('unconsciousrevivedefault' in (animationState cursorObject)) || (animationState cursorObject == 'ainjppnemstpsnonwrfldnon')) && (lifeState _this != 'INCAPACITATED') && !((_this getVariable ['MIL_playerIsDragging',[false,objNull]]) select 0)"
];

_idDrop = player addAction [
	"<t color='#C6E32E'>Drop unconscious player</t>",
	{
		private _casualty = (player getVariable "MIL_playerIsDragging") select 1;
		private _drop = [_casualty] execVM "dragging\dropUnconscious.sqf";
		waitUntil {scriptDone _drop};
		player setVariable ["MIL_playerIsDragging",[false,objNull]];
		player setVariable ["#rev_enabled",true];
	},
	nil,
	10,
	true,
	false,
	"",
	"(lifeState _this != 'INCAPACITATED') && ((_this getVariable ['MIL_playerIsDragging',[false,objNull]]) select 0)"
];

 

 

dragUnconscious.sqf:

Spoiler

params ["_casualty"];

private _currentWeapon = currentWeapon player;
private _workAround = [false,[]];
switch true do {
	case (_currentWeapon == ""): {};
	case (_currentWeapon == primaryWeapon player): {};
	case (_currentWeapon == secondaryWeapon player): {
		if ((primaryWeapon player) == "") then {
			private _weapon = handgunWeapon player;
			_currentWeapon = _weapon;
			player selectWeapon _weapon;
			waitUntil {([animationState player,16,19] call BIS_fnc_trimString) == "wpst"};
			} else {
			_currentWeapon = primaryWeapon player;
		};
	};
	case (_currentWeapon == handgunWeapon player): {
		if ((primaryWeapon player) != "") then {
			private _primaryWeapon = primaryWeapon player;
			private _magazinesAmmoFull = (magazinesAmmoFull player) select {(_x select 3) == 1};
			private _primaryWeaponMagazine = [];
			{
				_primaryWeaponMagazine pushBack [_x select 0,_x select 1];
			} forEach _magazinesAmmoFull;
			private _primaryWeaponItems = primaryWeaponItems player;
			
			player removeWeapon _primaryWeapon;
			
			_workAroundHolder = "Weapon_Empty" createVehicle [0,0,0];
			_workAroundHolder setPos (getPos player);
			_workAroundHolder addWeaponWithAttachmentsCargoGlobal [[_primaryWeapon,_primaryWeaponItems select 0,_primaryWeaponItems select 1,_primaryWeaponItems select 2,[(_primaryWeaponMagazine select 0) select 0,1],[],_primaryWeaponItems select 3],1];
			_workAroundHolder attachTo [player,[0,-0.2,0],"rightshoulder"];
			_workAroundHolder setDir 290;
			_workAroundHolder setVectorUp [0,-1,0.9];
			_workAroundHolder setDamage 1;			
			
			_workAround = [true,[_primaryWeapon,_primaryWeaponItems,_primaryWeaponMagazine],_workAroundHolder];
		};
	};
};

nul = [_workAround,_currentWeapon] execVM "dragging\restrictions.sqf";

[_casualty,"AinjPpneMrunSnonWnonDb_grab"] remoteExec ["switchMove",0];
player playActionNow "grabDrag";

_casualty attachTo [player,[0.1,0.9,-0.02]];
[_casualty,180] remoteExec ["setDir",_casualty];

nul = [_casualty] spawn {
	params ["_casualty"];
	waitUntil {
		sleep 0.1;
		(
			!alive player ||
			!alive _casualty ||
			!((player getVariable "MIL_playerIsDragging") select 0)
		)
	};
	if (!alive player || !alive _casualty) then {
		[_casualty,"AinjPpneMstpSnonWrflDb_release"] remoteExec ["switchMove",0];
		detach _casualty;
		player playActionNow "released";
		player setVariable ["MIL_playerIsDragging",[false,objNull]];
	};
};

 

 

dropUnconscious.sqf:

Spoiler

params ["_casualty"];

[_casualty,"AinjPpneMstpSnonWrflDb_release"] remoteExec ["switchMove",0];
player playActionNow "released";

detach _casualty;

 

 

restrictions.sqf:

Spoiler

params ["_workAround","_currentWeapon"];

private _ehIndex = player addEventHandler ["Fired",{
	params ["_unit","_weapon","","","","_magazine","_projectile"];
	if (({_weapon == _x} count ["Put","Throw"]) > 0) then {
		deleteVehicle _projectile;
		_unit addMagazine _magazine;
	};
}];

private _weaponEH = [
	format["%1_weaponEH",player],
	"onEachFrame",
	{
		params ["_currentWeapon"];
		if (currentWeapon player != _currentWeapon) then {
			player selectWeapon _currentWeapon;
		};
	},
	[_currentWeapon]
] call BIS_fnc_addStackedEventHandler;

waitUntil {!((player getVariable "MIL_playerIsDragging") select 0)};

[_weaponEH,"onEachFrame"] call BIS_fnc_removeStackedEventHandler;
player removeEventHandler ["Fired",_ehIndex];

if (_workAround select 0) then {
	waitUntil {animationState player != "acinpknlmstpsnonwpstdnon_amovpknlmstpsraswpstdnon"};
	_workAround params ["","_weaponData","_workAroundHolder"];
	_weaponData params ["_primaryWeapon","_primaryWeaponItems","_primaryWeaponMagazine"];
	deleteVehicle _workAroundHolder;
	player addWeapon _primaryWeapon;
	
	{
		player addWeaponItem [_primaryWeapon,_x,true];
	} forEach _primaryWeaponItems;
	
	private _grabbedMags = (magazinesAmmoFull player) select {(_x select 2) && ((_x select 3) == 1)};
	
	if (count (getArray (configFile >> "CfgWeapons" >> _primaryWeapon >> "muzzles")) == 1) then {
		if (count _grabbedMags > 0) then {
			player addMagazine [(_grabbedMags select 0) select 0,(_grabbedMags select 0) select 1];
		};
		if (count _primaryWeaponMagazine > 0) then {
			player setAmmo [_primaryWeapon,(_primaryWeaponMagazine select 0) select 1];
			} else {
			player setAmmo [_primaryWeapon,0];
		};
		
		} else {
		
		if (count _primaryWeaponMagazine == 1) then {
			private _check = _primaryWeaponMagazine;
			{
				if (((_check select 0) select 0) != (_x select 0)) then {
					_primaryWeaponMagazine = [_primaryWeaponMagazine,[["",0]],_forEachIndex] call BIS_fnc_arrayInsert;
				};
			} forEach _grabbedMags;
		};
		if (count _grabbedMags > 0) then {
			{
				player addMagazine [_x select 0,_x select 1];
				player removePrimaryWeaponItem (_x select 0);
			} forEach _grabbedMags;
		};
		if (count _primaryWeaponMagazine > 0) then {
			private _ehIndex = player addEventHandler ["Reloaded",{player setVariable ["MIL_Workaround_Reloaded",true]}];
			player setVariable ["MIL_Workaround_Reloaded",false];
			{
				private _mag = _x select 0;
				private _rounds = _x select 1;
				private _index = _forEachIndex;
				private _muzzle = [_primaryWeapon,(getArray (configFile >> "CfgWeapons" >> _primaryWeapon >> "muzzles")) select 1] select (_index > 0);

				if (_rounds > 0) then {
					player addMagazine [_mag,_rounds];
				};
				{
					private _exit = false;
					if (((_x select 0) == _mag) && ((_x select 1) == _rounds)) then {
						_id = parseNumber ((((magazinesDetail player) select _forEachIndex) splitstring "[:/]") select 4);
						_cr = parseNumber ((((magazinesDetail player) select _forEachIndex) splitstring "[:/]") select 5);
						player action ["loadMagazine",player,objNull,_cr,_id,primaryWeapon player,_muzzle];
						waitUntil {player getVariable "MIL_Workaround_Reloaded"};
						player setVariable ["MIL_Workaround_Reloaded",false];
						_exit = true;
					};
					if (_exit) exitWith {};
				} forEach (magazinesAmmo player);
				
			} forEach _primaryWeaponMagazine;
			player removeEventHandler ["Reloaded",_ehIndex];
		};
	};
};

 

 

If anyone finds themselves asking "Why did he do it like this?" then please just tell me I'm wrong instead, perhaps with an explanation as to why. That will probably be a question I cannot answer 🤣

 

edit: I'm still not happy with the workaround though. As it is, the player needs to run a scripted reload to get the right mags/ammo counts into their primary weapon if it has more than 1 muzzle.

  • Like 2
  • 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

×