Jump to content
Sign in to follow this  
foxykid09

make player have his weapons in the next mission (CAMPAIGN)

Recommended Posts

Hi Guys Im struggling with a key aspect of my campaign as I want to know how I carry through weapons to the next mission example:

Player X goes to the armoury and chooses his load out and once he's done he speaks to the commander to say he's ready or something like that and the next mission starts... And at the start of the mission he has his load out chosen from the last mission

I tried looking at the BIS Code but I didnt understand it. All I know is that addweaponpool is used?

Thanks

Share this post


Link to post
Share on other sites
saveStatus and loadStatus would be the simplest commands, provided they still work. Prettier solutions require a fair amount of scripting, similar to what BIS did. It's also a difference if you just want to save a unit's loadout or also maintain a weapon pool throughout the campaign.

Share this post


Link to post
Share on other sites

Ahh okay. I'll look into it and see what I can gather thanks!

Share this post


Link to post
Share on other sites
saveStatus and loadStatus would be the simplest commands, provided they still work. Prettier solutions require a fair amount of scripting, similar to what BIS did. It's also a difference if you just want to save a unit's loadout or also maintain a weapon pool throughout the campaign.

Cant seem to get it to work:(

Share this post


Link to post
Share on other sites

Here's a rough template, using profileNamespace.

Store the gear into an array in mission 1, then unpack it in mission 2.

//===== End of mission 1

_primaryWeapon = primaryWeapon player;
_primaryWeaponItems = primaryWeaponItems player;
_gearToSave = [_primaryWeapon,_primaryWeaponItems];
profileNamespace setVariable ["foxy_gear",_gearToSave];
saveProfileNamespace;

//===== Start of mission 2

if (!isNil {profileNamespace getVariable "foxy_gear"}) then {
_gearToLoad = profileNamespace getVariable "foxy_gear";
_primaryWeapon = _gearToLoad select 0;
_primaryWeaponItems = _gearToLoad select 1;
player addWeapon _primaryWeapon;
{player addPrimaryWeaponItem _x;} count _primaryWeaponItems;
};

https://community.bistudio.com/wiki/profileNamespace

Share this post


Link to post
Share on other sites

Recommendation based on bad experiences: Never ever use profileNamespace for campaigns! Stored data is accessible form anywhere in the game and it also doesn't work well with reverting to / replaying older missions. The campaign namespace is perfectly fine with saveVar.

My own framework is a bit too big and too much WIP to be posted here just now but its equipment saving core is based on four functions plus utilities. First, equipment setters and getters.

getLoadout.sqf

private ["_unit", "_ignoredGear", "_uniform", "_vest", "_backpack", "_goggles", "_headgear", "_assignedItems", "_primaryWeaponArr", "_secondaryWeaponArr", "_handgunWeaponArr", "_uniformItems", "_vestItems", "_backpackItems"];
_unit = [_this, 0, player, [ObjNull]] call BIS_fnc_param;
_ignoredGear = [_this, 1, [], [[]]] call BIS_fnc_param;

if (count _ignoredGear > 0) then {
{
	_entry = _ignoredGear select _forEachIndex;
	_ignoredGear set [_forEachIndex, toLower(_entry)];
} forEach _ignoredGear;
};

_uniform = if ("uniform" in _ignoredGear) then {false} else {(uniform _unit)};
_vest = if ("vest" in _ignoredGear) then {false} else {(vest _unit)};
_backpack = if ("backpack" in _ignoredGear) then {false} else {([(backpack _unit)] call IP_fnc_getBaseBackpack)};
_goggles = if ("goggles" in _ignoredGear) then {false} else {(goggles _unit)};
_headgear = if ("headgear" in _ignoredGear) then {false} else {(headgear _unit)};
_assignedItems = if ("assigneditems" in _ignoredGear) then {false} else {(assignedItems _unit)};

_primaryWeaponArr = if ("primaryweapon" in _ignoredGear) then {
false
} else {
_primaryWeapon = [(primaryWeapon _unit)] call IP_fnc_getBaseWeapon;
_primaryWeaponMagazine = if ("primaryweaponmagazine" in _ignoredGear) then {false} else {(primaryWeaponMagazine _unit)};
_primaryWeaponItems = if ("primaryweaponitems" in _ignoredGear) then {false} else {(primaryWeaponItems _unit)};
[_primaryWeapon, _primaryWeaponMagazine, _primaryWeaponItems]
};

_secondaryWeaponArr = if ("secondaryweapon" in _ignoredGear) then {
false
} else {
_secondaryWeapon = [(secondaryWeapon _unit)] call IP_fnc_getBaseWeapon;
_secondaryWeaponMagazine = if ("secondaryweaponmagazine" in _ignoredGear) then {false} else {(secondaryWeaponMagazine _unit)};
_secondaryWeaponItems = if ("secondaryweaponitems" in _ignoredGear) then {false} else {(secondaryWeaponItems _unit)};
[_secondaryWeapon, _secondaryWeaponMagazine, _secondaryWeaponItems]
};

_handgunWeaponArr = if ("handgunweapon" in _ignoredGear) then {
false
} else {
_handgunWeapon = [(handgunWeapon _unit)] call IP_fnc_getBaseWeapon;
_handgunMagazine = if ("handgunmagazine" in _ignoredGear) then {false} else {(handgunMagazine _unit)};
_handgunItems = if ("handgunitems" in _ignoredGear) then {false} else {(handgunItems _unit)};
[_handgunWeapon, _handgunMagazine, _handgunItems]
};

_uniformItems = if ("uniformitems" in _ignoredGear) then {false} else {(uniformItems _unit)};
_vestItems = if ("vestitems" in _ignoredGear) then {false} else {(vestItems _unit)};
_backpackItems = if ("backpackitems" in _ignoredGear) then {false} else {(backpackItems _unit)};

[_uniform, _vest, _backpack, _goggles, _headgear, _assignedItems, _primaryWeaponArr, _secondaryWeaponArr, _handgunWeaponArr, _uniformItems, _vestItems, _backpackItems]

setLoadout.sqf

#define REPLACE(X) (if (!(X isEqualTo "") && _replace) then {([X, _replacementIdentifier, (missionConfigFile >> "CfgWeaponReplacements"), false] call IP_fnc_replaceWeapons)} else {X})

private ["_unit", "_gear", "_ignoredGear", "_replacementIdentifier", "_replace", "_uniform", "_vest", "_backpack", "_goggles", "_headgear", "_assignedItems", "_primaryWeaponArr", "_secondaryWeaponArr", "_handgunWeaponArr", "_uniformItems", "_vestItems", "_backpackItems", "_uniformItemsOld", "_vestItemsOld", "_backpackItemsOld", "_primaryWeaponArrOld", "_secondaryWeaponArrOld", "_handgunWeaponArrOld"];
_unit = [_this, 0, player, [ObjNull]] call BIS_fnc_param;
_gear = [_this, 1, [], [[]], 12] call BIS_fnc_param;
_ignoredGear = [_this, 2, [], [[]]] call BIS_fnc_param;
_replacementIdentifier = [_this, 3, false, [true, ""]] call BIS_fnc_param;
_replace = (typeName _replacementIdentifier == "STRING") && {_replacementIdentifier != ""};

if (count _ignoredGear > 0) then {
{
	_entry = _ignoredGear select _forEachIndex;
	_ignoredGear set [_forEachIndex, toLower(_entry)];
} forEach _ignoredGear;
};

if ((count _gear == 0) OR ("all" in _ignoredGear)) exitWith {};

_uniform = if ("uniform" in _ignoredGear) then {false} else {REPLACE(_gear select 0)};
_vest = if ("vest" in _ignoredGear) then {false} else {REPLACE(_gear select 1)};
_backpack = if ("backpack" in _ignoredGear) then {false} else {REPLACE(_gear select 2)};
_goggles = if ("goggles" in _ignoredGear) then {false} else {REPLACE(_gear select 3)};
_headgear = if ("headgear" in _ignoredGear) then {false} else {REPLACE(_gear select 4)};
_assignedItems = if ("assigneditems" in _ignoredGear) then {false} else {(_gear select 5)};

_primaryWeaponArr = if ("primaryweapon" in _ignoredGear) then {
false
} else {
_primaryWeapon = REPLACE((_gear select 6) select 0);
_primaryWeaponMagazine = if ("primaryweaponmagazine" in _ignoredGear) then {false} else {((_gear select 6) select 1)};
_primaryWeaponItems = if ("primaryweaponitems" in _ignoredGear) then {false} else {((_gear select 6) select 2)};
[_primaryWeapon, _primaryWeaponMagazine, _primaryWeaponItems]
};

_secondaryWeaponArr = if ("secondaryweapon" in _ignoredGear) then {
false
} else {
_secondaryWeapon = REPLACE((_gear select 7) select 0);
_secondaryWeaponMagazine = if ("secondaryweaponmagazine" in _ignoredGear) then {false} else {((_gear select 7) select 1)};
_secondaryWeaponItems = if ("secondaryweaponitems" in _ignoredGear) then {false} else {((_gear select 7) select 2)};
[_secondaryWeapon, _secondaryWeaponMagazine, _secondaryWeaponItems]
};

_handgunWeaponArr = if ("handgunweapon" in _ignoredGear) then {
false
} else {
_handgunWeapon = REPLACE((_gear select 8) select 0);
_handgunMagazine = if ("handgunmagazine" in _ignoredGear) then {false} else {((_gear select 8) select 1)};
_handgunItems = if ("handgunitems" in _ignoredGear) then {false} else {((_gear select 8) select 2)};
[_handgunWeapon, _handgunMagazine, _handgunItems]
};

_uniformItems = if ("uniformitems" in _ignoredGear) then {false} else {(_gear select 9)};
_vestItems = if ("vestitems" in _ignoredGear) then {false} else {(_gear select 10)};
_backpackItems = if ("backpackitems" in _ignoredGear) then {false} else {(_gear select 11)};

if ((typeName _uniform) == "STRING") then {
_uniformItemsOld = uniformItems _unit;
removeUniform _unit;
_unit forceAddUniform _uniform;
};

if ((typeName _vest) == "STRING") then {
_vestItemsOld = vestItems _unit;
removeVest _unit;
_unit addVest _vest;
};

if ((typeName _backpack) == "STRING") then {
_backpackItemsOld = backpackItems _unit;
removeBackpack _unit;
_unit addBackpack _backpack;
};

if ((typeName _goggles) == "STRING") then {
removeGoggles _unit;
_unit addGoggles _goggles;
};

if ((typeName _headgear) == "STRING") then {
removeHeadgear _unit;
_unit addHeadgear _headgear;
};

if ((typeName _assignedItems) == "ARRAY") then {
removeAllAssignedItems _unit;
{_unit linkItem _x} forEach _assignedItems;	
};

if ({(typeName _x) == "ARRAY"} count [_primaryWeaponArr, _secondaryWeaponArr, _handgunWeaponArr] > 0) then {
_primaryWeaponArrOld = [([(primaryWeapon _unit)] call IP_fnc_getBaseWeapon), (primaryWeaponMagazine _unit), (primaryWeaponItems _unit)];
_secondaryWeaponArrOld = [([(secondaryWeapon _unit)] call IP_fnc_getBaseWeapon), (secondaryWeaponMagazine _unit), (secondaryWeaponItems _unit)];
_handgunWeaponArrOld = [([(handgunWeapon _unit)] call IP_fnc_getBaseWeapon), (handgunMagazine _unit), (handgunItems _unit)];
removeAllWeapons _unit;
};

if ((typeName _primaryWeaponArr) == "ARRAY") then {
if ((typeName (_primaryWeaponArr select 1)) == "BOOL") then {{_unit addMagazine _x} forEach (_primaryWeaponArrOld select 1)} else {{_unit addMagazine _x} forEach (_primaryWeaponArr select 1)};
_unit addWeapon (_primaryWeaponArr select 0);
if ((typeName (_primaryWeaponArr select 2)) == "BOOL") then {{_unit addPrimaryWeaponItem _x} forEach (_primaryWeaponArrOld select 2)} else {{_unit addPrimaryWeaponItem _x} forEach (_primaryWeaponArr select 2)};
} else {
if (!(isNil "_primaryWeaponArrOld")) then {
	_unit addMagazine (_primaryWeaponArrOld select 1);
	_unit addWeapon (_primaryWeaponArrOld select 0);
	{_unit addPrimaryWeaponItem _x} forEach (_primaryWeaponArrOld select 2);
};
};

if ((typeName _secondaryWeaponArr) == "ARRAY") then {
if ((typeName (_secondaryWeaponArr select 1)) == "BOOL") then {{_unit addMagazine _x} forEach (_secondaryWeaponArrOld select 1)} else {{_unit addMagazine _x} forEach (_secondaryWeaponArr select 1)};
_unit addWeapon (_secondaryWeaponArr select 0);
if ((typeName (_secondaryWeaponArr select 2)) == "BOOL") then {{_unit addSecondaryWeaponItem _x} forEach (_secondaryWeaponArrOld select 2)} else {{_unit addSecondaryWeaponItem _x} forEach (_secondaryWeaponArr select 2)};
} else {
if (!(isNil "_secondaryWeaponArrOld")) then {
	_unit addMagazine (_secondaryWeaponArrOld select 1);
	_unit addWeapon (_secondaryWeaponArrOld select 0);
	{_unit addSecondaryWeaponItem _x} forEach (_secondaryWeaponArrOld select 2);
};
};

if ((typeName _handgunWeaponArr) == "ARRAY") then {
if ((typeName (_handgunWeaponArr select 1)) == "BOOL") then {{_unit addMagazine _x} forEach (_handgunWeaponArrOld select 1)} else {{_unit addMagazine _x} forEach (_handgunWeaponArr select 1)};
_unit addWeapon (_handgunWeaponArr select 0);
if ((typeName (_handgunWeaponArr select 2)) == "BOOL") then {{_unit addHandgunItem _x} forEach (_handgunWeaponArrOld select 2)} else {{_unit addHandgunItem _x} forEach (_handgunWeaponArr select 2)};
} else {
if (!(isNil "_handgunWeaponArrOld")) then {
	_unit addMagazine (_handgunWeaponArrOld select 1);
	_unit addWeapon (_handgunWeaponArrOld select 0);
	{_unit addHandgunItem _x} forEach (_handgunWeaponArrOld select 2);
};
};

if ((typeName _uniformItems) == "BOOL") then {
if (!(isNil "_uniformItemsOld")) then {
	{_unit addItemToUniform _x} forEach _uniformItemsOld;
};
} else {
{_unit addItemToUniform _x} forEach _uniformItems;
};

if ((typeName _vestItems) == "BOOL") then {
if (!(isNil "_vestItemsOld")) then {
	{_unit addItemToVest _x} forEach _vestItemsOld;
};
} else {
{_unit addItemToVest _x} forEach _vestItems;
};

if ((typeName _backpackItems) == "BOOL") then {
if (!(isNil "_backpackItemsOld")) then {
	{_unit addItemToBackpack _x} forEach _backpackItemsOld;
};
} else {
{_unit addItemToBackpack _x} forEach _backpackItems;
};

Utility functions:

getBaseBackpack.sqf

private ["_backpack", "_baseCfg", "_cfg"];
_backpack = [_this, 0, "", [""]] call BIS_fnc_param;
_baseCfg = (configFile >> "CfgVehicles");
_cfg = _baseCfg >> _backpack;

while {{count("true" configClasses _x) > 0} count [(_cfg >> "TransportItems"), (_cfg >> "TransportMagazines"), (_cfg >> "TransportWeapons")] > 0} do {
_parent = configName(inheritsFrom(_cfg));
_cfg = _baseCfg >> _parent;
};

(configName _cfg)

getBaseWeapon.sqf

private ["_weapon", "_baseCfg", "_cfg"];
_weapon = [_this, 0, "", [""]] call BIS_fnc_param;
_baseCfg = (configFile >> "CfgWeapons");
_cfg = _baseCfg >> _weapon;

while {isClass(_cfg >> "LinkedItems")} do {
_parent = configName(inheritsFrom(_cfg));
_cfg = _baseCfg >> _parent;
};

(configName _cfg)

replaceWeapons.sqf (Requires CfgWeaponReplacements)

private ["_getIdentifier", "_getReplacement", "_classes", "_identifiers", "_config", "_result"];

_getIdentifier = {
private ["_identifiers", "_i", "_identifier"];
_identifiers = _this select 0;
_i = _this select 1;

_identifier = if (typeName _identifiers == "STRING") then {
	_identifiers
} else {
	_count = count _identifiers;

	_identifier = if (_i < _count) then {
		(_identifiers select _i)
	} else {
		(_identifiers select (_count - 1))
	};

	_identifier
};

_identifier
};

_getReplacement = {
private ["_class", "_identifier", "_config", "_replacement", "_getBaseWeapon"];
_class = _this select 0;
_identifier = _this select 1;
_config = _this select 2;
_getBaseWeapon = _this select 3;

if (_getBaseWeapon) then {
	_class = [_class] call IP_fnc_getBaseWeapon;
};

_replacement = if (isText(_config >> _class >> _identifier)) then {
	_wep = getText(_config >> _class >> _identifier);

	_replacement = if ((isClass(configFile >> "CfgWeapons" >> _wep)) OR {isClass(configFile >> "CfgVehicles" >> _wep)}) then {
		_wep
	} else {
		_class
	};

	_replacement
} else {
	_class
};

_replacement
};

_classes = [_this, 0, "", ["", []]] call BIS_fnc_param;
if (((typeName _classes == "STRING") && {_classes == ""}) OR {count _classes == 0}) exitWith {"_classes parameter empty!" call BIS_fnc_error};
_identifiers = [_this, 1, "", ["", []]] call BIS_fnc_param;
if (((typeName _identifiers == "STRING") && {_identifiers == ""}) OR {count _identifiers == 0}) exitWith {"_identifiers parameter empty!" call BIS_fnc_error};
_config = [_this, 2, (missionConfigFile >> "CfgWeaponReplacements"), [(configFile >> "CfgWeapons")]] call BIS_fnc_param;
if (!isClass _config) exitWith {["Config %1 not found!", _config] call BIS_fnc_error};
_getBaseWeapon = [_this, 3, true, [false]] call BIS_fnc_param;

_result = if (typeName _classes == "STRING") then {
_identifier = [_identifiers, 0] call _getIdentifier;
_replacement = [_classes, _identifier, _config, _getBaseWeapon] call _getReplacement;
_replacement
} else {
private "_replacements";
_replacements = [];

{
	_identifier = [_identifiers, _forEachIndex] call _getIdentifier;
	_replacement = [_x, _identifier, _config, _getBaseWeapon] call _getReplacement;
	_replacements pushBack _replacement;
} forEach _classes;

_replacements
};

_result

weaponReplacements.hpp (example)

class CfgWeaponReplacements
{
class SMG_02_F
{
	mp5 = "hlc_smg_MP5N";
	mp5sd = "hlc_smg_mp5sd6";
};

class arifle_TRG20_F
{
	snow = "IP_arifle_TRG20_FBlack";
};

class arifle_TRG21_F
{
	snow = "IP_arifle_TRG21_FBlack";
};

class arifle_TRG21_GL_F
{
	snow = "IP_arifle_TRG21_GL_FBlack";
};

class IP_arifle_TRG20_FBlack
{
	aks74u = "hlc_rifle_aks74u";
	saiga = "hlc_rifle_saiga12k";
};

class IP_arifle_Mk20c_FBlack
{
	m4 = "hlc_rifle_M4";
	saiga = "hlc_rifle_saiga12k";
};

class arifle_MXC_Black_F
{
	snow = "IP_arifle_MXC_Snow_F";
};

class IP_arifle_TRG21_FBlack
{
	ak47 = "hlc_rifle_ak47";
	akm = "hlc_rifle_akm";
	aks74 = "hlc_rifle_aks74";
	m4 = "hlc_rifle_M4";
};

class IP_arifle_Mk20_FBlack
{
	m4 = "hlc_rifle_M4";
};

class arifle_MX_Black_F
{
	snow = "IP_arifle_MX_Snow_F";
};

class IP_arifle_TRG21_GL_FBlack
{
	akm = "hlc_rifle_akmgl";
	aks74 = "hlc_rifle_aks74_GL";
	m4 = "hlc_rifle_m4m203";
};

class IP_arifle_Mk20_GL_FBlack
{
	m4 = "hlc_rifle_m4m203";
};

class arifle_MX_GL_Black_F
{
	snow = "IP_arifle_MX_GL_Snow_F";
};

class arifle_MX_SW_Black_F
{
	snow = "IP_arifle_MX_SW_Snow_F";
};

class LMG_Mk200_F
{
	rpk = "hlc_rifle_rpk";
};

class IP_MMG_01_Black_F
{
	snow = "IP_MMG_01_Snow_F";
};

class arifle_MXM_Black_F
{
	snow = "IP_arifle_MXM_Snow_F";
};

class srifle_DMR_06_olive_F
{
	m14 = "hlc_rifle_m14sopmod";
};

class srifle_DMR_03_F
{
	snow = "IP_srifle_DMR_03_Snow_F";
};

class srifle_DMR_02_F
{
	snow = "IP_srifle_DMR_02_Snow_F";
};

class srifle_GM6_F
{
	psg1 = "hlc_rifle_psg1";
};

// Headgear
class IP_H_MilCap_mcamoEFBlack
{
	snow = "IP_H_MilCap_mcamoEFSnow";
	woodland = "IP_H_MilCap_mcamoEFWoodland";
};

class IP_H_Booniehat_mcamoEFBlack
{
	snow = "IP_H_Booniehat_mcamoEFSnow";
	woodland = "IP_H_Booniehat_mcamoEFWoodland";
};

class H_Bandanna_gry
{
	snow = "IP_H_Bandanna_snw";
	woodland = "H_Bandanna_camo";
};

class H_HelmetB
{
	snow = "IP_H_HelmetB_snw";
};

class H_HelmetB_plain_mcamo
{
	snow = "IP_H_HelmetB_plain_mcamo_snw";
};

class H_HelmetB_grass
{
	snow = "IP_H_HelmetB_grass_snw";
};

class H_HelmetB_sand
{
	snow = "IP_H_HelmetB_sand_snw";
};

class H_HelmetB_paint
{
	snow = "IP_H_HelmetB_paint_snw";
};

class H_HelmetB_light
{
	snow = "IP_H_HelmetB_light_snw";
};

class H_HelmetB_light_desert
{
	snow = "IP_H_HelmetB_light_desert_snw";
};

class H_HelmetB_light_sand
{
	snow = "IP_H_HelmetB_light_sand_snw";
};

class H_HelmetB_light_grass
{
	snow = "IP_H_HelmetB_light_grass_snw";
};

class H_HelmetSpecB
{
	snow = "IP_H_HelmetSpecB_snw";
};

class H_HelmetSpecB_paint1
{
	snow = "IP_H_HelmetSpecB_paint1_snw";
};

class H_HelmetSpecB_paint2
{
	snow = "IP_H_HelmetSpecB_paint2_snw";
};

class H_HelmetSpecB_blk
{
	snow = "IP_H_HelmetSpecB_blk_snw";
};

// Vests
class IP_V_PlateCarrier1_blkEFWolf
{
	snow = "IP_V_PlateCarrier1_snwEFWolf";
	woodland = "IP_V_PlateCarrier1_rgrEFWolf";
};

class IP_V_PlateCarrier2_blkEFWolf
{
	snow = "IP_V_PlateCarrier2_snwEFWolf";
	woodland = "IP_V_PlateCarrier2_rgrEFWolf";
};

class IP_V_PlateCarrier3_blkEFWolf
{
	snow = "IP_V_PlateCarrier3_snwEFWolf";
	woodland = "IP_V_PlateCarrier3_rgrEFWolf";
};

class IP_V_PlateCarrierGL_blkEFWolf
{
	snow = "IP_V_PlateCarrierGL_snwEFWolf";
	woodland = "IP_V_PlateCarrierGL_rgrEFWolf";
};

class IP_V_PlateCarrierSpec_blkEFWolf
{
	snow = "IP_V_PlateCarrierSpec_snwEFWolf";
	woodland = "IP_V_PlateCarrierSpec_rgrEFWolf";
};

class V_TacVest_blk
{
	snow = "IP_V_TacVest_snwCamo";
	woodland = "V_TacVest_camo";
};
};

Then player init on mission start and a function running on mission end to save all the things.

mainInit.sqf (shortened)

_loadout = if (isNil "TAG_CMP_Loadout") then {[]} else {TAG_CMP_Loadout};	
[player, _loadout, [], false] call IP_fnc_setLoadout;

mainInit.sqf (original, for reference)

private ["_mission", "_cfg", "_keepLoadout", "_ignoredGear", "_replacement"];
_mission = getText(missionConfigFile >> "name");
_cfg = (missionConfigFile >> "ShopMissions" >> _mission);
_keepLoadout = [false, true] select (getNumber(_cfg >> "keepLoadout"));
_ignoredGear = if (isArray(_cfg >> "ignoredGear")) then {(getArray(_cfg >> "ignoredGear"))} else {[]};
_replacement = if (isText(_cfg >> "replacement")) then {(getText(_cfg >> "replacement"))} else {false};

if (!(isClass(campaignConfigFile >> "campaign"))) exitWith {
if (!(isNil "IP_BSMMain")) then {[iP_BSMMain, "BSM_Main", _mission] call IP_fnc_applyTemplate};
if (!(isNil "IP_EFMain")) then {[iP_EFMain, "EF_Main", _mission] call IP_fnc_applyTemplate};
player allowDamage false;
IP_MainInitDone = true;
};

if (!(isNil "IP_BSMMain")) then {
if (_keepLoadout) then {
	_loadout = if (isNil "IP_ICE_BSMLoadout") then {[]} else {IP_ICE_BSMLoadout};	
	[iP_BSMMain, _loadout, _ignoredGear, _replacement] call IP_fnc_setLoadout;
};
[iP_BSMMain, "BSM_Main", _mission] call IP_fnc_applyTemplate;

if (!(isNil "IP_BSMPlayerBox") && !(isNil "IP_ICE_BSMPlayerBox")) then {
	{IP_BSMPlayerBox addWeaponCargo _x} forEach (IP_ICE_BSMPlayerBox select 0);
	{IP_BSMPlayerBox addMagazineCargo _x} forEach (IP_ICE_BSMPlayerBox select 1);
	{IP_BSMPlayerBox addItemCargo _x} forEach (IP_ICE_BSMPlayerBox select 2);
	{IP_BSMPlayerBox addBackpackCargo _x} forEach (IP_ICE_BSMPlayerBox select 3);
};
};

if (!(isNil "IP_EFMain")) then {
if (_keepLoadout) then {
	_loadout = if (isNil "IP_ICE_EFLoadout") then {[]} else {IP_ICE_EFLoadout};
	[iP_EFMain, _loadout, _ignoredGear, _replacement] call IP_fnc_setLoadout;
};
[iP_EFMain, "EF_Main", _mission] call IP_fnc_applyTemplate;

if (!(isNil "IP_EFPlayerBox") && !(isNil "IP_ICE_EFPlayerBox")) then {
	{IP_EFPlayerBox addWeaponCargo _x} forEach (IP_ICE_EFPlayerBox select 0);
	{IP_EFPlayerBox addMagazineCargo _x} forEach (IP_ICE_EFPlayerBox select 1);
	{IP_EFPlayerBox addItemCargo _x} forEach (IP_ICE_EFPlayerBox select 2);
	{IP_EFPlayerBox addBackpackCargo _x} forEach (IP_ICE_EFPlayerBox select 3);
};
};

if (IP_TESTMODE) then {player allowDamage false};
IP_MainInitDone = true;

endMission.sqf (shortened)

TAG_CMP_Loadout = [player, []] call IP_fnc_getLoadout;
saveVar "TAG_CMP_Loadout";

endMission.sqf (original, for reference)

#define ADD(X) _toSave pushBack X;
#define BOX(X) [CLUSTER(weaponCargo X), CLUSTER(magazineCargo X), CLUSTER(itemCargo X), CLUSTER(backpackCargo X)]
#define CLUSTER(X) (X call IP_fnc_clusterArray)
#define GET(X) ([X, _ignoredGear] call IP_fnc_getLoadout)

if (!(isClass(campaignConfigFile >> "campaign"))) exitWith {_this call BIS_fnc_endMission};

private ["_isWin", "_mission", "_cfg", "_keepLoadout", "_ignoredGear", "_toSave"];
_isWin = [_this, 1, true, [false]] call BIS_fnc_param;
_mission = getText(missionConfigFile >> "name");
_cfg = (missionConfigFile >> "ShopMissions" >> _mission);
_keepLoadout = [false, true] select (getNumber(_cfg >> "keepLoadout"));
_ignoredGear = if (isArray(_cfg >> "ignoredGear")) then {(getArray(_cfg >> "ignoredGear"))} else {[]};
_toSave = ["IP_ICE_Date", "IP_ICE_Mission"];

IP_ICE_Date = date;
IP_ICE_Mission = _mission;

if (_isWin && !_isHub) then {
[_mission] call IP_fnc_setMissionDone;
ADD("IP_ICE_MissionsDone")
};

if (!(isNil "IP_BSMMain")) then {
if (_keepLoadout) then {
	IP_ICE_BSMLoadout = GET(IP_BSMMain);
	ADD("IP_ICE_BSMLoadout")
};

if (!(isNil "IP_BSMPlayerBox")) then {		
	IP_ICE_BSMPlayerBox = BOX(IP_BSMPlayerBox);
	ADD("IP_ICE_BSMPlayerBox")
};
};

if (!(isNil "IP_EFMain")) then {
if (_keepLoadout) then {
	IP_ICE_EFLoadout = GET(IP_EFMain);
	ADD("IP_ICE_EFLoadout")
};

if (!(isNil "IP_EFPlayerBox")) then {		
	IP_ICE_EFPlayerBox = BOX(IP_EFPlayerBox);
	ADD("IP_ICE_EFPlayerBox")
};
};

{saveVar _x} forEach _toSave;

// Turn off Glass NV
if ((player getVariable ['IP_Glass_Vision', 0]) == 1) then {setAperture -1};
_this call BIS_fnc_endMission;

Disclaimer: Above shown code is not ready-to-deploy; it's just a snapshot taken of work in progress for a hub-based, non-linear SP campaign project. Only meant to give an idea and a base to start for OP and future creators stumbling across this thread.

Edited by IndeedPete
  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×