script debugging help

Kill your comrades. Wholesale
Post Reply
User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

script debugging help

Post by wolfenswan »

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.
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;
};
Last edited by wolfenswan on Fri Dec 09, 2011 12:19 pm, edited 1 time in total.

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: script debugging help

Post by wolfenswan »

Two observations:

1. The script seem to run fine once, then it runs amok and repeats the loop over and over.

2. The "_grp = _grpsarray select _i;" part is probably unnecessary as arma seems to create grp-identifiers according to a default naming scheme if none is given.

3. Regarding the extra skill parameter: The f_setSkillAI handles the fourth case as it would handle the parameter set to low. It only affects the dynamically generated units because of that if-check.

4. If nothing helps i'm going to use BIS_fnc_spawnGroup (i wanted to use the FOLK gear script on the spawned units and have a better control over what is spawned) or simply get rid of the loop and use other methods of randomization (call BIS_fnc_selectRandom)

Nullkigan
Posts: 50
Joined: Sat May 28, 2011 4:44 pm

Re: script debugging help

Post by Nullkigan »

wolfenswan wrote:1. The script seem to run fine once, then it runs amok and repeats the loop over and over.
Indicates trigger problems, rather than a script problem?
wolfenswan wrote:3. Regarding the extra skill parameter: The f_setSkillAI handles the fourth case as it would handle the parameter set to low. It only affects the dynamically generated units because of that if-check.
You also want to set allowfleeing to 0 for defence missions.
wolfenswan wrote:4. If nothing helps i'm going to use BIS_fnc_spawnGroup (i wanted to use the FOLK gear script on the spawned units and have a better control over what is spawned) or simply get rid of the loop and use other methods of randomization (call BIS_fnc_selectRandom)
That's what I did for Iron Dyanmo ( :siiigh: ). I'll see if I can't find a copy, but it has been a while and the server is turning up blank. The only things that didn't work properly were the next wave triggers (which needed to be timed if the players didn't kill everyone) and the COIN (BIS broke it many patches ago).

Nullkigan
Posts: 50
Joined: Sat May 28, 2011 4:44 pm

Re: script debugging help

Post by Nullkigan »

I'm working on converting my BIS_fnc_SpawnGroup_MOD, BIS_fnc_ReturnGroupCompositon_MOD and Spawn_Random_BIS_Attackers.sqfs to something legible, but for now this is a script (untested) that detects, if passed a group, the loadouts of the group members and folk-ifies them. It can probably be optimised (e.g. by making common roles the first comparisons), but should work.
if (!isServer) exitWith {};

private ["_co_sc","_dc_sc","_md_sc","_ftl_sc","_ar_sc","_aar_sc","_rpg_sc","_at_sc","_mat_sc","_amat_sc","_mg_sc","_amg_sc","_sn_sc","_sp_sc","_grp","_unit","_doneYet"]

_co_sc=["FR_Commander", "CDF_Commander", "Ins_Commander", "RU_Commander", "RUS_Commander", "Ins_Soldier_CO", "Ins_Commander", "TK_Aziz_EP1", "TK_Commander_EP1", "GUE_Soldier_CO", "GUE_Commander", "USMC_Soldier_Officer", "CDF_Soldier_Officer", "US_Soldier_Officer_EP1", "BAF_Soldier_Officer_MTP", "RU_Soldier_Officer", "TK_Soldier_Officer_EP1", "UN_CDF_Soldier_Officer_EP1", "TK_INS_Warlord_EP1", "TK_GUE_Warlord_EP1"];
_dc_sc=[];
_md_sc=["Soldier_Medic_PMC", "USMC_Soldier_Medic", "CDF_Soldier_Medic", "US_Soldier_Medic_EP1", "US_Delta_Force_Medic_EP1", "GER_Soldier_Medic_EP1", "BAF_Soldier_Medic_MTP", "RU_Soldier_Medic", "Ins_Soldier_Medic", "TK_Soldier_Medic_EP1", "GUE_Soldier_Medic"];
_ftl_sc=["USMC_Soldier_SL", "CZ_Soldier_SL_DES_EP1", "US_Soldier_SL_EP1", "BAF_Soldier_SL_MTP", "RU_Soldier_SL", "TK_Soldier_SL_EP1", "UN_CDF_Soldier_SL_EP1", "USMC_Soldier_TL", "FR_TL", "CDF_Soldier_TL", "CZ_Special_Forces_TL_DES_EP1", "US_Soldier_TL_EP1", "US_Delta_Force_TL_EP1", "GER_Soldier_TL_EP1", "BAF_Soldier_TL_MTP", "RU_Soldier_TL", "RUS_Soldier_TL", "MVD_Soldier_TL", "TK_INS_Soldier_TL_EP1", "TK_Special_Forces_TL_EP1", "TK_GUE_Soldier_TL_EP1", "Soldier_TL_PMC"];
_ar_sc=["USMC_Soldier_AR", "FR_AR", "CDF_Soldier_AR", "US_Soldier_AR_EP1", "US_Delta_Force_AR_EP1", "BAF_Soldier_AR_MTP", "RU_Soldier_AR", "Ins_Soldier_AR", "TK_INS_Soldier_AR_EP1", "TK_Soldier_AR_EP1", "GUE_Soldier_AR", "TK_GUE_Soldier_AR_EP1"];
_aar_sc=["BAF_Soldier_AAR_MTP", "US_Soldier_AAR_EP1"];
_rpg_sc=["USMC_Soldier_LAT", "US_Soldier_LAT_EP1", "RU_Soldier_LAT", "TK_Soldier_LAT_EP1"];
_at_sc=["USMC_Soldier_AT", "CZ_Soldier_AT_DES_EP1", "US_Soldier_AT_EP1", "BAF_Soldier_AT_MTP", "RU_Soldier_AT", "MVD_Soldier_AT", "Ins_Soldier_AT", "TK_INS_Soldier_AT_EP1", "TK_Soldier_AT_EP1", "GUE_Soldier_AT", "TK_GUE_Soldier_AT_EP1", "UN_CDF_Soldier_AT_EP1", "Soldier_AT_PMC"];
_mat_sc=["USMC_Soldier_HAT", "US_Soldier_HAT_EP1", "BAF_Soldier_HAT_MTP", "RU_Soldier_HAT", "TK_Soldier_HAT_EP1", "TK_GUE_Soldier_HAT_EP1"];
_amat_sc=["BAF_Soldier_AAT_MTP", "BAF_Soldier_AHAT_MTP", "TK_INS_Soldier_AAT_EP1", "TK_Soldier_AAT_EP1", "TK_GUE_Soldier_AAT_EP1", "UN_CDF_Soldier_AAT_EP1", "US_Soldier_AHAT_EP1", "US_Soldier_AAT_EP1"];
_mg_sc=["USMC_Soldier_MG", "CDF_Soldier_MG", "CZ_Soldier_MG_DES_EP1", "CZ_Special_Forces_MG_DES_EP1", "US_Soldier_MG_EP1", "US_Delta_Force_MG_EP1", "GER_Soldier_MG_EP1", "BAF_Soldier_MG_MTP", "RU_Soldier_MG", "MVD_Soldier_MG", "Ins_Soldier_MG", "TK_INS_Soldier_MG_EP1", "TK_Soldier_MG_EP1", "TK_Special_Forces_MG_EP1", "GUE_Soldier_MG", "TK_GUE_Soldier_MG_EP1", "UN_CDF_Soldier_MG_EP1", "Soldier_MG_PMC", "Soldier_MG_PKM_PMC"];
_amg_sc=["CZ_Soldier_AMG_DES_EP1", "US_Soldier_AMG_EP1", "BAF_Soldier_AMG_MTP", "TK_Soldier_AMG_EP1", "UN_CDF_Soldier_AMG_EP1"];
_sn_sc=["USMC_SoldierS_Sniper", "CDF_Soldier_Sniper", "CZ_Soldier_Sniper_EP1", "US_Soldier_Sniper_EP1", "BAF_Soldier_Sniper_MTP", "RU_Soldier_Sniper", "MVD_Soldier_Sniper", "Ins_Soldier_Sniper", "TK_INS_Soldier_Sniper_EP1", "TK_Soldier_Sniper_EP1", "GUE_Soldier_Sniper", "TK_GUE_Soldier_Sniper_EP1", "Soldier_Sniper_PMC"];
_sp_sc=["USMC_SoldierS_Spotter", "CDF_Soldier_Spotter", "US_Soldier_Spotter_EP1", "BAF_Soldier_spotter_MTP", "RU_Soldier_Spotter", "TK_Soldier_Spotter_EP1"];

_grp = _this select 0; // squad this script is called on
{_unit=_x;
_doneYet = 0;
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['co',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _co_sc;};
//if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['dc',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _dc_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['m',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _md_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['ftl',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _ftl_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['ar',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _ar_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['aar',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _aar_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['rrpg',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _rpg_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['rat',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _at_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['mmgg',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _mg_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['mmgag',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _amg_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['matg',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _mat_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['matag',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _amat_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['sn',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _sn_sc;};
if (_doneYet == 0) then {{ if (_unit isKindOf _x) then {_doneYet=1;_unit setVehicleInit "nul = ['sp',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _sp_sc;};
if (_doneYet == 0) then {_doneYet=1;_unit setVehicleInit "nul = ['aar',this] execVM 'f\common\folk_assignGear.sqf';";} } ForEach _sp_sc;}; // catch riflemen and misc types
} forEach units _grp;
processInitCommands;
Or, in slightly more legible syntax (using Count and TypeOf instead of isKindOf):
if (!isServer) exitWith {};
private ["_co_sc","_dc_sc","_md_sc","_ftl_sc","_ar_sc","_aar_sc","_rpg_sc","_at_sc","_mat_sc","_amat_sc","_mg_sc","_amg_sc","_sn_sc","_sp_sc","_grp","_unit","_doneYet"]

_co_sc=["FR_Commander", "CDF_Commander", "Ins_Commander", "RU_Commander", "RUS_Commander", "Ins_Soldier_CO", "Ins_Commander", "TK_Aziz_EP1", "TK_Commander_EP1", "GUE_Soldier_CO", "GUE_Commander", "USMC_Soldier_Officer", "CDF_Soldier_Officer", "US_Soldier_Officer_EP1", "BAF_Soldier_Officer_MTP", "RU_Soldier_Officer", "TK_Soldier_Officer_EP1", "UN_CDF_Soldier_Officer_EP1", "TK_INS_Warlord_EP1", "TK_GUE_Warlord_EP1"];

_dc_sc=[];

_md_sc=["Soldier_Medic_PMC", "USMC_Soldier_Medic", "CDF_Soldier_Medic", "US_Soldier_Medic_EP1", "US_Delta_Force_Medic_EP1", "GER_Soldier_Medic_EP1", "BAF_Soldier_Medic_MTP", "RU_Soldier_Medic", "Ins_Soldier_Medic", "TK_Soldier_Medic_EP1", "GUE_Soldier_Medic"];

_ftl_sc=["USMC_Soldier_SL", "CZ_Soldier_SL_DES_EP1", "US_Soldier_SL_EP1", "BAF_Soldier_SL_MTP", "RU_Soldier_SL", "TK_Soldier_SL_EP1", "UN_CDF_Soldier_SL_EP1", "USMC_Soldier_TL", "FR_TL", "CDF_Soldier_TL", "CZ_Special_Forces_TL_DES_EP1", "US_Soldier_TL_EP1", "US_Delta_Force_TL_EP1", "GER_Soldier_TL_EP1", "BAF_Soldier_TL_MTP", "RU_Soldier_TL", "RUS_Soldier_TL", "MVD_Soldier_TL", "TK_INS_Soldier_TL_EP1", "TK_Special_Forces_TL_EP1", "TK_GUE_Soldier_TL_EP1", "Soldier_TL_PMC"];

_ar_sc=["USMC_Soldier_AR", "FR_AR", "CDF_Soldier_AR", "US_Soldier_AR_EP1", "US_Delta_Force_AR_EP1", "BAF_Soldier_AR_MTP", "RU_Soldier_AR", "Ins_Soldier_AR", "TK_INS_Soldier_AR_EP1", "TK_Soldier_AR_EP1", "GUE_Soldier_AR", "TK_GUE_Soldier_AR_EP1"];

_aar_sc=["BAF_Soldier_AAR_MTP", "US_Soldier_AAR_EP1"];

_rpg_sc=["USMC_Soldier_LAT", "US_Soldier_LAT_EP1", "RU_Soldier_LAT", "TK_Soldier_LAT_EP1"];

_at_sc=["USMC_Soldier_AT", "CZ_Soldier_AT_DES_EP1", "US_Soldier_AT_EP1", "BAF_Soldier_AT_MTP", "RU_Soldier_AT", "MVD_Soldier_AT", "Ins_Soldier_AT", "TK_INS_Soldier_AT_EP1", "TK_Soldier_AT_EP1", "GUE_Soldier_AT", "TK_GUE_Soldier_AT_EP1", "UN_CDF_Soldier_AT_EP1", "Soldier_AT_PMC"];

_mat_sc=["USMC_Soldier_HAT", "US_Soldier_HAT_EP1", "BAF_Soldier_HAT_MTP", "RU_Soldier_HAT", "TK_Soldier_HAT_EP1", "TK_GUE_Soldier_HAT_EP1"];

_amat_sc=["BAF_Soldier_AAT_MTP", "BAF_Soldier_AHAT_MTP", "TK_INS_Soldier_AAT_EP1", "TK_Soldier_AAT_EP1", "TK_GUE_Soldier_AAT_EP1", "UN_CDF_Soldier_AAT_EP1", "US_Soldier_AHAT_EP1", "US_Soldier_AAT_EP1"];

_mg_sc=["USMC_Soldier_MG", "CDF_Soldier_MG", "CZ_Soldier_MG_DES_EP1", "CZ_Special_Forces_MG_DES_EP1", "US_Soldier_MG_EP1", "US_Delta_Force_MG_EP1", "GER_Soldier_MG_EP1", "BAF_Soldier_MG_MTP", "RU_Soldier_MG", "MVD_Soldier_MG", "Ins_Soldier_MG", "TK_INS_Soldier_MG_EP1", "TK_Soldier_MG_EP1", "TK_Special_Forces_MG_EP1", "GUE_Soldier_MG", "TK_GUE_Soldier_MG_EP1", "UN_CDF_Soldier_MG_EP1", "Soldier_MG_PMC", "Soldier_MG_PKM_PMC"];

_amg_sc=["CZ_Soldier_AMG_DES_EP1", "US_Soldier_AMG_EP1", "BAF_Soldier_AMG_MTP", "TK_Soldier_AMG_EP1", "UN_CDF_Soldier_AMG_EP1"];

_sn_sc=["USMC_SoldierS_Sniper", "CDF_Soldier_Sniper", "CZ_Soldier_Sniper_EP1", "US_Soldier_Sniper_EP1", "BAF_Soldier_Sniper_MTP", "RU_Soldier_Sniper", "MVD_Soldier_Sniper", "Ins_Soldier_Sniper", "TK_INS_Soldier_Sniper_EP1", "TK_Soldier_Sniper_EP1", "GUE_Soldier_Sniper", "TK_GUE_Soldier_Sniper_EP1", "Soldier_Sniper_PMC"];

_sp_sc=["USMC_SoldierS_Spotter", "CDF_Soldier_Spotter", "US_Soldier_Spotter_EP1", "BAF_Soldier_spotter_MTP", "RU_Soldier_Spotter", "TK_Soldier_Spotter_EP1"];

_grp = _this select 0; // squad this script is called on
{_unit=_x;
_doneYet = 0;
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _co_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['co',this] execVM 'f\common\folk_assignGear.sqf';";};
};
//if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _dc_sc); // let _doneYet contain the number of matches
// if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['dc',this] execVM 'f\common\folk_assignGear.sqf';";};
//};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _md_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['m',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _ftl_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['ftl',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _ar_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['ar',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _aar_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['aar',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _rpg_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['rrpg',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _at_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['rat',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _mg_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['mmgg',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _amg_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['mmgag',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _mat_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['matg',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _amat_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['matag',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _sn_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['sn',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_doneYet = ({_unit == (typeOf _x)} count _sp_sc); // let _doneYet contain the number of matches
if (_doneYet >= 1) then {_unit setVehicleInit "nul = ['sp',this] execVM 'f\common\folk_assignGear.sqf';";};
};
if (_doneYet == 0) then {_unit setVehicleInit "nul = ['aar',this] execVM 'f\common\folk_assignGear.sqf';";}; // catch riflemen and misc types
};
} forEach units _grp;
processInitCommands;


This is the list of unit classes I used:
Commander nul = ["co",this] execVM "f\common\folk_assignGear.sqf";
FR_Commander
CDF_Commander
Ins_Commander
RU_Commander
RUS_Commander
Ins_Soldier_CO
Ins_Commander
TK_Aziz_EP1
TK_Commander_EP1
GUE_Soldier_CO
GUE_Commander
USMC_Soldier_Officer
CDF_Soldier_Officer
US_Soldier_Officer_EP1
BAF_Soldier_Officer_MTP
RU_Soldier_Officer
TK_Soldier_Officer_EP1
UN_CDF_Soldier_Officer_EP1
TK_INS_Warlord_EP1
TK_GUE_Warlord_EP1

Deputy Commander nul = ["dc",this] execVM "f\common\folk_assignGear.sqf";

Medic nul = ["m",this] execVM "f\common\folk_assignGear.sqf";
Soldier_Medic_PMC
USMC_Soldier_Medic
CDF_Soldier_Medic
US_Soldier_Medic_EP1
US_Delta_Force_Medic_EP1
GER_Soldier_Medic_EP1
BAF_Soldier_Medic_MTP
RU_Soldier_Medic
Ins_Soldier_Medic
TK_Soldier_Medic_EP1
GUE_Soldier_Medic

Fireteam Leader nul = ["ftl",this] execVM "f\common\folk_assignGear.sqf";
USMC_Soldier_SL
CZ_Soldier_SL_DES_EP1
US_Soldier_SL_EP1
BAF_Soldier_SL_MTP
RU_Soldier_SL
TK_Soldier_SL_EP1
UN_CDF_Soldier_SL_EP1
USMC_Soldier_TL
FR_TL
CDF_Soldier_TL
CZ_Special_Forces_TL_DES_EP1
US_Soldier_TL_EP1
US_Delta_Force_TL_EP1
GER_Soldier_TL_EP1
BAF_Soldier_TL_MTP
RU_Soldier_TL
RUS_Soldier_TL
MVD_Soldier_TL
TK_INS_Soldier_TL_EP1
TK_Special_Forces_TL_EP1
TK_GUE_Soldier_TL_EP1
Soldier_TL_PMC

Automatic Rifleman nul = ["ar",this] execVM "f\common\folk_assignGear.sqf";
USMC_Soldier_AR
FR_AR
CDF_Soldier_AR
US_Soldier_AR_EP1
US_Delta_Force_AR_EP1
BAF_Soldier_AR_MTP
RU_Soldier_AR
Ins_Soldier_AR
TK_INS_Soldier_AR_EP1
TK_Soldier_AR_EP1
GUE_Soldier_AR
TK_GUE_Soldier_AR_EP1

Assistant Automatic Rifleman nul = ["aar",this] execVM "f\common\folk_assignGear.sqf";
BAF_Soldier_AAR_MTP
US_Soldier_AAR_EP1

Rifleman (RPG) nul = ["rrpg",this] execVM "f\common\folk_assignGear.sqf";
USMC_Soldier_LAT
US_Soldier_LAT_EP1
RU_Soldier_LAT
TK_Soldier_LAT_EP1

Rifleman (AT) nul = ["rat",this] execVM "f\common\folk_assignGear.sqf";
USMC_Soldier_AT
CZ_Soldier_AT_DES_EP1
US_Soldier_AT_EP1
BAF_Soldier_AT_MTP
RU_Soldier_AT
MVD_Soldier_AT
Ins_Soldier_AT
TK_INS_Soldier_AT_EP1
TK_Soldier_AT_EP1
GUE_Soldier_AT
TK_GUE_Soldier_AT_EP1
UN_CDF_Soldier_AT_EP1
Soldier_AT_PMC

Medium MG Gunner nul = ["mmgg",this] execVM "f\common\folk_assignGear.sqf";
USMC_Soldier_MG
CDF_Soldier_MG
CZ_Soldier_MG_DES_EP1
CZ_Special_Forces_MG_DES_EP1
US_Soldier_MG_EP1
US_Delta_Force_MG_EP1
GER_Soldier_MG_EP1
BAF_Soldier_MG_MTP
RU_Soldier_MG
MVD_Soldier_MG
Ins_Soldier_MG
TK_INS_Soldier_MG_EP1
TK_Soldier_MG_EP1
TK_Special_Forces_MG_EP1
GUE_Soldier_MG
TK_GUE_Soldier_MG_EP1
UN_CDF_Soldier_MG_EP1
Soldier_MG_PMC
Soldier_MG_PKM_PMC

Medium MG Assistant Gunner nul = ["mmgag",this] execVM "f\common\folk_assignGear.sqf";
CZ_Soldier_AMG_DES_EP1
US_Soldier_AMG_EP1
BAF_Soldier_AMG_MTP
TK_Soldier_AMG_EP1
UN_CDF_Soldier_AMG_EP1

Medium AT Gunner nul = ["matg",this] execVM "f\common\folk_assignGear.sqf";
USMC_Soldier_HAT
US_Soldier_HAT_EP1
BAF_Soldier_HAT_MTP
RU_Soldier_HAT
TK_Soldier_HAT_EP1
TK_GUE_Soldier_HAT_EP1

Medium AT Assistant Gunner nul = ["matag",this] execVM "f\common\folk_assignGear.sqf";
BAF_Soldier_AAT_MTP
BAF_Soldier_AHAT_MTP
TK_INS_Soldier_AAT_EP1
TK_Soldier_AAT_EP1
TK_GUE_Soldier_AAT_EP1
UN_CDF_Soldier_AAT_EP1
US_Soldier_AHAT_EP1
US_Soldier_AAT_EP1

Sniper nul = ["sn",this] execVM "f\common\folk_assignGear.sqf";
USMC_SoldierS_Sniper
CDF_Soldier_Sniper
CZ_Soldier_Sniper_EP1
US_Soldier_Sniper_EP1
BAF_Soldier_Sniper_MTP
RU_Soldier_Sniper
MVD_Soldier_Sniper
Ins_Soldier_Sniper
TK_INS_Soldier_Sniper_EP1
TK_Soldier_Sniper_EP1
GUE_Soldier_Sniper
TK_GUE_Soldier_Sniper_EP1
Soldier_Sniper_PMC

Spotter nul = ["sp",this] execVM "f\common\folk_assignGear.sqf";
USMC_SoldierS_Spotter
CDF_Soldier_Spotter
US_Soldier_Spotter_EP1
BAF_Soldier_spotter_MTP
RU_Soldier_Spotter
TK_Soldier_Spotter_EP1

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: script debugging help

Post by wolfenswan »

great work; fairly easy to adapt to custom loadouts as well.

Nullkigan
Posts: 50
Joined: Sat May 28, 2011 4:44 pm

Re: script debugging help

Post by Nullkigan »

Found this interesting tidbit whilst digging through the help files to figure out why my scripts have stopped working (part of it is that getMarkerPos now expects a string instead of a marker, hooray patches):
scriptName "fn_spawnEnemy.sqf";
/*
Author: Karel Moricky

Description:
Spawns enemies around players

Parameter(s):
_this select 0: OBJECT - player
_this select 1: OBJECT - refence object (enemies will be spawned on opposite direction)
_this select 2: SIDE - side of enemies
_this select 3 (Optional): ARRAY - list of enemy classes
_this select 4 (Optional): NUMBER - delay between spawning
_this select 5 (Optional): CODE - code executed on every soldier. Unit is passed as _this

Returns:
ARRAY - list of all spawned crows
*/

_player = _this select 0;
_target = _this select 1;
_side = _this select 2;
_classList = _this select 3;
_maxCount = if (count _this > 4) then {_this select 4} else {10};
_delay = if (count _this > 5) then {_this select 5} else {30};
_code = if (count _this > 6) then {_this select 6} else {{}};

if (typename _target == typename objnull) then {_target = [_target,_target];};

_otherPlayer = (_players - [_player]) select 0;
_grp = creategroup _side;
_wp = _grp addwaypoint [position _player,10];
_wp setwaypointstatements ["false",""];
_wp setwaypointtype "guard";
_wp waypointattachvehicle _player;
_player setvariable ["BIS_spawnedEnemies",[]];

while {true} do {
waituntil {sleep 1; isplayer _player};
waituntil {sleep 1; {alive _x} count (_player getvariable "BIS_spawnedEnemies") < _maxCount};

_class = _classList call bis_fnc_selectrandom;
_dirToTarget = if (isMultiplayer) then {
_targetTemp = _target select 1;
([_player,_targetTemp] call bis_fnc_dirTo)
} else {
_targetTemp = _target select isMultiplayer;
([_player,_targetTemp] call bis_fnc_dirTo) + 180
};
_pos = [position _player, 180 + random 40, _dirToTarget + 90 + random 180] call BIS_fnc_relPos;
_unit = _grp createunit [_class,_pos,[],1,""];
_unit setskill (random 0.5);
_unit allowfleeing 0;
_unit setvehicleammo (0.5 + random 0.5);
if (random 1 > 0.5) then {_unit setunitpos "up"} else {_unit setunitpos "middle"};
[_player,"BIS_spawnedEnemies",[_unit]] call bis_fnc_variablespaceadd;
_wp setwaypointposition [position _player,0];

_unit call _code;

sleep _delay;
};

Nullkigan
Posts: 50
Joined: Sat May 28, 2011 4:44 pm

Re: script debugging help

Post by Nullkigan »

OK, this is a mostly working example with .pbo and source files: http://www.herosquad.org/null/%5Bco10%5 ... sert_E.zip
  • It spawns a random number of groups of a random number of soldiers (from OA content only!) at a random pick from a selection of markers.
  • It passes inits to spawned units (example is swapping all infantry weapons for NLAWs, as it's a nice visual example).
  • It spawns increasingly large waves of opposition as time goes on. The basic size of each wave is dependant upon the number of living players at the time the wave is triggered.
  • The most important script is Spawn_Random_BIS_Wave.sqf, although BIS_fnc_spawnGroup_Modv2.sqf contains some important modifications (for passing inits)
  • THE FUNCTIONS MANAGER, func_preprocs, IS IMPORTANT AS IT SETS UP THE SCRIPTS AT THE START OF THE MISSION. Something has changed since 1.57 so I can't work around that.
  • There's also a variables initialiser which creates the required ns_Waves (current wave) and ns_StartVehicleWaves (wave when vehicles start to spawn). If you don't have ns_StartVehicleWaves in your mission, you'll still get infantry so long as ns_Waves exists as a number. ns_WavesLimit is only used by the triggers, not the scripts.
  • A bunch of triggers exist to demonstrate usage.
  • Continue the marker naming format and then change the _NumMarkers variable in Spawn_Random_BIS_Wave.sqf to add more possible spawn locations. Move the infdestination marker with time for fun and profit.
  • It has been tested in multiplayer, but not with JIP. As almost everything is serverside, I think it'll be OK.
  • When localhosting, it will randomly spout debug text from the guy in front of the player.
  • It has a Description.ext, but it's not correctly hooked up. Wave time / max wave / vehicle wave are specified in the editor for now. OpFor difficuly defaults itself.
  • Spawn_Random_BIS_Wave.sqf specifies the side of the units to be spawned; edit that if you want it to spawn blufor
  • In BIS_fnc_spawnGroup_Modv2.sqf, _types = [_side, _chars] call GroupCompositionFunc; should become _types = [_side, _chars] call BIS_fnc_returnGroupComposition; if you want to spawn A2 units as well as OA.
  • yes, I know I'm not consistant with my naming schemes; this is an example
It's not yet fully integrated with F2, though some functionality is in place. I'll make a Working Example with the F2 stuff next.

Post Reply