Jump to content
Sign in to follow this  
fn_Quiksilver

[CODE SNIPPET] Overwriting the vanilla "Treat" user action

Recommended Posts

Hi lads,

 

Small code snippet I'd like to contribute which I strongly encourage all vanilla missions/servers to apply.

 

Problem:

 

When trying to "Treat" an injured player, if he moves even slightly, the Treat will fail, and your soldier will still go through the whole animation.

 

There are two issues here.

 

  1. The failure condition for the action is way too sensitive for regular gameplay.
  2. The animation will continue several seconds after the attempt has failed.

 

The result is that players get frustrated by an awkward game mechanic, attempting to treat someone over and over who may not be staying perfectly still.

 

Solution:

 

The below code means that the injured unit can still move slightly and do other normal movements, and will still be Treated/healed as long as they stay in proximity.

 

If the injured unit leaves proximity or dies or whatever, the Treat animation will terminate.

 

The result is that a very common and frustrating moment of gameplay is smoothed out.

 

https://github.com/auQuiksilver/Apex-Framework/blob/master/Apex_framework.terrain/code/functions/fn_clientInGameUIAction.sqf#L84-L149

 

We applied this change some time ago for use in the "Apex Framework" + I&A mission.

 

Here is a use-able code snippet:

 

// Treat Overwrite by Quiksilver
// Paste in player init script
// Multiplayer + Singleplayer

QS_fnc_treatOverwrite = {
	params ['_actionTarget'];
	player setVariable ['QS_treat_entryAnim',(animationState player),FALSE];
	player setVariable ['QS_treat_target',_actionTarget,FALSE];
	_animEvent = player addEventHandler [
		'AnimDone',
		{
			params ['_unit','_anim'];
			if (['medicdummyend',_anim,false] call (missionNamespace getVariable 'BIS_fnc_inString')) then {
				if ((lifeState _unit) in ['HEALTHY','INJURED']) then {
					_target = _unit getVariable ['QS_treat_target',objNull];
					if (!isNull _target) then {
						if (((_target distance _unit) <= 2.5) && (isNull (objectParent _target)) && ((lifeState _target) in ['HEALTHY','INJURED'])) then {
							_unit removeItem 'FirstAidKit';
							_target setDamage [([0.25,0] select (_unit getUnitTrait 'medic')),TRUE];
						};
					};
				};
				if (!isNull (_unit getVariable ['QS_treat_target',objNull])) then {
					_unit setVariable ['QS_treat_target',objNull,FALSE];
				};
			};
		}
	];
	player playActionNow 'MedicOther';
	[_actionTarget,_animEvent] spawn {
		params ['_injured','_animEvent'];
		_timeout = diag_tickTime + 10;
		uiSleep 0.5;
		waitUntil {
			uiSleep 0.05;
			((isNull (player getVariable 'QS_treat_target')) || {(!((lifeState player) in ['HEALTHY','INJURED']))} || {(diag_tickTime > _timeout)} || {((_injured distance player) > 2.5)})
		};
		if ((_injured distance player) > 2.5) then {
			player setVariable ['QS_treat_target',objNull,FALSE];
			if ((lifeState player) in ['HEALTHY','INJURED']) then {
				if (isMultiplayer) then {
					_nearbyPlayers = (allPlayers inAreaArray [(getPos player),100,100,0,FALSE,-1]) select {(!(_x isEqualTo player))};
					if (!(_nearbyPlayers isEqualTo [])) then {
						[player,(player getVariable ['QS_treat_entryAnim',''])] remoteExec ['switchMove',_nearbyPlayers,FALSE];
					};
				} else {
					player switchMove (player getVariable ['QS_treat_entryAnim','']);
				};
			};
		};
		if (!isNull (player getVariable 'QS_treat_target')) then {
			player setVariable ['QS_treat_target',objNull,FALSE];
		};
		player removeEventHandler ['AnimDone',_animEvent];
	};
};
inGameUISetEventHandler [
	"Action",
	"
		params ['_actionTarget','','','_actionName','','','','','','',''];
		private _return = FALSE;
		if (_actionName isEqualTo 'HealSoldier') then {
			_return = TRUE;
			[_actionTarget] call QS_fnc_treatOverwrite;
		};
		_return;
	"
];

 

  • Like 11
  • Thanks 3

Share this post


Link to post
Share on other sites

@fn_Quiksilver thanks mate I've been frustrated by this problem for awhile myself. Great work.

 

Cheers.

Share this post


Link to post
Share on other sites

Could this be made into an addon that we can then use to override the vanilla action ?

  • Like 1

Share this post


Link to post
Share on other sites

 

Great catch and fix -could have sworn the AI would immobilize in the old days when being healed

Share this post


Link to post
Share on other sites
5 hours ago, kremator said:

Could this be made into an addon that we can then use to override the vanilla action ?

 

yeah i can make it an addon.

 

only issue is that it uses “ingameuiseteventhandler”, which cant be stacked, so if its used by any other addon or the mission itself, there would be a conflict

  • Like 2

Share this post


Link to post
Share on other sites
On 4/25/2019 at 9:59 PM, cb65 said:

@fn_Quiksilver thanks mate I've been frustrated by this problem for awhile myself. Great work.

 

Cheers.

 

thanks for the feedback

 

a small issue which everyone gets frustrated by but tolerates without mentioning.

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  

×