Jump to content
Sign in to follow this  
Masheen

Created group becomes null group

Recommended Posts

UPDATE: The root cause of this issue appears to be due to the AI helicopter occasionally flying directly into the ground after being assigned a waypoint. I am still trying to figure out why this happens.

UPDATE: This issue has been resolved. For those looking for the solution, I've outlined the steps I've made here: http://forums.bistudio.com/showthread.php?158901-Created-group-becomes-null-group&p=2438215&viewfull=1#post2438215

Hi there. I've been encountering a problem that's had me completely stumped for the past few days. I'm working on a simple script to create a helicopter patrol group. The problem is that a few lines after the createGroup is used, the group immediately becomes a null group. Sometimes the group "survives", allowing the AI crew to to be spawned in later steps, but this happens only occasionally. Here is the relevant part of the script. I can post the rest of the script if it is helpful in figuring out the root cause of this problem.

if (!isServer) exitWith {};
if (DZAI_heliActive || DZAI_cancelHeliPatrol) exitWith {};

private ["_heliType","_startPos","_helicopter","_heliCrew","_unitGroup","_unitSide","_pilot","_gunner1","_gunner2"];

       _heliType = "UH1H_DZ";
//_startPos = [(getMarkerPos DZAI_centerMarker),random(DZAI_centerSize),random(360),true] call SHK_pos;
_startPos = [7175.6,9482.49];


//Create the patrol group
_unitGroup = createGroup (call DZAI_getFreeSide);
_unitGroup setVariable ["DZAI",1];
diag_log format ["Created group %1",_unitGroup];

//Create the helicopter and set variables
_helicopter = createVehicle [_heliType, [_startPos select 0, _startPos select 1, 200], [], 0, "FLY"];
_helicopter setFuel 1;
_helicopter engineOn true;
_helicopter setVariable ["DZAI",1];
_helicopter setVehicleAmmo 1;
[_helicopter] joinSilent _unitGroup;
_unitGroup setVariable ["helicopter",_helicopter];
diag_log format ["Helicopter group is %1.",_unitGroup];
_helicopter setVehicleInit "if (isServer) then {[this] spawn fnc_heliResupply;};";

if (DZAI_debugLevel > 0) then {diag_log format ["DZAI Debug: Created patrol helicopter for group %1 at %2.",_unitGroup,_startPos];};

//Create helicopter crew
_pilot = _unitGroup createUnit [(DZAI_BanditTypes call BIS_fnc_selectRandom), [(_startPos select 0) + 5, _startPos select 1, 0], [], 0.5, "NONE"];
_pilot assignAsDriver _helicopter;
_pilot moveInDriver _helicopter;
[_pilot] joinSilent _unitGroup;
_unitGroup selectLeader _pilot;

_gunner1 = _unitGroup createUnit [(DZAI_BanditTypes call BIS_fnc_selectRandom), [_startPos select 0, (_startPos select 1) + 5, 0], [], 0.5, "NONE"];
_gunner1 assignAsGunner _helicopter;
_gunner1 moveInTurret [_helicopter, [0]];
[_gunner1] joinSilent _unitGroup;

_gunner2 = _unitGroup createUnit [(DZAI_BanditTypes call BIS_fnc_selectRandom), [(_startPos select 0) + 5, (_startPos select 1) + 5, 0], [], 0.5, "NONE"];
_gunner2 assignAsGunner _helicopter;
_gunner2 moveInTurret [_helicopter, [1]];
[_gunner2] joinSilent _unitGroup;

_heliCrew = [_pilot, _gunner1, _gunner2];

{
	0 = [_x,2] spawn fnc_setSkills;
	_x addWeapon "NVGoggles";
	_x addEventHandler ["Killed",{[_this,"banditKills"] call local_eventKill;(_this select 0) setDamage 1;(_this select 0) removeWeapon "NVGoggles";}];
} forEach _heliCrew;

_helicopter setVariable ["crew",_heliCrew];
_helicopter setVariable ["unitGroup",_unitGroup];
processInitCommands;

if (DZAI_debugLevel > 0) then {diag_log format ["DZAI Debug: Created AI helicopter crew for group %1.",_unitGroup];};

//Set group behavior and waypoint
_unitGroup allowFleeing 0;
//_unitGroup setBehaviour "AWARE";
_unitGroup setBehaviour "SAFE";
_unitGroup setSpeedMode "NORMAL";
//_unitGroup setCombatMode "RED";
_unitGroup setCombatMode "BLUE";

_searchArea = getPos (DZAI_dynTriggerArray call BIS_fnc_selectRandom);
[_unitGroup,0] setWaypointTimeout [5,10,15];
[_unitGroup,0] setWaypointCompletionRadius 75;
[_unitGroup,0] setWaypointStatements ["true","[(group this),0] setWPPos (getPos (DZAI_dynTriggerArray call BIS_fnc_selectRandom)); (group this) setCurrentWaypoint [(group this),0];"];
[_unitGroup,0] setWPPos _searchArea;	
_unitGroup setCurrentWaypoint [_unitGroup,0];

The following is the diag_log output in my RPT log:

 0:18:20 "Assigned side EAST to AI group" //This is output from the function DZAI_getFreeSide
0:18:20 "Created group O 1-1-A" //The group is being created successfully
0:18:20 "Helicopter group is <NULL-group>." //The group immediately becomes null

I'm at my wit's end at this point, and I would be extremely grateful if someone could lend a helping hand. I will provide any additional information to help anyone who is willing to assist.

I'll keep this post updated as to my progress so that anyone with similar problems may be helped by this thread.

- I tracked down the helicopter's location when the group suddenly becomes null. I found the helicopter as a burning wreck, so a collision with terrain must have happened.

- I now have reason to believe the issue is collision related. However, I've seen other very similar scripts that spawn helicopters at a far lower altitude (< 80) that do not have this issue.

- Updated the code sample, same problem persists.

- I'm suspecting the problem is because I'm spawning the AI crew at the same altitude as the helicopter (in the air), causing the units to die. Note: the helicopter is scripted to destroy itself when the pilot is killed.

- I've set the AI crew to spawn at Z value of 0 (ground) and set the heli self-destruct script to wait until crew has been loaded in before monitoring for pilot's death, so that the pilot's death does not cause the heli to self destruct before he's been loaded in. Helicopter is still a burning wreck.

- I "cheated" a little by using setVelocity [0,0,10] on the helicopter to give it velocity in the Z axis after it spawns. First attempt has the helicopter crew successfully spawning and beginning their patrol.

- After repeat testing, it seems that 3 out of every 10 helicopters spawned take a nose-dive after spawning.

- Update: The cause for the crash appears when the group's first waypoint is modified. Removing the waypoint-related lines results in the helicopter hovering indefinitely without crashes.

Edited by Masheen

Share this post


Link to post
Share on other sites

Inb4: DayZ haters :D

Okay, I know this is not the thing you wanted to hear and I'm opposed to say this, but your problem is a DayZ specific one :D

DayZ keeps track of every "legit" vehicle in the server with a server monitor and a global array in which all the vehicles are referenced.

If your spawned vehicle is NOT in this array and does not have the appropriate attributes set (like OwnerID and such) it will automatically blow up everytime someone gets into that vehicle.

What I do in vanilla Arma2 is spawning the AI soldiers at coords [0,0,0] and then get them into the heli one after another, starting with the pilot of course :D

Never had any problems with this, but as I said, I highly recommand to look into DayZ-Forums to find out how to legitimately spawn vehicles.

Share this post


Link to post
Share on other sites

I have already bypassed DayZ's legit vehicle check with the necessary edits, so this is now essentially a generic ArmA2 scripting issue. This script is part of an AI addon I'm working on for DayZ, but this is one of the parts that does not rely on any DayZ-specific code.

Share this post


Link to post
Share on other sites

Groups don't contain vehicles. Groups contain people. Vehicles are in the group of whichever units are in it. (Guessing driver or commander decides). I'm guessing this is the reasons you get the null:

- There aren't any units in the heli belonging to the group and an empty vehicle does not belong to any group.

Share this post


Link to post
Share on other sites

I'll edit in the full text of the script in a moment. After the part where I've cut off the code sample is where I spawn the AI crew individually.

The thing that baffles me is that 50% of the time, the AI crew is fully spawned, board the helicopter and proceed to successfully patrol around the map.

Share this post


Link to post
Share on other sites

Well when programming there is one thumb I'm following: if somethings just working with a sporadically, it has something to do with race conditions or deadlocks. As we don't have to deal with any threading related problems here, I'll just assume it has to do with timing.

I also scripted something like this a while ago and also had scripted that the heli will automatically blow up once the driver is dead - which caused spontenous explosions every third or fourth time I spawned the heli with the crew.

To eliminate this problem, I made these steps: First create the crew at ground level, then create the heli (I also disabled simulation just for the case) and get the crew into the heli.

My script waited with waitUntil{!isNull (driver _heli)}; and then checked in a loop if the driver is alive. This last line really helped me out, because I didn't have to take care of any timing issues anymore.

You could also spawn your heli at ground level, mount the crew and then get the heli into the air, I think that would prevent any crashes you wouldn't want.

Share this post


Link to post
Share on other sites

Thank you XxAnimusxX for your help. Unfortunately having the helicopter spawn at ground level is not a very attractive option in a DayZ scenario since there is the ever-present risk that a player is nearby, which means the helicopter and its crew are vulnerable until the helicopter achieves flight. However, I will still consider this option.

After multiple trial runs, I observe this sequence of events for each helicopter spawned:

- Helicopter spawns in air with rotors spinning (as expected)

- Heli moves slightly upwards due to setVelocity command (expected)

- This is where the events diverge

-- 50% of helicopters hover for a second before adjusting orientation and continuing flight as expected

-- 50% of helicopters fly directly into the ground, without attempting to reorient themselves.

Update: The culprit of the crashing appears to be just before the helicopter's waypoint is assigned. Interrupting the script just after the combatMode is set causes the helicopter to hang around in the air just fine. It's the waypoint assignment that seems to cause the heli to fly into the ground.

Edit: Removed setVelocity command since it didn't help the crashing issue. I'm having trouble figuring out why some helicopter spawns fly directly towards the ground while others travel along to their waypoint just fine.

Video of several helicopter spawns using the same script (some crash, some do not):

I'm now suspecting that the pilot has not made it into the helicopter.

Edit: Suspicions confirmed - the null groups is the cause of the helicopter crashes, as no crew is inside.

Edited by Masheen

Share this post


Link to post
Share on other sites

I took a part of Muzzleflash's suggestion about vehicles and groups, so I rearranged the script so that the sequence of events is now as follows:

- Create the group

- Spawn the AI crew and assign them to the group

- Spawn the helicopter in flight with engines on and rotors spinning

- Assign pilot and gunner positions and load units into helicopter

- Begin waypoint assignment

Right now it seems that the issue is fixed. I had two helicopters crash but it was because one helicopter spawned too quickly and collided with another. Discounting that incident, there is now a 100% success rate in a trial of 15 spawns. I would also like to thank Animus and Muzzleflash for their assistance in this matter.

Edit: 15 more trials produced a 100% success rate. Looks like this issue is fixed for good.

Edited by Masheen

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  

×