Jump to content
Neviothr

Looking for a script that finds all units that are in buildings

Recommended Posts

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

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}
  • Like 1

Share this post


Link to post
Share on other sites

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

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"...

  • Like 1

Share this post


Link to post
Share on other sites

If it is a specific building you can put a trigger under it and use list command

  • Like 1

Share this post


Link to post
Share on other sites

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;
  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×