From aaab8292e20955565213c310a7cd121929d5280f Mon Sep 17 00:00:00 2001 From: worldwidesorrow Date: Wed, 11 Dec 2019 19:44:42 -0600 Subject: [PATCH] Update medTransfuse.sqf Infection chance does not have to be recalculated repeatedly. There is no reason that the start message should be inside the loop. Display control 1300 does not need to be enabled here. It always runs. Remove redundant player check. --- .../medical/publicEH/medTransfuse.sqf | 84 ++++++++----------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/SQF/dayz_code/medical/publicEH/medTransfuse.sqf b/SQF/dayz_code/medical/publicEH/medTransfuse.sqf index 6198861de..d282575ff 100644 --- a/SQF/dayz_code/medical/publicEH/medTransfuse.sqf +++ b/SQF/dayz_code/medical/publicEH/medTransfuse.sqf @@ -1,18 +1,23 @@ // animHealed.sqf -private["_array","_unit","_medic","_amount","_display","_control","_lowBlood","_started"]; -disableserialization; +private["_msg","_unit","_medic","_amount","_transfusionInfection","_timer"]; //[_unit,player,_bloodAmount] -_array = _this; //_this select 0; -_unit = _array select 0; //Player receving the blood -_medic = _array select 1; //Player sending the blood -_amount = _array select 2; //total amount of blood given + +_unit = _this select 0; //Player receving the blood +_medic = _this select 1; //Player sending the blood +_amount = _this select 2; //total amount of blood given + +if (_unit != player) exitWith {/* not the correct client */}; +if (_amount < 0) exitWith {/* someone is trying to kill the player */}; _timer = diag_tickTime; -_started = false; +_msg = ""; r_doLoop = true; r_interrupt = false; -if (_amount < 0) exitWith { /* someone is trying to kill the player */ }; +//Infection chance +_TransfusionInfection = ((random 20) < 0.3); + +localize "str_actions_medical_transfusion_start" call dayz_rollingMessages; //Start the loop to mimic the transfusion to cut back on issues flooding the server while {r_doLoop} do { @@ -20,62 +25,45 @@ while {r_doLoop} do { if ((diag_tickTime - _timer) >= 1) then { _timer = diag_tickTime; - //Infection chance - _rndInfection = (random 20); - _TransfusionInfection = (_rndInfection < 0.3); - //Mimic the transfer of the blood (cut out the server) if (_amount > 0) then { _amount = _amount - 500; }; - if (!_started) then { - localize "str_actions_medical_transfusion_start" call dayz_rollingMessages; - _started = true; + // update stats based on whats being sent (should mimic 500 units of blood being sent) + if ((r_player_blood + 500) >= r_player_bloodTotal) then { + r_player_blood = r_player_bloodTotal; + player setVariable["USEC_BloodQty",r_player_bloodTotal,true]; + } else { + r_player_blood = r_player_blood + 500; + player setVariable["USEC_BloodQty",r_player_blood,true]; }; - - //Make sure the unit is a player and update stats based on whats being sent (should mimic 500 units of blood being sent) - if (_unit == player) then { - if ((r_player_blood + 500) >= r_player_bloodTotal) then { - r_player_blood = r_player_bloodTotal; - player setVariable["USEC_BloodQty",r_player_bloodTotal,true]; - } else { - r_player_blood = r_player_blood + 500; - player setVariable["USEC_BloodQty",r_player_blood,true]; - }; - if (((r_player_blood / r_player_bloodTotal) >= 0.35) and (r_player_lowblood)) then { - r_player_lowblood = false; - player setVariable["USEC_lowBlood",false,true]; - }; - - if (_TransfusionInfection) then { - r_player_infected = true; - player setVariable["USEC_infected",true,true]; - }; - - //Ensure Control is visible - _display = uiNamespace getVariable 'DAYZ_GUI_display'; - _control = _display displayCtrl 1300; - _control ctrlShow true; + if (((r_player_blood / r_player_bloodTotal) >= 0.35) and (r_player_lowblood)) then { + r_player_lowblood = false; + player setVariable["USEC_lowBlood",false,true]; }; }; - //If the players blood is equals too or above r_player_bloodTotal stop or if the blood mimic amount reaches 0 end the loop. - _blood = _unit getVariable ["USEC_BloodQty", 0]; - //diag_log format["Player Blood %1 - %2, - %3, - %4",_blood,_unit,_medic,(_unit getVariable "USEC_BloodQty")]; - if (_blood >= r_player_bloodTotal or _amount == 0) then { - localize "str_actions_medical_transfusion_successful" call dayz_rollingMessages; + //If the players blood is equals too or above r_player_bloodTotal stop or if the blood mimic amount reaches 0 end the loop. + if ((_unit getVariable ["USEC_BloodQty", 0]) >= r_player_bloodTotal or _amount == 0) then { + _msg = "str_actions_medical_transfusion_successful"; r_doLoop = false; }; if (r_interrupt) then { - localize "str_actions_medical_transfusion_interrupted" call dayz_rollingMessages; + _msg = "str_actions_medical_transfusion_interrupted"; r_doLoop = false; }; - //Rerun the loop - sleep 1; -}; \ No newline at end of file + uiSleep 1; +}; + +if (_TransfusionInfection) then { + r_player_infected = true; + player setVariable["USEC_infected",true,true]; +}; + +localize _msg call dayz_rollingMessages;