Replace forEach with Count

Use count where you do not need _forEachIndex variable, it's quicker
than forEach.
This commit is contained in:
icomrade
2014-05-27 15:37:57 -04:00
parent 91d246e64e
commit e54b9983dd
210 changed files with 890 additions and 890 deletions

View File

@@ -17,7 +17,7 @@ if (_option == 1) then {
_objectUID = _x getVariable ["ObjectUID","0"];
if (_objectUID != "0") then {
_x setDamage 0;
_key = format["CHILD:397:%1:", _objectUID]; // use UID if not "0" and ID is "0"
_key = format["CHILD:397:%1:", _objectUID]; // use UID if not "0" && ID is "0"
_data = "HiveExt" callExtension _key;
};
} else {
@@ -26,7 +26,7 @@ if (_option == 1) then {
_data = "HiveExt" callExtension _key;
};
};
} forEach _objects;
} count _objects;
_name = if (alive _player) then { name _player; } else { "Dead Player"; };
diag_log format ["MAINTAIN AREA BY %1 - %2 Objects at %3", _name, count _objects, (getPosATL _player)];
};
@@ -37,7 +37,7 @@ if (_option == 2) then {
_objectUID = _targetObj getVariable ["ObjectUID","0"];
if (_objectUID != "0") then {
_targetObj setDamage 0;
_key = format["CHILD:397:%1:", _objectUID]; // use UID if not "0" and ID is "0"
_key = format["CHILD:397:%1:", _objectUID]; // use UID if not "0" && ID is "0"
_data = "HiveExt" callExtension _key;
};
} else {

View File

@@ -5,7 +5,7 @@ _playerObj = nil;
_playerPos = [];
{
if ((getPlayerUID _x) == _playerUID) exitWith {_playerObj = _x;};
} forEach playableUnits;
} count playableUnits;
if (isNil "_playerObj") then {
diag_log format["nil player object attempting PV, :%1", _this];
@@ -53,7 +53,7 @@ if (!isNull _playerObj) then {
if (alive _playerObj) then {
_isplayernearby = (DZE_BackpackGuard and !_invehicle and ({(isPlayer _x) and (alive _x)} count (_playerPos nearEntities ["AllVehicles", 5]) > 1));
_isplayernearby = (DZE_BackpackGuard && !_invehicle && ({(isPlayer _x) && (alive _x)} count (_playerPos nearEntities ["AllVehicles", 5]) > 1));
// prevent saving more than 20 magazine items
_magazines = [(magazines _playerObj),20] call array_reduceSize;
@@ -66,6 +66,6 @@ if (!isNull _playerObj) then {
//Update Vehicle
{
[_x,"gear"] call server_updateObject;
} foreach (nearestObjects [_playerPos, dayz_updateObjects, 10]);
} count (nearestObjects [_playerPos, dayz_updateObjects, 10]);
};
};

View File

@@ -13,8 +13,8 @@ _newObject setVariable ["bodyName", _victimName, true];
_killer = _victim getVariable["AttackedBy", "nil"];
_killerName = _victim getVariable["AttackedByName", "nil"];
// when a zombie kills a player _killer, _killerName and _weapon will be "nil"
// we can use this to determine a zombie kill and send a customized message for that. right now no killmsg means it was a zombie.
// when a zombie kills a player _killer, _killerName && _weapon will be "nil"
// we can use this to determine a zombie kill && send a customized message for that. right now no killmsg means it was a zombie.
if (_killerName != "nil") then
{
_weapon = _victim getVariable["AttackedByWeapon", "nil"];

View File

@@ -31,7 +31,7 @@ if (_playerID == "") then {
_playerID = getPlayerUID _playerObj;
};
if ((_playerID == "") or (isNil "_playerID")) exitWith {
if ((_playerID == "") || (isNil "_playerID")) exitWith {
#ifdef DZE_SERVER_DEBUG
diag_log ("LOGIN FAILED: Player [" + _playerName + "] has no login ID");
#endif
@@ -54,7 +54,7 @@ while {_doLoop < 5} do {
_doLoop = _doLoop + 1;
};
if (isNull _playerObj or !isPlayer _playerObj) exitWith {
if (isNull _playerObj || !isPlayer _playerObj) exitWith {
#ifdef DZE_SERVER_DEBUG
diag_log ("LOGIN RESULT: Exiting, player object null: " + str(_playerObj));
#endif

View File

@@ -47,7 +47,7 @@ while {_doLoop < 5} do {
_doLoop = _doLoop + 1;
};
if (isNull _playerObj or !isPlayer _playerObj) exitWith {
if (isNull _playerObj || !isPlayer _playerObj) exitWith {
diag_log ("SETUP RESULT: Exiting, player object null: " + str(_playerObj));
};
@@ -112,7 +112,7 @@ if (count _medical > 0) then {
//["usecBleed",[_playerObj,_x,_hit]] call broadcastRpcCallAll;
usecBleed = [_playerObj,_x,_hit];
publicVariable "usecBleed";
} forEach (_medical select 8);
} count (_medical select 8);
//Add fractures
_fractures = (_medical select 9);
@@ -194,12 +194,12 @@ if (_randomSpot) then {
_mkr = "";
while {_findSpot} do {
_counter = 0;
while {_counter < 20 and _findSpot} do {
while {_counter < 20 && _findSpot} do {
// switched to floor
_mkr = "spawn" + str(floor(random _spawnMC));
_position = ([(getMarkerPos _mkr),0,spawnArea,10,0,2000,spawnShoremode] call BIS_fnc_findSafePos);
_isNear = count (_position nearEntities ["Man",100]) == 0;
_isZero = ((_position select 0) == 0) and ((_position select 1) == 0);
_isZero = ((_position select 0) == 0) && ((_position select 1) == 0);
//Island Check //TeeChange
_pos = _position;
_isIsland = false; //Can be set to true during the Check
@@ -210,11 +210,11 @@ if (_randomSpot) then {
};
};
if ((_isNear and !_isZero) || _isIsland) then {_findSpot = false};
if ((_isNear && !_isZero) || _isIsland) then {_findSpot = false};
_counter = _counter + 1;
};
};
_isZero = ((_position select 0) == 0) and ((_position select 1) == 0);
_isZero = ((_position select 0) == 0) && ((_position select 1) == 0);
_position = [_position select 0,_position select 1,0];
if (!_isZero) then {
//_playerObj setPosATL _position;

View File

@@ -59,15 +59,15 @@ if (_characterID != "0") then {
//diag_log ("Found Character...");
//Check if update is requested
if (_isNewPos or _force) then {
if (_isNewPos || _force) then {
//diag_log ("position..." + str(_isNewPos) + " / " + str(_force)); sleep 0.05;
if (((_charPos select 0) == 0) and ((_charPos select 1) == 0)) then {
if (((_charPos select 0) == 0) && ((_charPos select 1) == 0)) then {
//Zero Position
} else {
//diag_log ("getting position..."); sleep 0.05;
_playerPos = [round(direction _character),_charPos];
_lastPos = _character getVariable["lastPos",_charPos];
if (count _lastPos > 2 and count _charPos > 2) then {
if (count _lastPos > 2 && count _charPos > 2) then {
if (!_isInVehicle) then {
_distanceFoot = round(_charPos distance _lastPos);
};
@@ -80,7 +80,7 @@ if (_characterID != "0") then {
};
_character setVariable ["posForceUpdate",false,true];
};
if (_isNewGear or _forceGear) then {
if (_isNewGear || _forceGear) then {
//diag_log ("gear..."); sleep 0.05;
_playerGear = [weapons _character,_magazines];
//diag_log ("playerGear: " +str(_playerGear));
@@ -92,7 +92,7 @@ if (_characterID != "0") then {
_playerBackp = [typeOf _backpack,getWeaponCargo _backpack,getMagazineCargo _backpack];
};
};
if (_isNewMed or _force) then {
if (_isNewMed || _force) then {
//diag_log ("medical..."); sleep 0.05;
if (!(_character getVariable["USEC_isDead",false])) then {
//diag_log ("medical check..."); sleep 0.05;
@@ -143,10 +143,10 @@ if (_characterID != "0") then {
_character setVariable ["model_CHK",typeOf _character];
};
if (_onLadder or _isInVehicle or _isTerminal) then {
if (_onLadder || _isInVehicle || _isTerminal) then {
_currentAnim = "";
//If position to be updated, make sure it is at ground level!
if ((count _playerPos > 0) and !_isTerminal) then {
if ((count _playerPos > 0) && !_isTerminal) then {
_charPos set [2,0];
_playerPos set[1,_charPos];
};
@@ -167,7 +167,7 @@ if (_characterID != "0") then {
_temp = round(_character getVariable ["temperature",100]);
_currentState = [_currentWpn,_currentAnim,_temp];
if(DZE_FriendlySaving) then {
// save only last/most recent 5 entrys as we only have 200 chars in db field and weapon + animation names are sometimes really long 60-70 chars.
// save only last/most recent 5 entrys as we only have 200 chars in db field && weapon + animation names are sometimes really long 60-70 chars.
_friendlies = [(_character getVariable ["friendlies",[]]),5] call array_reduceSizeReverse;
_currentState set [(count _currentState),_friendlies];
};
@@ -177,10 +177,10 @@ if (_characterID != "0") then {
if (count _playerPos > 0) then {
_array = [];
{
if (_x > dayz_minpos and _x < dayz_maxpos) then {
if (_x > dayz_minpos && _x < dayz_maxpos) then {
_array set [count _array,_x];
};
} forEach (_playerPos select 1);
} count (_playerPos select 1);
_playerPos set [1,_array];
};
if (!isNull _character) then {
@@ -206,7 +206,7 @@ if (_characterID != "0") then {
_pos = _this select 0;
{
[_x, "gear"] call server_updateObject;
} forEach nearestObjects [_pos, dayz_updateObjects, 10];
} count nearestObjects [_pos, dayz_updateObjects, 10];
//[_charPos] call server_updateNearbyObjects;
//Reset timer

View File

@@ -37,7 +37,7 @@ if (_spawnDMG) then {
_array set [count _array,[_selection,_dam]];
_totaldam = _totaldam + _dam;
};
} forEach _hitpoints;
} count _hitpoints;
// just set low base dmg - may change later
@@ -49,7 +49,7 @@ if (_spawnDMG) then {
};
};
// TODO: check if uid already exists and if so increment by 1 and check again as soon as we find nothing continue.
// TODO: check if uid already exists && if so increment by 1 && check again as soon as we find nothing continue.
//Send request
_key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, _damage , _characterID, _worldspace, [], _array, _fuel,_uid];
@@ -104,9 +104,9 @@ PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
{
_selection = _x select 0;
_dam = _x select 1;
if (_selection in dayZ_explosiveParts and _dam > 0.8) then {_dam = 0.8};
if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
[_object,_selection,_dam] call object_setFixServer;
} forEach _array;
} count _array;
_object setFuel _fuel;

View File

@@ -28,7 +28,7 @@ _location = _worldspace select 1;
//Generate UID test using time
_uid = _worldspace call dayz_objectUID3;
// TODO: check if uid already exists and if so increment by 1 and check again as soon as we find nothing continue.
// TODO: check if uid already exists && if so increment by 1 && check again as soon as we find nothing continue.
//Send request
_key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, 0 , _characterID, _worldspace, [], [], 1,_uid];

View File

@@ -9,7 +9,7 @@ _activatingPlayer = _this select 5;
_characterID = _keySelected;
_isOK = isClass(configFile >> "CfgVehicles" >> _class);
if(!_isOK or isNull _object) exitWith { diag_log ("HIVE-pv3: Vehicle does not exist: "+ str(_class)); };
if(!_isOK || isNull _object) exitWith { diag_log ("HIVE-pv3: Vehicle does not exist: "+ str(_class)); };
diag_log ("PUBLISH: Attempt " + str(_object));
_dir = _worldspace select 0;
@@ -96,7 +96,7 @@ _key call server_hiveWrite;
{
_object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
_countr = _countr + 1;
} forEach _objWpnTypes;
} count _objWpnTypes;
//Add Magazines
_objWpnTypes = _magazines select 0;
@@ -105,7 +105,7 @@ _key call server_hiveWrite;
{
_object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
_countr = _countr + 1;
} forEach _objWpnTypes;
} count _objWpnTypes;
//Add Backpacks
_objWpnTypes = _backpacks select 0;
@@ -114,7 +114,7 @@ _key call server_hiveWrite;
{
_object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
_countr = _countr + 1;
} forEach _objWpnTypes;
} count _objWpnTypes;
_object setVariable ["ObjectID", _oid, true];

View File

@@ -115,11 +115,11 @@ while {1 == 1} do {
diag_log(format["CRASHSPAWNER: Loot spawn at '%1' with loot table '%2'", _crashName, _lootTable]);
// ReammoBox is preferred parent class here, as WeaponHolder wouldn't match MedBox0 and other such items.
// ReammoBox is preferred parent class here, as WeaponHolder wouldn't match MedBox0 && other such items.
_nearby = _position nearObjects ["ReammoBox", sizeOf(_crashModel)];
{
_x setVariable ["permaLoot",true];
} forEach _nearBy;
} count _nearBy;
};
};

View File

@@ -26,7 +26,7 @@ epoch_eventIsAny = {
};
if (!_boolReturn) exitWith {};
_index = _index + 1;
} forEach _event;
} count _event;
_boolReturn
};
@@ -54,7 +54,7 @@ while {1 == 1} do {
diag_log ("RUNNING EVENT: " + (_x select 5) + " on " + _datestr);
_handle = [] execVM "\z\addons\dayz_server\modules\" + (_x select 5) + ".sqf";
};
} forEach EpochEvents;
} count EpochEvents;
};
};
sleep 10;

View File

@@ -38,7 +38,7 @@ if(_objectID == "0" && _objectUID == "0") then {
};
_allowed = [_object, "Server"] call check_publishobject;
if (!_allowed or !_proceed) exitWith {
if (!_allowed || !_proceed) exitWith {
if(!isNull(_object)) then {
deleteVehicle _object;
};

View File

@@ -10,7 +10,7 @@ if(isNull(_object)) exitWith {
};
_type = _this select 1;
_parachuteWest = ((typeOf _object == "ParachuteWest") or (typeOf _object == "ParachuteC"));
_parachuteWest = ((typeOf _object == "ParachuteWest") || (typeOf _object == "ParachuteC"));
_isbuildable = (typeOf _object) in dayz_allowedObjects;
_isNotOk = false;
_firstTime = false;
@@ -25,7 +25,7 @@ if ((typeName _objectID != "string") || (typeName _uid != "string")) then
_objectID = "0";
_uid = "0";
};
if (!_parachuteWest and !(locked _object)) then {
if (!_parachuteWest && !(locked _object)) then {
if (_objectID == "0" && _uid == "0") then
{
_object_position = getPosATL _object;
@@ -33,8 +33,8 @@ if (!_parachuteWest and !(locked _object)) then {
};
};
// do not update if buildable and not ok
if (_isNotOk and _isbuildable) exitWith { };
// do not update if buildable && not ok
if (_isNotOk && _isbuildable) exitWith { };
// delete if still not ok
if (_isNotOk) exitWith { deleteVehicle _object; diag_log(format["Deleting object %1 with invalid ID at pos [%2,%3,%4]",typeOf _object,_object_position select 0,_object_position select 1, _object_position select 2]); };
@@ -90,7 +90,7 @@ _object_damage = {
_selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
_object setHit ["_selection", _hit];
} forEach _hitpoints;
} count _hitpoints;
_key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
//diag_log ("HIVE: WRITE: "+ str(_key));
@@ -110,7 +110,7 @@ _object_killed = {
if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
_hit = 1;
_object setHit ["_selection", _hit];
} forEach _hitpoints;
} count _hitpoints;
if (_objectID == "0") then {
_key = format["CHILD:306:%1:%2:%3:",_uid,_array,_damage];
@@ -145,7 +145,7 @@ _object_repair = {
_selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
_object setHit ["_selection", _hit];
} forEach _hitpoints;
} count _hitpoints;
_key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
//diag_log ("HIVE: WRITE: "+ str(_key));

View File

@@ -20,7 +20,7 @@ _numWeatherOptions = count _weatherOptions;
// get inital weather forcast for the next 5 minutes
_forcastTime = 300;
if (isNil "WeatherForcast" and isNil "WeatherForcastTime") then {
if (isNil "WeatherForcast" && isNil "WeatherForcastTime") then {
WeatherForcast = floor(random(_numWeatherOptions));
WeatherForcastTime = diag_tickTime;
} else {
@@ -40,7 +40,7 @@ if (isNil "CurrentWeatherOption") then {
CurrentWeatherOption = ((CurrentWeatherOption + 1) min _numWeatherOptions);
} else {
// start transition down if forcast is lower in the array than current weather
if (CurrentWeatherOption != WeatherForcast and WeatherForcastTime >= _forcastTime) then {
if (CurrentWeatherOption != WeatherForcast && WeatherForcastTime >= _forcastTime) then {
CurrentWeatherOption = ((CurrentWeatherOption - 1) max 0) ;
};
};