OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Felonmarmer on 01 Mar 2009, 16:31:15
-
I have a bunch of fixed MG's named MG1...MG8, and I want to check if theirs a gunner in them or if they have been killed and if do replace them from a limited supply. I'm using an array rather than using a format ["MG%1",_var] so I can vary it with differently named objects.
The code is as follows but I get a type string expected error and a missing semicolon error and I can't fathom out where the codes wrong.
_UKNum=100;
_Location=["MG1","MG2","MG3","MG4","MG5","MG6","MG7","MG8"];
_BaseDefenders = createGroup West;
_debug=true;
while {_UKNum>0} do
{
for [{_i=0}, {_i<8}, {_i=_i+1}] do
{
if (_UKNum>1) then
{
_MGString = (_Location select _i);
_MG = call compile _MGString;
if (isNull gunner _MG) then
{
_UKNum=_UKNum-1;
if (_debug) then {hint format["Numbers : %1",_UKNum]};
_gunner= _BaseDefenders ["SoldierWB", position _MG, [], 0, "NONE"];
_gunner moveInGunner _MG;
};
};
};
sleep 30+(random 30);
};
Can anyone point out the error(s) before my head explodes.
-
We-eell, the most obvious thing that jumps into your face is that you've got the createUnit syntax wrong. More precisely, you forgot the actual command ;)
_gunner= _BaseDefenders createUnit ["SoldierWB", position _MG, [], 0, "NONE"];
As to the complicated for....do, I never understood the point of making it that damned complicated, but there might be something wrong there; ask someone who understands how that thing works ;)
Wolfrug out.
-
:-[ Doh
That fixed it, must remember to actually use the command!
Cheers
-
I took the liberty to rewrite the code to look a bit less complicated yet do the same thing ;)
_UKNum = 100;
_Location = ["MG1","MG2","MG3","MG4","MG5","MG6","MG7","MG8"];
_BaseDefenders = createGroup West;
_debug = true;
while {_UKNum>0} do
{
{
_MG = call compile _x;
if ( (isNull gunner _MG) && (_UKNum > 1) ) then
{
_UKNum = _UKNum-1;
if (_debug) then {hint format["Numbers : %1",_UKNum]};
_gunner = "SoldierWB" createUnit [position _MG, _BaseDefenders];
_gunner moveInGunner _MG;
};
} forEach _Location;
sleep 30+(random 30);
};
-
And I merely removed a few more things. Namely a compile, and made it so theres exactly 100 re-spawns, instead of 99. :D
_d = true;
_i = 100;
_m = [mg1, mg2, mg3, mg4, mg5, mg6, mg7, mg8];
_gr = creategroup west;
while {_i > 0} do {
{
if ( (isnull gunner _x) && (_i > 0) ) then {
_i = _i - 1;
if (_d) then {hint format ["Respawns Left : %1", _i]};
private "_g";
_g = "SoldierWB" createunit [getpos _x, _gr];
_g moveInGunner _x
}
} foreach _m;
sleep 30 + (random 30)
};
note: I also did the pain in the ass thing and re-named the variables to shorter representations. :whistle: