From 52e02b954c93d1ec2bf7ca42ed5d01e8324cdf6e Mon Sep 17 00:00:00 2001 From: vbawol Date: Sat, 2 Sep 2017 17:06:27 -0500 Subject: [PATCH] Optimize: nearestObjects use object instead of pos --- .../compile/EPOCH_SpawnTraderMiltia.sqf | 6 +- .../functions/EPOCH_fnc_addItemOverflow.sqf | 2 +- .../compile/inventory/EPOCH_equip.sqf | 82 +++++++++---------- .../compile/traders/EPOCH_startInteract.sqf | 2 +- .../craftingv2/EPOCH_crafting_checkGear.sqf | 2 +- .../craftingv2/EPOCH_crafting_craft.sqf | 2 +- .../EPOCH_server_unpackBackpack.sqf | 2 +- .../EPOCH_server_makeNPCTrade.sqf | 6 +- .../epoch_vehicle/EPOCH_load_storage.sqf | 6 +- .../init/server_securityfunctions.sqf | 2 +- 10 files changed, 56 insertions(+), 56 deletions(-) diff --git a/Sources/epoch_code/compile/EPOCH_SpawnTraderMiltia.sqf b/Sources/epoch_code/compile/EPOCH_SpawnTraderMiltia.sqf index 8fafd4b6..f94faddd 100644 --- a/Sources/epoch_code/compile/EPOCH_SpawnTraderMiltia.sqf +++ b/Sources/epoch_code/compile/EPOCH_SpawnTraderMiltia.sqf @@ -13,10 +13,10 @@ https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_SpawnTraderMiltia.sqf */ //[[[cog import generate_private_arrays ]]] -private ["_allpositions","_grp","_nrBuilds","_rndHouse","_startPos","_trgt","_unit"]; +private ["_allpositions","_grp","_nrBuilds","_rndHouse","_startPos","_unit"]; //[[[end]]] -_trgt = player; -_nrBuilds = nearestObjects [getPosATL _trgt,["house"],50]; + +_nrBuilds = nearestObjects [player,["house"],50]; _grp = createGroup [RESISTANCE, true]; for "_i" from 1 to 3 step 1 do diff --git a/Sources/epoch_code/compile/functions/EPOCH_fnc_addItemOverflow.sqf b/Sources/epoch_code/compile/functions/EPOCH_fnc_addItemOverflow.sqf index e05336a3..6b63d12a 100644 --- a/Sources/epoch_code/compile/functions/EPOCH_fnc_addItemOverflow.sqf +++ b/Sources/epoch_code/compile/functions/EPOCH_fnc_addItemOverflow.sqf @@ -35,7 +35,7 @@ for "_i" from 1 to _count do } else { _wH = objNull; if (isNil "_nearByHolder") then { - _nearByHolder = nearestObjects [position player,["groundWeaponHolder"],3]; + _nearByHolder = nearestObjects [player,["groundWeaponHolder"],3]; }; if (_nearByHolder isEqualTo []) then { _wHPos = player modelToWorld [0,1,0]; diff --git a/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf b/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf index 875b89f7..80b4d1cf 100644 --- a/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf +++ b/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf @@ -6,23 +6,23 @@ Description: Equips or un-equips item (if equipped) instantly. Item has to exist in the inventory. to switch weapons slowly use below in your code: player playAction "reloadMagazine"; - + _item - className _drop - drop on ground if inventory full, weapons will be stripped off attachments weapons stripped because attachments can only be added while weapon is equipped. _forceEquip - disables un-equip and forces new item to be equipped at all times - + Licence: Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike Github: https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/inventory/EPOCH_equip.sqf - Usage: + Usage: [_item, false] call epoch_equip; //don't drop item if inventory full. Does not equip requested item if another item already equipped, instead un-equips existing one. [_item, true,true] call epoch_equip; //drops item if not enough space. Removes existing weapon and equips new one. - - RETURNS: + + RETURNS: 0 - fail, item not provided 1 - success 2 - success, but item dropped on ground. @@ -55,7 +55,7 @@ _fnc_dropItem = { { _wH = objNull; if (isNil "_nearByHolder") then { - _nearByHolder = nearestObjects [position player,["groundWeaponHolder"],3]; + _nearByHolder = nearestObjects [player,["groundWeaponHolder"],3]; }; if (_nearByHolder isEqualTo []) then { _wHPos = player modelToWorld [0,1,0]; @@ -75,7 +75,7 @@ _fnc_dropItem = { _fnc_findItemInContainers = { private ["_item","_container","_index","_found","_currItem"]; params ["_item"]; - + _container = 0; _index = 0; _found = false; @@ -95,15 +95,15 @@ _fnc_findItemInContainers = { }; if _found exitWith {}; } forEach [_uniformItems,_vestItems,_bPackItems]; - + [_container,_index,_found] -}; +}; _fnc_moveWeaponFromContainer = { private ["_idx","_container","_sIdx","_dIdx"]; //_dIdx can only be 0, 1 and 2 - params ["_idx","_dIdx"]; + params ["_idx","_dIdx"]; _idx params ["_container","_sIdx"]; - + //copy old entry _temp = ((_loadout select (_container + 3)) select 1) select _sIdx select 0; //delete old entry @@ -116,14 +116,14 @@ _fnc_moveWeaponFromContainer = { _fnc_MoveWeaponToContainer = { private ["_container","_sIdx"]; //_sIdx can only be 0, 1 and 2 - params ["_container","_sIdx"]; - - /* + params ["_container","_sIdx"]; + + /* //Delete this block if no issues. //Commented out because increasing index alone is not enough due to unique attachement placements or ammo size _exists = _item call _fnc_findItemInContainers; _exists params ["_container","_idx","_found"]; - + if _found then { _cnt = ((_loadout select (_container + 3)) select 1) select _idx select 1; ((_loadout select (_container + 3)) select 1) select _idx set [1,_cnt + 1]; @@ -134,7 +134,7 @@ _fnc_MoveWeaponToContainer = { ((_loadout select (_container + 3)) select 1) append [[_loadout select _sIdx,1]]; //cut out from above comment, looks like appending alone works great _loadout set [_sIdx,[]]; - + player setUnitLoadout _loadout; }; @@ -150,13 +150,13 @@ _fnc_canMoveToContainer = { _fnc_dropEquipWeapon = { private ["_equipped","_slot"]; params ["_equipped","_slot"]; - + if (!_itemInInventory && (_item != _equipped)) exitWith {_return = 3}; //Item not found - + if (_equipped != "") then { //something equipped already if (player canAdd _equipped) then { //can we move it? _container = _equipped call _fnc_canMoveToContainer; - + if (_container != 4) then { [_container,_slot] call _fnc_MoveWeaponToContainer; _return = 1; @@ -193,13 +193,13 @@ _fnc_dropEquipWeapon = { _fnc_dropAssign= { private ["_equipped"]; params ["_equipped"]; - + if (!_itemInInventory && (_item != _equipped)) exitWith {_return = 3}; - + if (_equipped != "") then { if (player canAdd _equipped) then { _container = _equipped call _fnc_canMoveToContainer; - + if (_container != 4) then { player unassignItem _equipped; _return = 1; @@ -222,8 +222,8 @@ _fnc_dropAssign= { }; _fnc_MoveShellToContainer = { private ["_container"]; - params ["_container"]; - + params ["_container"]; + _temp = _loadout select 0 select 5; _temp2 = [(_temp select 0), 1, (_temp select 1)]; if ((_temp select 1) > 0) then { //only move if ammo not empty, delete otherwise @@ -235,12 +235,12 @@ _fnc_MoveShellToContainer = { _fnc_moveShellFromContainer = { private ["_idx","_container","_sIdx"]; //_dIdx can only be 0, 1 and 2 - params ["_idx"]; + params ["_idx"]; _idx params ["_container","_sIdx","_found"]; - + if (_found) then { _temp = ((_loadout select (_container + 3)) select 1) select _sIdx; - + if ((_temp select 1) > 1) then { _cnt = (((_loadout select (_container + 3)) select 1) select _sIdx) select 1; (((_loadout select (_container + 3)) select 1) select _sIdx) set [1,_cnt - 1]; @@ -255,13 +255,13 @@ _fnc_moveShellFromContainer = { _fnc_dropEquipShells = { private ["_equipped"]; params ["_equipped"]; - + if (!_itemInInventory && (_item != _equipped)) exitWith {_return = 3}; - + if (_equipped != "") then { if (player canAdd _equipped) then { _container = _equipped call _fnc_canMoveToContainer; - + if (_container != 4) then { [_container] call _fnc_MoveShellToContainer; _return = 1; @@ -287,11 +287,11 @@ _fnc_dropEquipShells = { _return = 1; }; _muzzle = (getArray (configFile >> "CfgWeapons" >> (primaryWeapon player) >> "muzzles")); - player selectWeapon (_muzzle select 1); + player selectWeapon (_muzzle select 1); }; _fnc_findAccessorySlot = { _item = toLower _item; - + private ["_found","_slot","_accessory","_compatibleMuzzles","_compatibleCows","_compatiblePointers","_compatibleBipods"]; _slot = 0; _accessory = 0; @@ -315,23 +315,23 @@ _fnc_findAccessorySlot = { for "_i" from 0 to (count _compatibleBipods) do { _compatibleBipods set [_i,toLower (_compatibleBipods select _i)]; }; - + if (_item in _compatibleMuzzles) exitWith {_found = true; _accessory = 1}; if (_item in _compatibleCows) exitWith {_found = true; _accessory = 3}; if (_item in _compatiblePointers) exitWith {_found = true; _accessory = 2}; if (_item in _compatibleBipods) exitWith {_found = true; _accessory = 6}; } forEach [(primaryWeapon player),(secondaryWeapon player),(handgunWeapon player)]; - + [_found,_slot,_accessory] }; _fnc_dropEquipAccessories = { - + _properties = call _fnc_findAccessorySlot; _properties params ["_found","_slot","_accessory"]; - + if !_found exitWith {_return = 5}; - + _itemsPlayer = (primaryWeaponItems player + secondaryWeaponItems player + handgunItems player); for "_i" from 0 to (count _itemsPlayer) do { _itemsPlayer set [_i,toLower (_itemsPlayer select _i)]; @@ -410,7 +410,7 @@ switch _slot do { "Use [Right Ctrl] + M to toggle GPS" call epoch_message; }; case "ItemMap": - { + { openMap true; }; case "ItemCompass": @@ -455,7 +455,7 @@ switch _slot do { private ["_allMuzzles","_muzzle","_found","_mags"]; if (_itemInInventory) then { _allMuzzles = getArray (configFile >> "CfgWeapons" >> "Put" >> "Muzzles"); - + _muzzle = ""; _found = false; { @@ -466,7 +466,7 @@ switch _slot do { } forEach _mags; if (_found) exitWith {}; } forEach _allMuzzles; - + player playActionNow "PutDown"; player selectWeapon _muzzle; player fire [_muzzle, _muzzle, _item]; @@ -474,7 +474,7 @@ switch _slot do { }; }; case 16: //Grenade launcher shells. - { + { _equipped = (primaryWeaponMagazine player) param [1,""]; _equipped call _fnc_dropEquipShells; }; diff --git a/Sources/epoch_code/compile/traders/EPOCH_startInteract.sqf b/Sources/epoch_code/compile/traders/EPOCH_startInteract.sqf index 55e41f66..1efd0490 100644 --- a/Sources/epoch_code/compile/traders/EPOCH_startInteract.sqf +++ b/Sources/epoch_code/compile/traders/EPOCH_startInteract.sqf @@ -18,7 +18,7 @@ if (!isNull cursorTarget) then { }; }; if (isNull _target) then { - _targets = nearestObjects [getPosATL player, ["WeaponHolder", "WeaponHolderSimulated"], 3]; + _targets = nearestObjects [player, ["WeaponHolder", "WeaponHolderSimulated"], 3]; if !(_targets isEqualTo []) then { _target = _targets select 0; _forceGear = true; diff --git a/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_checkGear.sqf b/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_checkGear.sqf index 2083441d..564d93f1 100644 --- a/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_checkGear.sqf +++ b/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_checkGear.sqf @@ -17,7 +17,7 @@ private ["_cN","_cP","_near","_nearObjects","_out","_player","_recipe"]; //[[[end]]] params ["_recipes"]; -_nearObjects = nearestObjects [position player,["WeaponHolder","LandVehicle","Air"],10]; +_nearObjects = nearestObjects [player,["WeaponHolder","LandVehicle","Air"],10]; _near = []; _out = []; { diff --git a/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_craft.sqf b/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_craft.sqf index e2ef50f3..62b1f376 100644 --- a/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_craft.sqf +++ b/Sources/epoch_code/gui/scripts/craftingv2/EPOCH_crafting_craft.sqf @@ -69,7 +69,7 @@ if !(false call EPOCH_crafting_checkResources) exitWith {}; }; } forEach _itemRecipeItems; - _nearByBench = nearestObjects [position player,["WorkBench_EPOCH"],3]; + _nearByBench = nearestObjects [player,["WorkBench_EPOCH"],3]; if (!(_nearByBench isEqualTo []) && (_needBench > 0)) then { //adds item on top of bench if bench was required (_nearByBench select 0) addItemCargoGlobal [_item,1]; diff --git a/Sources/epoch_server/compile/epoch_player/EPOCH_server_unpackBackpack.sqf b/Sources/epoch_server/compile/epoch_player/EPOCH_server_unpackBackpack.sqf index 9b0307a7..4d6322e3 100644 --- a/Sources/epoch_server/compile/epoch_player/EPOCH_server_unpackBackpack.sqf +++ b/Sources/epoch_server/compile/epoch_player/EPOCH_server_unpackBackpack.sqf @@ -20,7 +20,7 @@ params ["_item","_player",["_token","",[""]] ]; if !([_player,_token] call EPOCH_server_getPToken) exitWith {}; if (_item isKindOf "Bag_Base") then { _wH = objNull; - _nearByHolder = nearestObjects [position _player,["groundWeaponHolder"],3]; + _nearByHolder = nearestObjects [_player,["groundWeaponHolder"],3]; if (_nearByHolder isEqualTo []) then { _wHPos = _player modelToWorld [0,1,0]; if (surfaceIsWater _wHPos) then { diff --git a/Sources/epoch_server/compile/epoch_trading/EPOCH_server_makeNPCTrade.sqf b/Sources/epoch_server/compile/epoch_trading/EPOCH_server_makeNPCTrade.sqf index 82be32f3..a628d611 100644 --- a/Sources/epoch_server/compile/epoch_trading/EPOCH_server_makeNPCTrade.sqf +++ b/Sources/epoch_server/compile/epoch_trading/EPOCH_server_makeNPCTrade.sqf @@ -172,9 +172,9 @@ if (_slot != -1) then { if !(EPOCH_VehicleSlots isEqualTo[]) then { _position = getPosATL _player; - _helipad = nearestObjects[_position, ["Land_HelipadEmpty_F", "Land_HelipadCircle_F"], 100]; + _helipad = nearestObjects[_player, ["Land_HelipadEmpty_F", "Land_HelipadCircle_F"], 100]; _helipads = []; - _smoke = nearestObject[_position, "SmokeShell"]; + _smoke = nearestObject[_player, "SmokeShell"]; if (!isNull _smoke) then { _helipad pushBack _smoke; }; @@ -276,7 +276,7 @@ if (_slot != -1) then { if (_item isKindOf "Bag_Base") then { _wH = objNull; - _nearByHolder = nearestObjects [position _player,["groundWeaponHolder"],3]; + _nearByHolder = nearestObjects [_player,["groundWeaponHolder"],3]; if (_nearByHolder isEqualTo []) then { _wHPos = _player modelToWorld [0,1,0]; if (surfaceIsWater _wHPos) then { diff --git a/Sources/epoch_server/compile/epoch_vehicle/EPOCH_load_storage.sqf b/Sources/epoch_server/compile/epoch_vehicle/EPOCH_load_storage.sqf index 522082b3..d5a6d23c 100644 --- a/Sources/epoch_server/compile/epoch_vehicle/EPOCH_load_storage.sqf +++ b/Sources/epoch_server/compile/epoch_vehicle/EPOCH_load_storage.sqf @@ -38,9 +38,9 @@ for "_i" from 1 to _maxStorageLimit do { // legacy change class _class = switch (_class_raw) do { - case "LockBoxProxy_EPOCH": { "LockBox_EPOCH" }; - case "SafeProxy_EPOCH": { "Safe_EPOCH" }; - default { _class_raw }; + case "LockBoxProxy_EPOCH": { "LockBox_EPOCH" }; + case "SafeProxy_EPOCH": { "Safe_EPOCH" }; + default { _class_raw }; }; if !(_inventory isEqualType []) then { _inventory = []; }; diff --git a/Sources/epoch_server/init/server_securityfunctions.sqf b/Sources/epoch_server/init/server_securityfunctions.sqf index f60db450..eef4ca8b 100644 --- a/Sources/epoch_server/init/server_securityfunctions.sqf +++ b/Sources/epoch_server/init/server_securityfunctions.sqf @@ -391,7 +391,7 @@ for "_i" from 1 to 3 do { }; if ("MAP-LOOT" in _case) then { _temp = _temp + " - ,[' Loot Marker', [], {"+_skn_tg_map_loot+" = !"+_skn_tg_map_loot+"; if ("+_skn_tg_map_loot+") then {waitUntil {"+_skn_mapLootArray+" = nearestObjects[getPos player, ['WH_Loot', 'Animated_Loot'], 10000];uiSleep 10;!"+_skn_tg_map_loot+"};"+_skn_mapLootArray+" = []};['Loot MARKER',if ("+_skn_tg_map_loot+") then [{2},{1}]] call "+_skn_adminLog_PVC+"}, '2', []] + ,[' Loot Marker', [], {"+_skn_tg_map_loot+" = !"+_skn_tg_map_loot+"; if ("+_skn_tg_map_loot+") then {waitUntil {"+_skn_mapLootArray+" = nearestObjects[player, ['WH_Loot', 'Animated_Loot'], 10000];uiSleep 10;!"+_skn_tg_map_loot+"};"+_skn_mapLootArray+" = []};['Loot MARKER',if ("+_skn_tg_map_loot+") then [{2},{1}]] call "+_skn_adminLog_PVC+"}, '2', []] "; }; if ("MAP-VEHICLE" in _case) then {