Neviothr 102 Posted April 11, 2016 Does anyone know of a script that finds all the units which are inside a building, and then executes a code for all of those units? Thanks in advance. Share this post Link to post Share on other sites
Benoit Katecpo 2 Posted April 11, 2016 You can use findNearestEnnemy (https://community.bistudio.com/wiki/findNearestEnemy), and then execute the code with the returned array ;) Can be also used with https://community.bistudio.com/wiki/nearEntities nearEntities, it's more adapted to your demand :) 1 Share this post Link to post Share on other sites
ceeeb 147 Posted April 11, 2016 Here's a function I came up with to check if a unit or position is inside any building. I originally scripted it to do some pretests for nearby buildings before testing intersections, but it performed worse than the simplest way. For my purposes being inside includes standing on ground under a roof or other structure, or standing on top a building with nothing overhead. This might not match your expectations, but it should be easy enough to apply a more strict definition of being inside. /************************************************************************** File: CEEB_fnc_isInsideBuilding.sqf Description: (Function) Check if an object or position is within a building Version: 2016.01.27 Author(s): - ceeeb http://forums.bistudio.com/member.php?50952 License: This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ Input: - Parameter: (OBJECT) or (POSITION) ASL format Output: - Return: (BOOLEAN) true if object/position is within a building Dependencies: - **************************************************************************/ scriptName "CEEB_fnc_isInsideBuilding.sqf"; private ["_posASL", "_buildings", "_nearObjects"]; //check if parameter is a pos of object switch (typeName _this) do { case "ARRAY" : {_posASL = _this}; case "OBJECT" : {_posASL = getPosASL _this}; }; //get objects above and below _nearObjects = lineIntersectsWith [ [_posASL select 0, _posASL select 1, (_posASL select 2) + 40], [_posASL select 0, _posASL select 1, (_posASL select 2) - 2], objNull, objNull, true ]; //cull any that are not buildings { if (not (_x isKindOf "building")) then {_nearObjects = _nearObjects - [_x]}; } forEach _nearObjects; //if some left, must be inside if (count _nearObjects > 0) then {true} else {false} 1 Share this post Link to post Share on other sites
Neviothr 102 Posted April 12, 2016 I tried to use the next script from this thread: https://forums.bistudio.com/topic/170467-determine-if-unit-is-outside-a-building/?p=2662697 { if (count (lineIntersectsObjs [(getPosASL _x), [(getPosASL _x select 0), (getPosASL _x select 1), ((getPosASL _x select 2) + 20)]]) == 0) then { hint "works"; }; } forEach allUnits; But it always hints "works", any ideas? Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 12, 2016 idk what the mistake is but i tested this with allPlayers and it worked: { if (count (lineIntersectsObjs [(getPosASL _x), [(getPosASL _x select 0), (getPosASL _x select 1), ((getPosASL _x select 2) + 20)]]) == 0) then { hint "works"; } else { hint "wall" }; } forEach allPlayers; If i was inside a building it hinted "wall" outside it hinted "works"... 1 Share this post Link to post Share on other sites
Neviothr 102 Posted April 12, 2016 Ended up using CBA_fnc_taskDefend :p https://dev.withsix.com/docs/cba/files/ai/fnc_taskDefend-sqf.html Share this post Link to post Share on other sites
killzone_kid 1331 Posted April 12, 2016 If it is a specific building you can put a trigger under it and use list command 1 Share this post Link to post Share on other sites
davidoss 552 Posted April 12, 2016 killzone_kid what about your function KK_fnc_inHouse ? Could this be used here? _KK_fnc_inHouse = { lineIntersectsSurfaces [ getPosWorld _this, getPosWorld _this vectorAdd [0, 0, 50], _this, objNull, true, 1, "GEOM", "NONE" ] select 0 params ["","","","_house"]; if (_house isKindOf "House") exitWith {true}; false }; _inbuildingUnits =[]; { if (_x call _KK_fnc_inHouse) then { _inbuildingUnits pushback _x; }; } count allunits; 2 Share this post Link to post Share on other sites