diff --git a/dayz_code/actions/player_build.sqf b/dayz_code/actions/player_build.sqf index ca85ef571..70e6442fd 100644 --- a/dayz_code/actions/player_build.sqf +++ b/dayz_code/actions/player_build.sqf @@ -30,7 +30,7 @@ if(_classname == "Plastic_Pole_EP1_DZ") then { } else { _IsNearPlot = count (position player nearObjects ["Plastic_Pole_EP1_DZ",30]); }; -if(_IsNearPlot == 0) exitWith { TradeInprogress = false; cutText [format["Building requires plot within 30m %1",_missing] , "PLAIN DOWN"]; }; +if(_IsNearPlot == 0) exitWith { TradeInprogress = false; cutText ["Building requires plot within 30m" , "PLAIN DOWN"]; }; _missing = ""; _hasrequireditem = true; @@ -90,7 +90,7 @@ if (_hasrequireditem) then { _reason = "Moving to fast."; }; - if(_counter >= 10) exitWith { + if(_counter >= 3) exitWith { _isOk = false; _cancel = true; _reason = "Ran out of time to find position."; diff --git a/dayz_code/actions/player_craftItem.sqf b/dayz_code/actions/player_craftItem.sqf index 721ba34c6..d0eae468a 100644 --- a/dayz_code/actions/player_craftItem.sqf +++ b/dayz_code/actions/player_craftItem.sqf @@ -74,13 +74,8 @@ _reason = ""; _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1; _canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); -if (count _this == 2) then { - _item = _this select 0; - _crafting = _this select 1; // "Crafting1" -} else { - _item = _this; - _crafting = "Crafting"; -}; +_item = _this; +_crafting = "Crafting"; // check if fire is reqired _needNear = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "neednearby"); diff --git a/dayz_code/actions/player_craftItem1.sqf b/dayz_code/actions/player_craftItem1.sqf index 4690676fe..0fae2850a 100644 --- a/dayz_code/actions/player_craftItem1.sqf +++ b/dayz_code/actions/player_craftItem1.sqf @@ -1,3 +1,252 @@ -private["_crafting"]; +/* +* Crafting by [VB]AWOL +* usage: spawn player_craftitem; +*/ +private ["_onLadder","_canDo","_selectedRecipeOutput","_proceed","_itemIn","_countIn","_missing","_missingQty","_qty","_itemOut","_countOut","_started","_finished","_animState","_isMedic","_removed","_tobe_removed_total","_textCreate","_id","_textMissing","_selectedRecipeInput","_num_removed","_removed_total","_temp_removed_array","_abort","_reason","_isNear","_missingTools","_hastoolweapon","_selectedRecipeTools","_distance","_crafting","_needNear"]; + +if(TradeInprogress) exitWith { cutText ["Crafting already in progress." , "PLAIN DOWN"]; }; +TradeInprogress = true; + +/* +== Canned Foods +"FoodCanBakedBeans", +"FoodCanSardines", +"FoodCanFrankBeans", +"FoodCanPasta", +"FoodBioMeat" + +== Drinks +"ItemSodaCoke", +"ItemSodaPepsi", + +== Trash +"TrashTinCan", +"TrashJackDaniels", +"ItemSodaEmpty", +"ItemSodaCokeEmpty", +"ItemSodaPepsiEmpty", + +== community stuff Trash +"ItemSodaMdewEmpty", +"ItemSodaMtngreenEmpty", +"ItemSodaR4z0rEmpty", +"ItemSodaClaysEmpty", +"ItemSodaSmashtEmpty",. +"ItemSodaDrwasteEmpty",. +"ItemSodaLemonadeEmpty",. +"ItemSodaLvgEmpty",. +"ItemSodaMzlyEmpty",. +"ItemSodaRabbitEmpty" + +== Raw Meats +"FoodSteakRaw", +"FoodmeatRaw", +"FoodbeefRaw", +"FoodmuttonRaw", +"FoodchickenRaw", +"FoodrabbitRaw", +"FoodbaconRaw" + +== Cooked Meats +"FoodSteakCooked", +"FoodmeatCooked", +"FoodbeefCooked", +"FoodmuttonCooked", +"FoodchickenCooked", +"FoodrabbitCooked", +"FoodbaconCooked" +*/ + +// Removed metals: +// _recipe_ItemBronzeBar = [[["ItemBronzeBar",1] ],[["ItemCopperBar",3],["ItemTinBar",3]]]; + +// New item ideas: +// _recipe_FoodChickenNoodle = [["FoodchickenRaw",1],["FoodCanPasta",1],["ItemWaterbottle",1]]; +// _recipe_FoodBeefBakedBeans = [["FoodbeefRaw",1],["FoodCanBakedBeans",1]]; +// ItemSalt + +// temp array of removed parts +_temp_removed_array = []; +_abort = false; +_distance = 2; +_reason = ""; + +_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1; +_canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); + +_item = _this; _crafting = "Crafting1"; -[_this,_crafting] spawn player_craftitem; + +// check if fire is reqired +_needNear = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "neednearby"); + +if("fire" in _needNear) then { + _isNear = {inflamed _x} count (position player nearObjects _distance); + if(_isNear == 0) then { + _abort = true; + _reason = "fire"; + }; +}; + +if(_abort) exitWith { + cutText [format["Crafting needs a %1 within %2 meters",_reason,_distance], "PLAIN DOWN"]; + TradeInprogress = false; +}; + +// diag_log format["Checking for fire: %1", _isFireNear]; + +if (_canDo) then { + + // Moved all recipes input and outputs to configs + + _selectedRecipeOutput = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "output"); + _selectedRecipeInput = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "input"); + _selectedRecipeTools = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "requiretools"); + _consumeweapons = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "consumeweapons"); + + _missing = ""; + _missingTools = false; + { + _hastoolweapon = _x in weapons player; + if(!_hastoolweapon) exitWith { _missingTools = true; _missing = _x; }; + } forEach _selectedRecipeTools; + + if(!_missingTools) then { + + diag_log format["Selected Recipe Input: %1", _selectedRecipeInput]; + diag_log format["Selected Recipe Output: %1", _selectedRecipeOutput]; + + // Dry run to see if all parts are available. + _proceed = true; + { + _itemIn = _x select 0; + _countIn = _x select 1; + + diag_log format["Recipe Check: %1 %2", _itemIn,_countIn]; + + // not neccessary + //if (!(_itemIn in magazines player)) exitWith { _missing = _itemIn; _missingQty = _countIn; _proceed = false; }; + + // match against class and parentClass + _qty = { (_x == _itemIn) || (configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn) } count magazines player; + + if(_qty < _countIn) exitWith { _missing = _itemIn; _missingQty = (_countIn - _qty); _proceed = false; }; + + } forEach _selectedRecipeInput; + + // If all parts proceed + if (_proceed) then { + + cutText ["Crafting started", "PLAIN DOWN"]; + + player playActionNow "Medic"; + + [player,"repair",0,false] call dayz_zombieSpeak; + _id = [player,50,true,(getPosATL player)] spawn player_alertZombies; + + r_interrupt = false; + _animState = animationState player; + r_doLoop = true; + _started = false; + _finished = false; + + while {r_doLoop} do { + _animState = animationState player; + _isMedic = ["medic",_animState] call fnc_inString; + if (_isMedic) then { + _started = true; + }; + if (_started and !_isMedic) then { + r_doLoop = false; + _finished = true; + }; + if (r_interrupt) then { + r_doLoop = false; + }; + sleep 0.1; + }; + r_doLoop = false; + + if (_finished) then { + + _removed_total = 0; // count total of removed items + _tobe_removed_total = 0; // count total of all to be removed items + // Take items + { + _removed = 0; + _itemIn = _x select 0; + _countIn = _x select 1; + // diag_log format["Recipe Finish: %1 %2", _itemIn,_countIn]; + _tobe_removed_total = _tobe_removed_total + _countIn; + + { + if( (_removed < _countIn) && ((_x == _itemIn) || configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn)) then { + _num_removed = ([player,_x] call BIS_fnc_invRemove); + _removed = _removed + _num_removed; + _removed_total = _removed_total + _num_removed; + if(_num_removed >= 1) then { + _temp_removed_array set [count _temp_removed_array,_x]; + }; + }; + + } forEach magazines player; + + } forEach _selectedRecipeInput; + + diag_log format["removed: %1 of: %2", _removed, _tobe_removed_total]; + + // Only proceed if all parts were removed successfully + if(_removed_total == _tobe_removed_total) then { + + // Put items + { + // consumeweapons + { + player removeWeapon _x; + } forEach _consumeweapons; + + _itemOut = _x select 0; + _countOut = _x select 1; + diag_log format["Recipe Output: %1 %2", _itemOut,_countOut]; + + for "_x" from 1 to _countOut do { + player addMagazine _itemOut; + }; + + + + // get display name + _textCreate = getText(configFile >> "CfgMagazines" >> _itemOut >> "displayName"); + + // Add crafted item + cutText [format["Crafted Item: %1 x %2",_textCreate,_countOut], "PLAIN DOWN"]; + + } forEach _selectedRecipeOutput; + + } else { + // Refund parts since we failed + {player addMagazine _x;} forEach _temp_removed_array; + + cutText [format["Missing Parts after first check Item: %1 / %2",_removed_total,_tobe_removed_total], "PLAIN DOWN"]; + }; + + } else { + r_interrupt = false; + [objNull, player, rSwitchMove,""] call RE; + player playActionNow "stop"; + cutText ["Canceled crafting.", "PLAIN DOWN"]; + }; + + } else { + _textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName"); + cutText [format["Missing %1 more of %2",_missingQty, _textMissing], "PLAIN DOWN"]; + }; + } else { + _textMissing = getText(configFile >> "CfgWeapons" >> _missing >> "displayName"); + cutText [format["Missing Tool: %1",_textMissing], "PLAIN DOWN"]; + }; +} else { + cutText ["Crafting needs a fire within 2 meters.", "PLAIN DOWN"]; +}; + +TradeInprogress = false; \ No newline at end of file diff --git a/dayz_code/actions/player_craftItem2.sqf b/dayz_code/actions/player_craftItem2.sqf index 6e1d7fa14..6323f861b 100644 --- a/dayz_code/actions/player_craftItem2.sqf +++ b/dayz_code/actions/player_craftItem2.sqf @@ -1,3 +1,252 @@ -private["_crafting"]; +/* +* Crafting by [VB]AWOL +* usage: spawn player_craftitem; +*/ +private ["_onLadder","_canDo","_selectedRecipeOutput","_proceed","_itemIn","_countIn","_missing","_missingQty","_qty","_itemOut","_countOut","_started","_finished","_animState","_isMedic","_removed","_tobe_removed_total","_textCreate","_id","_textMissing","_selectedRecipeInput","_num_removed","_removed_total","_temp_removed_array","_abort","_reason","_isNear","_missingTools","_hastoolweapon","_selectedRecipeTools","_distance","_crafting","_needNear"]; + +if(TradeInprogress) exitWith { cutText ["Crafting already in progress." , "PLAIN DOWN"]; }; +TradeInprogress = true; + +/* +== Canned Foods +"FoodCanBakedBeans", +"FoodCanSardines", +"FoodCanFrankBeans", +"FoodCanPasta", +"FoodBioMeat" + +== Drinks +"ItemSodaCoke", +"ItemSodaPepsi", + +== Trash +"TrashTinCan", +"TrashJackDaniels", +"ItemSodaEmpty", +"ItemSodaCokeEmpty", +"ItemSodaPepsiEmpty", + +== community stuff Trash +"ItemSodaMdewEmpty", +"ItemSodaMtngreenEmpty", +"ItemSodaR4z0rEmpty", +"ItemSodaClaysEmpty", +"ItemSodaSmashtEmpty",. +"ItemSodaDrwasteEmpty",. +"ItemSodaLemonadeEmpty",. +"ItemSodaLvgEmpty",. +"ItemSodaMzlyEmpty",. +"ItemSodaRabbitEmpty" + +== Raw Meats +"FoodSteakRaw", +"FoodmeatRaw", +"FoodbeefRaw", +"FoodmuttonRaw", +"FoodchickenRaw", +"FoodrabbitRaw", +"FoodbaconRaw" + +== Cooked Meats +"FoodSteakCooked", +"FoodmeatCooked", +"FoodbeefCooked", +"FoodmuttonCooked", +"FoodchickenCooked", +"FoodrabbitCooked", +"FoodbaconCooked" +*/ + +// Removed metals: +// _recipe_ItemBronzeBar = [[["ItemBronzeBar",1] ],[["ItemCopperBar",3],["ItemTinBar",3]]]; + +// New item ideas: +// _recipe_FoodChickenNoodle = [["FoodchickenRaw",1],["FoodCanPasta",1],["ItemWaterbottle",1]]; +// _recipe_FoodBeefBakedBeans = [["FoodbeefRaw",1],["FoodCanBakedBeans",1]]; +// ItemSalt + +// temp array of removed parts +_temp_removed_array = []; +_abort = false; +_distance = 2; +_reason = ""; + +_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1; +_canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); + +_item = _this; _crafting = "Crafting2"; -[_this,_crafting] spawn player_craftitem; \ No newline at end of file + +// check if fire is reqired +_needNear = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "neednearby"); + +if("fire" in _needNear) then { + _isNear = {inflamed _x} count (position player nearObjects _distance); + if(_isNear == 0) then { + _abort = true; + _reason = "fire"; + }; +}; + +if(_abort) exitWith { + cutText [format["Crafting needs a %1 within %2 meters",_reason,_distance], "PLAIN DOWN"]; + TradeInprogress = false; +}; + +// diag_log format["Checking for fire: %1", _isFireNear]; + +if (_canDo) then { + + // Moved all recipes input and outputs to configs + + _selectedRecipeOutput = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "output"); + _selectedRecipeInput = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "input"); + _selectedRecipeTools = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "requiretools"); + _consumeweapons = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "consumeweapons"); + + _missing = ""; + _missingTools = false; + { + _hastoolweapon = _x in weapons player; + if(!_hastoolweapon) exitWith { _missingTools = true; _missing = _x; }; + } forEach _selectedRecipeTools; + + if(!_missingTools) then { + + diag_log format["Selected Recipe Input: %1", _selectedRecipeInput]; + diag_log format["Selected Recipe Output: %1", _selectedRecipeOutput]; + + // Dry run to see if all parts are available. + _proceed = true; + { + _itemIn = _x select 0; + _countIn = _x select 1; + + diag_log format["Recipe Check: %1 %2", _itemIn,_countIn]; + + // not neccessary + //if (!(_itemIn in magazines player)) exitWith { _missing = _itemIn; _missingQty = _countIn; _proceed = false; }; + + // match against class and parentClass + _qty = { (_x == _itemIn) || (configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn) } count magazines player; + + if(_qty < _countIn) exitWith { _missing = _itemIn; _missingQty = (_countIn - _qty); _proceed = false; }; + + } forEach _selectedRecipeInput; + + // If all parts proceed + if (_proceed) then { + + cutText ["Crafting started", "PLAIN DOWN"]; + + player playActionNow "Medic"; + + [player,"repair",0,false] call dayz_zombieSpeak; + _id = [player,50,true,(getPosATL player)] spawn player_alertZombies; + + r_interrupt = false; + _animState = animationState player; + r_doLoop = true; + _started = false; + _finished = false; + + while {r_doLoop} do { + _animState = animationState player; + _isMedic = ["medic",_animState] call fnc_inString; + if (_isMedic) then { + _started = true; + }; + if (_started and !_isMedic) then { + r_doLoop = false; + _finished = true; + }; + if (r_interrupt) then { + r_doLoop = false; + }; + sleep 0.1; + }; + r_doLoop = false; + + if (_finished) then { + + _removed_total = 0; // count total of removed items + _tobe_removed_total = 0; // count total of all to be removed items + // Take items + { + _removed = 0; + _itemIn = _x select 0; + _countIn = _x select 1; + // diag_log format["Recipe Finish: %1 %2", _itemIn,_countIn]; + _tobe_removed_total = _tobe_removed_total + _countIn; + + { + if( (_removed < _countIn) && ((_x == _itemIn) || configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn)) then { + _num_removed = ([player,_x] call BIS_fnc_invRemove); + _removed = _removed + _num_removed; + _removed_total = _removed_total + _num_removed; + if(_num_removed >= 1) then { + _temp_removed_array set [count _temp_removed_array,_x]; + }; + }; + + } forEach magazines player; + + } forEach _selectedRecipeInput; + + diag_log format["removed: %1 of: %2", _removed, _tobe_removed_total]; + + // Only proceed if all parts were removed successfully + if(_removed_total == _tobe_removed_total) then { + + // Put items + { + // consumeweapons + { + player removeWeapon _x; + } forEach _consumeweapons; + + _itemOut = _x select 0; + _countOut = _x select 1; + diag_log format["Recipe Output: %1 %2", _itemOut,_countOut]; + + for "_x" from 1 to _countOut do { + player addMagazine _itemOut; + }; + + + + // get display name + _textCreate = getText(configFile >> "CfgMagazines" >> _itemOut >> "displayName"); + + // Add crafted item + cutText [format["Crafted Item: %1 x %2",_textCreate,_countOut], "PLAIN DOWN"]; + + } forEach _selectedRecipeOutput; + + } else { + // Refund parts since we failed + {player addMagazine _x;} forEach _temp_removed_array; + + cutText [format["Missing Parts after first check Item: %1 / %2",_removed_total,_tobe_removed_total], "PLAIN DOWN"]; + }; + + } else { + r_interrupt = false; + [objNull, player, rSwitchMove,""] call RE; + player playActionNow "stop"; + cutText ["Canceled crafting.", "PLAIN DOWN"]; + }; + + } else { + _textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName"); + cutText [format["Missing %1 more of %2",_missingQty, _textMissing], "PLAIN DOWN"]; + }; + } else { + _textMissing = getText(configFile >> "CfgWeapons" >> _missing >> "displayName"); + cutText [format["Missing Tool: %1",_textMissing], "PLAIN DOWN"]; + }; +} else { + cutText ["Crafting needs a fire within 2 meters.", "PLAIN DOWN"]; +}; + +TradeInprogress = false; \ No newline at end of file diff --git a/dayz_code/actions/player_craftItem3.sqf b/dayz_code/actions/player_craftItem3.sqf index 4ff0fcd6b..279a0ce79 100644 --- a/dayz_code/actions/player_craftItem3.sqf +++ b/dayz_code/actions/player_craftItem3.sqf @@ -1,3 +1,252 @@ -private["_crafting"]; +/* +* Crafting by [VB]AWOL +* usage: spawn player_craftitem; +*/ +private ["_onLadder","_canDo","_selectedRecipeOutput","_proceed","_itemIn","_countIn","_missing","_missingQty","_qty","_itemOut","_countOut","_started","_finished","_animState","_isMedic","_removed","_tobe_removed_total","_textCreate","_id","_textMissing","_selectedRecipeInput","_num_removed","_removed_total","_temp_removed_array","_abort","_reason","_isNear","_missingTools","_hastoolweapon","_selectedRecipeTools","_distance","_crafting","_needNear"]; + +if(TradeInprogress) exitWith { cutText ["Crafting already in progress." , "PLAIN DOWN"]; }; +TradeInprogress = true; + +/* +== Canned Foods +"FoodCanBakedBeans", +"FoodCanSardines", +"FoodCanFrankBeans", +"FoodCanPasta", +"FoodBioMeat" + +== Drinks +"ItemSodaCoke", +"ItemSodaPepsi", + +== Trash +"TrashTinCan", +"TrashJackDaniels", +"ItemSodaEmpty", +"ItemSodaCokeEmpty", +"ItemSodaPepsiEmpty", + +== community stuff Trash +"ItemSodaMdewEmpty", +"ItemSodaMtngreenEmpty", +"ItemSodaR4z0rEmpty", +"ItemSodaClaysEmpty", +"ItemSodaSmashtEmpty",. +"ItemSodaDrwasteEmpty",. +"ItemSodaLemonadeEmpty",. +"ItemSodaLvgEmpty",. +"ItemSodaMzlyEmpty",. +"ItemSodaRabbitEmpty" + +== Raw Meats +"FoodSteakRaw", +"FoodmeatRaw", +"FoodbeefRaw", +"FoodmuttonRaw", +"FoodchickenRaw", +"FoodrabbitRaw", +"FoodbaconRaw" + +== Cooked Meats +"FoodSteakCooked", +"FoodmeatCooked", +"FoodbeefCooked", +"FoodmuttonCooked", +"FoodchickenCooked", +"FoodrabbitCooked", +"FoodbaconCooked" +*/ + +// Removed metals: +// _recipe_ItemBronzeBar = [[["ItemBronzeBar",1] ],[["ItemCopperBar",3],["ItemTinBar",3]]]; + +// New item ideas: +// _recipe_FoodChickenNoodle = [["FoodchickenRaw",1],["FoodCanPasta",1],["ItemWaterbottle",1]]; +// _recipe_FoodBeefBakedBeans = [["FoodbeefRaw",1],["FoodCanBakedBeans",1]]; +// ItemSalt + +// temp array of removed parts +_temp_removed_array = []; +_abort = false; +_distance = 2; +_reason = ""; + +_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1; +_canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); + +_item = _this; _crafting = "Crafting3"; -[_this,_crafting] spawn player_craftitem; \ No newline at end of file + +// check if fire is reqired +_needNear = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "neednearby"); + +if("fire" in _needNear) then { + _isNear = {inflamed _x} count (position player nearObjects _distance); + if(_isNear == 0) then { + _abort = true; + _reason = "fire"; + }; +}; + +if(_abort) exitWith { + cutText [format["Crafting needs a %1 within %2 meters",_reason,_distance], "PLAIN DOWN"]; + TradeInprogress = false; +}; + +// diag_log format["Checking for fire: %1", _isFireNear]; + +if (_canDo) then { + + // Moved all recipes input and outputs to configs + + _selectedRecipeOutput = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "output"); + _selectedRecipeInput = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "input"); + _selectedRecipeTools = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "requiretools"); + _consumeweapons = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "consumeweapons"); + + _missing = ""; + _missingTools = false; + { + _hastoolweapon = _x in weapons player; + if(!_hastoolweapon) exitWith { _missingTools = true; _missing = _x; }; + } forEach _selectedRecipeTools; + + if(!_missingTools) then { + + diag_log format["Selected Recipe Input: %1", _selectedRecipeInput]; + diag_log format["Selected Recipe Output: %1", _selectedRecipeOutput]; + + // Dry run to see if all parts are available. + _proceed = true; + { + _itemIn = _x select 0; + _countIn = _x select 1; + + diag_log format["Recipe Check: %1 %2", _itemIn,_countIn]; + + // not neccessary + //if (!(_itemIn in magazines player)) exitWith { _missing = _itemIn; _missingQty = _countIn; _proceed = false; }; + + // match against class and parentClass + _qty = { (_x == _itemIn) || (configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn) } count magazines player; + + if(_qty < _countIn) exitWith { _missing = _itemIn; _missingQty = (_countIn - _qty); _proceed = false; }; + + } forEach _selectedRecipeInput; + + // If all parts proceed + if (_proceed) then { + + cutText ["Crafting started", "PLAIN DOWN"]; + + player playActionNow "Medic"; + + [player,"repair",0,false] call dayz_zombieSpeak; + _id = [player,50,true,(getPosATL player)] spawn player_alertZombies; + + r_interrupt = false; + _animState = animationState player; + r_doLoop = true; + _started = false; + _finished = false; + + while {r_doLoop} do { + _animState = animationState player; + _isMedic = ["medic",_animState] call fnc_inString; + if (_isMedic) then { + _started = true; + }; + if (_started and !_isMedic) then { + r_doLoop = false; + _finished = true; + }; + if (r_interrupt) then { + r_doLoop = false; + }; + sleep 0.1; + }; + r_doLoop = false; + + if (_finished) then { + + _removed_total = 0; // count total of removed items + _tobe_removed_total = 0; // count total of all to be removed items + // Take items + { + _removed = 0; + _itemIn = _x select 0; + _countIn = _x select 1; + // diag_log format["Recipe Finish: %1 %2", _itemIn,_countIn]; + _tobe_removed_total = _tobe_removed_total + _countIn; + + { + if( (_removed < _countIn) && ((_x == _itemIn) || configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn)) then { + _num_removed = ([player,_x] call BIS_fnc_invRemove); + _removed = _removed + _num_removed; + _removed_total = _removed_total + _num_removed; + if(_num_removed >= 1) then { + _temp_removed_array set [count _temp_removed_array,_x]; + }; + }; + + } forEach magazines player; + + } forEach _selectedRecipeInput; + + diag_log format["removed: %1 of: %2", _removed, _tobe_removed_total]; + + // Only proceed if all parts were removed successfully + if(_removed_total == _tobe_removed_total) then { + + // Put items + { + // consumeweapons + { + player removeWeapon _x; + } forEach _consumeweapons; + + _itemOut = _x select 0; + _countOut = _x select 1; + diag_log format["Recipe Output: %1 %2", _itemOut,_countOut]; + + for "_x" from 1 to _countOut do { + player addMagazine _itemOut; + }; + + + + // get display name + _textCreate = getText(configFile >> "CfgMagazines" >> _itemOut >> "displayName"); + + // Add crafted item + cutText [format["Crafted Item: %1 x %2",_textCreate,_countOut], "PLAIN DOWN"]; + + } forEach _selectedRecipeOutput; + + } else { + // Refund parts since we failed + {player addMagazine _x;} forEach _temp_removed_array; + + cutText [format["Missing Parts after first check Item: %1 / %2",_removed_total,_tobe_removed_total], "PLAIN DOWN"]; + }; + + } else { + r_interrupt = false; + [objNull, player, rSwitchMove,""] call RE; + player playActionNow "stop"; + cutText ["Canceled crafting.", "PLAIN DOWN"]; + }; + + } else { + _textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName"); + cutText [format["Missing %1 more of %2",_missingQty, _textMissing], "PLAIN DOWN"]; + }; + } else { + _textMissing = getText(configFile >> "CfgWeapons" >> _missing >> "displayName"); + cutText [format["Missing Tool: %1",_textMissing], "PLAIN DOWN"]; + }; +} else { + cutText ["Crafting needs a fire within 2 meters.", "PLAIN DOWN"]; +}; + +TradeInprogress = false; \ No newline at end of file diff --git a/dayz_code/actions/player_craftItem4.sqf b/dayz_code/actions/player_craftItem4.sqf index 02fff2e8b..7a41f4be7 100644 --- a/dayz_code/actions/player_craftItem4.sqf +++ b/dayz_code/actions/player_craftItem4.sqf @@ -1,3 +1,252 @@ -private["_crafting"]; +/* +* Crafting by [VB]AWOL +* usage: spawn player_craftitem; +*/ +private ["_onLadder","_canDo","_selectedRecipeOutput","_proceed","_itemIn","_countIn","_missing","_missingQty","_qty","_itemOut","_countOut","_started","_finished","_animState","_isMedic","_removed","_tobe_removed_total","_textCreate","_id","_textMissing","_selectedRecipeInput","_num_removed","_removed_total","_temp_removed_array","_abort","_reason","_isNear","_missingTools","_hastoolweapon","_selectedRecipeTools","_distance","_crafting","_needNear"]; + +if(TradeInprogress) exitWith { cutText ["Crafting already in progress." , "PLAIN DOWN"]; }; +TradeInprogress = true; + +/* +== Canned Foods +"FoodCanBakedBeans", +"FoodCanSardines", +"FoodCanFrankBeans", +"FoodCanPasta", +"FoodBioMeat" + +== Drinks +"ItemSodaCoke", +"ItemSodaPepsi", + +== Trash +"TrashTinCan", +"TrashJackDaniels", +"ItemSodaEmpty", +"ItemSodaCokeEmpty", +"ItemSodaPepsiEmpty", + +== community stuff Trash +"ItemSodaMdewEmpty", +"ItemSodaMtngreenEmpty", +"ItemSodaR4z0rEmpty", +"ItemSodaClaysEmpty", +"ItemSodaSmashtEmpty",. +"ItemSodaDrwasteEmpty",. +"ItemSodaLemonadeEmpty",. +"ItemSodaLvgEmpty",. +"ItemSodaMzlyEmpty",. +"ItemSodaRabbitEmpty" + +== Raw Meats +"FoodSteakRaw", +"FoodmeatRaw", +"FoodbeefRaw", +"FoodmuttonRaw", +"FoodchickenRaw", +"FoodrabbitRaw", +"FoodbaconRaw" + +== Cooked Meats +"FoodSteakCooked", +"FoodmeatCooked", +"FoodbeefCooked", +"FoodmuttonCooked", +"FoodchickenCooked", +"FoodrabbitCooked", +"FoodbaconCooked" +*/ + +// Removed metals: +// _recipe_ItemBronzeBar = [[["ItemBronzeBar",1] ],[["ItemCopperBar",3],["ItemTinBar",3]]]; + +// New item ideas: +// _recipe_FoodChickenNoodle = [["FoodchickenRaw",1],["FoodCanPasta",1],["ItemWaterbottle",1]]; +// _recipe_FoodBeefBakedBeans = [["FoodbeefRaw",1],["FoodCanBakedBeans",1]]; +// ItemSalt + +// temp array of removed parts +_temp_removed_array = []; +_abort = false; +_distance = 2; +_reason = ""; + +_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1; +_canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); + +_item = _this; _crafting = "Crafting4"; -[_this,_crafting] spawn player_craftitem; \ No newline at end of file + +// check if fire is reqired +_needNear = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "neednearby"); + +if("fire" in _needNear) then { + _isNear = {inflamed _x} count (position player nearObjects _distance); + if(_isNear == 0) then { + _abort = true; + _reason = "fire"; + }; +}; + +if(_abort) exitWith { + cutText [format["Crafting needs a %1 within %2 meters",_reason,_distance], "PLAIN DOWN"]; + TradeInprogress = false; +}; + +// diag_log format["Checking for fire: %1", _isFireNear]; + +if (_canDo) then { + + // Moved all recipes input and outputs to configs + + _selectedRecipeOutput = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "output"); + _selectedRecipeInput = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "input"); + _selectedRecipeTools = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "requiretools"); + _consumeweapons = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> _crafting >> "consumeweapons"); + + _missing = ""; + _missingTools = false; + { + _hastoolweapon = _x in weapons player; + if(!_hastoolweapon) exitWith { _missingTools = true; _missing = _x; }; + } forEach _selectedRecipeTools; + + if(!_missingTools) then { + + diag_log format["Selected Recipe Input: %1", _selectedRecipeInput]; + diag_log format["Selected Recipe Output: %1", _selectedRecipeOutput]; + + // Dry run to see if all parts are available. + _proceed = true; + { + _itemIn = _x select 0; + _countIn = _x select 1; + + diag_log format["Recipe Check: %1 %2", _itemIn,_countIn]; + + // not neccessary + //if (!(_itemIn in magazines player)) exitWith { _missing = _itemIn; _missingQty = _countIn; _proceed = false; }; + + // match against class and parentClass + _qty = { (_x == _itemIn) || (configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn) } count magazines player; + + if(_qty < _countIn) exitWith { _missing = _itemIn; _missingQty = (_countIn - _qty); _proceed = false; }; + + } forEach _selectedRecipeInput; + + // If all parts proceed + if (_proceed) then { + + cutText ["Crafting started", "PLAIN DOWN"]; + + player playActionNow "Medic"; + + [player,"repair",0,false] call dayz_zombieSpeak; + _id = [player,50,true,(getPosATL player)] spawn player_alertZombies; + + r_interrupt = false; + _animState = animationState player; + r_doLoop = true; + _started = false; + _finished = false; + + while {r_doLoop} do { + _animState = animationState player; + _isMedic = ["medic",_animState] call fnc_inString; + if (_isMedic) then { + _started = true; + }; + if (_started and !_isMedic) then { + r_doLoop = false; + _finished = true; + }; + if (r_interrupt) then { + r_doLoop = false; + }; + sleep 0.1; + }; + r_doLoop = false; + + if (_finished) then { + + _removed_total = 0; // count total of removed items + _tobe_removed_total = 0; // count total of all to be removed items + // Take items + { + _removed = 0; + _itemIn = _x select 0; + _countIn = _x select 1; + // diag_log format["Recipe Finish: %1 %2", _itemIn,_countIn]; + _tobe_removed_total = _tobe_removed_total + _countIn; + + { + if( (_removed < _countIn) && ((_x == _itemIn) || configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn)) then { + _num_removed = ([player,_x] call BIS_fnc_invRemove); + _removed = _removed + _num_removed; + _removed_total = _removed_total + _num_removed; + if(_num_removed >= 1) then { + _temp_removed_array set [count _temp_removed_array,_x]; + }; + }; + + } forEach magazines player; + + } forEach _selectedRecipeInput; + + diag_log format["removed: %1 of: %2", _removed, _tobe_removed_total]; + + // Only proceed if all parts were removed successfully + if(_removed_total == _tobe_removed_total) then { + + // Put items + { + // consumeweapons + { + player removeWeapon _x; + } forEach _consumeweapons; + + _itemOut = _x select 0; + _countOut = _x select 1; + diag_log format["Recipe Output: %1 %2", _itemOut,_countOut]; + + for "_x" from 1 to _countOut do { + player addMagazine _itemOut; + }; + + + + // get display name + _textCreate = getText(configFile >> "CfgMagazines" >> _itemOut >> "displayName"); + + // Add crafted item + cutText [format["Crafted Item: %1 x %2",_textCreate,_countOut], "PLAIN DOWN"]; + + } forEach _selectedRecipeOutput; + + } else { + // Refund parts since we failed + {player addMagazine _x;} forEach _temp_removed_array; + + cutText [format["Missing Parts after first check Item: %1 / %2",_removed_total,_tobe_removed_total], "PLAIN DOWN"]; + }; + + } else { + r_interrupt = false; + [objNull, player, rSwitchMove,""] call RE; + player playActionNow "stop"; + cutText ["Canceled crafting.", "PLAIN DOWN"]; + }; + + } else { + _textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName"); + cutText [format["Missing %1 more of %2",_missingQty, _textMissing], "PLAIN DOWN"]; + }; + } else { + _textMissing = getText(configFile >> "CfgWeapons" >> _missing >> "displayName"); + cutText [format["Missing Tool: %1",_textMissing], "PLAIN DOWN"]; + }; +} else { + cutText ["Crafting needs a fire within 2 meters.", "PLAIN DOWN"]; +}; + +TradeInprogress = false; \ No newline at end of file