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

@@ -15,7 +15,7 @@
- dayz_allowedObjects --> DayZ_SafeObjects
- dayz_CLBase --> dz_loot_groups (similar not identical)
- dayz_CLChances --> dz_loot_weighted (similar not identical)
- dayz_combat --> no longer exists use (player getVariable["combattimeout",0] >= diag_tickTime)
- dayz_combat --> no longer exists use (player getVariable["inCombat",false])
- dayz_fullMoonNights --> dayz_ForcefullmoonNights
- dayz_MapArea --> no longer exists (was only used for DynamicVehicleArea and HeliCrashArea)
- dayz_sellDistance_vehicle, dayz_sellDistance_boat, dayz_sellDistance_air --> Z_VehicleDistance

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")] };
@@ -174,10 +175,9 @@ if (_unit == player) then {
if (!_isZombieHit) then { // don't log any zombie wounds, even from remote zombies
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",[]];

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

View File

@@ -27,7 +27,7 @@ if (isNil "_playerObj") exitWith {
//If the the playerObj exists lets run all sync systems
_characterID = _playerObj getVariable["characterID", "?"];
_inCombat = _playerObj getVariable ["inCombat",0];
_inCombat = _playerObj getVariable ["inCombat",false];
_Sepsis = _playerObj getVariable["USEC_Sepsis",false];
//Login processing do not sync
@@ -58,7 +58,7 @@ if (_characterID != "?") exitwith {
*/
//Punish combat log
if (_inCombat > 0 && _playerPos distance (getMarkerPos "respawn_west") > 1500) then {
if (_inCombat && _playerPos distance (getMarkerPos "respawn_west") > 1500) then {
// Moved setVariables to server_playerSync since they are high priority
// Messages are low priority. Player object not needed
diag_log format["PLAYER COMBAT LOGGED: %1(%3) at location %2",_playerName,_playerPos,_playerUID];

View File

@@ -149,7 +149,7 @@ if (_currentModel == _modelChk) then {
_character setVariable ["model_CHK",typeOf _character];
};
if (count _this > 4) then { //calling from player_onDisconnect
if (_this select 4 > 0) then { //combat logged
if (_this select 4) then { //combat logged
_medical set [1, true]; //set unconcious to true
_medical set [10, 150]; //combat timeout
//_character setVariable ["NORRN_unconscious",true,true]; // Set status to unconscious