Jump to content
VoxKoshka

Patching a countdown timer that resets on hit onto this script

Recommended Posts

Hey all. I found this code snippit for an 'energy shield' and I've been working on adding a few things here and there to it, but my command of scripting is pretty bad.

 

I can call it for whatever unit I want in different ways. What I'm struggling to do is add a timer that resets on hit. I can always change the timer variable back on hit, but I don't know how to get a timer to countdown for each unit that resets on hit for them.

 

That being said. I'm not a great scripter, but I'm pretty sure there's some bad practice stuff with spawn in here? I've been really struggling to get my own script of this kind (to do the same) working at all.

 

// Simple shield script
// hint
Shielded = ["B_Protagonist_VR_F"];
{
	private _unit = _x;
	if (typeOf (vehicle _unit) in Shielded) then {
		_unit setVariable ["hmhits",30,true];//(3+(ceil random 7))
		_unit setVariable ["HitVar",_unit addEventHandler ['HandleDamage', {
				params ["_unit", "_hitSelection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
				if ((_unit getVariable "hmhits") > 0) then {
					_Shielddamage = (_unit getVariable "hmhits") - _damage;
					hint str [_Shielddamage,(_unit getVariable "hmhits")];
					_unit setVariable ["hmhits",_Shielddamage,true];
					[_unit,_damage] spawn {
						params ["_unit","_damage"];
						_unit setDamage 0;
					};
				} else {
					[_unit,_damage] spawn{
						params ["_unit","_damage"];
						_unit setDamage ((_damage*.15)+(damage _unit));
					};
				};
			}]];
		};
}
forEach AllUnits;

 

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

×