Giving players body armour

Party-approved programming
Post Reply
Nullkigan
Posts: 50
Joined: Sat May 28, 2011 4:44 pm

Giving players body armour

Post by Nullkigan »

The following bit of code lets players take four or five hits from a Lee Enfield at close range without dying. Hit effects, such as reduced aim and mobility, still apply but at a slightly reduced rate. Best of all? It only works on bullets. A tank shell to the face still ends poorly.

bodyarmourfunc.sqf

Code: Select all

private ["_unit","_damage","_ammo","_gethit","_damMults"];

// Stolen from Celery's Chernarus Apocalypse missions, modifications by Nullkigan

_unit=_this select 0;
_damage=_this select 2;
_ammo=_this select 4;
_damMults=[0.1,0.2,0.2,0.8,0.4];

//player sideChat format ["%1 isKindOf BulletCore = %2",_ammo,(_ammo isKindOf "BulletCore")];

if (!(_ammo isKindOf "BulletCore")) then {_damMults=[1.0,1.0,1.0,1.0,1.0];};										// Only modify damage if from a bullet; grenades and stuff still hurt!

if (isNil {_unit getVariable "gethit"}) then {_unit setVariable ["gethit",[0,0,0,0]]}; 								// fresh unit starts at full health
_gethit=_unit getVariable "gethit"; // load health of each part of body

switch (_this select 1) do {       																					// depending on which part of body is damaged
	case "":{ 																										// overall structure
		_damage=damage _unit+_damage*(_damMults select 0)
	};
	
	case "head_hit":{
		_damage=(_gethit select 0)+(_damage-(_gethit select 0))*(_damMults select 1);_gethit set [0,_damage]
	};
	
	case "body":{
		_damage=(_gethit select 1)+(_damage-(_gethit select 1))*(_damMults select 2);_gethit set [1,_damage]
	};    
	
	case "hands":{    																							  	// cannot kill a unit on own, only affect aim
		_damage=(_gethit select 2)+(_damage-(_gethit select 2))*(_damMults select 3);_gethit set [2,_damage]
	};    	
	
	case "legs":{    																							  	// cannot kill a unit on own, only affect movement
		_damage=(_gethit select 3)+(_damage-(_gethit select 3))*(_damMults select 4);_gethit set [3,_damage]
	}; 
};      

_damage
This even works with Norrin's, so long as you put it in the right part of the init.sqf (i.e. before Norrin's is initialised):

Init.sqf example

Code: Select all

// ====================================================================================

// F2 - Norrin's Revive Respawn
// Credits: Please see the F2 online manual (http://www.ferstaberinde.com/f2/en/)
BodyArmourFunc = compile preprocessFileLineNumbers "bodyarmourfunc.sqf";
player addEventHandler ["HandleDamage",{call bodyarmourfunc;}	];
server execVM "revive_init.sqf"; 

// ====================================================================================

Nullkigan
Posts: 50
Joined: Sat May 28, 2011 4:44 pm

Re: Giving players body armour

Post by Nullkigan »

I realised that after being revived, a player's GetHit variable would still be full, so if you're using Norrin's (or whatever), have "this setVariable ['gethit',[0,0,0,0]];" run by the player on revive/respawn. That would be NORRNCustomExec1 and NORRNCustomExec3. For other solutions you might have to use setVehicleInit and processInitCommands as appropriate.

Post Reply