Crafting System

POST 1 of 2.

Hello, long time viewer, but here is my first contribution back to the community. I initially did these modifications to Manatees server, so many of the variables are named as such.

First off, special thanks to the original crafting system that was posted on these forums, sorry I can no longer find the name - but thanks to them for the crafting idea.

So if you used the crafting system, you'll find it very hard to add more combinations or items and easily customize it - I use the crafting system concept but make it so that the server admin can customize it much easier.

I'm going to assume that you already have a custom fn_selfActions.sqf file set up within your mission - if not, please view Krixes self blood on the initial setup for a custom fn_selfActions.sqf.

Step 1: Set up an "Activator" that will bring up the crafting menu. The crafting menu will subdivide all the crafting items by Survival supplies, Industrial supplies and Weapons.
This piece of code goes within your fn_selfActions.sqf,

Code:
// custom crafting menu system
    if ((inflamed cursorTarget && cursorTarget distance player < 10) && _canDo && !crafting_menu_open) then {
        if (s_player_smeltItems < 0) then {
            s_player_smeltItems = player addaction[("<t color=""#FFC726"">" + ("Crafting Menu") +"</t>"),"crafting\craftmenu.sqf","",10,true,true,"", ""];
        };
    } else {
        player removeAction s_player_smeltItems;
        s_player_smeltItems = -1;
    };
you'll also want to add at the end where you'll see a large list of similar actions.
Code:
 player removeAction s_player_smeltItems;
        s_player_smeltItems = -1;
Note: You'll need to add the global variable crafting_menu_open = false;, i.e. within your init.sqf

The above code will first check if the player is looking into a flame, the player is close to the flame, and the menu has not yet been opened.

Step 2: The player activated the Crafting Menu!
so we'll need to place all the menu and "oven" files.

First create a folder in the root of your mission folder called "crafting".
within it, create the files:

craftmenu.sqf
closemenu.sqf
industrial.sqf
survival.sqf
weapons..sqf

craftmenu.sqf:

Code:
{
    player removeAction _x
} forEach manatee_craft_menu;
manatee_craft_menu = [];
crafting_menu_open = true;
show_industrial = false;
show_survival = false;
show_weapons = false;
 
sleep 1;
cutText ["Opened Crafting Menu. Scroll your mouse to access it.","PLAIN",2];
sleep 1;
_restriction = "count ((position player) nearObjects ['Land_fire', 10]) > 0";
 
manatee_craft_menu = [];
manatee_craft_menu set [count manatee_craft_menu, player addaction [("<t color=""#0074E8"">" + ("Crafting Menu") +"</t>"),"","",99,false,false,"",_restriction]];
manatee_craft_menu set [count manatee_craft_menu, player addaction [("<t color=""#FF7300"">" + (" Close Menu") +"</t>"),"crafting\closemenu.sqf","",98,false,true,"",_restriction]];
manatee_craft_menu set [count manatee_craft_menu, player addaction [("<t color=""#4AC925"">" + ("  Industrial Parts") +"</t>"),"crafting\industrial.sqf","",97,false,false,"",_restriction]];
manatee_craft_menu set [count manatee_craft_menu, player addaction [("<t color=""#4AC925"">" + ("  Survival Gear") +"</t>"),"crafting\survival.sqf","",95,false,false,"",_restriction]];
manatee_craft_menu set [count manatee_craft_menu, player addaction [("<t color=""#4AC925"">" + ("  Weapons Crafting") +"</t>"),"crafting\weapons.sqf","",93,false,false,"",_restriction]];
manatee_craft_menu set [count manatee_craft_menu, player addaction [("<t color=""#0074E8"">" + ("-----------------------------") +"</t>"),"","",91,false,false,"",_restriction]];
The above code executes when the player actives the crafting menu. It will then add mouse scroll options to access the submenus for Industrial, Survival or Weapon crafting. You can also close the crafting menu all together.

Here are examples of the submenus for survival, industrial and weapons. These are the files you will need to edit to create new items for crafting as well as their input/output requirements for the crafting procedure. You should have some basic understanding of arrays within the Arma engine to make life a lot easier on you.

industrial.sqf:
Code:
// parameter format, array of:
// output item, array of input items and how many of each item. Treat each input item as an array
// that includes the class name and the number required.
 
 
// PARAMETER STRUCTURE VERY IMPORTANT
// type = 0 for magazine, 1 for weapon/toolbelt
// [ [ type, "Finished Readable Item Name","FinishedItemClassName","FinishedQty" ] , [ [type, "RequiredClassName","RequiredQty"] , [type, "RequiredClassName2","RequiredQty"] ... ]]
 
 
sleep 1;
 
if (!show_industrial) then {
    show_industrial = true;
    _restriction = "count ((position player) nearObjects ['Land_fire', 10]) > 0";
 
    manatee_craft_menu_ind = [];
    manatee_craft_menu_ind set [count manatee_craft_menu_ind, player addaction [("<t color=""#FFC726"">" + ("    Scrap Metal") +"</t>"),"crafting\oven.sqf",[[0,"Scrap Metal","PartGeneric",1],[[0,"TrashTinCan",6]]],96,false,false,"",_restriction]];
    manatee_craft_menu_ind set [count manatee_craft_menu_ind, player addaction [("<t color=""#FFC726"">" + ("    Tank Trap") +"</t>"),"crafting\oven.sqf",[[0,"Tank Trap","ItemTankTrap",1],[[0,"PartGeneric",4]]],96,false,false,"",_restriction]];
    manatee_craft_menu_ind set [count manatee_craft_menu_ind, player addaction [("<t color=""#FFC726"">" + ("    Wire Kit") +"</t>"),"crafting\oven.sqf",[[0,"Wire Kit","ItemWire",1],[[0,"ItemTrashRazor",8],[0,"ItemTankTrap",2]]],96,false,false,"",_restriction]];
    manatee_craft_menu_ind set [count manatee_craft_menu_ind, player addaction [("<t color=""#FFC726"">" + ("    Windscreen") +"</t>"),"crafting\oven.sqf",[[0,"Windscreen","PartGlass",1],[[0,"TrashJackDaniels",8],[0,"PartGeneric",1]]],96,false,false,"",_restriction]];
    manatee_craft_menu_ind set [count manatee_craft_menu_ind, player addaction [("<t color=""#FFC726"">" + ("    Empty Jerrycan") +"</t>"),"crafting\oven.sqf",[[0,"Empty Jerrycan","ItemJerrycanEmpty",1],[[0,"ItemWaterbottleUnfilled",4],[0,"PartGeneric",2]]],96,false,false,"",_restriction]];
} else {
    show_industrial = false;
    {player removeAction _x;} foreach manatee_craft_menu_ind; manatee_craft_menu_ind = [];
};
You can see the format of the passed parameters per menu item that is being sent to the "oven" for crafting.

From the above code, we can create a Wire Kit, we can see the output is [0,"ItemWire",1] meaning a magazine, ItemWire, and qty1. Now for the requirements to craft this item: [0,"ItemTrashRazor",8],[0,"ItemTankTrap",2] so we need 8 razors and 2 tank trap kits to convert into a wire kit. You can easily modify the produced and required arrays with as many items that fit into the main inventory.

survival.sqf:
Code:
// parameter format, array of:
// output item, array of input items and how many of each item. Treat each input item as an array
// that includes the class name and the number required.
 
 
// PARAMETER STRUCTURE VERY IMPORTANT
// type = 0 for magazine, 1 for weapon/toolbelt
// [ [ type, "Finished Readable Item Name","FinishedItemClassName","FinishedQty" ] , [ [type, "RequiredClassName","RequiredQty"] , [type, "RequiredClassName2","RequiredQty"] ... ]]
 
 
sleep 1;
 
if (!show_survival) then {
    show_survival = true;
    _restriction = "count ((position player) nearObjects ['Land_fire', 10]) > 0";
    manatee_craft_menu_sur = [];
    manatee_craft_menu_sur set [count manatee_craft_menu_sur, player addaction [("<t color=""#FFC726"">" + ("    Bandage") +"</t>"),"crafting\oven.sqf",[[0,"Bandage","ItemBandage",1],[[0,"ItemTrashToiletpaper",4]]],94,false,false,"",_restriction]];
    manatee_craft_menu_sur set [count manatee_craft_menu_sur, player addaction [("<t color=""#FFC726"">" + ("    Splint (Morphine)") +"</t>"),"crafting\oven.sqf",[[0,"Splint (Morphine)","ItemMorphine",1],[[0,"ItemBandage",4],[0,"PartWoodPile",2]]],94,false,false,"",_restriction]];
    manatee_craft_menu_sur set [count manatee_craft_menu_sur, player addaction [("<t color=""#FFC726"">" + ("    Hatchet") +"</t>"),"crafting\oven.sqf",[[1,"Hatchet","ItemHatchet",1],[[0,"ItemTrashRazor",4],[0,"PartWoodPile",2]]],94,false,false,"",_restriction]];
    manatee_craft_menu_sur set [count manatee_craft_menu_sur, player addaction [("<t color=""#FFC726"">" + ("    Box of Matches") +"</t>"),"crafting\oven.sqf",[[1,"Box of Matches","ItemMatchbox",1],[[0,"ItemBandage",4],[0,"HandRoadFlare",1]]],94,false,false,"",_restriction]];
    manatee_craft_menu_sur set [count manatee_craft_menu_sur, player addaction [("<t color=""#FFC726"">" + ("    Hunting Knife") +"</t>"),"crafting\oven.sqf",[[1,"Hunting Knife","ItemKnife",1],[[0,"ItemTrashRazor",3],[0,"ItemMachete",1]]],94,false,false,"",_restriction]];
    manatee_craft_menu_sur set [count manatee_craft_menu_sur, player addaction [("<t color=""#FFC726"">" + ("    Old Camping Tent") +"</t>"),"crafting\oven.sqf",[[0,"Old Camping Tent","ItemTent",1],[[0,"ItemTankTrap",2],[0,"PartGeneric",1],[0,"Skin_Sniper3_DZC",2]]],94,false,false,"",_restriction]];
} else {
    show_survival = false;
    {player removeAction _x;} foreach manatee_craft_menu_sur; manatee_craft_menu_sur = [];
};
 
Post 2 of 2.

Again we can see that the sub menus all simply pass a parameters of [[What you Get],[What you need]].

As a weapon, you can convert weapons using materials, i.e. svd + ghilli = svd camo or create satchels with grenades etc.

weapons.sqf:
Code:
// parameter format, array of:
// output item, array of input items and how many of each item. Treat each input item as an array
// that includes the class name and the number required.
 
 
// PARAMETER STRUCTURE VERY IMPORTANT
// type = 0 for magazine, 1 for weapon/toolbelt
// [ [ type, "Finished Readable Item Name","FinishedItemClassName","FinishedQty" ] , [ [type, "RequiredClassName","RequiredQty"] , [type, "RequiredClassName2","RequiredQty"] ... ]]
 
sleep 1;
 
if (!show_weapons) then {
    show_weapons = true;
    _restriction = "count ((position player) nearObjects ['Land_fire', 10]) > 0";
 
    manatee_craft_menu_wea = [];
    manatee_craft_menu_wea set [count manatee_craft_menu_wea, player addaction [("<t color=""#FFC726"">" + ("    Satchel Charge") +"</t>"),"crafting\oven.sqf",[[0,"Satchel Charge","PipeBomb",1],[[0,"1Rnd_HE_M203",3],[0,"HandGrenade_West",3]]],92,false,false,"",_restriction]];
    manatee_craft_menu_wea set [count manatee_craft_menu_wea, player addaction [("<t color=""#FFC726"">" + ("    DE Ammo Clip") +"</t>"),"crafting\oven.sqf",[[0,"Desert Eagle Ammo","RH_7Rnd_50_AE",1],[[0,"Item_DEagle_empty_DZC",7]]],92,false,false,"",_restriction]];
    manatee_craft_menu_wea set [count manatee_craft_menu_wea, player addaction [("<t color=""#FFC726"">" + ("    M24 Ammo Clip") +"</t>"),"crafting\oven.sqf",[[0,"M24 Sniper Ammo","5Rnd_762x51_M24",1],[[0,"5x_22_LR_17_HMR",4]]],92,false,false,"",_restriction]];
    manatee_craft_menu_wea set [count manatee_craft_menu_wea, player addaction [("<t color=""#FFC726"">" + ("    M24 Sniper Rifle") +"</t>"),"crafting\oven.sqf",[[1,"M24 Sniper Rifle","M24",1],[[1,"huntingrifle",1],[0,"PartGeneric",4]]],92,false,false,"",_restriction]];
    manatee_craft_menu_wea set [count manatee_craft_menu_wea, player addaction [("<t color=""#FFC726"">" + ("    M24 Desert Camo") +"</t>"),"crafting\oven.sqf",[[1,"M24 Desert Camo Rifle","M24_des_EP1",1],[[1,"M24",1],[0,"Skin_Sniper1_DZC",1]]],92,false,false,"",_restriction]];
    manatee_craft_menu_wea set [count manatee_craft_menu_wea, player addaction [("<t color=""#FFC726"">" + ("    M40A3 Sniper Rifle") +"</t>"),"crafting\oven.sqf",[[1,"M40A3 Sniper Rifle","M40A3",1],[[1,"M24",1],[0,"Skin_Sniper3_DZC",1]]],92,false,false,"",_restriction]];
} else {
    show_weapons = false;
    {player removeAction _x;} foreach manatee_craft_menu_wea; manatee_craft_menu_wea = [];
};
And now for the most important part, the "oven.sqf" which does the actual conversion.
Code:
// MANATEES CUSTOM BUILD SCRIPT
// http://manatees.enjin.com
 
disableUserInput true;
 
// close the menu
_nil = execVM "crafting\closemenu.sqf";
 
// get all the parameters
_parameters = _this select 3;
_makeItem = _parameters select 0;
_neededItems = _parameters select 1;
_makeItemType = _makeItem select 0;
_makeItemName = _makeItem select 1;
_makeItemClass = _makeItem select 2;
_makeItemQty = _makeItem select 3;
 
 
player playActionNow "Medic";
[player,"repair",0,false] call dayz_zombieSpeak;
cutText [ format ["Attempting to craft %1, Qty: %2",_makeItemName, _makeItemQty],"PLAIN DOWN"];
sleep 5;
 
// get players inventory and story them as arrays
_mags = magazines player;
_weps = weapons player;
 
_correctInventory = true; // assume true until otherwise proven false
 
// loop through the array of needed items for the build
{
    _itemType = _x select 0;
    _itemClass = _x select 1;
    _itemQty = _x select 2;
 
    if (_itemType == 0) then {
        if (_itemClass in _mags) then {
            _inUserInv = {_x == _itemClass} count magazines player;
            if (_inUserInv < _itemQty) then {
                _correctInventory = false;
            };
        } else {
            _correctInventory = false;
        };
    } else {
        if (_itemClass in _weps) then {
            _inUserInv = 1;
        } else {
            _correctInventory = false;
        };
    };
} forEach _neededItems;
 
if (_correctInventory) then { // appears the player has everything needed
    // remove the items now
    {
        _itemType2 = _x select 0;
        _itemClass2 = _x select 1;
        _itemQty2 = _x select 2;
        for "_i" from 0 to _itemQty2-1 do {
            if (_itemType2 == 0) then {
                player removeMagazine _itemClass2;
            } else {
                player removeWeapon _itemClass2;
            };
        };
    } forEach _neededItems;
 
    sleep 2;
    player playActionNow "Medic";
    [player,"repair",0,false] call dayz_zombieSpeak;
    cutText [ format ["Crafting a %1",_makeItemName],"PLAIN DOWN"];
    sleep 6;
 
    if (alive player) then { // see if they weren't killed in the process
        _error = false;
        for "_i" from 0 to _makeItemQty-1 do {
            if (_makeItemClass == "PipeBomb") then {
                _result = player addMagazine "PipeBomb";
            } else {
                _result = [player,_makeItemClass] call BIS_fnc_invAdd;
            };
            if (!_result) then {
                _error = true;
            };
        };
        if(_error) then {
            cutText ["One or more items were lost in the crafting process.", "PLAIN DOWN"];
        } else {
            cutText [ format ["You have successfully created: %1",_makeItemName],"PLAIN DOWN"];
        };
    };
} else {
    // the players gear does not match
    _neededString = [];
    {
        _itemClass3 = _x select 1;
        _itemQty3 = _x select 2;
        _inUserInv3 = {_x == _itemClass3} count magazines player;
        _neededString set [count _neededString, format["%1/%2 %3",_inUserInv3,_itemQty3,_itemClass3]];
     
    } forEach _neededItems;
 
    cutText [format ["%1 Requirements: %2",_makeItemName, _neededString], "PLAIN DOWN",1];
};
 
disableUserInput false;
So if the user has the minimum requirements, then the item is converted into their inventory, otherwise the requirements for that item are shown to the player.

Lastly, closemenu.sqf
Code:
{
    player removeAction _x
} forEach manatee_craft_menu;
manatee_craft_menu = [];
{
    player removeAction _x
} forEach manatee_craft_menu_ind;
manatee_craft_menu_ind = [];
{
    player removeAction _x
} forEach manatee_craft_menu_sur;
manatee_craft_menu_sur = [];
{
    player removeAction _x
} forEach manatee_craft_menu_wea;
manatee_craft_menu_wea = [];
crafting_menu_open = false;
show_industrial = false;
show_survival = false;
show_weapons = false;
Just wanted to say thanks to all the people that posted their scripts as all of them have been a learning opportunity for me. (I'm a programmer, but had no experiences with arma engine few months ago.)
 
Top