Jump to content
HazJ

Return direction of a door

Recommended Posts

Hi all,

I have this little function that creates booby traps on doors. I can't seem to figure out how to return the direction of a door though. Any ideas?

/*
	Code written by Haz
*/

scriptName "fn_doorBoobyTraps";
#define __FILENAME "fn_doorBoobyTraps.sqf"

// #include "..\..\..\includes.sqf"

// __tky_starts;

CQBCleanupArr = [];
pt_tripmines = [];

// TODO: Code refactoring

// (?) TODO: Switch to a blacklist approach rather than whitelist?
_eligibleBuildings = [
	/*
	"Land_building_Big_01_F",
	"Land_building_Small_01_F",
	"Land_building_Small_02_F",
	"Land_building_Small_03_F",
	"Land_building_Small_04_F",
	"Land_building_Small_05_F",
	"Land_building_Small_06_F",
	"Land_Shed_02_F",
	"Land_Shed_05_F",
	"Land_Shop_Town_01_F",
	"Land_Shop_Town_03_F",
	"Land_Slum_01_F",
	"Land_Slum_03_F",
	"Land_i_building_Big_01_V2_F",
	"Land_i_building_Big_02_V1_F",
	"Land_i_building_Big_02_V2_F",
	"Land_i_building_Big_02_V3_F",
	"Land_i_building_Small_02_V2_F",
	"Land_i_building_Small_02_V3_F",
	"Land_i_Shed_Ind_F",
	"Land_i_Stone_buildingSmall_V1_F",
	"Land_i_Stone_buildingSmall_V2_F",
	"Land_i_Stone_buildingSmall_V3_F",
	"Land_u_building_Big_01_V1_F",
	"Land_u_building_Small_02_V1_F"
	*/
];

_fnc_getDoors = {
	params ["_building"];
	_buildingPositions = _building buildingPos -1;
	_buildingPosition = selectRandom _buildingPositions;
	hintSilent str selectionNames _building;
	{
		_arrow = "Sign_Arrow_Cyan_F" createVehicleLocal _x;
		_arrow setPosATL _x;
	} forEach _buildingPositions;
	_doors = [];
	_doorPositions = [];
	_worldPos = [];
	_inModelPosition = [];
	{
		if (_x find "door" >= 0 and _x find "handle" < 0) then {
			_doors pushBack _x;
			_inModelPosition = _building selectionPosition _x;
			hintSilent str _inModelPosition;
			_arrow = "Sign_Arrow_Yellow_F" createVehicleLocal [0, 0, 0];
			_arrow setPos (_building modelToWorld _inModelPosition);
			// _doorPositions pushBack (getPosATL _arrow);
			_doorPositions pushBack [getPosATL _arrow, 0]; // TODO: Figure out how to return the direction of a door
		};
	} forEach selectionNames _building;
	_doorPositions
};

_fnc_createMine = {
	params ["_pos", "_dir"];
	_building = nearestBuilding _pos;
	_m = createMine ["APERSTripMine", _pos, [], 0];
	_m setDir _dir;
	CQBCleanupArr pushBack _m;
	pt_tripmines pushBack _m;
	// [_m, "mymine"] call fnc_setVehicleName;
	_m
};

{
	_doors = _x call _fnc_getDoors;
	{
		_x params ["_pos", "_dir"];
		systemChat format [":: %1", _x];
		[_pos, _dir] spawn _fnc_createMine;
	} forEach _doors;
} forEach nearestObjects [player, _eligibleBuildings, 500];

// __tky_ends;

There are some elevation issues that I haven't addressed yet. Though that isn't the focus at the moment.

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Hi @HazJ I have solution for this in my door breach script but the way it gets the door direction is that it selects direction (front or back of the door) closest to player for the bomb surface. So this code probably wont directly work for you but hopefully it gives you idea how to implement this. The script is also not standalone but look for _doorDir variable

 

the function:

 


placeExplosiveOnDoor =
{
params ["_plr","_projectile"];

_bldg = nearestBuilding _plr;
_doorIndex = [_bldg,getposatl _plr] call getNearestDoorIndex;
if(_doorIndex < 0) exitwith { };

_doorpos = [_bldg,_doorIndex] call getDoorPos;


if(_doorpos distance _plr > MAX_DOOR_EXPLOSIVE_DIST) exitWith { };

private _pos = _bldg selectionPosition format ["Door_%1", _doorIndex];
private _posTrigger = _bldg selectionPosition format ["Door_%1_trigger", _doorIndex];
private _posAxis = _bldg selectionPosition format ["Door_%1_axis", _doorIndex];



_doorAngle = _posTrigger getdir _posAxis;

_vec = [];
_aa = 0;
_doorDir = -1;

_closestDist = 100000;
_doorFrontPos = [];
{

_distFromDoor = 0.05;
_tryAngle = _doorAngle + _x;

_x = sin _tryAngle * _distFromDoor;
_y = cos _tryAngle * _distFromDoor;

_vec = [_x,_y,0];

_checkPos = _posTrigger vectorAdd _vec;

_checkPos = _bldg modelToWorld _checkPos;
_dist = _checkPos distance2D _plr;

if(_dist < _closestDist) then
{
_closestDist = _dist;
_doorFrontPos = _checkPos;
_aa = _tryAngle;

_cen = _bldg modelToWorld _posTrigger;
_doorDir = _cen getdir _checkPos; // Get where the door is pointing in world coords

};
} foreach [90,-90];


_chargepos = _doorFrontPos;

_projectile setposAtl _chargepos;


_projectile setVectorDirAndUp [[sin _doorDir,cos _doorDir,0],[0,0,1]];

};

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Interesting problem.  Please post your solution when you find it.  I had a similar issue with determining which side of door was where the handle and latch are.  I needed this for my shotgun breach script that is part of my AI Movement Scripts.  Unit needs to shoot where the door handle is, and not at the hinged side of the door.  In the small set of buildings I was dealing with (about 10), the handle position was on one side, but the big building Land_i_House_Big_01_V1_F was reversed.  So I decided to black list.  But like you said, a true function to determine this would be way better.  I wonder if your solution to door swing direction will also solve my door handle position problem.

 

Anyway, I love your script idea.  Booby trapping doors is awesome!🚶‍♂️🚪🔥

  • Like 2

Share this post


Link to post
Share on other sites
2 hours ago, johnnyboy said:

Interesting problem.  Please post your solution when you find it.  I had a similar issue with determining which side of door was where the handle and latch are.  I needed this for my shotgun breach script that is part of my AI Movement Scripts.  Unit needs to shoot where the door handle is, and not at the hinged side of the door.  In the small set of buildings I was dealing with (about 10), the handle position was on one side, but the big building Land_i_House_Big_01_V1_F was reversed.  So I decided to black list.  But like you said, a true function to determine this would be way better.  I wonder if your solution to door swing direction will also solve my door handle position problem.

 

Anyway, I love your script idea.  Booby trapping doors is awesome!🚶‍♂️🚪🔥

At the moment, the mission places charges on doors using preset relative positions using handmade data for a small number of buildings. But the data is unreliable (I made it while drunk) and players get to know where the charges will.

  • Haha 2

Share this post


Link to post
Share on other sites

Here's the current implementation in action.

But it uses premade door positions figured out by hand. It's very effective, but a bit precidctable.

  • Like 3

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

×