Change inCombat to bool instead of number

When a variable is only going to be 0 or 1 it makes more sense to use a
bool.

Also avoided unnecessary network broadcasts of inCombat from e446603
This commit is contained in:
ebaydayz
2016-10-01 13:07:59 -04:00
parent 76273d06cd
commit 0a17804e36
11 changed files with 31 additions and 24 deletions

View File

@@ -68,7 +68,9 @@ dayz_lastDamageSourceNull = false;
if (_unit == player) then {
//Set player in combat
_unit setVariable["startcombattimer", 1];
_unit setVariable["inCombat", 1, true];
if (_unit getVariable["inCombat",false]) then {
_unit setVariable["inCombat",true,true];
};
if (_hit == "") exitWith //Ignore none part dmg. Exit after processing humanity hit
{
@@ -152,14 +154,13 @@ if (_unit == player) then {
};
};
//Overkill logging. PVS network send every two seconds = lag. Not worth it just for extra anticheat logs.
//Log to server :-( OverProcessing really not needed.
if (((!(isNil {_source})) AND {(!(isNull _source))}) AND {((_source isKindOf "CAManBase") AND {(!local _source )})}) then {
/*if (((!(isNil {_source})) AND {(!(isNull _source))}) AND {((_source isKindOf "CAManBase") AND {(!local _source )})}) then {
_wpst = weaponState _source;
if (diag_ticktime-(_source getVariable ["lastloghit",0])>2) then {
//private ["_sourceWeap"];
private ["_sourceWeap"];
_source setVariable ["lastloghit",diag_ticktime];
/* // Excessively intensive logging (Network send on every hit)
_sourceDist = round(_unit distance _source);
_sourceWeap = switch (true) do {
case ((vehicle _source) != _source) : { format ["in %1",getText(configFile >> "CfgVehicles" >> _sourceVehicleType >> "displayName")] };
@@ -175,9 +176,8 @@ if (_unit == player) then {
PVDZ_sec_atp = [_unit, _source, toArray _sourceWeap, _sourceDist]; //Send arbitrary string as array to allow stricter publicVariableVal.txt filter
publicVariableServer "PVDZ_sec_atp";
};
*/
};
};
};*/
dayz_lastDamageSource = switch (true) do {
case (_falling): {"fall"};
@@ -185,8 +185,9 @@ if (_unit == player) then {
case (_ammo == "RunOver"): {"runover"};
case (_ammo == "Dragged"): {"eject"};
case (_ammo in MeleeAmmo): {"melee"};
case (!isNil "_wpst" && {!(_wpst select 0 in ["","Throw"])}): {"shot"};
case (_sourceVehicleType isKindOf "LandVehicle" or {_sourceVehicleType isKindOf "Air"} or {_sourceVehicleType isKindOf "Ship"}): {"shot"};
case (_source isKindOf "CAManBase" && !local _source && !(currentWeapon _source in ["","Throw"])): {"shot"};
//(vehicle _source != _source) does not work to detect if source unit is in a vehicle in HandleDamage EH
case (_sourceVehicleType isKindOf "LandVehicle" or _sourceVehicleType isKindOf "Air" or _sourceVehicleType isKindOf "Ship"): {"shot"};
default {"none"};
};
if (dayz_lastDamageSource != "none") then {dayz_lastDamageTime = diag_tickTime;};

View File

@@ -66,7 +66,7 @@ player setVariable ["USEC_isCardiac",false,true];
player setVariable ["medForceUpdate",true,true];
player setVariable ["bloodTaken", false, true];
player setVariable ["startcombattimer", 0]; //remove combat timer on death
player setVariable ["inCombat", 0, true];
player setVariable ["inCombat", false, true];
r_player_unconscious = false;
r_player_cardiac = false;
_model = typeOf player;

View File

@@ -24,7 +24,7 @@ _humanKills = player getVariable ["humanKills",0];
_banditKills = player getVariable ["banditKills",0];
_achievements = player getVariable ["Achievements",[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]];
_combattimeout = player getVariable["combattimeout",0];
_inCombat = player getVariable["inCombat",0];
_inCombat = player getVariable ["inCombat",false];
_ConfirmedHumanKills = player getVariable ["ConfirmedHumanKills",0];
_ConfirmedBanditKills = player getVariable ["ConfirmedBanditKills",0];
_friendlies = player getVariable ["friendlies",[]];
@@ -83,7 +83,7 @@ player setVariable ["characterID",_charID,true];
player setVariable ["worldspace",_worldspace];
player setVariable ["Achievements",_achievements];
player setVariable ["combattimeout",_combattimeout,false];
player setVariable ["inCombat", _inCombat, true];
player setVariable ["inCombat",_inCombat,true];
player setVariable ["ConfirmedHumanKills",_ConfirmedHumanKills,true];
player setVariable ["ConfirmedBanditKills",_ConfirmedBanditKills,true];

View File

@@ -34,7 +34,7 @@ while {(alive _projectile) && !(isNull _projectile) && (_callCount < 85)} do {
_isInCombat = _nearVehicle getVariable["startcombattimer",0];
if ((alive _nearVehicle) and _isInCombat == 0) then {
_nearVehicle setVariable["startcombattimer", 1];
_nearVehicle setVariable["inCombat", 1, true];
_nearVehicle setVariable["inCombat", true, true];
diag_log("Now in Combat (Player): " + name _unit);
};
};
@@ -44,7 +44,7 @@ while {(alive _projectile) && !(isNull _projectile) && (_callCount < 85)} do {
_isInCombat = _x getVariable["startcombattimer",0];
if (isPlayer _x and _isInCombat == 0 and alive _x) then {
_x setVariable["startcombattimer", 1];
_x setVariable["inCombat", 1, true];
_x setVariable["inCombat", true, true];
diag_log("Now in Combat (Crew): " + name _x);
};
} forEach (crew _nearVehicle);

View File

@@ -22,10 +22,14 @@ private ["_handled"];
// Both the firer and those nearby (<=8m) go into "combat" to prevent ALT-F4
//diag_log ("DEBUG: AMMO TYPE: " +str(_ammo));
_firer setVariable["startcombattimer", 1];
_firer setVariable["inCombat", 1, true];
if (_firer getVariable["inCombat",false]) then {
_firer setVariable["inCombat",true,true];
};
if (_distance <= 8) then {
_unit setVariable["startcombattimer", 1];
_unit setVariable["inCombat", 1, true];
if (_unit getVariable["inCombat",false]) then {
_unit setVariable["inCombat",true,true];
};
};
if (_inVehicle) exitWith {};

View File

@@ -3,6 +3,8 @@ _amm=_this select 4;
_this call (call compile GetText (configFile >> "CfgAmmo" >> _amm >> "muzzleEffect"));
//Handle combat in vehicle
if (player in (crew (_this select 0))) then {
player setVariable ["inCombat", 1, true];
if (player getVariable ["inCombat",false]) then {
player setVariable ["inCombat",true,true];
};
player setVariable["combattimeout", diag_tickTime + 30, false];
};

View File

@@ -344,7 +344,7 @@ while {1 == 1} do {
_startcombattimer = player getVariable["startcombattimer", 0];
if (_startcombattimer == 1) then { //Do not use _PlayerNearby it makes building impossible, this is handled in player_onPause.sqf just fine
player setVariable["combattimeout", diag_tickTime + 30, false];
player setVariable["inCombat", 1, true];
if (player getVariable["inCombat",false]) then {player setVariable["inCombat",true,true];};
player setVariable["startcombattimer", 0, false];
}; /* else {
if (_ZedsNearby && !_isPZombie) then { //this makes building a nightmare, this is handled in player_onPause.sqf just fine

View File

@@ -7,8 +7,8 @@ sched_playerActions = {
call fnc_usec_upgradeActions;
//combat check
if ((player getVariable ["combattimeout",0] < diag_tickTime) && {player getVariable ["inCombat", 0] > 0}) then {
player setVariable ["inCombat", 0, true];
if ((player getVariable ["combattimeout",0] < diag_tickTime) && {player getVariable ["inCombat",false]}) then {
player setVariable ["inCombat", false, true];
};
objNull