Jump to content
Pantom

We are going to make incapacitated player invincible

Recommended Posts

Hey! you can check the state of the player by using:

 

_lifeState = lifeState player;

and then make him invincible based on that.

while{alive player} do
{
	if(_lifeState == "INCAPACITATED") then
	{
		player allowDamage false;
	}
	else
	{
		player allowDamage true;
	}
}

I haven´t tried it but this should work. Now, this is a simple SP method, if you want this to work on MP you'll have to put that code in "initPlayerLocal.sqf". At least from the top of my head, this should work, but as i said, it´s not tested.

Happy Holidays!

USE SOLUTION PROVIDED BY pierremgi BELOW

Share this post


Link to post
Share on other sites

First, it's not valid because your _lifeState is never updated... So, fail.

Second, never loop like this! (no waitUntil, no sleep). Even if in a scheduled scope, you can't imagine how many time you run these lines for the same result (then wasting resource for nuts).

At least, I'd add that in initPlayerLocal.sqf (example):

0 = [] spawn {
  while {true} do {

    waitUntil {sleep 0.5; lifeState player == "incapacitated"};

    player allowDamage FALSE;

    waitUntil {sleep 0.5; lifeState player != "incapacitated"};

    player allowDamage TRUE;
  };
};

That's for your loop.

Or, better:

this addEventHandler ["AnimChanged", {
 params ["_unit", "_anim"];
  if ("unconscious" in _anim) then {_unit allowDamage FALSE} else { if !(isDamageAllowed _unit) then {_unit allowDamage TRUE}}
 }];

in init field of player

 

 

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

×