From 0a17804e36c6ca90e2400be5bc817d38457e7881 Mon Sep 17 00:00:00 2001 From: ebaydayz Date: Sat, 1 Oct 2016 13:07:59 -0400 Subject: [PATCH] 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 --- Documents/1.0.6 Variable Name Changes.txt | 2 +- SQF/dayz_code/compile/fn_damageHandler.sqf | 19 ++++++++++--------- SQF/dayz_code/compile/player_death.sqf | 2 +- .../compile/player_humanityMorph.sqf | 4 ++-- .../compile/player_projectileNear.sqf | 4 ++-- .../compile/player_weaponFiredNear.sqf | 8 ++++++-- SQF/dayz_code/system/BIS_Effects/fired.sqf | 4 +++- SQF/dayz_code/system/player_spawn_2.sqf | 2 +- .../system/scheduler/sched_playerActions.sqf | 4 ++-- .../compile/server_onPlayerDisconnect.sqf | 4 ++-- SQF/dayz_server/compile/server_playerSync.sqf | 2 +- 11 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Documents/1.0.6 Variable Name Changes.txt b/Documents/1.0.6 Variable Name Changes.txt index 47bdfecf4..2a226d9c7 100644 --- a/Documents/1.0.6 Variable Name Changes.txt +++ b/Documents/1.0.6 Variable Name Changes.txt @@ -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 diff --git a/SQF/dayz_code/compile/fn_damageHandler.sqf b/SQF/dayz_code/compile/fn_damageHandler.sqf index eb6339359..e5567c5cb 100644 --- a/SQF/dayz_code/compile/fn_damageHandler.sqf +++ b/SQF/dayz_code/compile/fn_damageHandler.sqf @@ -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;}; diff --git a/SQF/dayz_code/compile/player_death.sqf b/SQF/dayz_code/compile/player_death.sqf index 72e6588dc..4fb45eada 100644 --- a/SQF/dayz_code/compile/player_death.sqf +++ b/SQF/dayz_code/compile/player_death.sqf @@ -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; diff --git a/SQF/dayz_code/compile/player_humanityMorph.sqf b/SQF/dayz_code/compile/player_humanityMorph.sqf index 039d10dfa..d134b181d 100644 --- a/SQF/dayz_code/compile/player_humanityMorph.sqf +++ b/SQF/dayz_code/compile/player_humanityMorph.sqf @@ -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]; diff --git a/SQF/dayz_code/compile/player_projectileNear.sqf b/SQF/dayz_code/compile/player_projectileNear.sqf index b945cd977..0c19ecf47 100644 --- a/SQF/dayz_code/compile/player_projectileNear.sqf +++ b/SQF/dayz_code/compile/player_projectileNear.sqf @@ -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); diff --git a/SQF/dayz_code/compile/player_weaponFiredNear.sqf b/SQF/dayz_code/compile/player_weaponFiredNear.sqf index 1c9dc4f86..e47c03e11 100644 --- a/SQF/dayz_code/compile/player_weaponFiredNear.sqf +++ b/SQF/dayz_code/compile/player_weaponFiredNear.sqf @@ -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 {}; diff --git a/SQF/dayz_code/system/BIS_Effects/fired.sqf b/SQF/dayz_code/system/BIS_Effects/fired.sqf index 3224775f6..0c8e0ea49 100644 --- a/SQF/dayz_code/system/BIS_Effects/fired.sqf +++ b/SQF/dayz_code/system/BIS_Effects/fired.sqf @@ -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]; }; \ No newline at end of file diff --git a/SQF/dayz_code/system/player_spawn_2.sqf b/SQF/dayz_code/system/player_spawn_2.sqf index 77386e28c..f03e0d971 100644 --- a/SQF/dayz_code/system/player_spawn_2.sqf +++ b/SQF/dayz_code/system/player_spawn_2.sqf @@ -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 diff --git a/SQF/dayz_code/system/scheduler/sched_playerActions.sqf b/SQF/dayz_code/system/scheduler/sched_playerActions.sqf index 25721e7cb..ab51928bb 100644 --- a/SQF/dayz_code/system/scheduler/sched_playerActions.sqf +++ b/SQF/dayz_code/system/scheduler/sched_playerActions.sqf @@ -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 diff --git a/SQF/dayz_server/compile/server_onPlayerDisconnect.sqf b/SQF/dayz_server/compile/server_onPlayerDisconnect.sqf index 6dcd0f438..9a0003643 100644 --- a/SQF/dayz_server/compile/server_onPlayerDisconnect.sqf +++ b/SQF/dayz_server/compile/server_onPlayerDisconnect.sqf @@ -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]; diff --git a/SQF/dayz_server/compile/server_playerSync.sqf b/SQF/dayz_server/compile/server_playerSync.sqf index b7538bde4..f107750b8 100644 --- a/SQF/dayz_server/compile/server_playerSync.sqf +++ b/SQF/dayz_server/compile/server_playerSync.sqf @@ -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