Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
victim913

Units that disembark = leave group and join new

Recommended Posts

I have a pretty big armor mission. If I have 4 tanks in a group and the leaders tank gets hit, he leaves the tank and continues his attack against enemy armor on foot.

2 problems.

1. That tank group is now completely useless. They only go as fast as their leader and as long as they see OPFOR, the leader stays in "danger" mode and moves about 10 feet every couple minutes. And with hills and other things, the entire attack plan is ruined because they lose ability to be where they need to be.

2. The tank crew, now on foot, will not attack armor. So most of the time they don't even move.

Another problem is amphibious vehicles. If they get shot, the whole squad gets out and tries to swim, losing all weapons. The crew holding up other amphibious ends up worse than the tanks. Everything is WAYYYYYYY slower in water.

So what i am hoping for is that someone here will be able to help me to come up with a script or code that will clean this mess up.

What I'm thinking will be good is:

-Any crew that gets out of specified vehicles will be dismissed from their group so that the rest can move on without them. I say specified, because other vehicles like a humvee will not need to be dismissed.

-Once they are dismissed from group, they will be put in a new or different group. If I can get them to join rescue boat groups I can have them get picked up. And on land I can put them in a group with medics. I will also be able to get all the crews to join together and fight against other infantry as a group with focus rather than random stragglers.

So if someone can tell me how to get this scripted right I would appreciate it. And also maybe you have a better or seperate option. Like how would I get their new group to pick them up? Waypoints won't work because you don't know where they will neeed to be.

So any help? Thanks

Share this post


Link to post
Share on other sites

for the tanks:

name the leader of the boatrescue group and place this in the init of the leader or leadvehicle of the tank group, or any other group for that matter aswell.

_null = [this,nameOfLeadeOfBoatRescueGroup] execVM "tank.sqf";

save this as tank.sqf


_tankGrp = group (_this select 0);  // the tank group
_rescueGrp = group (_this select 1);  // the rescue group wich dismounted units should join.

// function used to join and regroup the dismounted crewmembers from the tank group.
_join_fnc = {
_unit = _this select 0;
_grp = _this select 1;

[_unit] joinSilent grpNull;

while {alive _unit AND ( (getPos _unit) distance (getPos (vehicle (leader _grp))) ) > 50} do {
	_pos = getPos (vehicle (leader _grp));
	_unit doMove _pos;
	(getPos (vehicle (leader _grp)));
	waitUntil {sleep 1; !alive _unit OR (_pos distance (getPos (vehicle (leader _grp)))) > 50 OR (_unit distance (vehicle (leader _grp))) < 50};

	if (alive _unit AND (_unit distance (vehicle (leader _grp))) < 50) then {
		[_unit] joinSilent _grp;
	};	
};
};

while {(count (units _tankGrp)) != 0} do {
{
	// if unit is on foot run the join and regroup function on it.
	if (alive _x AND (vehicle _x) == _x) then {
		[_x,_rescueGrp] spawn _join_fnc;
	};
} foreach units _tankGrp;
sleep 1;
};

purpose of code is to monitor the tank group or any other vehicle group, then when any member of the group is out on foot (exited own vehicle) he will be removed from the group (grpNull) and then start to move towards the location of the nameOfLeadeOfBoatRescueGroup´s group and then join them when within 50 meters, this way a tank crew 1500 meter away will not hold oup the rescue group with "where are you?", "report location" etc stuff.

weapons lost in water:

For the water issue with lost weapons, maybe this will work for your purpose, it will save the weapons and give them back to the AI when on solid ground.

place this below in any amphibious groups leader init that needs to "keep" their weapons.

_null = this execVM "water.sqf";

save this as water.sqf


_grp = group _this;

_arr = [];

{
_arr = [[_x,(weapons _x),(magazines _x)]];
} foreach units _grp;

while {({surfaceIsWater (getPos _x)} count units _grp) > 0} do {
{
	_unit = _x select 0;
	_weap = _x select 1;
	_magz = _x select 2;
	if (!(surfaceIsWater (getPos _unit)) AND alive _unit) then {
		{_unit addMagazine _x} foreach _magz;
		{_unit addWeapon _x} foreach _weap;
		_unit selectWeapon (primaryWeapon _unit);
	};
} foreach _arr;
sleep 1;
};

But this will not fix any slow water swimming, just the loss of weapons.

I recomend you design your mission to make the amphibious vehicles invulnarable or use an eventhandler that "blocks" all damage unless its high damage, so it will only explode if given a critical hit, and will not tke damage if it was not a critical hit.

example maybe eventhandler added to the boats of a group.

place in init of the boat group leader or leadvehicle if placed "not empty" in editor:

_null = this execVM "boats.sqf";

save as boats.sqf


_grp = group _this;
_arr = [];

{
_veh = vehicle _x;
if (_veh != _x AND !(_veh in _arr)) then {
               _arr = _arr + [_veh];
	_veh addeventhandler ["HandleDamage",{
		_dam = _this select 2;
		if (_dam < 0.9) then {_dam = 0};
		_dam;
	}];
};
} foreach units _grp;

this will make all damage less than 0.9 give no damage at all aka invulnarable.

damage given above 0.9 will result in regular damage aka kaboom.

untested codes btw, but should give you something to work with, also give that guide by Mr Murray in my sig a read, alot of helpful ideas in there.

Share this post


Link to post
Share on other sites

Thanks. I think it's exactly what I want. It also lets me see what's going on a little better so I will end up learning how to do things like this myself. I've asked this before and never got an answer.

I usually use a trigger to give units back their gear but that script will be alot better.

As for the amphibioius vehicles, it gets tough these days cause there are so many AT weapons that take them out WAY before they get close to the shore. Not like WW2 days where machine guns were the most common. So most amphibious landings will probably be done away from enemies.

The script though will be very useful. I have alot of air missions so downed pilots will now havre a chance to live when they hit water.

Is there any script that will actually get them picked up out of the water? Once they join rescue group they will most likely be told to move to leader but not picked up into the boat.

Actually while im at it, looking at your script, what would I change if I have an infantry group and I want heavily wounded soldiers to leave squad and join medical group to be taken back to hospital tent? I'll look at the First aid module too, it looks similar. But my online connection is terrible so I'll ask you so that if you know i won't have to fight my wireless connection too much.

Thank you so much

Share this post


Link to post
Share on other sites

As for the amphibioius vehicles, it gets tough these days cause there are so many AT weapons that take them out WAY before they get close to the shore. Not like WW2 days where machine guns were the most common. So most amphibious landings will probably be done away from enemies.

yes this comes down to mission designer.

one thing ive used for fun is to set the aimskill of enemys to 0, then AT guys fire rpgs all around my tanks creating illusion of heavy fire without killing off my tank or members, actually it makes the enemy AI fire utterly worthless, so any hits is just pure luck.

try this out:

it may do what you want, make a trigger near the landing, with the amphibious side present.

in on act place this:

aimTrue = true;

place this in init.sqf:

aimTrue = false;
[] spawn {
_arr = [];
{
	// asuming here enemys are east side, change acordingly if not.
	if (side _x == east) then {
		_skl = _x skill "aimingAccuracy";  // gather the original aiming skill of the unit.
		_x setskill ["aimingAccuracy",0];  // set his aiming to zero.
		_arr = _arr + [[_x,_skl]];  // add the unit with his original skill number to the array for later use.
	};
} foreach allUnits;

waitUntil {sleep 5; aimTrue};  // wait until the trigger is activated so aimTrue is set to true, and only check for it every 5 seconds to relive CPU stress.

{
	_unit = _x select 0;  // select the unit from the array.
	_skl = _x select 1;  // select the original skill of that unit.

	// if alive unit, set his skill back to the original he had before we set it to zero.
	if (alive _unit) then {
		_unit setskill ["aimingAccuracy",_skl];
	};
} foreach _arr;
};

this will set the skill aiming of all east units to 0, once the trigger is activated by the landing party, all enemys that are alive will get their original aiming skill again.

Is there any script that will actually get them picked up out of the water? Once they join rescue group they will most likely be told to move to leader but not picked up into the boat.

well, this will require some micro managing.

name the boat rescue group leader, and place this in any amphibious group leader init wich will be rescued by the boat group.

_null = [this,nameOfBoatRescueLeader] execVM "boatpickup.sqf";

save this as boatpickup.sqf

_grp = group (_this select 0);
_res = group (_this select 1);

// here we create a function wich we can acess multiple times when needed.
_pickUp_fnc = {
_unit = _this select 0;
_res = _this select 1;
_grp = _this select 2;

// check if any boats are available, if not reset variable on unit and exit.
_vehicles = [];
{
	_veh = vehicle _x;  // vehicle of group member.
	if (_veh != _x AND !(_veh in _vehicles) AND (_veh getVariable ["available", true])) then {
		_vehicles = _vehicles + [_veh];
	};
} foreach units _res;

// find the nearest rescue boat with available cargo space.
_range = 99999;
_boat = _unit;
{
	if (canmove _x AND (_x emptyPositions "cargo") != 0) then {
		_rangeVeh = _x distance _unit;  // range, boat to swimming unit.
		// if this range is less than the previous range and its not the same boat, replace it.
		if (_x != _boat AND _rangeVeh < _range) then {
			_boat = _x;
			_range = _rangeVeh;
		};
	};
} foreach _vehicles;

// now we have a range and a boat, lets exit the script if there are no more boats available, meaning if the boat is the same as the unit as we did before the foreach code. (_boat = _unit)
if (_boat == _unit) exitWith {};

// if not exited, we now order the boat driver to drive to the swimming units position.
_boat setVariable ["available", false, true];  // set a variable to the boat so we know its busy.
_drv = driver _boat;
_drv doMove (getPos _unit);

// waitUntil boat in range, or unit or boat is dead, you probably need to tweak the 5 range here for better results.
waitUntil {sleep 1; !alive _unit OR !canMove _boat OR (_boat distance _unit) < 5};

if (alive _unit AND canMove _boat) then {
	_unit action ["getInCargo", _boat];
	[_unit] joinSilent (group _drv);
	_boat setVariable ["available", true, true];  // set a variable to the boat so we know available again.
};
// if boat dead make unit availabel again, and rejoin old group to be taken into account in the while loop again.
if (alive _unit AND !canMove _boat) then {
	[_unit] joinSilent _grp;
	_unit setVariable ["noPickup", true, true];  // set a variable to the unit so we know its not being picked up by someone.
};
// if unit dead, stop boat and make him available again for other pickups.
if (!alive _unit AND canMove _boat) then {
	_drv doMove (getPos _boat);  // will now resume any waypoints he has.
	_boat setVariable ["available", true, true];  // set a variable to the boat so we know available again.
};
};

while {({surfaceIsWater (getPos (vehicle _x))} count units _grp) > 0} do {

{
	if (vehicle _x == _x AND alive _x AND (_x getVariable ["noPickup", true])) then {
		if (!(surfaceIsWater (getPos _x))) then {

			_x setVariable ["noPickup", false, true];  // set a variable to the unit so we know its in being picked up by someone.
			if ((count (units _grp)) > 1) then {
				[_x] joinSilent grpNull;  // join his own group until pickup.
			};
			[_x,_res,_grp] spawn _pickUp_fnc;  // run the function on the unit.
		};
	};
} foreach units _grp;
};

there is ofcours alot more detail you can add into that, boats going to drowned units, closest unit in many groups get priority etc etc... alot of details will go into that....

Actually while im at it, looking at your script, what would I change if I have an infantry group and I want heavily wounded soldiers to leave squad and join medical group to be taken back to hospital tent? I'll look at the First aid module too, it looks similar.

this code will make any unit in a specific group join a another group when damaged/wounded, for the first aid module you need to find the getVariables used when wounded, i dont have them handy here atm, a forum search will find them though.

while {({alive _x} count units groupname) != 0} do {
{
	// here damage treshold is set to 0.6     -   0 = not wounded    - 1 = dead    with First Aid Module, i think wounded is above 0.8 or something, and its body part specific as well.
	// so if more damage than 0.6 (adjust if needed) then unit will leave group and join medics and do what ever.
	if ((getDammage _x) > 0.6) then {
		[_x] joinSilent medicalGroupName;
		// delete the line below that you do not wish to use, or both if you want AI leader of medic team to command them on their own.
		_x doMove (leader medicalGroupName);  // this line makes unit move towards the leader of medics.
		_x doMove (getPos mashTent);  // this line makes unit run towards the mash tent.
	};
} foreach units groupname;
sleep 1;
};

Nothing have been tested at all, just typing from memory and there might be errors and such, use showscripterrors, and squint is also a very useful tool for error checking scripts, but should give you something to work with or towards atleast.

best of luck mate, scripting is fun, but man its tedious work when going into details, you need to be a bit anal when micro managing AI ;)

To get more into scripting.

1: read the guide from my sig, you can download it in pdf and read it offline.

2: bookmark this site http://community.bistudio.com/wiki/Category:Scripting_Commands_ArmA2 to check commands and how to use them properly.

3: download others scripts and see how they did what, many ways to acomplish any task, armaholic is a great place to get such things, and ideas for your own scripts.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×