Jump to content
MinervaArts

Revive player over distance with pistol

Recommended Posts

Hi guys,

I'm currently working on a script that will allow a player to shoot another unconscious player and then revive him immediately. I already have the revive system ready, but I haven't found a way to make it so that only the player who was shot is revived.

Do you have an idea how I can make it so that the code is only executed on the player who was hit?
I have already tried to rebuild a taser script but didn't really get anywhere.

 

Thanks for your help!

Share this post


Link to post
Share on other sites

For starting tests, you could try something like this to init box for your player in editor ( I haven't tested it yet).
Add the class of the specific pistol that should be shot to work, and "cursorObject" should guarantee it only works upon the unit in target. But this could potentially "heal" dammaged vehicles as well, so you might want to remove the "setDamage" line.
 

this addEventHandler ["Fired", 
                      { params ["_unit", "_weapon"];
                      _unit = _this select 0;
                      _weapon = "" // add here the class of the pistol that must be used;
					  cursorObject setUnconscious false;
					  cursorObject setDamage 0;
                      }];

 

Share this post


Link to post
Share on other sites
8 hours ago, MinervaArts said:

Hi guys,

I'm currently working on a script that will allow a player to shoot another unconscious player and then revive him immediately. I already have the revive system ready, but I haven't found a way to make it so that only the player who was shot is revived.

Do you have an idea how I can make it so that the code is only executed on the player who was hit?
I have already tried to rebuild a taser script but didn't really get anywhere.

 

Thanks for your help!

 

I'd use the HandleDamage eventhandler in combination with initPlayerLocal.sqf. That puts the responsibility on the receiving player's client to handle the revive, which is where the unconscious player is local anyway.

Setup is simple:

  1. Paste the contents into your initPlayerLocal.sqf (create the file in your mission root if needed).
  2. Change the TAG in TAG_healingGuns (in both places) to avoid conflicts with other scripts. You just need to worry about other scripts in your mission so keep it short and sweet.
  3. Replace the examples gunClass1 and gunClass2 with weapon classnames you want to use.

The below code assumes your using the BIS standard revive system but should be easy to match to your requirements.

Only did a runtime syntax-check but should be logically sound and fully MP compatible as long as you use BIS standard revive. Other revive systems will depend on their implementation.

// initPlayerLocal.sqf

// Guns classes that revive
TAG_healingGuns = [
	"gunClass1",
	"gunClass2"
];

// Just a helper macro to improve readability of the eventhandler
#define CONTAINS( arr, string ) ({ _x == string } count arr > 0)

// Handle damage EH
player addEventHandler [
	"HandleDamage",
	{
		params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint", "_directHit"];

		private _isUnconscious = lifeState _unit == "INCAPACITATED";

		// Filter on selection "head" since the EH triggers for all selections, head is selected simply because there's only one ;)
		if( _isUnconscious && _directHit && _selection == "head" ) then { 

			// currentWeapon is probably good enough, but if not you can check the projectile class against the gun classes instead, more complicated though.
			private _weapon = currentWeapon _source; 			
			if( CONTAINS( TAG_healingGuns, _weapon ) ) then {	

				// If using another revive system than BIS standard replace this row with appropiate revive call
				[ "#rev", 1, player ] call BIS_fnc_reviveOnState; 
			};	
		};
	}
];

 

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

×