What it means it is that earlier in my missions I created infantry squad and helicopter with crew which flew the inf squad into target location then returned to base where they were deleted again, but right now I have the helicopters pre-set for example in mission editor. No more "fake" artificial helos spawn out of thin air, now the helos get damaged, they need to be refueled, accidents happen (you know AI landing hehe) and you need to care about the airframes.
Maybe its bit difficult to explain or reason why I wanted this system, but please feel free to ask questions if I'm again confusing everyone.
Okay for editing this piece of junk. The scripts I'm about to show here are unfinished work in progress ones, they aren't much commented, don't have helo death checks and even have hard coded stuff still in, I just wanted to post this now as I got it finally working OK.
So I have simply two scripts to run. But first I was in mission editor and placed two helicopters, named "helo1" and "helo2", then four infantry squads on their init line "usinf1 = group this;" and that being usinf2, usinf3 and usinf4 for all of the names.
Then first script PMC_Helo_Transport.sqf which is run from init.sqf for example:
Code: Select all
private
[
"_grp",
"_Helo",
"_lz",
"_PMC_Check_Helo_List",
"_tmp"
];
sleep 1;
// array list of helicopters
PMC_HeloList =
[
helo1,
helo2
];
// array list of infantry groups
PMC_Infantry =
[
usinf1,
usinf2,
usinf3,
usinf4
];
// check and return helo name
_PMC_Check_Helo_List =
{
// clear the _Helo variable
_Helo = objnull;
// check if we have available helos.
if (count PMC_HeloList > 0) then
{
// grab the first helo
_Helo = (PMC_HeloList select 0);
// remove it from the helolist
PMC_HeloList = PMC_HeloList - [PMC_HeloList select 0];
hint format["_PMC_HeloList after we took first guy out:\n%1\n\nAnd first guy: %2", PMC_HeloList, _Helo];
};
// return the helo name
_Helo;
};
_PMC_Load_Troops =
{
// troops are loaded into helo.
{
_x assignAsCargo _Helo;
[_x] orderGetIn true;
player sidechat format["_x: %1. _Helo: %2", _x, _Helo];
} forEach units _grp;
};
/*
main program ;)
*/
_lz = pmc_1;
while {true} do
{
// until we have helo and infantry available.
waitUntil
{
sleep 5;
player sidechat format["PMC_HeloList: %1, PMC_Infantry: %2", (count PMC_HeloList), (count PMC_Infantry)];
( (count PMC_HeloList > 0) && (count PMC_Infantry > 0) );
};
// first infantry group calls in for transport
_grp = PMC_Infantry select 0;
// remove the first group from the array.
PMC_Infantry = PMC_Infantry - [PMC_Infantry select 0];
_Helo = [] call _PMC_Check_Helo_List;
player sidechat "_PMC_Check_Helo_List completed.";
[] call _PMC_Load_Troops;
player sidechat "_PMC_Load_Troops completed.";
// make the helo fly.
[_lz, _Helo, _grp, homebase] execVM "PMC_Helo_Transport_fly.sqf";
};
hint "_PMC_Infantry is empty, they are all on their way!";
player sidechat "_PMC_Infantry is empty, they are all on their way!";
And this is the second script which is called from the first one, its name: PMC_Helo_Transport_fly.sqf
Code: Select all
private
[
"_grp",
"_Helo",
"_homebase",
"_PMC_Helo_Return_To_Base",
"_PMC_Send_Helo_On_Way",
"_PMC_Unload_Troops",
"_lz",
"_tmp"
];
_PMC_Send_Helo_On_Way =
{
// helo send to destination.
_Helo move _lz;
waitUntil
{
sleep 2;
_Helo distance _lz < 100;
};
};
_PMC_Unload_Troops =
{
// troops unloaded from the helo.
{
unAssignVehicle _x;
} forEach units _grp;
// this makes sure function runs "easy" and not return
// while helo is still very much unloading troops. its not perfect though.
waitUntil
{
sleep 2;
((getPos _Helo select 2) < 3 );
};
};
_PMC_Helo_Return_To_Base =
{
// helo returns to base.
_Helo move getPos _homebase;
waitUntil
{
sleep 2;
_Helo distance _homebase < 100;
};
// helo inserted back to _PMC_HeloList[].
_Helo land "land";
waitUntil
{
sleep 1;
((getPos _Helo select 2) < 2 );
};
PMC_HeloList = PMC_HeloList + [_Helo];
};
/*
main program :)
*/
_tmp = _this select 0;
_Helo = _this select 1;
_grp = _this select 2;
_homebase = _this select 3;
_lz = getPos _tmp;
[] call _PMC_Send_Helo_On_Way;
player sidechat "_PMC_Send_Helo_On_Way completed.";
[] call _PMC_Unload_Troops;
player sidechat "_PMC_Unload_Troops completed.";
[] call _PMC_Helo_Return_To_Base;
player sidechat "_PMC_Helo_Return_To_Base completed.";
I'll try to update this topic when I refine this system bit more. Also this is not really usable for anyone's missions as is because even though this is the backbone for helo transport system... you totally need to build the "request transport" scripting design on top of this (unless you manage to use the current waituntil condition which is very very generic).
All feedback is welcome (which I know there will be none).