Jump to content
dudleyaz

Solutions for invulnerable pilot not working, looking for ideas.

Recommended Posts

Hi all,

I am looking for help with what I thought was an easy problem to fix, but so far the solution has eluded me.  In a mission I am creating, I am looking for a simple way for any player that is operating as either the driver or gunner in a specific vehicle or vehicles to be invulnerable to weapon damage.  But I want them vulnerable again as soon as they exit the vehicle.  I am fine if they die if the vehicle is destroyed/shot down.  It needs to work in single and multiplayer. In general it will be a helicopter in question, but it may be a special car or truck down the road. I have been trying a few different solutions offered in other posts related to this topic, but I can't find anything that works correctly for me. I would prefer to have something I could place into the init line of the specific vehicle if possible.  The latest two tries were:

 

1) Tried placing this code in the init line, but it doesn't do anything in single player.  In multiplayer it did keep the player from taking any damage while in the heli, however the player was still invulnerable after landing and getting out...

 

driver this allowDamage false;  


2) I have also tried placing this code in the init field of the player controlled character who I want to be invulnerable while piloting, but it didn't seem to do anything at all in single or MP....

 

_unit addEventHandler ["HandleDamage", {
    _unit = _this select 0;
    if (vehicle _unit != _unit) then {0};
}];


I don't want to create a new asset/addon for every vehicle I want this to work with (especially since I don't have a clue where to start with that idea), so unless there is a way to modify the vehicle config file in the editor by script or init line code, I don't know how the vehicle config entry crewVulnerable = 1; is of use to me because I can't find a way to work with it. 

 

3) I tried this just to see if it would work...

 

this set crewVulnerable = 0;

 

but it immediately generated an init error of... this set crewVulnerable |#|=0;}' Error missing ;   So no go there.

 

I am the first to say that I really have no skill or talent for script writing in Arma 3, so I rely heavily on finding scripts/code that others have posted and either copied them as is or done very small modifications to them to make them fit my need.  Any and all help is greatly appreciated.

Thanks,
Dudley

Share this post


Link to post
Share on other sites

in a init code you'd better write:

this addEventHandler ["HandleDamage", {
      _unit = _this select 0;
      if (!isnull objectParent _unit && local _unit) then {0};
}];

 

Share this post


Link to post
Share on other sites

Thanks pierre,

But no luck.  I pasted that into the init of a vehicle, and I got shot out of the drivers seat right away in MP and SP.

I didn't get any error messages or anything at least....

Dudley

Share this post


Link to post
Share on other sites

Ha!  I guess that would be a good idea huh?

 

Had slightly better results... worked in SP, but no go in MP.  Bad guy immediately shot me out of a truck cab and a little bird cockpit.  Does it make any difference that when I play it in MP I host the game on the same PC I play it on?

Dudley

Share this post


Link to post
Share on other sites

It works for me. SP/MP. I removed the if (isserver) then {}. Did yo copy the right code?

Share this post


Link to post
Share on other sites

if (isServer) then { 
  this addEventHandler ["HandleDamage", { 
      _unit = _this select 0; 
      if (!isnull objectParent _unit) then {0}; 
  }]; 
};

 

Copied right out of your post earlier.  What is above I copied right out of the init field of my player character.  Not sure why it works for you and not for me... I don't have anything else in the init field for that unit.  Any ideas?

Share this post


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

Any ideas?

 

Pierremgi edited his post to remove the server check from his code.

 

*bad info redacted*

Share this post


Link to post
Share on other sites

Harzach and pierre,

Thanks for clarifying that for my Harzach... saw the words but they didn't sink in... So I copied and pasted the lines of code exactly as they were listed above but I still get the same result.  SP works perfectly, but dead driver on first contact with the enemy in MP.   I tried it in MP directly from the editor, then backed all the way out and tried it from a self hosted MP session.. same results.  Here it is copied back out of the init field:

 

this addEventHandler ["HandleDamage", {  
    _unit = _this select 0;  
    if (!isnull objectParent _unit) then {0};  
}]; 

 

 

Share this post


Link to post
Share on other sites

Truly? I changed my code 10 hours ago and it seems to me you copy paste the Harzach one... Never mind. I send it here once again:

this addEventHandler ["HandleDamage", {
      _unit = _this select 0;
      if (!isnull objectParent _unit && local _unit) then {0};
}];

 

Share this post


Link to post
Share on other sites

/facepalm

 

I grabbed both snippets then pasted the incorrect one. I'll see myself out...

  • Haha 1

Share this post


Link to post
Share on other sites

Still no luck.  SP works fine, MP I die as soon as he starts shooting.  Here is what I have copied back out of the init field of the player character.  I have tried it driving a stock vehicle, RHS truck, and RHS little bird, all with the same results... fine SP, no protection in MP.  Is there something I would have to be running or scripting in an init.sqf for this to work in MP or something like that (yes, I'm probably showing my spectacular lack of knowledge in this arena by asking this...)?

 

Even though it isn't working yet... thanks to both of you for continuing to help out.... I greatly appreciate it!

 

this addEventHandler ["HandleDamage", { 
      _unit = _this select 0; 
      if (!isnull objectParent _unit && local _unit) then {0}; 
}];

Share this post


Link to post
Share on other sites

Aight only got access to phone right now so bare with me. I went for Air class so all planes are also included. If you don't want that just change to Helicopter. 

 

1. Create initPlayerLocal.Sqf

2. In it write 

if(vehicle player iskindof "Air") then { player allowDamage false; };
player addEventHandler [
  	"GetInMan", 
	{
		if((_this select 2) isKindOf "Air") then {
			player allowDamage false;
		};
	}
];
player addEventHandler [
  	"GetOutMan", 
	{
		Player allowDamage true;
	}
];

3. Save and profit 

 

Sorry for terrible formatting, I'll clean it once back on the PC.  Fixed

Edited by mrcurry

Share this post


Link to post
Share on other sites

I will give it a try during the week and let you know.  Thanks mucho mrcurry!

Share this post


Link to post
Share on other sites

mrcurry, I just tried it and it worked PERFECTLY!  :don11:Thanks so much to everyone for the assistance!

Dudley

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

×