//-----------------------------------------------------------------------------
// Craft Zombie Bait Bomb
// Gives players the ability to craft zombie bait bomb that attracts zombies for
// a configurable amount of time and then detonates killing all nearby.
//
// DayZ Version: 1.7.7.1 - Chernarus
//
// Author: KungFuCharlie
//
// Contributors:
// Original Zombie Bait Bomb script created by Freaking Fred
// http://opendayz.net/threads/release-freds-zombie-bait-wip.10701
//
// Change Log:
// Version 1.0.0 - [July 9, 2013]
// Initial release of script that works on 1.7.7.1
//-----------------------------------------------------------------------------
private ["_attractDistance","_attractChance","_baitDuration","_meatRequired","_bloodBagsRequired","_craftingStartTime","_craftingUseTime","_started","_finished","_hasMeatType","_rawmeat","_grenadesRequired","_grenades","_removed","_dis","_sfx","_position","_heading","_bait","_zombies","_bomb","_i","_animState","_isCrafting"];
_attractDistance = 75; // Distance in meters to draw zombies attention
_attractChance = 100; // Chance a zombie is attracted to bait (30 = 30%,..,100 = 100%)
_baitDuration = 30; // Number of seconds until bait explodes
_craftingUseTime = 8; // Number of seconds it takes to craft bait
//-----------------------------------------------------------------------------
// These variables must be updated in your compiles.sqf file whenever they are changed!
_meatRequired = 1; // Number of meats required to set explosive bait
_bloodBagsRequired = 1; // Number of blood bags required to set explosive bait
_grenadesRequired = 1; // Number of grenades required to set explosive bait
_grenades = ["HandGrenade_West","HandGrenade_East"];
//-----------------------------------------------------------------------------
player removeAction s_player_craftZombieBaitBomb;
s_player_craftZombieBaitBomb = -1;
a_player_customAction = true;
_craftingStartTime = time;
// Remove the correct number of meats from the players inventory.
_rawmeat = meatraw;
_removed = 0;
while {_removed < _meatRequired} do {
{
if ( _x in magazines player) exitWith {
player removeMagazine _x; // ADD TO BE SCRIPTS.TXT!
_removed = _removed + 1;
};
} forEach _rawmeat;
};
// Remove the correct number of blood bags from the players inventory.
for [{_i = 0}, {_i < _bloodBagsRequired}, {_i = _i + 1}] do
{
player removeMagazine "ItemBloodbag"; // ADD TO BE SCRIPTS.TXT!
};
// Remove the correct number of grenades from players inventory.
for [{_i = 0}, {_i < _grenadesRequired}, {_i = _i + 1}] do
{
if ("HandGrenade_West" in magazines player) then {
player removeMagazine "HandGrenade_West"; // ADD TO BE SCRIPTS.TXT!
} else {
player removeMagazine "HandGrenade_East";
};
};
// Play the medic animation and alert nearby zombies.
player playActionNow "Medic";
_dis = 5;
_sfx = "repair";
[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
// Cancel if interrupted
r_interrupt = false;
_animState = animationState player;
r_doLoop = true;
_started = false;
_finished = false;
while {r_doLoop} do {
_animState = animationState player;
_isCrafting = ["medic",_animState] call fnc_inString;
if (_isCrafting) then {
_started = true;
} else {
if (_started and !r_interrupt) then {
if ((time - _craftingStartTime) <= _craftingUseTime) then {
player playActionNow "Medic";
} else {
r_doLoop = false;
_finished = true;
};
};
};
if (r_interrupt) then {
r_doLoop = false;
};
sleep 0.1;
};
r_doLoop = false;
a_player_customAction = false;
if (_finished) then {
// Create the bait object and set its position.
_heading = getDir player;
_position = getPosATL player;
_position = [(_position select 0) + (2 * sin(_heading)), (_position select 1) + (2 * cos(_heading)), (_position select 2)];
_createBait = createVehicle ["Land_Bucket_EP1", _position, [], 0, "CAN_COLLIDE"]; // ADD TO BE CREATEVEHICLE.TXT!
_createBait setDir _heading;
_createBait setPosATL _position; // ADD TO BE SCRIPTS.TXT!
_bait = nearestObject [player, "Land_Bucket_EP1"];
_zombies = (getPosATL _bait) nearEntities ["zZombie_Base", _attractDistance];
// Add the bait to the targets list of every zombie group that is within the
// attraction zone and passes the random chance of attraction check.
{
private ["_chance","_group","_targets"];
_chance = random 100;
if (_chance <= _attractChance ) then {
_group = group _x;
if (isNull group _x) then {
_group = _x;
};
_x reveal [_bait, 4];
_targets = _group getVariable ["targets", []];
if (!(_bait in _targets)) then {
_targets set [count _targets, _bait];
_group setVariable ["targets", _targets, true];
};
};
} forEach _zombies;
cutText [format["You have placed a zombie bait bomb with a %1 second detonation timer... You should run!", _baitDuration], "PLAIN DOWN"];
titleFadeOut 5;
// Wait the correct duration and then make ze explosive bait go BOOM!
sleep _baitDuration - 10;
titleText ["Zombie bait bomb detonation in 10 seconds!", "PLAIN DOWN"];
titleFadeOut 5;
sleep 10;
_bomb = createVehicle ["grenade", _position, [], 0, "NONE"]; // ADD TO BE SCRIPTS.TXT!
sleep 1;
deleteVehicle _bait;
} else {
// This is for handling if interrupted
r_interrupt = false;
player switchMove "";
player playActionNow "stop";
cutText [format["Your crafting of a zombie bait bomb has been interrupted."], "PLAIN DOWN"];
};