Jump to content
djules

reduce vehicle damage

Recommended Posts

hey guys,

i want to reduce the damage that vehicles do on civilians if they crash. i want to reduce the damage to 49 so you need to hit others at least 3 times.

any help with scripting this will be greatly appreciated!

many thanks in advance

D.

Share this post


Link to post
Share on other sites

I'm not quite sure what you're asking, but I think I get the premise. Anyway, you are going to want to "getHit" and then set the damage yourself via Event Handlers.

Here is an example of what I use in a helicopter mission to reduce the damage (by 1/7, in this case) that a helicopter takes from enemy projectiles.

helimain setVariable ["selections", []];
helimain setVariable ["gethit", []];

helimain addEventHandler 
[	"HandleDamage",
{
	_unit = _this select 0;
	_selections = helimain getVariable ["selections", []];
	_gethit = helimain getVariable ["gethit", []];
	_selection = _this select 1;
	_projectile = _this select 4;
	if !(_selection in _selections) then
	{
		_selections set [count _selections, _selection];
		_gethit set [count _gethit, 0];
	};
	_i = _selections find _selection;
	_olddmg = _gethit select _i;
	_curdmg = _this select 2;
	if (_projectile == "") then {
		_curdmg;
	}
	else
	{
		_newdmg = _olddmg + (_curdmg - _olddmg) / 6;
		_gethit set [_i, _newdmg];
		_newdmg;
	};
}
];

Here is a link to where I modified that EH from, and a more in depth explanation.

Share this post


Link to post
Share on other sites

well, i want the units (people's characters) to only get 49 damage if the get hit by a vehicle (to prevent roadkills.

sorry for misunderstanding and a lot of thanks for your help

Share this post


Link to post
Share on other sites
well, i want the units (people's characters) to only get 49 damage if the get hit by a vehicle (to prevent roadkills.

sorry for misunderstanding and a lot of thanks for your help

I really don't know what you mean by 49 damage. Besides, I gave you all the info you needed. However, here's a little more.

test setVariable ["selections", []];
test setVariable ["gethit", []];

test addEventHandler 
[	"HandleDamage",
{
	_unit = _this select 0;
	_selections = test getVariable ["selections", []];
	_gethit = test getVariable ["gethit", []];
	_selection = _this select 1;
	_projectile = _this select 4;
	player sideChat str _projectile;
	if !(_selection in _selections) then
	{
		_selections set [count _selections, _selection];
		_gethit set [count _gethit, 0];
	};
	_i = _selections find _selection;
	_olddmg = _gethit select _i;
	_curdmg = _this select 2;
	if (_projectile == "") then {
		_newdmg = _olddmg;
		_gethit set [_i, _newdmg];
		_newdmg;
	}
	else
	{
	_curdmg; 
	};
}
];

Look in the scope where projectile == "". First off, the "projectile" of a vehicle running someone over is "" because there is no projectile. So this does what you want. However, it also includes anything else where the projectile is "". This DOES NOT include explosions, but it does include fall damage. In this example, the person (in this case "test") will take NO damage from any projectile of "", such as a vehicle running them over.

Now, see this.

	if (_projectile == "") then {
		_newdmg = _olddmg + (_curdmg - _olddmg) / 20;
		_gethit set [_i, _newdmg];
		_newdmg;
	}

You'll notice the difference in the first line. What this line would do is divide down the damage to a smaller number, still inclusive of any "" projectile. In this case, I've divided the damage dealt by the projectile, "", by 20. In my testing, it required me to run over the soldier 3 times with a tank before he died, without healing in between. You can play with that number to get a better feel for what you want. If you want to use this method, just replace it into the right section of the script.

To get this on every player, simply execute the script in the init.sqf, and replace "test" in the script with player.

Edit: Left my sideChat debugger in there, sorry. I'll leave it for your use so you see what I mean by projectile == "" for vehicles, but be sure to remove that for use.

Edited by Grimes [3rd ID]

Share this post


Link to post
Share on other sites

i have added the following code of yours to the init.sqf but it still doesnt work :(

player addEventHandler 
[    "HandleDamage",
   {
       _unit = _this select 0;
       _selections = player getVariable ["selections", []];
       _gethit = player getVariable ["gethit", []];
       _selection = _this select 1;
       _projectile = _this select 4;
       if !(_selection in _selections) then
       {
           _selections set [count _selections, _selection];
           _gethit set [count _gethit, 0];
       };
       _i = _selections find _selection;
       _olddmg = _gethit select _i;
       _curdmg = _this select 2;
       if (_projectile == "") then {
           _newdmg = _olddmg + (_curdmg - _olddmg) / 20;
           _gethit set [_i, _newdmg];
           _newdmg;
       }  
       else
       {
       _curdmg; 
       };
   }
]; 

Share this post


Link to post
Share on other sites

It doesn't work because you are testing it on AI, not players. AI do not execute the init.sqf, only machines do. What it does is add that to every player, so that when they receive that type of damage, it is reduced. You can test that it is working for a player by jumping off a building. Do the following if you want it to effect every player AND AI.

{
_x addEventHandler 
[    "HandleDamage",
	{
		_unit = _this select 0;
		_selections = _x getVariable ["selections", []];
		_gethit = _x getVariable ["gethit", []];
		_selection = _this select 1;
		_projectile = _this select 4;
		if !(_selection in _selections) then
		{
			_selections set [count _selections, _selection];
			_gethit set [count _gethit, 0];
		};
		_i = _selections find _selection;
		_olddmg = _gethit select _i;
		_curdmg = _this select 2;
		if (_projectile == "") then {
			_newdmg = _olddmg + (_curdmg - _olddmg) / 20;
			_gethit set [_i, _newdmg];
			_newdmg;
		}  
		else
		{
		_curdmg; 
		};
	}
];
} forEach allUnits; 

If you want it to effect only AI which are playable along with active players, change allUnits at the bottom to playableUnits.

Share this post


Link to post
Share on other sites

do i still need to setveriables with your last version?

like this:

_x setVariable ["selections", []];
_x setVariable ["gethit", []];

again, a lot of thanks for your support!

Share this post


Link to post
Share on other sites

YES! You do. Sorry, didn't notice you had clipped it out of the code you posted. Without those 2 lines it will not work. However, I'll place them, since we are doing it a bit differently now.

{
   _x setVariable ["selections", []];
   _x setVariable ["gethit", []];

   _x addEventHandler 
   [    "HandleDamage",
       {
           _unit = _this select 0;
           _selections = _x getVariable ["selections", []];
           _gethit = _x getVariable ["gethit", []];
           _selection = _this select 1;
           _projectile = _this select 4;
           if !(_selection in _selections) then
           {
               _selections set [count _selections, _selection];
               _gethit set [count _gethit, 0];
           };
           _i = _selections find _selection;
           _olddmg = _gethit select _i;
           _curdmg = _this select 2;
           if (_projectile == "") then {
               _newdmg = _olddmg + (_curdmg - _olddmg) / 20;
               _gethit set [_i, _newdmg];
               _newdmg;
           }  
           else
           {
           _curdmg; 
           };
       }
   ];
} forEach allUnits;  

Share this post


Link to post
Share on other sites

Sorry for pulling this old post up but has anyone find a good way to reduce vehicle damage a AI unit will take when hit while walking? I don't want to prevent damage but limited death from the first hit.

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

×