AlexVestin 24 Posted November 4, 2013 Hello! I got this piece of code and I am trying to apply it to units of a certain faction. Whole map, every unit. sleep 0.3; if NOT(isServer) exitWith {}; _magazines = magazines _this; _items = items _this; _aItems = assignedItems _this; removeAllItems _this; removeVest _this; _vests = ["","V_TacVestCamo_khk","V_TacVest_oli","V_TacVest_khk","V_TacVest_camo","V_TacVest_brn","V_TacVest_blk","V_HarnessOSpec_gry","V_HarnessOSpec_brn","V_HarnessOGL_gry","V_HarnessOGL_brn","V_HarnessO_gry","V_HarnessO_brn","V_Chestrig_rgr","V_Chestrig_oli","V_Chestrig_khk","V_Chestrig_blk","V_BandollierB_rgr","V_BandollierB_oli","V_BandollierB_khk","V_BandollierB_cbr","V_BandollierB_blk"]; _count = count _vests; _this addVest (_vests select floor random _count); removeUniform _this; _uniforms = ["U_IG_Guerilla3_2","U_IG_Guerilla3_1","U_IG_Guerilla2_3","U_IG_Guerilla2_2","U_IG_Guerilla2_1"]; _count = count _uniforms; _this addUniform (_uniforms select floor random _count); removeHeadgear _this; _headgear = ["","H_shemag_olive","H_shemag_olive","H_shemag_olive","H_Bandanna_sgg","H_Bandanna_khk","H_Bandanna_gry","H_Bandanna_cbr","H_Bandanna_camo"]; _count = count _headgear; _this addHeadGear (_headgear select floor random _count); {_this addItem _x} forEach _items; {_this addMagazine _x} forEach _magazines; {_this addItem _x} forEach _items; {_this assignItem _x} forEach _aItems; removeGoggles _this; _addGoggles = true; if ((_headgear == "H_shemag_olive")) then {_addGoggles = false}; _goggles = ["","G_Shades_Black","G_Shades_Blue","G_Spectacles","G_Spectacles_Tinted","G_Shades_Green","G_Shades_Red","G_Squares","G_Squares_Tinted"]; if (_addGoggles) then { _count = count _goggles; _r = random 100; if (_r > 20) then {_this addGoggles (_goggles select floor random _count)}; }; I'm having problems initiating it. As an example, I've tried things like this in the init.sqf: { if (faction _x == "OPF_F") then { _x exec "script\gear_militia.sqf"; }; } foreach allunits; Share this post Link to post Share on other sites
iceman77 18 Posted November 4, 2013 (edited) Use execVM instead of exec. { if (faction _x == "OPF_F") then { _x [color=#ff0000]execVM[/color] "script\gear_militia.sqf"; }; } foreach allunits; Also, here's how I spawn a random group based on faction. Maybe you can apply some of the same concepts to your script? /* ------------------------------------------------------------------- File: GrpSpawn.sqf Author: Iceman77 Description: Spawn a random group that patrols an area. The possibility exists that a group wont spawn at all (for more randomness) Parameter(s): _this select 0: <side> side of the group that will be spawned _this select 1: <side string> side of the group that will be spawned (string - Must match appropriate side) _this select 2: <faction> faction of the group that will be spawned (must match the appropriate side) _this select 3: <spawn position> the spawn position of the group (Marker - String) _this select 4: <radius> radius of the groups patrol area (number) _this select 5: <bool> Show a marker where the patrol has spawned How to use: if (isServer) then { [WEST, "West", "BLU_F","myMarker1", random 200, true] call TAG_Grp_Spawn; // BLUFOR [EAST, "East", "OPF_F","mymarker2", random 200, true] call TAG_Grp_Spawn; // OPFOR [RESISTANCE, "Indep", "IND_F","mymarker3", random 200, true] call TAG_Grp_Spawn; // INDEPENDENT }; ------------------------------------------------------------------- */ TAG_Grp_Spawn = { Private ["_grp","_grpType","_infGrp","_motGrp","_mechGrp","_markPatrol"]; _side = _this select 0; _sideStr = _this select 1; _faction = _this select 2; _spawnPos = getMarkerPos (_this select 3); _radius = _this select 4; _markPatrol = _this select 5; switch (_faction) do { case "BLU_F":{ _infGrp = ["BUS_InfSentry","BUS_InfSquad","BUS_InfSquad_Weapons","BUS_InfTeam","BUS_InfTeam_AA","BUS_InfTeam_AT","BUS_ReconPatrol","BUS_ReconSentry","BUS_ReconTeam","BUS_SniperTeam"] call BIS_fnc_selectRandom; _motGrp = ["BUS_MotInf_AA","BUS_MotInf_AT","BUS_MotInf_GMGTeam","BUS_MotInf_MGTeam","BUS_MotInf_MortTeam","BUS_MotInf_Team"] call BIS_fnc_selectRandom; _mechGrp = ["BUS_MechInf_AA","BUS_MechInf_AT","BUS_MechInf_Support","BUS_MechInfSquad"] call BIS_fnc_selectRandom; _grpType = [_infGrp, _motGrp, _mechGrp, 0, 0] call BIS_fnc_selectRandom; }; case "OPF_F":{ _infGrp = ["OI_reconPatrol","OI_reconSentry","OI_reconTeam","OIA_InfSentry","OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AA","OIA_InfTeam_AT","OI_SniperTeam"] call BIS_fnc_selectRandom; _motGrp = ["OIA_MotInf_AA","OIA_MotInf_AT","OIA_MotInf_GMGTeam","OIA_MotInf_MGTeam","OIA_MotInf_MortTeam","OIA_MotInf_Team"] call BIS_fnc_selectRandom; _mechGrp = ["OIA_MechInf_AA","OIA_MechInf_AT","OIA_MechInf_Support","OIA_MechInfSquad"] call BIS_fnc_selectRandom; _grpType = [_infGrp, _motGrp, _mechGrp, 0, 0] call BIS_fnc_selectRandom; }; case "IND_F":{ _infGrp = ["HAF_InfSentry","HAF_InfSquad","HAF_InfSquad_Weapons","HAF_InfTeam","HAF_InfTeam_AA","HAF_InfTeam_AT","HAF_SniperTeam"] call BIS_fnc_selectRandom; _motGrp = ["HAF_MotInf_AA","HAF_MotInf_AT","HAF_MotInf_GMGTeam","HAF_MotInf_MGTeam","HAF_MotInf_MortTeam","HAF_MotInf_Team"] call BIS_fnc_selectRandom; _mechGrp = ["HAF_MechInf_AA","HAF_MechInf_AT","HAF_MechInf_Support","HAF_MechInfSquad"] call BIS_fnc_selectRandom; _grpType = [_infGrp, _motGrp, _mechGrp, 0, 0] call BIS_fnc_selectRandom; }; }; switch (_grpType) do { case _infGrp:{_grp = [_spawnPos, _side, (configFile >> "CfgGroups" >> _sideStr >> _faction >> "Infantry" >> _grpType)] call BIS_fnc_spawnGroup;}; case _motGrp:{_grp = [_spawnPos, _side, (configFile >> "CfgGroups" >> _sideStr >> _faction >> "Motorized" >> _grpType)] call BIS_fnc_spawnGroup;}; case _mechGrp:{_grp = [_spawnPos, _side, (configFile >> "CfgGroups" >> _sideStr >> _faction >> "Mechanized" >> _grpType)] call BIS_fnc_spawnGroup;}; default {}; }; if (!isNil "_grp") then { [_grp, _spawnPos, _radius] call BIS_fnc_taskPatrol; if (_markPatrol) then { _marker = createMarker [str(random 99999), getPosATL (leader _grp)]; _marker setMarkerShape "ICON"; _marker setMarkerSize [0.75,0.75]; _marker setMarkerType "mil_unknown"; _marker setMarkerText "Patrol"; _marker setMarkerColor "colorRed"; }; }; }; Edited November 4, 2013 by Iceman77 Share this post Link to post Share on other sites
AlexVestin 24 Posted November 5, 2013 (edited) Thank you! Will try it asap. Your group spawning script - Not sure how I can make use if it in my current mission, but it seems really handy to have at my disposal. Really appreciate you posting it :) /edit It worked. Opfor soldiers all over the map switched to using random gear I chose for them :) http://cloud-2.steampowered.com/ugc/487806724491741145/D1F03531BBB4C65D5834B7EC7085492C09D5C0C7/ Mods used: All In ArmA Nothing else is required. Script in init.sqf: { if (faction _x == "BIS_TK_INS") then { _x exec "script\gear_militia.sqf"; }; } foreach allunits; Main script in folder (missionnamefolder)/script/gear_militia.sqf sleep 0.3; if NOT(isServer) exitWith {}; _magazines = magazines _this; _items = items _this; _aItems = assignedItems _this; removeAllItems _this; removeVest _this; _vests = ["","V_TacVestCamo_khk","V_TacVest_oli","V_TacVest_khk","V_TacVest_camo","V_TacVest_brn","V_TacVest_blk","V_HarnessOSpec_gry","V_HarnessOSpec_brn","V_HarnessOGL_gry","V_HarnessOGL_brn","V_HarnessO_gry","V_HarnessO_brn","V_Chestrig_rgr","V_Chestrig_oli","V_Chestrig_khk","V_Chestrig_blk","V_BandollierB_rgr","V_BandollierB_oli","V_BandollierB_khk","V_BandollierB_cbr","V_BandollierB_blk"]; _count = count _vests; _this addVest (_vests select floor random _count); removeUniform _this; _uniforms = ["U_IG_Guerilla3_2","U_IG_Guerilla3_1","U_IG_Guerilla2_3","U_IG_Guerilla2_2","U_IG_Guerilla2_1"]; _count = count _uniforms; _this addUniform (_uniforms select floor random _count); removeHeadgear _this; _headgear = ["","H_shemag_olive","H_shemag_olive","H_shemag_olive","H_Bandanna_sgg","H_Bandanna_khk","H_Bandanna_gry","H_Bandanna_cbr","H_Bandanna_camo"]; _count = count _headgear; _this addHeadGear (_headgear select floor random _count); {_this addItem _x} forEach _items; {_this addMagazine _x} forEach _magazines; {_this addItem _x} forEach _items; {_this assignItem _x} forEach _aItems; removeGoggles _this; _addGoggles = true; if ((_headgear == "H_shemag_olive")) then {_addGoggles = false}; _goggles = ["","G_Shades_Black","G_Shades_Blue","G_Spectacles","G_Spectacles_Tinted","G_Shades_Green","G_Shades_Red","G_Squares","G_Squares_Tinted"]; if (_addGoggles) then { _count = count _goggles; _r = random 100; if (_r > 20) then {_this addGoggles (_goggles select floor random _count)}; }; Add these two up and spawn a few Takistani Milita from ArmA2OA and you've got a nice set of units to fight against :) Edited November 5, 2013 by AlexVestin Share this post Link to post Share on other sites