Spawning random enemies can be troublesome in Arma 3. But this makes it easier. This will spawn the enemies in the middle of the map and this will find a safe location to spawn them. Fixed code for 2022.
Loc = [worldSize / 2, worldsize / 2, 0]; SafePos2 = [Loc, 95, 600, 20, 0, 0.3, 0] call BIS_fnc_findSafePos; _RandCorp = floor(random(6)); switch (_RandCorp) do { case 0: { _grup1 = [SafePos2, EAST, (configfile >> "CfgGroups" >> "East" >> "LOP_ChDKZ" >> "Infantry" >> "LOP_ChDKZ_Rifle_squad")] call BIS_fnc_spawnGroup; [_grup1, Loc] call CBA_fnc_taskDefend; }; case 1: { _grup2 = [SafePos2, EAST, (configfile >> "CfgGroups" >> "East" >> "LOP_AFR_OPF" >> "Infantry" >> "LOP_AFR_OPF_Rifle_squad")] call BIS_fnc_spawnGroup; [_grup2, this, 450, 7, "MOVE", "AWARE", "YELLOW", "FULL", "STAG COLUMN", "", [3,6,9]] call CBA_fnc_taskPatrol; }; case 2: { _grup1 = [SafePos2, EAST, (configfile >> "CfgGroups" >> "East" >> "LOP_AM_OPF" >> "Motorized" >> "LOP_AM_OPF_Motor_squad_OffroadM2")] call BIS_fnc_spawnGroup; [_grup1, Loc, 450, 7, "MOVE", "AWARE", "YELLOW", "FULL", "STAG COLUMN", "", [3,6,9]] call CBA_fnc_taskPatrol; }; case 3: { _grup1 = [SafePos2, EAST, (configfile >> "CfgGroups" >> "East" >> "LOP_ChDKZ" >> "Mechanized" >> "LOP_ChDKZ_Mech_squad_BMP1")] call BIS_fnc_spawnGroup; [_grup1, Loc, 450, 7, "MOVE", "AWARE", "YELLOW", "FULL", "STAG COLUMN", "", [3,6,9]] call CBA_fnc_taskPatrol; }; case 4: { _grup1 = [SafePos2, EAST, (configfile >> "CfgGroups" >> "East" >> "LOP_ChDKZ" >> "Mechanized" >> "LOP_ChDKZ_Mech_squad_BMP2")] call BIS_fnc_spawnGroup; [_grup1, Loc, 450, 7, "MOVE", "AWARE", "YELLOW", "FULL", "STAG COLUMN", "", [3,6,9]] call CBA_fnc_taskPatrol; }; case 5: { _grup1 = [SafePos2, EAST, (configfile >> "CfgGroups" >> "East" >> "LOP_ChDKZ" >> "Armored" >> "LOP_ChDKZ_BTR_Combined_Platoon")] call BIS_fnc_spawnGroup; [_grup1, Loc, 450, 7, "MOVE", "AWARE", "YELLOW", "FULL", "STAG COLUMN", "", [3,6,9]] call CBA_fnc_taskPatrol; }; }; |
This code will spawn a random group of enemies from a selection. This is a great way to have a few sets of code spawn various things, and they are randomly chosen. This is the proper way to use the switch statement with a random number.
Getting a random number from 0 to 6.
_RandCorp = floor(random(6)); |
It really helps your mission out, if you add a lot of random elements to it. This makes it more replayable.
Another very useful Arma 3 script. Put this in the initPlayerLocal.sqf file. This will put a random image on a billboard in your mission for each player.
_randomPic = [ "a3\missions_f_exp\data\Img\EXP_m01_Overview_CO.paa", "a3\missions_f_exp\data\Img\EXP_m01_Overview_large_CO.paa", "a3\missions_f_exp\data\Img\EXP_m01_Overview02_large_CO.paa", "a3\missions_f_exp\data\Img\EXP_m01_Overview03_large_CO.paa", "a3\missions_f_exp\data\Img\EXP_m02_Overview_CO.paa", "a3\missions_f_exp\data\Img\EXP_m02_Overview_large_CO.paa", "a3\missions_f_exp\data\Img\EXP_m02_Overview02_large_CO.paa", "a3\missions_f_exp\data\Img\EXP_m02_Overview03_large_CO.paa", "a3\missions_f_exp\data\Img\EXP_m03_Overview_CO.paa", "a3\missions_f_exp\data\Img\EXP_m03_Overview_large_CO.paa", "a3\missions_f_exp\data\Img\EXP_m03_Overview02_large_CO.paa", "a3\missions_f_exp\data\Img\Showcase_EndGame_overview_CA.paa", "a3\missions_f_exp\data\Img\Showcase_VTOL_overview_blackwhite_CA.paa", "\a3\missions_f\data\img\mp_coop_m01_overview_ca.paa", "\a3\missions_f\data\img\mp_coop_m02_overview_ca.paa", "\A3\Missions_F\data\img\Showcase_Helicopters_overview_CA.paa", "\a3\missions_f\data\img\showcase_infantry_overview_ca.paa", "\A3\Missions_F\data\img\Showcase_SCUBA_overview_CA.paa", "\A3\Missions_F\data\img\Showcase_Vehicles_overview_CA.paa", "\a3\Missions_F_Beta\data\img\SP_FD04_overview_CA.paa", "\a3\Missions_F_Bootcamp\data\img\Boot_VR_overview_CA.paa", "\a3\Missions_F_Gamma\data\img\mp_coop_m03_overview_ca.paa", "\a3\Missions_F_Kart\data\img\MP_ZR_Altis_overview_CA.paa", "\a3\Missions_F_Kart\data\img\MP_ZR_Stratis_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_in_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_in2_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_hub01_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_m01_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_m02_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_m03_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_m05_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_skirmish01_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_m04_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_hub02_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_skirmish02_overview_CA.paa", "\a3\Missions_F_EPA\data\img\A_out_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_in_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_in2_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_hub01_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_skirmish01_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_m06_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_hub02_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_skirmish02_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_m03_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_m01_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_m05_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_m02_1_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_m02_2_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_hub03_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_skirmish03_overview_CA.paa", "\a3\Missions_F_EPA\data\img\B_out2_overview_CA.paa", "\a3\Missions_F_EPA\data\img\C_in1_overview_CA.paa", "\a3\Missions_F_EPA\data\img\C_in2_overview_CA.paa", "\a3\Missions_F_EPA\data\img\C_m01_overview_CA.paa", "\a3\Missions_F_EPA\data\img\C_m02_overview_CA.paa", "\a3\Missions_F_EPA\data\img\C_out1_overview_CA.paa", "\a3\Missions_F_EPA\data\img\C_out2_overview_CA.paa", "\a3\Missions_F_EPA\data\img\C_EA_overview_CA.paa", "\a3\Missions_F_EPA\data\img\C_EB_overview_CA.paa"] call BIS_fnc_selectRandom; _iff = [units group player] execVM "a3\missions_f_exp\campaign\functions\fn_exp_camp_iff.sqf"; if (395180 in getDLCs 1) then { bill1 setObjectTexture [0, _randomPic]; } else { bill1 setObjectTexture [0, "\a3\Missions_F_EPA\data\img\B_skirmish02_overview_CA.paa"]; }; |
name the billboard “bill1”, then load the mission, and the billboard will have a random image on it each time you join. This will only work if the player has the APEX DLC. This is how to check if a player has the APEX DLC, this can be very useful in a mission.
Put this code in the initServer.sqf. This will set a random mission start time either sunrise or sunset.
private _date = missionStart select [0, 5]; private _times = [_date] call BIS_fnc_sunriseSunsetTime; private _startTime = (_times select 0) + (random ((_times select 1) - (_times select 0) - 1)); private _startHour = floor _startTime; private _startMinute = (_startTime - _startHour) * 60; _date set [3, _startHour]; _date set [4, _startMinute]; setDate _date; |
Yep, still doesn’t work….
I fixed the code.
When running as an .sqf from a trigger, I get an error “Error undefined variable in expression: loc”
Sorry, I forgot to add a line of code to get the initial location. I have amended the code.
This is it.