Item Crafting and Weapon Accessories

Here is my update for the FN FAL selfaction. It doesn't require the NV goggles, but I'm updating that version too. The script now requires the weapon to be unloaded before you can work on it. Basically got the idea from an addition Frank McGee made to the suicide script in another thread. Hope he doesn't mind I borrowed it. I'll be updating each of the weapon scripts in this way.
Code:
// FN ADD START
 
private ["_rifle"];
_rifle = currentWeapon player;
if ((_rifle in ["FN_FAL"]) && (player ammo _rifle == 0)) then {
    hasRifle = true;
} else {
    hasRifle = false;
};
if (player ammo _rifle == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasRifle && weaponSafe && _canDo) then {
    if (addNV < 0) then {
        addNV = player addAction [("<t color=""#0096ff"">" + ("Add Night Vision Scope") +"</t>"),"scripts\AddFN.sqf",_rifle,0,false,true,"", ""];
    };
} else {
    player removeAction addNV;
    addNV = -1;
};
 
// FN ADD END
 
// FN REMOVE START
 
private ["_rifle"];
_rifle = currentWeapon player;
if ((_rifle in ["FN_FAL_ANPVS4"]) && (player ammo _rifle == 0)) then {
    hasRifle = true;
} else {
    hasRifle = false;
};
if (player ammo _rifle == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasRifle && weaponSafe && _canDo) then {
    if (RemNV < 0) then {
        RemNV = player addAction [("<t color=""#0096ff"">" + ("Remove Night Vision Scope") +"</t>"),"scripts\RemFN.sqf",_rifle,0,false,true,"", ""];
    };
} else {
    player removeAction RemNV;
    RemNV = -1;
};
 
// FN REMOVE END
 
USP update

Code:
// USP SILENCER ADD START
 
private ["_pistol"];
_pistol = currentWeapon player;
if ((_pistol in ["RH_usp"]) && (player ammo _pistol == 0)) then {
    hasUSP = true;
} else {
    hasUSP = false;
};
if (player ammo _pistol == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasUSP && weaponSafe && _canDo) then {
    if (addSil < 0) then {
        addSil = player addAction [("<t color=""#0096ff"">" + ("Add Silencer") +"</t>"),"scripts\uspaddsil.sqf",_pistol,0,false,true,"", ""];
    };
} else {
    player removeAction addSil;
    addSil = -1;
};
 
// USP SILENCER ADD END
 
// USP REMOVE SILENCER START
 
private ["_pistol"];
_rifle = currentWeapon player;
if ((_pistol in ["RH_uspsd"]) && (player ammo _pistol == 0)) then {
    hasUSP = true;
} else {
    hasUSP = false;
};
if (player ammo _pistol == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasUSP && weaponSafe && _canDo) then {
    if (remUSPsil < 0) then {
        remUSPsil = player addAction [("<t color=""#0096ff"">" + ("Remove Silencer") +"</t>"),"scripts\uspremsil.sqf",_pistol,0,false,true,"", ""];
    };
} else {
    player removeAction remUSPsil;
    remUSPsil = -1;
};
 
// USP REMOVE SILENCER END
 
update or the as50 selfaction
Code:
// AS50 TWS ADD START
 
private ["_rifle"];
_rifle = currentWeapon player;
if ((_rifle in ["BAF_AS50_scoped"]) && (player ammo _rifle == 0)) then {
    hasas50 = true;
} else {
    hasas50 = false;
};
if (player ammo _rifle == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasas50 && weaponSafe && _canDo) then {
    if (addTWS < 0) then {
        addTWS = player addAction [("<t color=""#0096ff"">" + ("Add Thermal Weapon Scope") +"</t>"),"scripts\AddTWS.sqf",_rifle,0,false,true,"", ""];
    };
} else {
    player removeAction addTWS;
    addTWS = -1;
};
 
// AS50 TWS ADD END
 
// AS50 TWS REMOVE START
 
private ["_rifle"];
_rifle = currentWeapon player;
if ((_rifle in ["BAF_AS50_TWS"]) && (player ammo _rifle == 0)) then {
    hasTWS = true;
} else {
    hasTWS = false;
};
if (player ammo _rifle == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasTWS && weaponSafe && _canDo) then {
    if (remTWS < 0) then {
        remTWS = player addAction [("<t color=""#0096ff"">" + ("Remove Thermal Weapon Scope") +"</t>"),"scripts\RemTWS.sqf",_rifle,0,false,true,"", ""];
    };
} else {
    player removeAction remTWS;
    remTWS = -1;
};
 
// AS50 TWS REMOVE END


update for the m9:

Code:
// M9 SILENCER ADD START
 
private ["_pistol"];
_pistol = currentWeapon player;
if ((_pistol in ["M9"]) && (player ammo _pistol == 0)) then {
    hasM9 = true;
} else {
    hasM9 = false;
};
if (player ammo _pistol == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasM9 && weaponSafe && _canDo) then {
    if (addM9sil < 0) then {
        addM9sil = player addAction [("<t color=""#0096ff"">" + ("Add Silencer") +"</t>"),"scripts\m9addsil.sqf",_pistol,0,false,true,"", ""];
    };
} else {
    player removeAction addM9sil;
    addM9sil = -1;
};
 
// M9 SILENCER ADD END
 
// M9 SILENCER REMOVE START
 
private ["_pistol"];
_rifle = currentWeapon player;
if ((_pistol in ["M9SD"]) && (player ammo _pistol == 0)) then {
    hasM9SD = true;
} else {
    hasM9SD = false;
};
if (player ammo _pistol == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasM9SD && weaponSafe && _canDo) then {
    if (remM9sil < 0) then {
        remM9sil = player addAction [("<t color=""#0096ff"">" + ("Remove Silencer") +"</t>"),"scripts\m9remsil.sqf",_pistol,0,false,true,"", ""];
    };
} else {
    player removeAction remM9sil;
    remM9sil = -1;
};
 
// M9 SILENCER REMOVE END

update for the rh makarov:
Code:
// RH MAK SILENCER ADD START
 
private ["_pistol"];
_pistol = currentWeapon player;
if ((_pistol in ["RH_pm"]) && (player ammo _pistol == 0)) then {
    haspm = true;
} else {
    haspm = false;
};
if (player ammo _pistol == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && haspm && weaponSafe && _canDo) then {
    if (addPMsil < 0) then {
        addPMsil = player addAction [("<t color=""#0096ff"">" + ("Add Silencer") +"</t>"),"scripts\pmaddsil.sqf",_pistol,0,false,true,"", ""];
    };
} else {
    player removeAction addPMsil;
    addPMsil = -1;
};
 
// RH MAK SILENCER ADD END
 
// RH MAK SILENCER REMOVE START
 
private ["_pistol"];
_rifle = currentWeapon player;
if ((_pistol in ["RH_pmsd"]) && (player ammo _pistol == 0)) then {
    haspmsd = true;
} else {
    haspmsd = false;
};
if (player ammo _pistol == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && haspmsd && weaponSafe && _canDo) then {
    if (rempmsil < 0) then {
        rempmsil = player addAction [("<t color=""#0096ff"">" + ("Remove Silencer") +"</t>"),"scripts\pmremsil.sqf",_pistol,0,false,true,"", ""];
    };
} else {
    player removeAction rempmsil;
    rempmsil = -1;
};
 
// RH MAK SILENCER REMOVE END

update for the GOSHAWK AK:

Code:
// GOSHAWK ADD START
 
private ["_rifle"];
_rifle = currentWeapon player;
if ((_rifle in ["AKS_74"]) && (player ammo _rifle == 0)) then {
    hasAK = true;
} else {
    hasAK = false;
};
if (player ammo _rifle == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasAK && weaponSafe && _canDo) then {
    if (addGO < 0) then {
        addGO = player addAction [("<t color=""#0096ff"">" + ("Add GOSHAWK") +"</t>"),"scripts\Addgoshawk.sqf",_rifle,0,false,true,"", ""];
    };
} else {
    player removeAction addGO;
    addGO = -1;
};
 
// GOSHAWK ADD END
 
// GOSHAWK REMOVE START
 
private ["_rifle"];
_rifle = currentWeapon player;
if ((_rifle in ["AKS_74_GOSHAWK"]) && (player ammo _rifle == 0)) then {
    hasGO = true;
} else {
    hasGO = false;
};
if (player ammo _rifle == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasGO && weaponSafe && _canDo) then {
    if (remGO < 0) then {
        remGO = player addAction [("<t color=""#0096ff"">" + ("Remove GOSHAWK") +"</t>"),"scripts\Remgoshawk.sqf",_rifle,0,false,true,"", ""];
    };
} else {
    player removeAction remGO;
    remGO = -1;
};
 
// GOSHAWK REMOVE END
 
Update for the Crossbow break down self action:
Code:
// BREAK BOW START
private ["_bow"];
_bow = currentWeapon player;
if ((_bow in ["Crossbow_DZ"]) && (player ammo _bow == 0)) then {
    hasBow = true;
} else {
    hasBow = false;
};
if (player ammo _bow == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasBow && weaponSafe && _canDo) then {
    if (breakBow < 0) then {
        breakBow = player addAction [("<t color=""#0096ff"">" + ("Deconstruct Crossbow") +"</t>"),"scripts\breakbow.sqf",_bow,0,false,true,"", ""];
    };
} else {
    player removeAction breakBow;
    breakBow = -1;
};
// BREAK BOW END

Update for shotgun breakdown self action:

Code:
// BREAK SHOTGUN START
 
private ["_shot"];
_shot = currentWeapon player;
if ((_shot in ["MR43"]) && (player ammo _shot == 0)) then {
    hasGun = true;
} else {
    hasGun = false;
};
if (player ammo _shot == 0) then {
    weaponSafe = true;
} else {
    weaponSafe = false;
};
if((speed player <= 1) && hasGun && weaponSafe && _canDo) then {
    if (breakGun < 0) then {
        breakGun = player addAction [("<t color=""#0096ff"">" + ("Deconstruct Shotgun") +"</t>"),"scripts\breakshotgun.sqf",_shot,0,false,true,"", ""];
    };
} else {
    player removeAction breakGun;
    breakGun = -1;
};
 
// BREAK SHOTGUN END
 
Got this working and it's perfect, thanks. One if the items I want to craft is a Rangefinder, however, and that seems a little more difficult. I'm using ingredients - binoculars, military flashlight, heat pack (have to use them for something) - and I'm not sure how to mark the binocs and rangefinder, as in_items doesn't seem to work. Any thoughts? Here's the code I used. And if anyone knows of a good tutorial on working with items like this, please link it. Thanks much!

Code:
private["_items","_item","_tool","_pos"];
_items = magazines player;
_tool = items player;
if (("ItemToolbox" in _tool) && ("Binocular" in _items) && ("ItemFlashlightRed" in _tool) && ("ItemHeatPack" in _items)) then {
player removeAction s_player_craftBullet; //remove the action from users scroll menu
player playActionNow "Medic"; //play craft animation
sleep 5;
player removeMagazine "Binocular"; //remove the used item from inventory
player removeTool "ItemFlashlightRed"; //remove the used item from inventory
player removeMagazine "ItemHeatPack"; //remove the used item from inventory
_pos = player modeltoWorld [0,1,0];
_item = createVehicle ["WeaponHolder", _pos, [], 0.0, "CAN_COLLIDE"];
_item setPosATL _pos;
_item addMagazineCargoGlobal ["Binocular_Vector",1];
cutText [format["You have crafted a rangefinder, it's on the ground."], "PLAIN DOWN"]; //display text at bottom.
}
else
{
cutText [format["You must have binoculars, a heat pack, a military flashlight and a toolbox to craft this item."], "PLAIN DOWN"]; //display text at bottom.
};
 
Binoculars and Rangefinders are classified as weapons so ...

player removeWeapon "Binocular"; //remove the used item from inventory

And so on.
 
Binoculars and Rangefinders are classified as weapons so ...

player removeWeapon "Binocular"; //remove the used item from inventory

And so on.
Yeah, what he said. Binoculars and rangefinders are technically weapons in the eyes of the game. It should be something like
Code:
("Binocular" in weapons player)
 
Yeah, what he said. Binoculars and rangefinders are technically weapons in the eyes of the game. It should be something like
Code:
("Binocular" in weapons player)


Thank you, I got that part, and it's working to a point. I can select rangefinder, go through the motion of crafting, have my ingredient items taken away, but when it comes time to drop the rangefinder I get -

No entry 'bin\config.bin/CfgMagazines.rangefinder'.

I've used both "rangefinder" and "Binocular_Vector" as the class name and got the same error. I've seen both listed as the class name for rangefinders, it might have changed at some point.

It's the last piece of the puzzle, does anyone know what I'm doing wrong? If we can fix it I'll post so other folks here can use it. I should note that I'm testing this on Takistan.

Here's my (mostly working) code -

Code:
private["_items","_item","_tool","_pos"];
_items = magazines player;
_tool = items player;
if (("ItemToolbox" in _tool) && ("Binocular" in weapons player) && ("ItemFlashlightRed" in _tool) && ("ItemHeatPack" in _items)) then {
    player removeAction s_player_craftBullet; //remove the action from users scroll menu
    player playActionNow "Medic"; //play craft animation
    sleep 5;
    player removeWeapon "Binocular"; //remove the used item from inventory
    player removeWeapon "ItemFlashlightRed"; //remove the used item from inventory
    player removeMagazine "ItemHeatPack"; //remove the used item from inventory
    _pos = player modeltoWorld [0,1,0];
    _item = createVehicle ["WeaponHolder", _pos, [], 0.0, "CAN_COLLIDE"];
    _item setPosATL _pos;
    _item addMagazineCargoGlobal ["Binocular_Vector",1];
    cutText [format["You have crafted a rangefinder, it's on the ground."], "PLAIN DOWN"]; //display text at bottom.
    }
    else
    {
    cutText [format["You must have binoculars, a heat pack, a military flashlight and a toolbox to craft this item."], "PLAIN DOWN"]; //display text at bottom.
    };
 
_item addMagazineCargoGlobal ["Binocular_Vector",1];
There's your problem, it's not a magazine, it's a weapon. So it should look like this instead:
Code:
_item addWeaponCargoGlobal ["Binocular_Vector",1];
I would do player addweapon "Binocular_Vector" instead of the globalcargo command, but that's just me.

Edit: the ,1 might need to be removed after "Binocular_Vector". Not sure exactly, cause you can add multiple magazines to inventory but not multiple weapons since they all go in their own slots.
 
There's your problem, it's not a magazine, it's a weapon. So it should look like this instead:
Code:
_item addWeaponCargoGlobal ["Binocular_Vector",1];
I would do player addweapon "Binocular_Vector" instead of the globalcargo command, but that's just me.

Edit: the ,1 might need to be removed after "Binocular_Vector". Not sure exactly, cause you can add multiple magazines to inventory but not multiple weapons since they all go in their own slots.

Gah, it was staring right at me. Thanks for the help everyone, and I agree with the preference for 'player addWeapon' and so have added it. This is tested and working in Takistan, someone with a Chernarus server will have to test it there.

Here's the final working rangefinder crafting code if anyone wants it. You get to keep your toolbox, but you give up a military flashlight. I was going to add a GPS for some kind of range calibration, but it just broke the code, so I'm leaving well enough alone. I add heatpacks to all of my recipes, assuming you'll need warm and nimble fingers to craft, and because those things really need to find a place in this game.

Code:
/*
 
Coded by: SASZane(Kris) and Matt Lampley
 
*/
private["_items","_item","_tool","_pos"];
_items = magazines player;
_tool = items player;
if (("ItemToolbox" in _tool) && ("Binocular" in weapons player) && ("ItemFlashlightRed" in _tool) && ("ItemHeatPack" in _items)) then {
    player removeAction s_player_craftBullet; //remove the action from users scroll menu
    player playActionNow "Medic"; //play craft animation
    sleep 5;
    player removeWeapon "Binocular"; //remove the used item from inventory
    player removeWeapon "ItemFlashlightRed"; //remove the used item from inventory
    player removeMagazine "ItemHeatPack"; //remove the used item from inventory
    player addWeapon "Binocular_Vector";
    cutText [format["You have crafted a rangefinder."], "PLAIN DOWN"]; //display text at bottom.
    }
    else
    {
    cutText [format["You must have binoculars, a heat pack, a military flashlight and a toolbox to craft this item."], "PLAIN DOWN"]; //display text at bottom.
    };
 
I'll definitely try it out. I'm with you on making things more functional. On my server all the trash type items have a use, even the razor. I'm also working on a script for pooping with the toilet paper, but I don't know if I would get banned for posting such a thing here. It's really, really funny though.
 
Back
Top