Skip to content

Instantly share code, notes, and snippets.

@headswe
Forked from harakka/csvdump.sqf
Last active August 29, 2015 14:06
Show Gist options
  • Save headswe/02d7db4de10aa727b437 to your computer and use it in GitHub Desktop.
Save headswe/02d7db4de10aa727b437 to your computer and use it in GitHub Desktop.
///////// XML EXPORT
///////// Usage: [name,CfgPatches name]
///////// Usage : [name] to export bis stuff
_CfgPatches = false;
_configPath = "";
_collectionName = "BIS";
if(count [] > 1) then
{
_configPath = _configPath + _this select 1;
_CfgPatches = true;
};
_getClass = {
_out = "";
if(typename _this == "STRING") then
{
_out = _this;
}
else
{
_out = configName _this;
};
_out;
};
_wepsEx = [];
_itemsEx = [];
_magsEx = [];
_backEx = [];
_weapons = [];
_backpacks = [];
_magazines = [];
if(_CfgPatches) then
{
_weapons = _weapons + getArray(configfile >> "CfgPatches" >> _configPath >> "weapons");
_backpacks = _backpacks + getArray(configFile >> "CfgPatches" >> _configPath >> "units");
}
else
{
_magazines = [configfile >> "CfgMagazines"] call BIS_fnc_returnChildren;
_weapons = [configFile >> "CfgWeapons"] call BIS_fnc_returnChildren;
_backpacks = [configFile >> "CfgVehicles"] call BIS_fnc_returnChildren;
};
{
_configName = _x call _getClass;
_name = getText(configFile >> "CfgWeapons" >> _configName >> "displayname");
_picture = getText(configFile >> "CfgWeapons" >> _configName >> "picture");
if(_name != "" && _picture != "" && !(isClass (configFile >> "CfgWeapons" >> _configName >> "LinkedItems"))) then
{
_parents = [_x, true] call BIS_fnc_returnParents;
_iteminfoParents = [];
if(isClass (Configfile >> "CfgWeapons" >> _configName >> "ItemInfo")) then {_iteminfoParents = [(Configfile >> "CfgWeapons" >> _configName >> "ItemInfo"), true] call BIS_fnc_returnParents;};
_type = switch true do {
case ("InventoryOpticsItem_Base_F" in _iteminfoParents): {"OpticAttachment"};
case ("InventoryMuzzleItem_Base_F" in _iteminfoParents || getText(configFile >> "CfgWeapons" >> _configName >> "ItemInfo" >> "muzzleend") != ""): {"MuzzleAttachment"};
case ("InventoryFlashLightItem_Base_F" in _iteminfoParents): {"SideAttachment"};
case ("InventoryUnderItem_Base_F" in _iteminfoParents): {"UnderAttachment"};
case ("Rifle" in _parents): {"PrimaryWeapon"};
case ("Pistol" in _parents): {"SecondaryWeapon"};
case ("Launcher" in _parents): {"Launcher"};
case ("H_HelmetB" in _parents): {"HeadGear"};
case ("Uniform_Base" in _parents): {"Uniform"};
case ("Vest_Camo_Base" in _parents || "Vest_NoCamo_Base" in _parents): {"Vest"};
case ("ItemCore" in _parents || "DetectorCore" in _parents): {"CommonItem"};
case ("ItemMap" in _parents): {"Map"};
case ("ItemWatch" in _parents): {"Watch"};
case ("ItemCompass" in _parents): {"Compass"};
case ("ItemGPS" in _parents): {"GPS"};
case ("ItemRadio" in _parents): {"Radio"};
case ("NVGoggles" in _parents || _configName == "NVGoggles"): {"NVGoggles"};
case ("Binocular" in _parents): {"Binocular"};
default {"unknown"};
};
if(_type == "unknown") exitWith {systemChat _configName};
_classname = _configName;
_mags = getArray(configFile >> "CfgWeapons" >> _configName >> "magazines");
if(_CfgPatches) then
{
_magazines = _magazines + _mags;
};
if(_type in ["PrimaryWeapon","SecondaryWeapon","Launcher"]) then
{
_mass = getNumber(configFile >> "CfgWeapons" >> _configName >> "WeaponSlotsInfo" >> "mass");
_capacity = 0;
_wepsEx = _wepsEx + [[_name,_type,_classname,_mags,_mass]];
};
if(_type != "unknown" && !(_type in ["PrimaryWeapon","SecondaryWeapon","Launcher"]) ) then
{
_mass = getNumber(configFile >> "CfgWeapons" >> _configName >> "ItemInfo" >> "mass");
_capacity = getText(configFile >> "CfgWeapons" >> _configName >> "ItemInfo" >> "containerclass");
if(_capacity != "") then
{
_capacity = getNumber(configFile >> "CfgVehicles" >> _capacity >> "maximumload");
}
else
{
_capacity = 0;
};
_itemsEx = _itemsEx + [[_name,_type,_classname,_mass,_capacity]];
};
};
} foreach _weapons;
{
_configName = _x call _getClass;
_name = getText(configFile >> "CfgMagazines" >> _configName >> "displayname");
_picture = getText(configFile >> "CfgMagazines" >> _configName >> "picture");
_mass = getNumber(configFile >> "CfgMagazines" >> _configName >> "mass");
if(_name != "" && _picture != "") then
{
_classname = _configName;
_magsEx = _magsEx + [[_name,_classname,_mass]];
};
} foreach _magazines;
{
_configName = _x call _getClass;
_parents = [(configFile >> "CfgVehicles" >> _configName), true] call BIS_fnc_returnParents;
_name = getText(configFile >> "CfgVehicles" >> _configName >> "displayname");
_picture = getText(configFile >> "CfgVehicles" >> _configName >> "picture");
_mass = getNumber(configFile >> "CfgVehicles" >> _configName >> "mass");
_capacity = getNumber(configFile >> "CfgVehicles" >> _configName >> "maximumload");
if(_name != "" && _picture != "" && !(isClass (configFile >> "CfgVehicles" >> _configName >> "TransportItems")) && "Bag_Base" in _parents && _configName != "Bag_Base") then
{
_backEx = _backEx + [[_name,_configName,_mass,_capacity]];
};
} foreach _backpacks;
_append = {
outputXML = outputXML + _this;
diag_log text _this;
};
outputXML = "";
'<?xml version="1.0" encoding="utf-8"?>' call _append;
'<Collection>' call _append;
' <Name>'+_collectionName+'</Name>' call _append;
' <Weapons>' call _append;
{
_name = _x select 0;
_type = _x select 1;
_classname = _x select 2;
_magazines = _x select 3;
_mass = _x select 4;
" <Weapon>" call _append;
format [" <Name>%1</Name>",_name] call _append;
format [" <ClassName>%1</ClassName>",_classname] call _append;
format [" <WeaponType>%1</WeaponType>",_type] call _append;
format [" <Mass>%1</Mass>",_mass] call _append;
if(count _magazines > 0) then
{
" <Magazines>" call _append;
{
" <Magazine>" call _append;
format[" <ClassName>%1</ClassName>",_x] call _append;
" </Magazine>" call _append;
} foreach _magazines;
" </Magazines>" call _append;
};
" </Weapon>" call _append;
} foreach _wepsEx;
' </Weapons>' call _append;
' <Magazines>' call _append;
{
_name = _x select 0;
_classname = _x select 1;
_mass = _x select 2;
" <Magazine>" call _append;
format [" <Name>%1</Name>",_name] call _append;
format [" <ClassName>%1</ClassName>",_classname] call _append;
format [" <Mass>%1</Mass>",_mass] call _append;
" </Magazine>" call _append;
} foreach _magsEx;
' </Magazines>' call _append;
' <Items>' call _append;
{
_name = _x select 0;
_type = _x select 1;
_classname = _x select 2;
_mass = _x select 3;
_capacity = _x select 4;
" <Item>" call _append;
format [" <Name>%1</Name>",_name] call _append;
format [" <ClassName>%1</ClassName>",_classname] call _append;
format [" <ItemType>%1</ItemType>",_type] call _append;
format [" <Mass>%1</Mass>",_mass] call _append;
format [" <Capacity>%1</Capacity>",_capacity] call _append;
" </Item>" call _append;
} foreach _itemsEx;
{
_name = _x select 0;
_classname = _x select 1;
_mass = _x select 2;
_capacity = _x select 3;
" <Item>" call _append;
format [" <Name>%1</Name>",_name] call _append;
format [" <ClassName>%1</ClassName>",_classname] call _append;
format [" <ItemType>%1</ItemType>","Backpack"] call _append;
format [" <Mass>%1</Mass>",_mass] call _append;
format [" <Capacity>%1</Capacity>",_capacity] call _append;
" </Item>" call _append;
} foreach _backEx;
' </Items>' call _append;
'</Collection>' call _append;
copyToClipboard outputXML;
systemchat "Done";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment