script debugging help
Posted: Fri Dec 09, 2011 1:47 am
I have a problem with a spawn script i want to implement.
For some weird reason it seems to repeat the for loop at the end infinitely, maybe even speeding up in the process.
For some weird reason it seems to repeat the for loop at the end infinitely, maybe even speeding up in the process.
if (!isServer) exitWith {};
private ["_spawnarea","_grpsarray","_max","_men","_spawn","_wp1","_wp2","_pos1","_pos2"];
_spawnarea = toLower (_this select 0); //takes the spawnarea from the trigger
if (!(_spawnarea == "west") and !(_spawnarea == "east") and !(_spawnarea == "centerl")and !(_spawnarea == "centerr")and !(_spawnarea == "centerc") and !(_spawnarea == "debug")) exitwith {player globalchat format ["DEBUG : Spawnlocation is not in the list"];};
{if (({alive _x} count units _x) == 0) then {deleteGroup _x}} foreach allGroups; //deletes all empty groups
_sleep = 0; //defining the later used variables
_spawn = [];
_pos1 = [];
_pos2 = [];
_men = var_spawnmen; // (Mission Parameter) it's probably unnecessary to make var_spawnmen
_max = ceil(random 3); //random number from 1 to maximum amount of groups wanted
switch (_spawnarea) do
{
case "west":
{
_spawn = spawnwest;
_pos1 = getmarkerpos "West_WP1";
_pos2 = getmarkerpos "West_WP2";
_grpsarray = grpsW;
};
case "east":
{
_spawn = spawneast;
_pos1 = getmarkerpos "East_WP1";
_pos2 = getmarkerpos "East_WP2";
_grpsarray = grpsE;
};
case "centerc":
{
_spawn = spawncenterc;
_pos1 = getmarkerpos "Centerc_WP1";
_pos2 = getmarkerpos "Center_WP2";
_grpsarray = grpsCC;
};
case "centerr":
{
_spawn = spawncenterr;
_pos1 = getmarkerpos "Centerr_WP1";
_pos2 = getmarkerpos "Center_WP2";
_grpsarray = grpsCR;
};
case "centerl":
{
_spawn = spawncenterl;
_pos1 = getmarkerpos "Centerl_WP1";
_pos2 = getmarkerpos "Center_WP2";
_grpsarray = grpsCL;
};
case "debug": //Debug spawn
{
_spawn = spawndebug;
_pos1 = getmarkerpos "Centerc_WP1";
_pos2 = getmarkerpos "Center_WP2";
player globalchat format ["DEBUG : Debug spawn selected, _max = %1, _men = %2, _grpscnt: %3",_max, _men, _grpscnt];
};
};
for "_i" from 0 to _max do {
if (f_var_debugMode == 1) then {player globalchat format ["DEBUG : Spawning soldiers, loop = %1",_i];}; //DEBUG line
_grp = _grpsarray select _i; //take the name from the grps database in spawn_init (e.g. grpsW = [GrpInd1_W,GrpInd2_W,GrpInd3_W]
_grp = CreateGroup resistance; //and create a group with that name
if (f_var_debugMode == 1) then {player globalchat format ["DEBUG : Group created, selected grp is: %1, spawn is: %2", _grp, _spawn];}; //DEBUG LINE
//we create the main body of the group:
"GUE_Soldier_CO" createunit [_spawn,_grp, "nul = ['ftl',this] execVM 'f\common\folk_assignGear.sqf'"];
sleep 0.5;
"GUE_Soldier_2" createunit [_spawn,_grp, "nul = ['r',this] execVM 'f\common\folk_assignGear.sqf'"];
sleep 0.5;
"GUE_Soldier_3" createunit [_spawn,_grp, "nul = ['rb',this] execVM 'f\common\folk_assignGear.sqf'"];
sleep 0.5;
if (f_var_debugMode == 1) then {player globalchat format ["DEBUG : 3 Soldiers created, selected grp is: %1, spawn is: %2", _grp, _spawn];}; //DEBUG LINE
//and extra soldiers according to the spawnmen parameter:
if (_men == 1) then {
"GUE_Soldier_1" createunit [_spawn,_grp, "nul = ['r',this] execVM 'f\common\folk_assignGear.sqf'"];
if (f_var_debugMode == 1) then {player globalchat format ["DEBUG : Extra soldier1 created"];}; //DEBUG LINE
};
if (_men == 2) then {
"GUE_Soldier_AR" createunit [_spawn,_grp, "nul = ['ar',this] execVM 'f\common\folk_assignGear.sqf'"];
};
if (_men == 3) then {
"GUE_Soldier_AT" createunit [_spawn,_grp, "nul = ['rrpg',this] execVM 'f\common\folk_assignGear.sqf'"];
};
sleep 2; //sleep to give the spawned guys a moment to move
if (f_var_debugMode == 1) then {player globalchat format ["DEBUG : soldiers created, then adding skill"];};
if (f_param_AISkill_Enemy == 4) then { //if we're using the extra enemy skill parameter
{ //the skills will be adjusted individually
_x setskill ["aimingAccuracy",0.20];
_x setskill ["aimingShake",0.20];
_x setskill ["aimingSpeed",0.25];
_x setskill ["spotDistance",0.65];
_x setskill ["spotTime",0.65];
_x setskill ["courage",0.85];
_x setskill ["commanding",0.75];
} forEach units _grp;}
else {
{_x setSkill f_skillRES} forEach units _grp; //otherwise it just uses the FOLK standard
};
_wp1 = _grp addwaypoint [_pos1, 50]; //add the first waypoint and make them charge
_wp1 setwaypointspeed "FULL";
_wp1 setwaypointtype "SENTRY";
_wp1 setWaypointFormation "LINE";
_wp1 setWaypointBehaviour "AWARE";
_wp2 = _grp addwaypoint [_pos2, 50];
if (f_var_debugMode == 1) then {player globalchat format ["DEBUG : Sending group off _pos1 is: %1, _pos2 is: %2, _wp1: %3, _wp2: %4", _pos1, _pos2, _wp1, _wp2];}; //DEBUG LINE
sleep 10;
};