Rework death messages

MPHit does not always fire when a player is killed:
https://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#MPHit

Using either MPHit or MPKilled is not a good idea here. There is already
a local 'killed' event handler which fires on player death
(player_death.sqf). That script sends a PV (priority message) to the
server which triggers server_playerDied. That means fnc_plyrHit needed
to finish sending its data to the server via public setVariables
(non-priority messages) before server_playerDied executed. Triggering
both these scripts at the same time was a bad idea.

Instead of sending the data to the server via setVariable I just
included it in PVDZ_plr_Death. This also lets us pass extra information
from the damage handler like ammo type, cause of death, etc. Still need
to test, but it should be more reliable and performant than
fnc_playerHit called from MPHit or MPKilled.
This commit is contained in:
ebaydayz
2016-03-23 19:52:04 -04:00
parent debb714277
commit 3ed4a95c14
14 changed files with 188 additions and 246 deletions

View File

@@ -7,7 +7,7 @@ scriptName "Functions\misc\fn_damageHandler.sqf";
- Function
- [unit, selectionName, damage, source, projectile] call fnc_usec_damageHandler;
************************************************************/
private ["_unit","_hit","_damage","_unconscious","_source","_ammo","_Viralzed","_isMinor","_isHeadHit","_isPlayer","_isBandit","_punishment","_humanityHit","_myKills","_wpst","_sourceDist","_sourceWeap","_scale","_type","_nrj","_rndPain","_hitPain","_wound","_isHit","_isbleeding","_rndBleed","_hitBleed","_isInjured","_lowBlood","_rndInfection","_hitInfection","_isCardiac","_chance","_breakaleg","_model"];
private ["_unit","_hit","_damage","_unconscious","_source","_ammo","_Viralzed","_isMinor","_isHeadHit","_isPlayer","_isBandit","_punishment","_humanityHit","_myKills","_wpst","_sourceDist","_sourceWeap","_scale","_type","_nrj","_rndPain","_hitPain","_wound","_isHit","_isbleeding","_rndBleed","_hitBleed","_isInjured","_lowBlood","_rndInfection","_hitInfection","_isCardiac","_chance","_breakaleg","_model","_isZombieHit"];
_unit = _this select 0;
_hit = _this select 1;
_damage = _this select 2;
@@ -15,6 +15,7 @@ _unconscious = _unit getVariable ["NORRN_unconscious", false];
_source = _this select 3;
_isPZombie = player isKindOf "PZombie_VB";
_ammo = _this select 4;
_isZombieHit = (_ammo == "zombie");
_model = typeOf player;
_Viralzed = typeOf _source in DayZ_ViralZeds;
_isMinor = (_hit in USEC_MinorWounds);
@@ -124,7 +125,7 @@ if (_unit == player) then
_sourceDist = round(_unit distance _source);
_sourceWeap = switch (true) do {
case ((vehicle _source) != _source) : { format ["in %1",getText(configFile >> "CfgVehicles" >> (typeOf (vehicle _source)) >> "displayName")] };
case (_ammo == "zombie") : { _ammo };
case (_isZombieHit) : { _ammo };
case (_wpst select 0 == "Throw") : { format ["with %1 thrown", _wpst select 3] };
case (["Horn", currentWeapon _source] call fnc_inString) : {"with suspicious vehicle "+str((getposATL _source) nearEntities [["Air", "LandVehicle", "Ship"],5])};
case (["Melee", _wpst select 0] call fnc_inString) : { format ["with %2%1",_wpst select 0, if (_sourceDist>6) then {"suspicious weapon "} else {""}] };
@@ -132,7 +133,7 @@ if (_unit == player) then
case (_wpst select 0 != "") : { format ["with %1/%2 <ammo left:%3>", _wpst select 0, _ammo, _wpst select 4] };
default { "with suspicious weapon" };
};
if (_ammo != "zombie") then { // don't log any zombie wounds, even from remote zombies
if (!_isZombieHit) then { // don't log any zombie wounds, even from remote zombies
PVDZ_sec_atp = [_unit, _source, _sourceWeap, _sourceDist];
publicVariableServer "PVDZ_sec_atp";
};
@@ -151,11 +152,11 @@ if ((_ammo isKindof "B_127x107_Ball") or (_ammo isKindof "B_127x99_Ball")) then
};
if (_damage > 0.4) then {
if (_ammo != "zombie") then {
if (!_isZombieHit) then {
_scale = _scale + 50; //250
};
//Start body part scale
if (_ammo == "zombie") then {
if (_isZombieHit) then {
//_scale = _scale * 3; //600 = Normal, 900 = Viral
_scale = getNumber (configFile >> "CfgVehicles" >> (typeOf _source) >> "damageScale");
if (dayz_DamageMultiplier > 1) then {
@@ -190,7 +191,7 @@ if (_damage > 0.4) then {
//Record Damage to Minor parts (legs, arms)
if (_hit in USEC_MinorWounds) then {
private ["_type"];
if (_ammo == "zombie") then {
if (_isZombieHit) then {
if (_hit == "legs") then {
[_unit,_hit,(_damage / 6)] call object_processHit;
} else {
@@ -252,7 +253,7 @@ if (_damage > 0.4) then {
};
if ((_damage > 1.5) and _isHeadHit) then {
_id = [_source,"shothead"] spawn player_death;
if (_isZombieHit) then {_id = [_source,"shothead",1] spawn player_death;} else {_id = [_source,"shothead"] spawn player_death;};
};
};
@@ -274,7 +275,7 @@ if (_damage > 0.4) then {
};
};
if (_ammo == "zombie") then {
if (_isZombieHit) then {
if (!_isHit && _isbleeding && !_isPZombie) then {
//Create Wound
@@ -290,7 +291,7 @@ if (_damage > 0.4) then {
if (!_isInjured) then {
_unit setVariable["USEC_injured",true,true];
if ((_unit == player) and (_ammo != "zombie")) then {
if ((_unit == player) and (!_isZombieHit)) then {
dayz_sourceBleeding = _source;
};
};
@@ -305,7 +306,7 @@ if (_damage > 0.4) then {
//HitInfection from zombies
if ((!r_player_infected) and !(r_player_Sepsis select 0)) then {
if (_ammo == "zombie") then {
if (_isZombieHit) then {
_rndSepsis = floor(random 100);
_sepsisChance = getNumber (configFile >> "CfgVehicles" >> (typeOf _source) >> "sepsisChance");
//_hitInfection = (_rndInfection < _infectionChance);
@@ -328,7 +329,7 @@ if (_damage > 0.4) then {
_isInjured = _unit getVariable["USEC_injured",false];
if (!_isInjured) then {
_unit setVariable["USEC_injured",true,true];
if ((_unit == player) and (_ammo != "zombie")) then {
if ((_unit == player) and (!_isZombieHit)) then {
dayz_sourceBleeding = _source;
};
};
@@ -387,7 +388,7 @@ if (_type == 2) then {
};
};
if (_ammo == "zombie") then {
if (_isZombieHit) then {
if (!_unconscious and !_isMinor and _isHeadHit) then {
_chance = random 1;
if ((_damage > 0.8) and (_chance < 0.5)) then {

View File

@@ -1,8 +1,8 @@
private ["_display","_body","_playerID","_array","_source","_method","_isBandit","_punishment","_humanityHit","_myKills","_humanity","_kills","_killsV","_myGroup"];
private ["_pos","_display","_body","_playerID","_array","_source","_method","_isBandit","_punishment","_humanityHit","_myKills","_humanity","_kills","_killsV","_myGroup","_model"];
disableSerialization;
if (deathHandled) exitWith {};
deathHandled = true;
if (alive player) then {dayz_playerName = name player;};
_bodyName = if (alive player) then {name player} else {"unknown"};
//Prevent client freezes
_display = findDisplay 49;
@@ -28,8 +28,26 @@ if (dayz_onBack != "") then {
*/
};
_infected = if (r_player_infected && DZE_PlayerZed) then {1} else {0};
_killerMethod = "unknown";
_killerName = "unknown";
_killerDist = 0;
if (count _this > 0) then {
_killerObj = _this select 0;
_killerMethod = _this select 1;
if (!isNull _killerObj) then {
if (!isNull _body) then {_killerDist = _body distance _killerObj;};
_killerVehicle = vehicle _killerObj;
_killerWeapon = if (_killerVehicle != _killerObj) then {typeOf _killerVehicle} else {currentWeapon _killerObj};
if (alive _killerObj) then {
_killerName = if (isPlayer _killerObj) then {name _killerObj} else {"AI"};
};
};
if (count _this > 2) then {_killerMethod = "zombie";};
};
if (isNil "_killerWeapon") then {_killerWeapon = "unknown weapon";};
//Send Death Notice
PVDZ_plr_Death = [dayz_characterID,0,_body,_playerID,_infected,toArray dayz_playerName]; // Send as array to avoid publicVariable value restrictions
PVDZ_plr_Death = [dayz_characterID,0,_body,_playerID,toArray _bodyName,_infected,toArray _killerName,toArray _killerWeapon,_killerDist,toArray _killerMethod]; //Send name as array to avoid publicVariable value restrictions
publicVariableServer "PVDZ_plr_Death";
_id = [player,20,true,getPosATL player] call player_alertZombies;

View File

@@ -78,7 +78,7 @@ if ((_maxlocalspawned < _maxControlledZombies) && (dayz_CurrentNearByZombies < d
if (_tooClose) exitwith { diag_log "Zombie_Generate: was too close to player."; };
if (count _unitTypes == 0) then {
_unitTypes = getArray (configFile >> "CfgLoot" >> "Buildings" >> "Default" >> "zombieClass");
_unitTypes = if (DZE_MissionLootTable) then {getArray (missionConfigFile >> "CfgLoot" >> "Buildings" >> "Default" >> "zombieClass")} else {getArray (configFile >> "CfgLoot" >> "Buildings" >> "Default" >> "zombieClass")};
};
// lets create an agent

View File

@@ -660,7 +660,6 @@ if (!isDedicated) then {
deathHandled = false;
dayz_firstGroup = group player;
dayz_originalPlayer = player;
dayz_playerName = "Unknown";
dayz_sourceBleeding = objNull;
dayz_clientPreload = false;
dayz_authed = false;

View File

@@ -620,7 +620,6 @@ class FSM
" };" \n
"};" \n
"" \n
"dayz_playerName = name player;" \n
"_model call player_switchModel;" \n
"" \n
"gear_done= true;" \n
@@ -1972,7 +1971,7 @@ class FSM
"_nearestCity = nearestLocations [getPos player, [""NameCityCapital"",""NameCity"",""NameVillage"",""NameLocal""],1000];" \n
"Dayz_logonTown = ""Wilderness"";" \n
"if (count _nearestCity > 0) then {Dayz_logonTown = text (_nearestCity select 0)};" \n
"[_world,Dayz_logonTown,format[localize ""str_player_06"",dayz_Survived]] spawn { uiSleep 5; _this spawn BIS_fnc_infoText;};" \n
"[_world,Dayz_logonTown,format[localize ""str_player_06"",dayz_Survived]] spawn {uiSleep 5; _this spawn BIS_fnc_infoText;};" \n
"dayz_myPosition = getPosATL player;" \n
"Dayz_loginCompleted = true;" \n
"" \n