Jump to content
Sign in to follow this  
DaveP

AI Urban Building/Combat Positioning Script (with Example Mission)

Recommended Posts

Retreat to building is great idea ... well done..

I sure will try as soon as I get my copy

:bounce3:

Share this post


Link to post
Share on other sites

A very nice script!, but why in sqs? Isn't sqf far better performance wise?

Share this post


Link to post
Share on other sites

Could we have a demonstration video of these please?

Share this post


Link to post
Share on other sites
A very nice script!, but why in sqs? Isn't sqf far better performance wise?

Like I said, last time I scripted, functions were in their infancy; I have no clue how to make them

Could we have a demonstration video of these please?

I'll throw one together soonish

Edited by DaveP

Share this post


Link to post
Share on other sites

@DaveP: Sqf are no longer only a function type, but used for most scripting. You can do both functions (returning a value) and regular sqs type scripts with them, with a few changes.

Check sqf vs old sqs syntax.

Share this post


Link to post
Share on other sites

Just a quick issue, a lot of the time when units are placed they are spawned slightly too high or low in the building and die after around 15-30 seconds, leaving corpses. Is this a bug with the script or am I missing something?

Share this post


Link to post
Share on other sites

SQF variant of "Place in building" script:

/*
; ****************************************************************
; Place infantry in buildings script, by DaveP (BIStudio forum PM for help/info)
; Reworked into SQF by DiRaven (BIStudio forum PM for help/info)
; Free to use it in whatever and enjoy! Chop and change as you wish (credit is appreciated)
;
; Place soldier near building of choice, then:
; 	syntax:
;		unitname execVM "PlaceInBuilding.sqf"
;
; 	example:
;	(unit's init field)
;		_script = this execVM "PlaceInBuilding.sqf"
;
;Extra info:
;-Removes hand grenades, otherwise dumb infantry try and throw a grenade from inside a building and frag themselves
;-Will delete unit if no building position is found
; ****************************************************************
*/
_unit = _this;
_arr_buildings = nearestObjects [_unit, ["HOUSE"], 50];
_buildingcount = count _buildings;

_arr_positions = [];
{
_i = 0;
_positions_checked = FALSE;
while {not _positions_checked} do {
	_position = _x buildingPos _i;
	_coord_x = _position select 0;
	_coord_y = _position select 1;
	_coord_z = _position select 2;
	_coord_sum = _coord_x + _coord_y + _coord_z;
	if (_coord_sum == 0) then {
		_positions_checked = TRUE;
	} else {
		_arr_positions = _arr_positions + [_position];
		_i = _i + 1;
	};
};
} foreach _arr_buildings;

if (count _arr_positions == 0) then {
deleteVehicle _unit;
};

_position = _arr_positions select random count _arr_positions;

_unit setPos _position;
_unit setDir random 360;

_unit removeWeapon "HandGrenade_East"; _unit removeMagazines "HandGrenade_East";
_unit removeWeapon "HandGrenade_West"; _unit removeMagazines "HandGrenade_West";
_unit removeWeapon "HandGrenade"; _unit removeMagazines "HandGrenade";
_unit setUnitPos "UP";

---------- Post added at 06:38 PM ---------- Previous post was at 06:36 PM ----------

Just a quick issue, a lot of the time when units are placed they are spawned slightly too high or low in the building and die after around 15-30 seconds, leaving corpses. Is this a bug with the script or am I missing something?

According to the script code it is problem of the building LOD, not the script itself. Script just gets one of the available positions predefined by LOD and places soldier there. Nothing less, nothing more.

Edited by DiRaven

Share this post


Link to post
Share on other sites

So is there anything that can be done to remedy it?

Share this post


Link to post
Share on other sites

You can search for buggy houses/positions and restrict them in the script. But it is a lot of work. Mostly needless. In future versions this issues might be fixed by the developers.

For now with my current level of knowladge i do not have any idea to solve the problem.

---------- Post added at 07:20 PM ---------- Previous post was at 07:02 PM ----------

BTW u can remove dead units by the script to make feeling that nothing happened. =))

---------- Post added at 07:30 PM ---------- Previous post was at 07:20 PM ----------

Improved variant of the script to place infantry groups into the buildings:

/*
==========================================================================
Place infantry groups in buildings script 
==========================================================================
Credits:
Original idea is by DaveP.
Improved, reworked into SQF and changed to group positioning by [MB]  DiRaven
You can use, rework, change and enjoy this script anyhow you want.
Still credit is appreciated.
==========================================================================
Description:
This script places desired group of infantry units into the nearest available buildings.
==========================================================================
HowTo:

Place group leader near building of choice, then:
	syntax for scripts:
	group execVM "PlaceInBuilding.sqf"

	syntax for init field for the leader of the desired group:
	_script = group this execVM "PlaceInBuilding.sqf"

Extra info:
- Removes hand grenades, otherwise dumb infantry try and throw a grenade from inside a building and frag themselves
- Will delete group if no building position is found
- Buildings id being searched near group leader's position
- All members of the group are each joined into another newly created groups to prevent them from getting back into formation
- You can change _check_distance variable to change search distance for entrable buildings
==========================================================================
History:
v0.1 - First version of the script.
==========================================================================
*/
_group = _this;

_leader = leader _group;

_check_distance = 50; // Change this to tweak building searching distance

_arr_buildings = nearestObjects [_leader, ["HOUSE"], _check_distance];
_buildingcount = count _buildings;

_arr_positions = [];
{
_i = 0;
_positions_checked = FALSE;
while {not _positions_checked} do {
	_position = _x buildingPos _i;
	_coord_x = _position select 0;
	_coord_y = _position select 1;
	_coord_z = _position select 2;
	_coord_sum = _coord_x + _coord_y + _coord_z;
	if (_coord_sum == 0) then {
		_positions_checked = TRUE;
	} else {
		_arr_positions = _arr_positions + [_position];
		_i = _i + 1;
	};
};
} foreach _arr_buildings;

{
_newgroup = createGroup side _leader;

[_x] join _newgroup;

if (count _arr_positions == 0) then {
	deleteVehicle _x;
};

_position = _arr_positions select random count _arr_positions;

_x setPos _position;
_x setDir random 360;

_x removeWeapon "HandGrenade_East"; _x removeMagazines "HandGrenade_East";
_x removeWeapon "HandGrenade_West"; _x removeMagazines "HandGrenade_West";
_x removeWeapon "HandGrenade"; _x removeMagazines "HandGrenade";
_x setUnitPos "UP";
} foreach units _group;

Version listed above is not the last one, last one available here.

Edited by DiRaven

Share this post


Link to post
Share on other sites

Thread resurrection! :)

Is there a way to check if a building position is already occupied by another unit (not placed into the position by the script)?

I want to move a group of infantry into editor placed trenches and bunkers with the script. However some of the positions are already occupied by friendly units and I only want to move the new units into empty positions of course...

Share this post


Link to post
Share on other sites

Assuming that you don't want to edit the other script to be compatible, the only way I cant think of is checking if there is a unit within 1 meter of the position using nearObjects with "man". And even that would not be reliable because if another AI is moving towards that position but isn't there yet it still won't work.

The only reliable way to make AI work together is to make their scripts work together as well.

Share this post


Link to post
Share on other sites

Thank you for digging this up! Looks nice :)

So, does this script work in OA? I.e. it doesn't screw up with the changed buildings?

(Same question for Tophe's House Patrol - http://www.armaholic.com/page.php?id=6078 - does it work in OA, too?)

Cheers.

Edit: From Tophe's Script's Armaholic page;

Will you be porting this script over to arrowhead? as alls i get is the guard cannot patrol that building due to game bug, choose another building, which i do and it comes up again....

Guess it doesn't :(

Edited by HateDread

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
Sign in to follow this  

×