Item Crafting and Weapon Accessories

SmokeyMeadow

Well-Known Member
Big thanks to Freaking Fred for this. I had the idea a while back and had been searching for a way to implement it. By adapting the anti zombie emitter script, I found I was able to craft all sorts of items, and even modify weapons to include things like removable silencers and scopes.

So far, I've added the option to craft baseball bats and arrows from piles of wood if you are carrying a knife. Also made it so gathering a tin can, scrap metal and a wire fence kit allows you to build a crossbow. As for modding weapons, I've made the M9 convertible to an M9SD. Also did this for the USP and Makarov from the rh pistol pack, but this won't be of interest to you unless you run rmod.

Pretty easy to do, you will need to use a custom fn_selfactions.sqf if you aren't using one already. If you already have this set up, skip ahead while I explain to the rest how that is done.

Extract both the "complies.sqf" and "fn_selfactions.sqf" from dayzcode.pbo. Place both in your mission folder. Alter your mission's init.sqf so that this line is commented out (place a // at the beginning)

Code:
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\compiles.sqf";                    //Compile regular functions

Now beneath it, add this:

Code:
call compile preprocessFileLineNumbers "compiles.sqf";                    //Compile regular functions

Now your init will look for the special code we're adding instead of just the vanilla code from the dayzcode.pbo. Open up compiles.sqf and find this line and place a // at the start of it:

Code:
fnc_usec_selfActions = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_selfActions.sqf";        //Checks which actions for self

Now, add this in directly below:
Code:
fnc_usec_selfActions = compile preprocessFileLineNumbers "fn_selfActions.sqf";

Now for the fun part, editing the fn_selfaction.sqf to allow the new actions we want. Open it up and add this at the very bottom to allow players to craft bats and arrows:

Code:
// MAKE A BAT START
if (("PartWoodPile" in magazines player) && ("ItemKnife" in items player)) then {
    hasBatParts = true;
} else {
    hasBatParts = false;
};
if (hasBatParts) then {
    if (makeBat < 0) then {
    makeBat = player addAction [("<t color=""#00c362"">" + ("Craft Baseball Bat") +"</t>"),"scripts\makebat.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction makeBat;
    makeBat = -1;
};
// MAKE A BAT END
 
// MAKE ARROW START
if (("PartWoodPile" in magazines player) && ("ItemKnife" in items player)) then {
    hasArrowParts = true;
} else {
    hasArrowParts = false;
};
if (hasArrowParts) then {
    if (makeArrows < 0) then {
    makeArrows = player addAction [("<t color=""#00c362"">" + ("Craft an Arrow") +"</t>"),"scripts\makearrow.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction makeArrows;
    makeArrows = -1;
};
// MAKE ARROW END

Then create a folder inside your mission folder called Scripts. Place this file and this file in it.
Your players will now be able to craft a baseball bat or an arrow if they are carrying wood and a hunting knife (Thanks, Mamu1234 for helping on this).

Add this to the fn_selfactions to allow players to build their own crossbows:

Code:
// MAKE CROSSBOW START
if (("TrashTinCan" in magazines player) && ("ItemWire" in magazines player) && ("PartGeneric" in magazines player) && ("ItemKnife" in items player) && ("ItemToolbox" in items player)) then {
    hasBowparts = true;
} else {
    hasBowparts = false;
};
if (hasBowparts) then {
    if (makeBow < 0) then {
    makeBow = player addAction [("<t color=""#00c362"">" + ("Construct Crossbow") +"</t>"),"scripts\makebow.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction makeBow;
    makeBow = -1;
};
// MAKE CROSSBOW END

Then add this file into your scripts folder. Now by gathering a tin can, scrap metal, a wire kit and a toolbox, players will be able to make a hand built crossbow.

Add this to allow players to clear brush with a hatchet:

Code:
// CLEAR BRUSH START
if (("MeleeHatchet" in weapons player)) then {
    hasbrushclear = true;
} else {
    hasbrushclear = false;
};
if (hasbrushclear) then {
    if (clearBrush < 0) then {
    clearBrush = player addAction [("<t color=""#00c362"">" + ("Clear Brush") +"</t>"),"scripts\clearbrush.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction clearBrush;
    clearBrush = -1;
};
// CLEAR BRUSH END
 
// CLEAR BRUSH MACHETE START
 
if (("MeleeMachete" in weapons player)) then {
 
hasbrushclear = true;
 
} else {
 
hasbrushclear = false;
 
};
 
if (hasbrushclear) then {
 
if (clearBrushMachete < 0) then {
 
clearBrushMachete = player addAction [("<t color=""#00c362"">" + ("Clear Brush") +"</t>"),"scripts\clearbrush.sqf","",5,false,true,"",""];
 
};
 
} else {
 
player removeAction clearBrushMachete;
 
clearBrushMachete = -1;
 
};
 
// CLEAR BRUSH MACHETE END

And add this into the scripts folder. Players carrying a hatchet or machete will be able to clear the surrounding area of brush.

This code will allow the player to add and remove the silencer from the standard Day Z M9 pistol.

Code:
// M9 SILENCER ADD START
if (("M9" in weapons player)) then {
    hasM9 = true;
} else {
    hasM9 = false;
};
if (hasM9) then {
    if (addM9sil < 0) then {
    addM9sil = player addAction [("<t color=""#00c362"">" + ("Add Silencer to M9") +"</t>"),"scripts\m9addsil.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction addM9sil;
    addM9sil = -1;
};
// M9 SILENCER ADD END
 
// M9 SILENCER REMOVE START
if (("M9SD" in weapons player)) then {
    hasM9SD = true;
} else {
    hasM9SD = false;
};
if (hasM9SD) then {
    if (remM9sil < 0) then {
    remM9sil = player addAction [("<t color=""#00c362"">" + ("Remove M9 Silencer") +"</t>"),"scripts\m9remsil.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction remM9sil;
    remM9sil = -1;
};
// M9 SILENCER REMOVE END

Now add this file and also this file into the scripts folder.

Please note the following issues:
*If you log in and have the necessary items to craft in your inventory, but don't see the option on the scroll menu, try dropping them and picking them back up. I will address this issue as soon as I figure out what causes it.
*Swapping the silencer off and on sometimes requires you to cycle weapons in order for the weapon to fire again.
*Adding a silencer will not actually silence the gun unless you also have sd magazines.
*The effects of Battleye on this are UNKNOWN. Repeat: I do not run BE on my server, so I have no idea if it will kick you for some kind of restriction. If this becomes an issue we'll just have to add exceptions. Someone who is less n00bish than me might have a better idea of how that is done.


I hope this is of use to some of you. I'm making this topic so people can share their ideas for possible future combinations and crafted items. Once again, big thanks to Freaking Fred for providing the code that made this idea possible.
 
This next section is for people running rmod/rmod2/rmod2.1, so skip over it if you're running vanilla Day Z.

To add silencers to the rh makarov (NOT the standard Arma Makarov) and USP, paste this code:

Code:
// USP SILENCER ADD START
 
if (("RH_usp" in weapons player)) then {
 
    hasUSP = true;
 
} else {
 
    hasUSP = false;
 
};
 
if (hasUSP) then {
 
    if (addUSPsil < 0) then {
 
    addUSPsil = player addAction [("<t color=""#00c362"">" + ("Add Silencer") +"</t>"),"scripts\uspaddsil.sqf","",5,false,true,"",""];
 
    };
 
} else {
 
    player removeAction addUSPsil;
 
    addUSPsil = -1;
 
};
 
// USP SILENCER ADD END
 
// USP SILENCER REMOVE START
 
if (("RH_uspsd" in weapons player)) then {
 
    hasUSPsd = true;
 
} else {
 
    hasUSPsd = false;
 
};
 
if (hasUSPsd) then {
 
    if (remUSPsil < 0) then {
 
    remUSPsil = player addAction [("<t color=""#00c362"">" + ("Remove Silencer") +"</t>"),"scripts\uspremsil.sqf","",5,false,true,"",""];
 
    };
 
} else {
 
    player removeAction remUSPsil;
 
    remUSPsil = -1;
 
};
 
// USP SILENCER REMOVE END
 
// MAK SILENCER ADD START
if (("RH_pm" in weapons player)) then {
    haspm = true;
} else {
    haspm = false;
};
if (haspm) then {
    if (addPMsil < 0) then {
    addPMsil = player addAction [("<t color=""#00c362"">" + ("Add Silencer to Makarov PM") +"</t>"),"scripts\pmaddsil.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction addPMsil;
    addPMsil = -1;
};
// MAK SILENCER ADD END
 
// RH MAK SILENCER REMOVE START
if (("RH_pmsd" in weapons player)) then {
    haspmsd = true;
} else {
    haspmsd = false;
};
if (haspmsd) then {
    if (rempmsil < 0) then {
    rempmsil = player addAction [("<t color=""#00c362"">" + ("Remove Makarov Silencer") +"</t>"),"scripts\pmremsil.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction rempmsil;
    rempmsil = -1;
};
// RH MAK SILENCER REMOVE END

And download this archive and extract the files inside into your scripts folder.

Also, Rmod users, if the AS50 is still in use on your server (banned in vanilla Day Z) you can use the script below to make the Thermal Weapon Scope removable:

Code:
// AS50 TWS ADD START
 
if (("BAF_AS50_scoped" in weapons player)) then {
 
    hasas50 = true;
 
} else {
 
    hasas50 = false;
 
};
 
if (hasas50) then {
 
    if (addTWS < 0) then {
 
    addTWS = player addAction [("<t color=""#00c362"">" + ("Add Thermal Weapon Scope") +"</t>"),"scripts\AddTWS.sqf","",5,false,true,"",""];
 
    };
 
} else {
 
    player removeAction addTWS;
 
    addTWS = -1;
 
};
 
// AS50 TWS ADD END
 
// AS50 TWS REMOVE START
 
if (("BAF_AS50_TWS" in weapons player)) then {
 
    hasTWS = true;
 
} else {
 
    hasTWS = false;
 
};
 
if (hasTWS) then {
 
    if (remTWS < 0) then {
 
    remTWS = player addAction [("<t color=""#00c362"">" + ("Remove Thermal Weapon Scope") +"</t>"),"scripts\RemTWS.sqf","",5,false,true,"",""];
 
    };
 
} else {
 
    player removeAction remTWS;
 
    remTWS = -1;
 
};
 
// // AS50 TWS REMOVE END

And add this and this to your scripts folder.
 
This will allow you to build a double barrel shotgun in similar fashion to the crossbow.

Code:
// MAKE SHOTGUN START
if (("TrashTinCan" in magazines player) && ("PartWoodPile" in magazines player) && ("PartGeneric" in magazines player) && ("ItemKnife" in items player) && ("ItemToolbox" in items player)) then {
    hasGunparts = true;
} else {
    hasGunparts = false;
};
if (hasGunparts) then {
    if (makeGun < 0) then {
    makeGun = player addAction [("<t color=""#00c362"">" + ("Construct Shotgun") +"</t>"),"scripts\makeshotgun.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction makeGun;
    makeGun = -1;
};
// MAKE SHOTGUN END

And place this in the scripts folder. What I would like to do is make a conditional chance for these homemade weapons to backfire, destroying the weapon and injuring the player. Not really possible at this time since once crafted, the weapon becomes like any other shotgun or crossbow. However, on my server the spawn tables have been altered so that shotguns and crossbows only exist as crafted items, not spawned by the game itself. But for now, such coding is beyond my depth.

This next bit will allow players to break the shotgun and crossbow back down into their respective parts, should you so desire. Then players can carry a spare wire kit and wood pile, and swap back and forth between shotgun and crossbow. It's like having two crappy guns for the price of one.

Code:
// BREAK SHOTGUN START
if (("MR43" in weapons player) && ("ItemKnife" in items player) && ("ItemToolbox" in items player)) then {
    hasGun = true;
} else {
    hasGun = false;
};
if (hasGun) then {
    if (breakGun < 0) then {
    breakGun= player addAction [("<t color=""#00c362"">" + ("Deconstruct Shotgun") +"</t>"),"scripts\breakshotgun.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction breakGun;
    breakGun = -1;
};
// BREAK SHOTGUN END
 
// BREAK BOW START
if (("Crossbow_DZ" in weapons player) && ("ItemKnife" in items player) && ("ItemToolbox" in items player)) then {
    hasBow = true;
} else {
    hasBow = false;
};
if (hasBow) then {
    if (breakBow < 0) then {
    breakBow= player addAction [("<t color=""#00c362"">" + ("Deconstruct Crossbow") +"</t>"),"scripts\breakbow.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction breakBow;
    breakBow = -1;
};
// BREAK BOW END

And extract this archive into the scripts folder.
 
Gun crafting has been revised. The building process now uses the wrench sfx and should be audible to zeds. There is the chance of failure and injury. Currently, in the case of the shotgun, it creates a B_23mm_AA muzzle in the event of failure. This may cause a BE error on some servers, and I will probably change it since it makes little sense for a gun to go off without being loaded. But it's kind of what I want to do with the firing failure, that is to make it conditional every time the shotgun fires that it might blow up. Still trying to figure that part out.

For now, here is the knife script I accidentally uploaded earlier. For fn_selfactions:

Code:
// MAKE A KNIFE START
if (("TrashTinCan" in magazines player) && ("ItemSodaEmpty" in magazines player) && ("ItemToolbox" in items player)) then {
    hasKnifeParts = true;
} else {
    hasKnifeParts = false;
};
if (hasKnifeParts) then {
    if (makeKnife < 0) then {
    makeKnife = player addAction [("<t color=""#00c362"">" + ("Craft Hunting Knife") +"</t>"),"scripts\makeknife.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction makeKnife;
    makeKnife = -1;
};
// MAKE A KNIFE END

And then this goes in the scripts folder.
 
Any way to put a thermal scope on a gun? Or is it just the thermal AS50?


I have a script here to swap the goshawk on and off of the aks-74. If you run rmod, this will work for you.

This goes in fn_selfactions
Code:
// GOSHAWK ADD START
if (("AKS_74" in weapons player)) then {
    hasAK = true;
} else {
    hasAK = false;
};
if (hasAK) then {
    if (addGO < 0) then {
    addGO = player addAction [("<t color=""#00c362"">" + ("Add GOSHAWK") +"</t>"),"scripts\Addgoshawk.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction addGO;
    addGO = -1;
};
// GOSHAWK ADD END
 
// GOSHAWK REMOVE START
if (("AKS_74_GOSHAWK" in weapons player)) then {
    hasGO = true;
} else {
    hasGO = false;
};
if (hasGO) then {
    if (remGO < 0) then {
    remGO = player addAction [("<t color=""#00c362"">" + ("Remove GOSHAWK") +"</t>"),"scripts\Remgoshawk.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction remGO;
    remGO = -1;
};
// // GOSHAWK REMOVE END

Then this archive is extracted into scripts.

There's also this script on armaholic. I've never heard of anyone getting it to work on day z, but it might be worth looking at.
 
I have no idea. I am not skilled in scripting or editing these files.
It's okay. Maybe someone else will have some suggestions, otherwise I'll keep studying the issue, and trying to make it work. In the meantime, this code will let you swap the NV scope on and off of the FAL. This will at least make the NV scoped version usable in the daytime.

Code:
// FN ADD START
if (("FN_FAL" in weapons player)) then {
    hasFN = true;
} else {
    hasFN = false;
};
if (hasFN) then {
    if (addNV < 0) then {
    addNV = player addAction [("<t color=""#00c362"">" + ("Add Night Vision Scope") +"</t>"),"scripts\AddFN.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction addNV;
    addNV = -1;
};
// FN ADD END
 
// FN REMOVE START
if (("FN_FAL_ANPVS4" in weapons player)) then {
    hasNV = true;
} else {
    hasNV = false;
};
if (hasNV) then {
    if (remNV < 0) then {
    remNV = player addAction [("<t color=""#00c362"">" + ("Remove Night Vision Scope") +"</t>"),"scripts\RemFN.sqf","",5,false,true,"",""];
    };
} else {
    player removeAction remNV;
    remNV = -1;
};
// // FN REMOVE END

Then this part gets extracted into the scripts folder. Like I said, I'll keep trying to find a solution for altering that config file.
 
Back
Top