diff --git a/SQF/dayz_code/actions/player_breakin.sqf b/SQF/dayz_code/actions/player_breakin.sqf index 1ecf58660..5630fd399 100644 --- a/SQF/dayz_code/actions/player_breakin.sqf +++ b/SQF/dayz_code/actions/player_breakin.sqf @@ -1,5 +1,5 @@ private ["_brokein","_isOk","_hasSledgeHammer","_gps","_vars","_hasToolbox","_hasCrowbar","_limit","_proceed","_counter", -"_dis","_sfx","_roll","_finished","_isGate","_values"]; +"_dis","_end","_msg","_sfx","_roll","_finished","_isGate","_values","_crowBarChance","_sledgeChance","_breakinChance"]; _target = _this select 3; _pos = getPos _target; @@ -7,16 +7,21 @@ _isWoodenGate = (typeOf cursorTarget) in ["WoodenGate_2","WoodenGate_3","WoodenG _isMetalGate = (typeOf cursorTarget) in ["MetalGate_2","MetalGate_3","MetalGate_4"]; _limit = 2 + round(random 3); +if (_target getVariable ["actionInProgress",false]) exitWith { "Action is already underway" call dayz_rollingMessages;}; +_target setVariable ["actionInProgress",true,true]; + _hasSledgeHammer = "ItemSledge" in items player; _hasCrowbar = "ItemCrowbar" in items player; if (!_hasSledgeHammer) exitWith { localize "STR_BLD_BREAKIN_NEED_SLEDGE" call dayz_rollingMessages; + _target setVariable ["actionInProgress",false,true]; uiSleep 1; }; if (!_hasCrowbar) exitWith { localize "STR_BLD_BREAKIN_NEED_CROWBAR" call dayz_rollingMessages; + _target setVariable ["actionInProgress",false,true]; uiSleep 1; }; @@ -24,17 +29,26 @@ _isOk = true; _proceed = false; _counter = 0; _brokein = false; +_msg = ""; +_end = false; //[ChanceToBreakin,SledgeChance,CowbarChance] _values = switch (1==1) do { - case (_isWoodenGate): { [0.04,0.30,0.20] }; - case (_isMetalGate): { [0.02,0.60,0.40] }; + case (_isWoodenGate): { [0.07,0.30,0.20] }; + case (_isMetalGate): { [0.03,0.15,0.10] }; default { [] }; }; -if ( (count _values) == 0 ) exitwith {}; +if ( (count _values) == 0 ) exitwith { _target setVariable ["actionInProgress",false,true]; }; + +//Move breakin chance outside the loop we only test for breakin at the very end of _limit +_breakinChance = [(_values select 0)] call fn_chance; while {_isOk} do { +//check chance, for a maximum amount of 5 loops allowing 5 possiable chances to breakin we also now divide the max chance by the amount of trys. + _sledgeChance = [((_values select 1) / _limit)] call fn_chance; + _crowBarChance = [((_values select 2) / _limit)] call fn_chance; + //Check if we have the tools to start _hasSledgeHammer = "ItemSledge" in items player; _hasCrowbar = "ItemCrowbar" in items player; @@ -60,45 +74,32 @@ while {_isOk} do { //Run animation loop _finished = ["Medic",1] call fn_loopAction; -//Interrupt and end - if(!_finished) exitWith { - _isOk = false; - _proceed = false; - }; - //Everything happened as it should if(_finished) then { //Add to Counter _counter = _counter + 1; - - //start chance to gain access. - if ([(_values select 0)] call fn_chance) then { - _isOk = false; + } else { + _isOk = false; + _proceed = false; + _sledgeChance = false; + _crowBarChance = false; + }; + + //some debug + diag_log format["breakinChance: %1(%7%9), sledgeChance: %2(%5%9), crowBarChance: %3(%6%9), Attempt: %8 of %4",_breakinChance,_sledgeChance,_crowBarChance,_limit,(((_values select 1) / _limit) * 100),(((_values select 2) / _limit) * 100),(((_values select 0) / _limit) * 100),_counter,"%"]; + + +//Chances to damage tools + if (dayz_toolBreaking && (_sledgeChance or _crowBarChance)) exitWith { _proceed = false; }; + +//End when _counter hits _limit decide if the breakin has been successful + if(_counter == _limit) exitWith { + //start chance to gain access. + if (_breakinChance) then { _proceed = true; _brokein = true; - _target setVariable ["isOpen", "1", true]; }; - }; - - if (dayz_toolBreaking) then { - //Chances to damage tools - if ([(_values select 1)] call fn_chance) then { - player removeWeapon "ItemSledge"; - player addMagazine "ItemSledgeHandle"; - player addMagazine "ItemSledgeHead"; - - localize "STR_BLD_BREAKIN_BROKEN_SLEDGE" call dayz_rollingMessages; - }; - - if ([(_values select 2)] call fn_chance) then { - player removeWeapon "ItemCrowbar"; - player addWeapon "ItemCrowbarBent"; - - localize "STR_BLD_BREAKIN_BENT_CROWBAR" call dayz_rollingMessages; - }; - }; - - if(_counter == _limit) exitWith { + //stop loop _isOk = false; //Set Done var @@ -108,27 +109,66 @@ while {_isOk} do { format [localize "STR_BLD_BREAKIN", _counter,_limit] call dayz_rollingMessages; uiSleep 0.03; }; +//End Loop + //Tool issues -if (isnil "_proceed") exitwith {}; +if (isnil "_proceed") then { + _proceed = false; + _sledgeChance = false; + _crowBarChance = false; +}; + +if (_proceed) then { + //Completed but no success. + if (!_brokein) then { + PVDZ_Server_LogIt = format["BROKEINFAILED: Player %1 Broke into Failed %2 at %3 chances:%4,%5",player, (typeof _target), (mapGridPosition _pos) , _sledgeChance, _crowBarChance]; + + _msg = "STR_BLD_BREAKIN_COMPLETE_FAIL"; + } else { + //Completed and successful + //Unlock gate + _target setVariable ["isOpen", "1", true]; + //Open Gate. + _target animate ["DoorR", 1]; + _target animate ["DoorL", 1]; + + + PVDZ_Server_LogIt = format["BROKEINSUCCESSFUL: Player %1 Broke into %2 at %3",player, (typeof _target), (mapGridPosition _pos)]; + + _msg = "STR_BLD_BREAKIN_COMPLETE"; + }; + //Send info to server for admins + publicVariableServer "PVDZ_Server_LogIt"; +}; //Interrupted for some reason if (!_proceed) then { - localize "STR_BLD_BREAKIN_CANCELLED" call dayz_rollingMessages; + + if (_sledgeChance && dayz_toolBreaking) then { + player removeWeapon "ItemSledge"; + player addMagazine "ItemSledgeHandle"; + player addMagazine "ItemSledgeHead"; + + _msg = "STR_BLD_BREAKIN_BROKEN_SLEDGE"; + }; + + if (_crowBarChance && dayz_toolBreaking) then { + player removeWeapon "ItemCrowbar"; + player addWeapon "ItemCrowbarBent"; + + _msg = "STR_BLD_BREAKIN_BENT_CROWBAR"; + }; + + if (!_crowBarChance and !_sledgeChance) then { + _msg = "STR_BLD_BREAKIN_CANCELLED"; + }; }; -// Working-Factor for chopping wood. +//Reset action switch +_target setVariable ["actionInProgress",false,true]; + +// Working-Factor. ["Working",0,[100,15,10,0]] call dayz_NutritionSystem; -//Completed but no success. -if (_proceed and !_brokein) then { - localize "STR_BLD_BREAKIN_COMPLETE_FAIL" call dayz_rollingMessages; -}; - -//Completed and successful -if (_proceed and _brokein) then { - localize "STR_BLD_BREAKIN_COMPLETE" call dayz_rollingMessages; - - //Open Gate. - _target animate ["DoorR", 1]; - _target animate ["DoorL", 1]; -}; \ No newline at end of file +//Send info to player +localize _msg call dayz_rollingMessages; \ No newline at end of file diff --git a/SQF/dayz_code/actions/player_chopWood.sqf b/SQF/dayz_code/actions/player_chopWood.sqf index 8a454f6e8..762de7569 100644 --- a/SQF/dayz_code/actions/player_chopWood.sqf +++ b/SQF/dayz_code/actions/player_chopWood.sqf @@ -1,5 +1,5 @@ -private ["_dis","_sfx","_breaking","_countOut","_counter","_isOk","_proceed","_finished","_itemOut","_tree","_distance2d"]; +private ["_dis","_sfx","_breaking","_countOut","_counter","_isOk","_proceed","_finished","_itemOut","_tree","_distance2d","_chanceResult"]; call gear_ui_init; closeDialog 1; @@ -24,6 +24,9 @@ if (!isNull _tree) then { _counter = 0; _isOk = true; _proceed = false; + + //check chance before loop, for a maximum amount of 5 loops allowing 5 possiable chances + _chanceResult = dayz_HarvestingChance call fn_chance; while {_isOk} do { //setup alert and speak @@ -43,7 +46,7 @@ if (!isNull _tree) then { if (_finished) then { ["Working",0,[50,10,5,0]] call dayz_NutritionSystem; _breaking = false; - if (dayz_toolBreaking && {[0.09] call fn_chance}) then { + if (dayz_toolBreaking && _chanceResult) then { _breaking = true; if ("MeleeHatchet" in weapons player) then { player removeWeapon "MeleeHatchet"; diff --git a/SQF/dayz_code/actions/player_mineStone.sqf b/SQF/dayz_code/actions/player_mineStone.sqf index a7d8480ef..b1e5f6278 100644 --- a/SQF/dayz_code/actions/player_mineStone.sqf +++ b/SQF/dayz_code/actions/player_mineStone.sqf @@ -1,4 +1,4 @@ -private ["_item","_dis","_sfx","_breaking","_counter","_rocks","_findNearestRock","_objName","_countOut","_isOk","_proceed","_finished","_itemOut"]; +private ["_mineChance","_item","_dis","_sfx","_breaking","_counter","_rocks","_findNearestRock","_objName","_countOut","_isOk","_proceed","_finished","_itemOut"]; _item = _this; call gear_ui_init; @@ -25,6 +25,9 @@ if (!isNull _findNearestRock) then { _counter = 0; _isOk = true; _proceed = false; + + //check chance before loop, for a maximum amount of 5 loops allowing 5 possiable chances + _mineChance = dayz_HarvestingChance call fn_chance; while {_isOk} do { //setup alert and speak @@ -44,7 +47,7 @@ if (!isNull _findNearestRock) then { ["Working",0,[100,15,10,0]] call dayz_NutritionSystem; _breaking = false; - if (dayz_toolBreaking && {[0.09] call fn_chance}) then { + if (dayz_toolBreaking && _mineChance) then { _breaking = true; if ("MeleePickaxe" in weapons player) then { player removeWeapon "MeleePickaxe"; diff --git a/SQF/dayz_code/compile/fn_selectRandomChance.sqf b/SQF/dayz_code/compile/fn_selectRandomChance.sqf index d68748d72..5231bd18f 100644 --- a/SQF/dayz_code/compile/fn_selectRandomChance.sqf +++ b/SQF/dayz_code/compile/fn_selectRandomChance.sqf @@ -10,6 +10,6 @@ _return = [0.25] call fn_chance; // will return TRUE 25% of the time *************************************************************/ private ["_result"]; -if ((_this select 0) > (random 1)) then {_result = true;} else {_result = false;}; +_result = if (((_this select 0) * 100) > floor(random 100)) then { true } else { false }; _result diff --git a/SQF/dayz_code/compile/fn_selfActions.sqf b/SQF/dayz_code/compile/fn_selfActions.sqf index 6149ad188..7edb123dd 100644 --- a/SQF/dayz_code/compile/fn_selfActions.sqf +++ b/SQF/dayz_code/compile/fn_selfActions.sqf @@ -523,6 +523,8 @@ if (!isNull _cursorTarget && !_inVehicle && !_isPZombie && (player distance _cur //Only the owners can lock the gates _isLockableGate = _typeOfCursorTarget in ["WoodenGate_2","WoodenGate_3","WoodenGate_4","MetalGate_2","MetalGate_3","MetalGate_4"]; _isUnlocked = _cursorTarget getVariable ["isOpen","0"] == "1"; + + _isActionInProgress = _cursorTarget getVariable ["actionInProgress",false]; //Allow the gates to be opened when not locked by anyone _isOpen = ((_cursorTarget animationPhase "DoorL") == 1) || ((_cursorTarget animationPhase "DoorR") == 1); @@ -597,7 +599,7 @@ if (!isNull _cursorTarget && !_inVehicle && !_isPZombie && (player distance _cur s_player_lockhouse = -1; }; //Break In - if ((_isHouse or _isLockableGate) && (_ownerPID != _uid) && !_isUnlocked) then { + if ((_isHouse or _isLockableGate) && (_ownerPID != _uid) && !_isUnlocked && !_isActionInProgress) then { if (s_player_breakinhouse < 0) then { s_player_breakinhouse = player addAction [localize "STR_BLD_ACTIONS_BREAKIN", "\z\addons\dayz_code\actions\player_breakin.sqf",_cursorTarget, 1, true, true]; }; diff --git a/SQF/dayz_code/init/publicEH.sqf b/SQF/dayz_code/init/publicEH.sqf index 1368b83c2..df644cfce 100644 --- a/SQF/dayz_code/init/publicEH.sqf +++ b/SQF/dayz_code/init/publicEH.sqf @@ -198,9 +198,7 @@ if (isServer) then { }; /*"PVDZ_Server_LogIt" addPublicVariableEventHandler { - _unitSending = _this select 0; _info = _this select 1; - diag_log format["WARNING: %1",_info]; };*/ @@ -318,7 +316,7 @@ if (!isDedicated) then { if (toLower DZE_DeathMsgChat != "none" or DZE_DeathMsgRolling or DZE_DeathMsgDynamicText) then { "PVDZE_deathMessage" addPublicVariableEventHandler {(_this select 1) call dze_deathMessage}; }; - + if (dayz_enableFlies) then { // flies and swarm sound sync call compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\client_flies.sqf"; diff --git a/SQF/dayz_code/init/variables.sqf b/SQF/dayz_code/init/variables.sqf index 2c96e3f05..c1ee3b203 100644 --- a/SQF/dayz_code/init/variables.sqf +++ b/SQF/dayz_code/init/variables.sqf @@ -590,6 +590,7 @@ if (!isDedicated) then { //player special variables dayz_bloodBagHumanity = 300; + dayz_HarvestingChance = [0.09]; dayz_lastCheckBit = 0; dayz_lastDamageSourceNull = false; dayz_lastDamageSource = "none";