Jump to content
MrSydney

First aid kits use

Recommended Posts

Hello. I am not sure if this has been asked before so apologies if it has.

I am trying to make it so that combat life savers always use up a single first aid kit when healing themselves or other players. When they have none, then a hint should show up saying that "You do not have a first aid kit" or something. Medics will then have to carry both medikits to revive incapacitated players, but also first aid kits to heal injured players that are not incapacitated. In the base game, medics that have the big medikits can heal players without their First aid kits ever depleting. Any ideas on how I could do this with a script? I was thinking that I have to first do a check if the player is a medic, then if the medic has first aid kits, and if he does it should remove a single first aid kit from his inventory whenever he heals someone. But I am not sure how to stop the medic from using the medikit. I wrote a little script, but it does not seem to do anything.

 

Any help would be appreciated, thanks.

 

_playerType = typeOf player;

if ((_playerType == "B_medic_F") or (_playerType == "B_recon_medic_F") or (_playerType == "B_G_medic_F") or (_playerType == "B_T_Medic_F")) then 
{

 player addEventHandler ["HandleHeal", 
{
	_this spawn 
	{
		params ["_injured", "_healer"];
	
		_items = items _healer;

		if ("Item_FirstAidKit" in _items) then 
		{
			_healer removeItem Item_FirstAidKit;
		}
		else
		{
			private _damage = damage _injured;
			if (_injured == _healer) then 
				{
					waitUntil {damage _injured != _damage};
					if (damage _injured < _damage) then 
					{
						uiSleep 0.3;
						_injured setDamage _damage;
						hint "You do not have a first aid kit.";
					};
				};
		};
	};
 }];

} 
else {};

 

Share this post


Link to post
Share on other sites

You can use inGameUISetEventhandler:

TAG_fnc_handleHeal = {
	params ["_target", "_caller", "_index", "_engineName", "_text", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_visibleMenu", "_eventName"];
	if !(_engineName in ["HealSoldierSelf", "HealSoldier"]) exitWith {false};
	if (items _caller findIf {_x == "FirstAidKit"} == -1) exitWith {
		//--- No remaining FAKs
		hint "You do not have any First Aid Kits";
		true
	};
	//--- player has enough FAKs to heal
	_caller removeItem "FirstAidKit";
	false
};
inGameUISetEventHandler ["Action", "_this call TAG_fnc_handleHeal"];

 

  • Like 2

Share this post


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

You can use inGameUISetEventhandler:


TAG_fnc_handleHeal = {
	params ["_target", "_caller", "_index", "_engineName", "_text", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_visibleMenu", "_eventName"];
	if !(_engineName in ["HealSoldierSelf", "HealSoldier"]) exitWith {false};
	if (items _caller findIf {_x == "FirstAidKit"} == -1) exitWith {
		//--- No remaining FAKs
		hint "You do not have any First Aid Kits";
		true
	};
	//--- player has enough FAKs to heal
	_caller removeItem "FirstAidKit";
	false
};
inGameUISetEventHandler ["Action", "_this call TAG_fnc_handleHeal"];

 

Thank you very much for this. That works almost perfectly. I noticed that if you are a normal player (not a combat life saver with a medikit), and you try to heal someone else with the last FAK in your inventory, they don't regain any health and the healing does not work. Any ideas what might be causing this to happen? Sorry, I am still a noob at scripting.

Share this post


Link to post
Share on other sites
6 hours ago, 7erra said:

You can use inGameUISetEventhandler:


TAG_fnc_handleHeal = {
	params ["_target", "_caller", "_index", "_engineName", "_text", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_visibleMenu", "_eventName"];
	if !(_engineName in ["HealSoldierSelf", "HealSoldier"]) exitWith {false};
	if (items _caller findIf {_x == "FirstAidKit"} == -1) exitWith {
		//--- No remaining FAKs
		hint "You do not have any First Aid Kits";
		true
	};
	//--- player has enough FAKs to heal
	_caller removeItem "FirstAidKit";
	false
};
inGameUISetEventHandler ["Action", "_this call TAG_fnc_handleHeal"];

 

 

Hey Terra, I did not know about this EH.

 

Do you think that it can be used to delete the default "Heal Action" everytime the player uses the scroll down mouse button or something? Or will the action (the Default Heal Action) be re-added constantly due to a loop on the unit?

Share this post


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

Thank you very much for this. That works almost perfectly. I noticed that if you are a normal player (not a combat life saver with a medikit), and you try to heal someone else with the last FAK in your inventory, they don't regain any health and the healing does not work. Any ideas what might be causing this to happen? Sorry, I am still a noob at scripting.

That might be because the FAK gets removed twice for normal players, once the action starts (my script) and once the action finishes (engine). Maybe adding a check to see if the player has a Medikit before removing the FAK would solve that issue, so something like

	//--- player has enough FAKs to heal
	if ("Medikit" in items _caller && _caller getUnitTrait "Medic") then {
		_caller removeItem "FirstAidKit";
	};
	false

 

3 hours ago, LSValmont said:

Do you think that it can be used to delete the default "Heal Action" everytime the player uses the scroll down mouse button or something?

Can't fight the engine, so no. But you can overwrite the engine behaviour by returning true at the end of your code.

Share this post


Link to post
Share on other sites

Just tested it and everything is working great. Thank you for the help.

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

×