Jump to content
Sign in to follow this  
mikey74

AI respawn script

Recommended Posts

http://www76.zippyshare.com/v/12475526/file.html

updated 8/27/2013

Now mind you this is set on Atlis. But you can still use these scripts on stratis.

This is a respawn script from Arma 2. Its not completely mine. I looked at a few and edited them to my liking and mostly for learning. Norrin AIrespawn script, Murkspawn script And had help long long time ago by ArmaholicII, and cobra. It basically respawns any AI you put on map after they are killed or incompasitated.

_nil = [this, 7, 1, "spawnMarker", "operationMarker", "Operation", "start"] execvm "Init_respawn.sqf";

this is the actual AI unit, AI Vehicle, or AI group you want to respawn.

7 is how many times you want the AI to respawn.

1 is how many seconds delay before AI respawns.

"spawnMarker" would be the name of the marker you wish them to respawn at.

"operationMarker" would be the area you want the AI to operate in.

"Operation" would be the operation you want them to perform ie "attack", "defend", or "patrol".

"start" will start Operations before respawn, and nothing there will start operations after respawn. This way if you want them to do something else at start you can. Good for counter attacks, or simulating reinforcements.

Remember quotes on the last four expressions you want to achieve.

Don't forget to put both Init_respawn.sqf and AI_respawn.sqf scripts in your mission folder. Or else when the game makes the script call it will not know what you want it to do. ;)

This works with groups of AI with men, but on the vehicle end it only will do 1 vehicle at a time.

So far I haven't figure out how to respawn groups of vehicles so just use one vehicle unit per script call. IT will work with groups of men though. ;) More details in my latest post.

Feel free to use as you want as I used it to learn and make mission with my son. I've never really shared anything before. Hope it makes your gameing experience easier and less taxing on your PC. :)

Edited by Mikey74

Share this post


Link to post
Share on other sites

Thanks for a great script! Do you have any idea how to make it work on civilians? I have got it working on OPFOR and BLUFOR; havn't tested Independent yet but I figured it wouldn't be possible until a later update.

Share this post


Link to post
Share on other sites

Does anyone have any idea how to make this work for the current beta version... I have errors on it. Converted to new class names fine but errors not respawning.

Share this post


Link to post
Share on other sites

WOW I should subscribe to my own threads. lol ummm here is my latest script of respawning. lol 5 MONTHS later. lol sorry guys didnt think anyone was interested at alll.

Paste this in units leaders init: _nil = [this, 7, 1, "spawnMarker", "operationMarker", "Operation", "start"] execvm "Init_respawn.sqf";

Make sure the spawnMarker, OperationMarker are correctly labled from your own unique marker name with quotes. As for operation attack, defend, and patrol which ever you choose must be in quotes as well.

/*_nil = [this, 7, 1, "spawnMarker", "operationMarker", "Operation", "start"] execvm "Init_respawn.sqf";  Would be put into leading AI units init to perform AI respawn.
Below this line is a detailed explanation of what each means:
this is the actual AI unit, AI Vehicle, or AI group you want to respawn.
7 is how many times you want the AI to respawn. 
1 is how many seconds delay before AI respawns.
"spawnMarker" would be the name of the marker you wish them to respawn at.
"operationMarker" would be the area you want the AI to operate in.
"Operation" would be the operation you want them to perform ie "attack", "defend", or "patrol".
"start" will start Operations before respawn, and nothing there will start operations after respawn. This way if you want them to do something else at start you can. Good for counter attacks, or simulating reinforcements.
Remember quotes on the last four expressions you want to achieve.
Don't forget to put both Init_respawn.sqf and AI_respawn.sqf scripts in your mission folder. Or else when the game makes the script call it will not know what you want it to do. ;)
This works with groups of AI with men, but on the vehicle end it only will do 1 vehicle at a time.*/
if (!isServer) exitWith {};
//private ["_countThis","_unit","_rspawns","_delay","_spawn","_where","_task","_rad","_when"];
_countThis = 0;
SPscript = compile preprocessFileLineNumbers "AI_respawn.sqf";
PTscript = compile preprocessFileLineNumbers "fn_taskPatrol.sqf";
DFscript = compile preprocessFileLineNumbers "fn_taskDefend.sqf";
ATscript = compile preprocessFileLineNumbers "fn_taskAttack.sqf";
_countThis 		= count _this;
_unit 			= _this select 0;
_rspawns		= _this select 1;
_delay			= _this select 2;
_spawn			= _this select 3;
_where			= _this select 4; 
_warad			= getMarkerSize _where;
_ard			= getMarkerSize _where select 0;
_brd			= getMarkerSize _where select 1;
_warad			= _ard + _brd;
_warad			= random _warad + 20;
_task 			= _this select 5;
//_Rad			= _this select 6; 
_when			= if (_countThis == 7) then {_this select 6;} else { ""};
//hint format ["%1 %2 %3", _warad, _ard, _brd];
_group			= group _unit;
if (_when == "start") then { 
if (_task == "attack") then {_attack = [_group, _where, _warad] spawn ATscript;};
if (_task == "patrol") then {_patrol = [_group, _where, _warad] spawn PTscript;};
if (_task == "defend") then {_defend = [_group, _where] spawn DFscript;};
};
_spawn = [_unit, _rspawns, _delay, _spawn, _where, _task, _when, _warad] spawn SPscript;

if (true) exitWith {};

That script will call this one:

if (!isServer) exitWith {};

//_countThis 		= count _this;
_unit 			= _this select 0;
_type 			= typeOf _unit;
_rspawns		= _this select 1;
_delay			= _this select 2;
_spawn			= _this select 3;
//_here			= getMarkerPos _spawn;
_aax			= getMarkerPos _spawn select 0;
_bax			= getMarkerPos _spawn select 1;
_arad			= getMarkerSize _spawn select 0;
_brad			= getMarkerSize _spawn select 1;
_aax			= _aax + random _arad - random _arad;
_bax			= _bax + random _brad - random _brad;
_pos			= [(_aax), (_bax),0];
_where			= _this select 4;
_task 			= _this select 5;
//_rad			= _this select 6;
_when			= _this select 6;
_warad			= _this select 7;
//hint format ["%1 %2", _here, _pos];
_dir			= getDir _unit;
_group			= group _unit;
_unitsGroup		= units group _unit;
_side 			= side _unit;
_ans			= count _unitsGroup;

sleep 5;
_qtr			= _ans/4;
if (_ans <= 3) then { _qtr = 0;};


if (_type isKindOf "Man") then
	{
while{ ({(alive _x) && (canStand _x)} count _unitsGroup) > 0} do { 
sleep 2;};
_wait = Time + _delay;
waitUntil {Time > _wait};
if (_rspawns == 0) exitWith {};
_rspawns = _rspawns - 1;
//deleteGroup _group;
_AI_unitArray  = [];
{_AI_unitArray = _AI_unitArray + [typeOf _x];}forEach _unitsGroup;
_group = [_pos, _side, _AI_unitArray ,[],[],[],[],[],_dir] call BIS_fnc_spawnGroup;
_leader = leader _group;
if (_when != "start") then {
if (_task == "attack") then {_attack = [_group, _where, _warad] spawn ATscript;};
if (_task == "patrol") then {_patrol = [_group, _where, _warad] spawn PTscript;};
if (_task == "defend") then {_defend = [_group,  _where] spawn DFscript;};};

[_leader, _rspawns, _delay, _spawn, _where, _task, _when] execVM "Init_respawn.sqf";
} 

else 		{ 
while{ ({(alive _x) && (canMove _x)} count _unitsGroup) > 0 } do { 
sleep 2;};
_wait = Time + _delay;
waitUntil {Time > _wait};
if (_rspawns == 0) exitWith {};
_rspawns = _rspawns - 1;
deleteGroup _group;
if (_type isKindOf "Air") then 
       { _pos 		= [(getMarkerPos _spawn select 0), (getMarkerPos _spawn select 1), 100];};
if (_type isKindOf "Land") then
       {_pos 		= getMarkerPos _spawn;};
_group = CreateGroup _side;
_veh = [_pos, _dir, (_type), _group] call BIS_fnc_spawnVehicle;
_leader = leader _group;
_NV = _veh select 0;
if (_task == "attack") then {_attack = [_group, _where, _warad] spawn ATscript;};
if (_task == "patrol") then {_patrol = [_group, _where, _warad] spawn PTscript;};
if (_task == "defend") then {_defend = [_group,  _where] spawn DFscript;};

[_leader, _rspawns, _delay, _spawn, _where, _task, _when] execVM "Init_respawn.sqf";
};
if (true) exitWith {};

These scripts were pulled from arma config searcher thingy. I edited them to my taste Patrol script :

/*
File: taskPatrol.sqf
Author: Joris-Jan van 't Land (edited by Mikey)

Description:
Create a random patrol of several waypoints around a given position.

Parameter(s):
_this select 0: the group to which to assign the waypoints (Group)
_this select 1: the position on which to base the patrol (Array)
_this select 2: the maximum distance between waypoints (Number)
_this select 3: (optional) blacklist of areas (Array)

Returns:
Boolean - success flag
*/

//Validate parameter count
if ((count _this) < 3) exitWith {debugLog "Log: [taskPatrol] Function requires at least 3 parameters!"; false};

private ["_grp", "_pos", "_maxDist", "_blacklist"];
_grp			= _this select 0;
_pos			= _this select 1;
_maxDist		= _this select 2;
_maxDist		= _maxDist * 2;
_aax			= getMarkerPos _pos select 0;
_bax			= getMarkerPos _pos select 1;
_pos			= [(_aax), (_bax),0];


_blacklist = [];
if ((count _this) > 3) then {_blacklist = _this select 3};

//Validate parameters
if ((typeName _grp) != (typeName grpNull)) exitWith {debugLog "Log: [taskPatrol] Group (0) must be a Group!"; false};
if ((typeName _pos) != (typeName [])) exitWith {debugLog "Log: [taskPatrol] Position (1) must be an Array!"; false};
//if ((typeName _maxDist) != (typeName 0)) exitWith {debugLog "Log: [taskPatrol] Maximum distance (2) must be a Number!"; false};
//if ((typeName _blacklist) != (typeName [])) exitWith {debugLog "Log: [taskPatrol] Blacklist (3) must be an Array!"; false};

_grp setBehaviour "SAFE";

//Create a string of randomly placed waypoints.
private ["_prevPos"];

_prevPos = _pos;


for "_i" from 0 to (4 + (floor (random 4))) do
{
private ["_wp", "_newPos"];

_newPos =  [(_aax + random _maxDist - random _maxDist ), (_bax + random _maxDist - random _maxDist ),0];

Sleep 1;
_prevPos = _newPos;

_wp = _grp addWaypoint [_newPos, 0];
_wp setWaypointType "MOVE";
_wp setWaypointCompletionRadius _maxDist;

//Set the group's speed and formation at the first waypoint.
if (_i == 0) then
{
	_wp setWaypointSpeed "LIMITED";
	_wp setWaypointFormation "STAG COLUMN";
};
sleep 1;
};

//Cycle back to the first position.
private ["_wp"];
_wp = _grp addWaypoint [_pos, 0];
_wp setWaypointType "CYCLE";
_wp setWaypointCompletionRadius _maxDist;

true

/*
File: taskDefend.sqf
Author: Joris-Jan van 't Land (edited by mikey)

Description:
Group will man nearby static defenses and guard the position.

Parameter(s):
_this select 0: group (Group)
_this select 1: defense position (Array)

Returns:
Boolean - success flag
*/

//Validate parameter count
if ((count _this) < 2) exitWith {debugLog "Log: [taskDefend] Function requires at least 2 parameters!"; false};
private ["_grp", "_pos"];
_grp	= _this select 0;
_pos	= _this select 1;
hint format ["%1", _pos];
_aax			= getMarkerPos _pos select 0;
_bax			= getMarkerPos _pos select 1;
_pos			= [(_aax + random 50 - random 50 ), (_bax + random 50 - random 50 ),0];
hint format ["%1", _pos];
_side	= side _grp;
_units = units _grp;
if (_side == west) then { "WEST G" };
if (_side == east) then { "EAST G" };
if (_side == Independent) then { "GUER G" };

//Validate parameters
if ((typeName _grp) != (typeName grpNull)) exitWith {debugLog "Log: [taskDefend] Group (0) must be a Group!"; false};
if ((typeName _pos) != (typeName [])) exitWith {debugLog "Log: [taskDefend] Position (1) must be an Array!"; false};


_grp setBehaviour "AWARE";

private ["_list", "_units"];
_list = _pos nearObjects ["ALL", 100];
_units = (units _grp) - [leader _grp]; //The leader should not man defenses
_staticWeapons = [];

//Find all nearby static defenses without a gunner
{
if ((_x emptyPositions "gunner") > 0) then 
{
	_staticWeapons = _staticWeapons + [_x];	
};
} forEach _list;

//Have the group man most empty static defenses
{
//Are there still units available?
if ((count _units) > 0) then 
{
	//Big random chance
	if ((random 1) > 0.1) then 
	{
		private ["_unit"];
		_unit = (_units select ((count _units) - 1));

		_unit assignAsGunner _x;
		[_unit] orderGetIn true;

		_units resize ((count _units) - 1);
	};
};
} forEach _staticWeapons;

// create trigger to guard
deletevehicle _trg;
_trg = createTrigger["EmptyDetector" , _pos];
_trg setTriggerType _grd;
_trg setTriggerArea[50,50,0,false];

//Give the rest a guard WP.
private ["_wp"];
_wp = _grp addWaypoint [_pos, 10];
_wp setWaypointType "GUARD";
_wp setWaypointFormation "DIAMOND";
true

/*
File: taskAttack.sqf
Author: Joris-Jan van 't Land (edited by Mikey)

Description:
Group will attack the position.

Parameter(s):
_this select 0: group (Group)
_this select 1: attack position (Array)

Returns:
Boolean - success flag
*/

//Validate parameter count
if ((count _this) < 2) exitWith {debugLog "Log: [taskAttack] Function requires at least 2 parameters!"; false};

private ["_grp", "_pos"];
_grp			= _this select 0;
_pos			= _this select 1;
_maxDist		= _this select 2;
_aax			= getMarkerPos _pos select 0;
_bax			= getMarkerPos _pos select 1;
_pos			= [(_aax), (_bax),0];
_maxDist		= _maxDist / 2;

//Validate parameters
if ((typeName _grp) != (typeName grpNull)) exitWith {debugLog "Log: [taskAttack] Group (0) must be a Group!"; false};
if ((typeName _pos) != (typeName [])) exitWith {debugLog "Log: [taskAttack] Position (1) must be an Array!"; false};

//Set group properties.
_grp setBehaviour "AWARE";

//Create the waypoint.
private ["_wp", "_wp1","_wp2"];
_wp = _grp addWaypoint [_pos, _maxDist];
_wp setWaypointType "SAD";
_wp setWaypointCompletionRadius _maxDist;

_wp1 = _grp addWaypoint [_pos, _maxDist];
_wp1 setWaypointType "SAD";
_wp1 setWaypointCompletionRadius _maxDist;

_wp2 = _grp addWaypoint [_pos, 0];
_wp2 setWaypointType "CYCLE";
_wp2 setWaypointCompletionRadius 0;



true

I havent tried this with civilian yet. Though I think what I have here should work. What I'd like to do eventually as for the call in script for armor is to make it group friendly. Ive not delved into that yet as Im working on a few other things.

P.S. Zippy is updated...... It now works with civilians. If you using dev update for atlis you will get errors but it still works. Again you will need ALLInArma as well till I can convert it out in next day or two. ;)

p.s.s new link at top for one on stratis with no added addons. ;)

Edited by Mikey74

Share this post


Link to post
Share on other sites

In addition to the error every time a new group spawns, I'm finding that when I run this script, it seems to disable the ability to control the UAVs ingame. Any updates that address the apparent code errors? This was going to replace my UPS script from A2, but now it seems that the latest updates/beta has caused some serious issues.

Share this post


Link to post
Share on other sites
In addition to the error every time a new group spawns, I'm finding that when I run this script, it seems to disable the ability to control the UAVs ingame.

Oops. Disregard this part...I had my player set to captive and apparently that makes it so you can't connect to UAVs.

Share this post


Link to post
Share on other sites

Sorry man we have been slammed at work. I havent had time to mess with anything. lol Im hoping when the final game is released some of that will go away. I get errors and everything now. My scripts and others that Im using. I'm going to investigate it as soon as I can. Hopefully this weekend. Been trying to get mine and my sons campaign going good when we got slammed at work. lol. Any ways thanks for letting me know about it. I'll get to it as soon as I can. :)

Just tested it. The errors is coming of bis_spawn_group fnc. I may have to just spawn inf the old way. When I do I'll post it again.

Edited by Mikey74

Share this post


Link to post
Share on other sites

No sweat. I understand that real life has it's priorities. Thanks for at least continuing to look at this.

Share this post


Link to post
Share on other sites

http://www43.zippyshare.com/v/69479872/file.html Here is a new version. It works, but I'm getting a different error on my end, but I'm thinking its from another script from someone else, becuase I do not use CBA that I know of in my scripts. Could you try it and let me know?

edited: just tested with other scripts turned off.... No errors on my end. yayyyy!!!!!

Edited by Mikey74

Share this post


Link to post
Share on other sites
http://www76.zippyshare.com/v/4968712/file.html This is a perfect final release of these scripts. Rewrote them so that you can use 1 unit to whole groups now. Yup I figured it out. lol no errors, works pretty good so far. may give 1 or two more hotfixes, but I think this is what I was trying to accomplish! I'm not sure if I should or can post another thread for final release or actually which section to put it in though. SO hopefully if this is useful you can just grab it from here. Edited by Mikey74

Share this post


Link to post
Share on other sites

Pulling it down now...

Since you allow the group to patrol within the dimensions of the marker, any chance you can make the marker disappear in the mission? As of now, you have to either make the marker "Empty," which makes the area small, or you have to try and size an "Empty" marker, which isn't easy.

Share this post


Link to post
Share on other sites

I've not figured that out yet. I supposed I could examine UPS script by I think it was by Norrin. I've been using mission markers for setmarker positions to move them around on the mission Im working on. I'll up load that one if you'd like to have a look. Its a long way from finished. lol I dont think I'm using any addons on it. If so its Allinarma, and I've been trying to avoid Massies units and weapons as I want to release this one when I finish it. Not everyone uses those. :( Ive restarted it several times. lol any ways here it is:

http://www76.zippyshare.com/v/12475526/file.html

I highly recommend : http://www.armaholic.com/page.php?id=22096&highlight=ZOOLOO

Very good MG suppression and Artillery suppression scripts! Till I make up my own Artillery one, but I have a feeling its a bit more complicated. lol

http://forums.bistudio.com/showthread.php?152435-How-to-make-a-marker-disappear-on-the-map

haha yeh bis confirmed it Description:

Sets the marker alpha. The marker is modified on all computers in a network session. When alpha equal one, the marker is visible, but if alpha equal zero, then the marker is invisible. Alpha can be numbers and fractions.

LOL ok edited it it works I'm uploading on top of other upload. So if you have already DL it in last few minutes redo the dl. lol No other addons on this one except for jsrs 2.0 for arma 3.

By the way I have it set up also to spawn in random positions based on the marker size. BEcarefull with that one as it will spawn a vehicle in a building. Which doesnt have good results. ;)

Here are the codes I've used :

Init_respawn.sqf

/*
_nil = [this, 7, 1, "spawnMarker", "operationMarker", "Operation", "start"] execvm "Init_respawn.sqf";  Would be put into leading AI units init to perform AI respawn.

Below this line is a detailed explanation of what each means:

this is the actual AI unit, AI Vehicle, or AI group you want to respawn.

7 is how many times you want the AI to respawn. 

1 is how many seconds delay before AI respawns.

"spawnMarker" would be the name of the marker you wish them to respawn at.

"operationMarker" would be the area you want the AI to operate in.

"Operation" would be the operation you want them to perform ie "attack", "defend", or "patrol".

"start" will start Operations before respawn, and nothing there will start operations after respawn. This way if you want them to do something else at start you can. Good for counter attacks, or simulating reinforcements.

Remember quotes on the last four expressions you want to achieve.

Don't forget to put both Init_respawn.sqf and AI_respawn.sqf scripts in your mission folder. Or else when the game makes the script call it will not know what you want it to do. ;)
This works with groups of AI with men, and vehicles*/
if (!isServer) exitWith {};
private ["_c","_unit","_rspawns","_delay","_spawn","_where","_ard","_brd","_task","_when","_c","_unitsgroup","_group","_gcount","_pos","_side","_dir","_AI_unit","_vtype"];
_countThis = 0;
SPscript = compile preprocessFileLineNumbers "AI_respawn.sqf";
PTscript = compile preprocessFileLineNumbers "fn_taskPatrol.sqf";
DFscript = compile preprocessFileLineNumbers "fn_taskDefend.sqf";
ATscript = compile preprocessFileLineNumbers "fn_taskAttack.sqf";
_countThis 		= count _this;
_unit 			= _this select 0;
_rspawns		= _this select 1;
_delay			= _this select 2;
_spawn			= _this select 3;
_where			= _this select 4;
_spawn setMarkerAlpha 0;  
_where setMarkerAlpha 0; 

_warad			= getMarkerSize _where;
_ard			= getMarkerSize _where select 0;
_brd			= getMarkerSize _where select 1;
_warad			= _ard + _brd;
_warad			= random _warad + 20;
_task 			= _this select 5;
_when			= if (_countThis == 7) then {_this select 6;} else { ""};
_group			= group _unit;
_c				= 0;
_unitsgroup 	= units group _unit;
_gcount 		= count _unitsgroup;
_pos 			= getMarkerPos _spawn;
_side 			= side _unit;
_dir			= getDir _unit;
_AI_unit  = [];
_vtype = [];

For "_i" from 0 to _gcount -1 do
{_c = _c + 1;
_veh = _unitsgroup select _i; 
_v 	= vehicle _veh;
If (_v isKindOf "LandVehicle" or _v isKindOf "air") then {_ccrew = count crew _v; _i = _i + _ccrew; _vtype = _vtype + [typeOf _v]} else {
_AI_unit = _AI_unit + [typeOf _veh]};
};
_Grp = _vtype + _AI_unit;
_cvtype	= count _vtype;
_gcount		= count _AI_unit;

if (_when == "start") then { 
if (_task == "attack") then {_attack = [_group, _where, _warad] spawn ATscript;};
if (_task == "patrol") then {_patrol = [_group, _where, _warad] spawn PTscript;};
if (_task == "defend") then {_defend = [_group, _where] spawn DFscript;};
};
_spawn = [_unit, _rspawns, _delay, _spawn, _where, _task, _when, _warad,_group,_c,_unitsgroup,_gcount,_pos,_side,_dir,_AI_unit,_vtype,_Grp,_Cvtype,_gcount] spawn SPscript;

true

AI_respawn.sqf

if (!isServer) exitWith {};
private["_unit","_rspawns","_delay","_spawn","_where","_task","_when","_warad","_group","_c","_unitsgroup","_gcount","_pos","_side","_dir","_AI_unit","_vtype","_Grp","_Cvtype","_gcount"];
_unit 			= _this select 0;
_rspawns		= _this select 1;
_delay			= _this select 2;
_spawn			= _this select 3;
_where			= _this select 4;
_task 			= _this select 5;
_when			= _this select 6;
_warad			= _this select 7;
_group			= _this select 8;
_c				= _this select 9;
_unitsgroup		= _this select 10;
_gcount			= _this select 11;
_pos			= _this select 12;
_side			= _this select 13;
_dir			= _this select 14;
_AI_unit		= _this select 15;
_vtype			= _this select 16;
_Grp			= _this select 17;
_Cvtype			= _this select 18;
_gcount			= _this select 19;

sleep .5;

while{ ({(alive _x) && (canStand _x) && (canMove _x)} count _unitsGroup) > 0} do { 
sleep 2;};
_wait = Time + _delay;
waitUntil {Time > _wait};
if (_rspawns == 0) exitWith {};
_rspawns = _rspawns - 1;
deleteGroup _group;
_aax			= _pos select 0;
_bax			= _pos select 1;
_arad			= 10;
_brad			= 10; 
_aax			= _aax + random _arad - random _arad + 10;
_bax			= _bax + random _brad - random _brad - 10;
_pos			= [(_aax), (_bax),0];
if (_gcount >= 1) then {
_group = createGroup _side; 
{_x createUnit [ _pos, _group];} forEach _AI_unit;};

if (_cvtype >= 1) then {
For "_u" from 0 to _cvtype - 1 do {
_veh = _vtype select _u;
_aax			= _pos select 0;
_bax			= _pos select 1;
_arad			= 10;
_brad			= 10; 
_aax			= _aax + random _arad - random _arad + 10;
_bax			= _bax + random _brad - random _brad - 10;
if (_veh isKindOf "air") then {
_pos			= [(_aax), (_bax),50];}
else {_pos			= [(_aax), (_bax),0];};
_vgrp = [_pos, _dir, _veh, _group] call BIS_fnc_spawnVehicle;
_NV = _vgrp select 0;
if (_gcount >= 1) then { {_x moveInCargo _NV } foreach units _group };
};
};

_leader = leader _group;
if (_when != "start") then {
if (_task == "attack") then {_attack = [_group, _where, _warad] spawn ATscript;};
if (_task == "patrol") then {_patrol = [_group, _where, _warad] spawn PTscript;};
if (_task == "defend") then {_defend = [_group,  _where] spawn DFscript;};};

[_leader, _rspawns, _delay, _spawn, _where, _task, _when] execVM "Init_respawn.sqf";


if (true) exitWith {};

fn_taskPatrol.sqf (All the ones here down are Bis scripts that Ive did little small edits to fit in with what I wanted to see. SLIGHT edits. The ones above was inspired by Norrin, Murk and a few other fellows thats tought me little bits here and there.)

/*
File: taskPatrol.sqf
Author: Joris-Jan van 't Land (edited by Mikey)

Description:
Create a random patrol of several waypoints around a given position.

Parameter(s):
_this select 0: the group to which to assign the waypoints (Group)
_this select 1: the position on which to base the patrol (Array)
_this select 2: the maximum distance between waypoints (Number)
_this select 3: (optional) blacklist of areas (Array)

Returns:
Boolean - success flag
*/

//Validate parameter count
if ((count _this) < 3) exitWith {debugLog "Log: [taskPatrol] Function requires at least 3 parameters!"; false};

private ["_grp", "_pos", "_maxDist", "_blacklist"];
_grp			= _this select 0;
_pos			= _this select 1;
_maxDist		= _this select 2;
_maxDist		= _maxDist * 2;
_aax			= getMarkerPos _pos select 0;
_bax			= getMarkerPos _pos select 1;
_pos			= [(_aax), (_bax),0];


_blacklist = [];
if ((count _this) > 3) then {_blacklist = _this select 3};

//Validate parameters
if ((typeName _grp) != (typeName grpNull)) exitWith {debugLog "Log: [taskPatrol] Group (0) must be a Group!"; false};
if ((typeName _pos) != (typeName [])) exitWith {debugLog "Log: [taskPatrol] Position (1) must be an Array!"; false};
//if ((typeName _maxDist) != (typeName 0)) exitWith {debugLog "Log: [taskPatrol] Maximum distance (2) must be a Number!"; false};
//if ((typeName _blacklist) != (typeName [])) exitWith {debugLog "Log: [taskPatrol] Blacklist (3) must be an Array!"; false};

_grp setBehaviour "SAFE";

//Create a string of randomly placed waypoints.
private ["_prevPos"];

_prevPos = _pos;


for "_i" from 0 to (4 + (floor (random 4))) do
{
private ["_wp", "_newPos"];

_newPos =  [(_aax + random _maxDist - random _maxDist ), (_bax + random _maxDist - random _maxDist ),0];

Sleep 1;
_prevPos = _newPos;

_wp = _grp addWaypoint [_newPos, 0];
_wp setWaypointType "MOVE";
_wp setWaypointCompletionRadius _maxDist;

//Set the group's speed and formation at the first waypoint.
if (_i == 0) then
{
	_wp setWaypointSpeed "LIMITED";
	_wp setWaypointFormation "STAG COLUMN";
};
sleep 1;
};

//Cycle back to the first position.
private ["_wp"];
_wp = _grp addWaypoint [_pos, 0];
_wp setWaypointType "CYCLE";
_wp setWaypointCompletionRadius _maxDist;

true

fn_taskAttack.sqf

/*
File: taskAttack.sqf
Author: Joris-Jan van 't Land (edited by Mikey)

Description:
Group will attack the position.

Parameter(s):
_this select 0: group (Group)
_this select 1: attack position (Array)

Returns:
Boolean - success flag
*/

//Validate parameter count
if ((count _this) < 2) exitWith {debugLog "Log: [taskAttack] Function requires at least 2 parameters!"; false};

private ["_grp", "_pos"];
_grp			= _this select 0;
_pos			= _this select 1;
_maxDist		= _this select 2;
_aax			= getMarkerPos _pos select 0;
_bax			= getMarkerPos _pos select 1;
_pos			= [(_aax), (_bax),0];
_maxDist		= _maxDist / 2;

//Validate parameters
if ((typeName _grp) != (typeName grpNull)) exitWith {debugLog "Log: [taskAttack] Group (0) must be a Group!"; false};
if ((typeName _pos) != (typeName [])) exitWith {debugLog "Log: [taskAttack] Position (1) must be an Array!"; false};

//Set group properties.
_grp setBehaviour "AWARE";

//Create the waypoint.
private ["_wp", "_wp1","_wp2"];
_wp = _grp addWaypoint [_pos, _maxDist];
_wp setWaypointType "SAD";
_wp setWaypointCompletionRadius _maxDist;

_wp1 = _grp addWaypoint [_pos, _maxDist];
_wp1 setWaypointType "SAD";
_wp1 setWaypointCompletionRadius _maxDist;

_wp2 = _grp addWaypoint [_pos, 0];
_wp2 setWaypointType "CYCLE";
_wp2 setWaypointCompletionRadius 0;



true

fn_taskDefend.sqf

/*
File: taskDefend.sqf
Author: Joris-Jan van 't Land (edited by mikey)

Description:
Group will man nearby static defenses and guard the position.

Parameter(s):
_this select 0: group (Group)
_this select 1: defense position (Array)

Returns:
Boolean - success flag
*/

//Validate parameter count
if ((count _this) < 2) exitWith {debugLog "Log: [taskDefend] Function requires at least 2 parameters!"; false};
private ["_grp", "_pos"];
_grp	= _this select 0;
_pos	= _this select 1;
//hint format ["%1", _pos];
_aax			= getMarkerPos _pos select 0;
_bax			= getMarkerPos _pos select 1;
_pos			= [(_aax + random 50 - random 50 ), (_bax + random 50 - random 50 ),0];
//hint format ["%1", _pos];
_side	= side _grp;
_units = units _grp;
if (_side == west) then { "WEST G" };
if (_side == east) then { "EAST G" };
if (_side == Independent) then { "GUER G" };

//Validate parameters
if ((typeName _grp) != (typeName grpNull)) exitWith {debugLog "Log: [taskDefend] Group (0) must be a Group!"; false};
if ((typeName _pos) != (typeName [])) exitWith {debugLog "Log: [taskDefend] Position (1) must be an Array!"; false};


_grp setBehaviour "AWARE";

private ["_list", "_units"];
_list = _pos nearObjects ["ALL", 100];
_units = (units _grp) - [leader _grp]; //The leader should not man defenses
_staticWeapons = [];

//Find all nearby static defenses without a gunner
{
if ((_x emptyPositions "gunner") > 0) then 
{
	_staticWeapons = _staticWeapons + [_x];	
};
} forEach _list;

//Have the group man most empty static defenses
{
//Are there still units available?
if ((count _units) > 0) then 
{
	//Big random chance
	if ((random 1) > 0.1) then 
	{
		private ["_unit"];
		_unit = (_units select ((count _units) - 1));

		_unit assignAsGunner _x;
		[_unit] orderGetIn true;

		_units resize ((count _units) - 1);
	};
};
} forEach _staticWeapons;

// create trigger to guard
deletevehicle _trg;
_trg = createTrigger["EmptyDetector" , _pos];
_trg setTriggerType _grd;
_trg setTriggerArea[50,50,0,false];

//Give the rest a guard WP.
private ["_wp"];
_wp = _grp addWaypoint [_pos, 10];
_wp setWaypointType "GUARD";
_wp setWaypointFormation "DIAMOND";

//[_units] commandWatch player;

/*private ["_handle"];
_handle = _units spawn 
{
sleep 5;

//Make some of the remaining unit sit down.
{
	if ((random 1) > 0.4) then 
	{
		doStop _x;

		sleep 0.5;

		_x action ["SitDown", _x];	
	};	
} forEach _this;
};*/

true

Edited by Mikey74

Share this post


Link to post
Share on other sites

Oops, I forgot to come back and reply...

Your update seems to be working well. Thanks a bunch for releasing it. Now I can mix and match between yours and UPS.

Share this post


Link to post
Share on other sites

I actually need to update this one again. Will tomorrow I guess. lol I can probably incorporate it back into ups. I used to use them together, but kept getting anoying errors off of ups when the beta hit. lol Its probably stopped now. I'll see about that down the road if ya like.

Updated no UPS in it yet: http://www34.zippyshare.com/v/54283822/file.html

Edited by Mikey74

Share this post


Link to post
Share on other sites

I'm not seeing in-game errors with your update, but I did notice that you don't have any code to spawn AI with updated configurations in the mission. UPS did that in the past. What I mean is that if you changed their weapon/magazine loadout (and now uniform loadout), when the AI respawned, they had what the mission maker had set for them. Looks like there were arrays set up in either UPS or the respawn scripts (I can't remember which) that checked all of this (for A2).

I bring this up because I have CSAT AI "dressed up" in insurgent clothing (along with some Marines that have had their uniforms and weapons tweaked), but when they die, they respawn with the default BIS loadout.

Just giving some feedback. I still greatly appreciate your contribution. Thanks for continuing to update it.

Share this post


Link to post
Share on other sites

lol Guess not a final release after all :P. Yeh I could probably figure something out to make that work. May take me a bit. been working on something else. An AI artillery script. One that will use all artillery. Hoping to give that a release in next few days.

In next few weeks I'm certian I'm going to converge this into AISS addon.

Edited by Mikey74

Share this post


Link to post
Share on other sites

Hello. I'm interested in your script as a way of making a simulated battle to be fought ongoing in the background. I've implemented it and it works for the infantry groups. However, when manned vehicles respawn, they appear on the ground and immediately rocket into the air, subsequently falling and exploding. I've noticed nobody has commented on this happening for them. I've tried placing the marker in various places, even on the flat, empty runways, but the vehicles still launch into the air on respawn. Is there something that needs to be done to prevent this?

This is with your latest release as of Sep. 26.

Edited by AKinthesky

Share this post


Link to post
Share on other sites

yes there are a couple things I may add. I'm actually adding a more up to date respawn script to my AISS mod. It still needs some work before I release it with AISS. But if you have scripting knowledge you can use the near objects command to make sure they are not respawning on buildings or huge rocks, or if they are spawning on top of each other you can make the randomizers bigger or place a non random number with it like Random 3 + 10. Hope this helps. I'll up date this one as soon as I can. Most likely when I release the AI respawn with AISS I'll also up date this one. ;)

P.S. There are a few much much better AI respawn scripts floating around. Try Armaholic download section under Miscellaneous. ;)

Share this post


Link to post
Share on other sites

Cool, thanks! Just a heads up, it doesn't appear to support boats. The crew spawns in the water, but no boat. And they're not on the sea floor either.

Share this post


Link to post
Share on other sites

to install: add the whole atlis_tanding.altis folder from the .rar file into your mission folder, if you are trying to export a mission to multiplayer you have to copy the folder from missions to mpmissions , the arma 3 editor export to mp is broken !) so that it turns blue when you go to select it in multiplayer, also the respawn system wont work if it is not lan multiplayer (the description.ext file with respawn = "base" in missions folder) once you copied the folder to your missions folder example (C:\Users\jg\Documents\Arma 3 - Other Profiles\namus\mpmissions\a53.Altis) in there you need to open altis_landing.altis folder and copy the  Init_respawn.sqf and AI_respawn.sqf files from that folder and paste them into your mission folder again where you just placed this folder you extracted, in this example into the a53.altis folder as well as leave them in the altis_landing.altis folder you copied from)

before you copy this mission to a multiplayer mission folder thus turning it into a mpmission, you have to set up the respawns by adding this line into the initialization of any ai unit on the map you placed in the editor and want that unit to respawn!

 

 

_nil = [this, 7, 1, "spawnMarker", "operationMarker", "Operation", "start"] execvm "Init_respawn.sqf";

 

 

you have to match/edit the "marker" name of the marker with the initialization line you entered into the ai unit you want to respawn, ill just use one marker for endless enemies and leave the default:

spawnmarker

then in the initialization line edit it to match what you labeled the marker where you want the ai's to respawn

in this example it is already     spawnmarker

so that's where they will all respawn if you add that line into the intitilization when creating the ai unit in editor

you can change the "operation" with "attack" which is what i did, they don't respawn with same loadout its the default rifleman one if that's what you placed the unit, you can change the number 7 by however many times you want that ai to respawn there at the marker you placed and the number 1 in the line above to however long you want the ai to wait before respawning.

also if anyone knows how to disable smoke grenades tell me

place a marker and call it respawn_west  then in description.ext type

respawn = "BASE";
respawndelay = 3;
corpseManagerMode = 1;
corpseLimit = 1;
corpseRemovalMinTime = 1; //seconds
corpseRemovalMaxTime = 2; //seconds

this will remove dead bodies and allow the player to respawn (only works when hostin lan mission by copyin mission folder over to mpmissions from missions after savin, you cannot edit it then)

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  

×