Need Scripting Help (Combat-Check and Loop)

SchwEde

OpenDayZ Rockstar!
hey guys,

im trying to get my blood regenartion script a bit better. So far its working well, there needs to be only a few little things to make, before i can release it.
Here is the Script so far (ignore the systemChat, they are just for texting ^^):
call it from init.sqf:
[] execVM "Scripts\regen_blood.sqf";
Code:
private ["_regeneration","_timeout","_inCombat"];
_timeout = player getVariable["combattimeout", 0];
_inCombat = if (_timeout >= diag_tickTime) then { true } else { false };
_regeneration = 1;

while {true} do
{

if (_inCombat) then {
    r_player_blood = r_player_blood;
    systemChat ('Combat');   
    } else {   
        if(r_player_unconscious  or r_player_injured  or r_player_infected  or r_fracture_legs  or r_fracture_arms  or r_player_inpain or r_player_loaded or dayz_hunger < 0.5 or dayz_thirst < 0.5) then {
        r_player_blood = r_player_blood;
        systemChat ('computer sagt nein');
        } else {
            if (!(vehicle player == player)) then {
                r_player_blood = r_player_blood + (_regeneration * 5);
                systemChat ('auto');
                } else {
                    switch (true) do {
                    systemChat ('funzt');
                    case (speed player >= 14):    {r_player_blood = r_player_blood + _regeneration;}; //when running _regeneration = 2
                    case (speed player >= 5) :    {r_player_blood = r_player_blood + (_regeneration * 2);}; //when walking _regeneration = 4
                    case (speed player >= 3) :    {r_player_blood = r_player_blood + (_regeneration * 3);}; //when sneaking _regeneration = 6
                    case (speed player >= 1) :    {r_player_blood = r_player_blood + (_regeneration * 4);}; //when crawling _regeneration = 8
                    case (speed player == 0) :    {r_player_blood = r_player_blood + (_regeneration * 10);}; //when seating or staying _regeneration = 20
                    };
                };
            };
        };
sleep 2;
};

So what is missing is to break the loop and to check if the player is in Combat.
Nothing I've tried could get me check if the player is in combat and "dayz_combat == 1" even breaks the code.

Next thing is i cannot get to stop the Script if it reached 12000. Only work around so far that is working is:
Code:
if (r_player_blood > r_player_bloodTotal) then {
    r_player_blood = r_player_bloodTotal;
};
this just set the amount of blood back on 12k when its over 12k.

I also tried it with:
Code:
while {r_player_blood < r_player_bloodTotal} do
{
But this way its not even starts the script.

Hope someone can help me with this one =)

Cheers
 
I am run out with this already, it seems we almost have finished the script, but there is always something wrong, lack of experience is evident. Seems it won't be finished without help of some advansced coder
 
Code:
_inCombat = if (_timeout >= diag_tickTime) then { true } else { false };
if (_inCombat) exitWith {...};

Code:
if (r_player_blood > 12000) then {
            r_player_blood = 12000;
        };
 
thanks for the help cyrq, but sadly still no luck with combat check. Its working almost like i want to if i add this to it:
Code:
if (r_player_blood > 11999) then {
            r_player_blood = 12000;
        };
but i want to break the loop if the player is fully healed.
Something like this:

Code:
private ["_regeneration","_timeout","_inCombat","_check"];
_timeout = player getVariable["combattimeout", 0];
_inCombat = if (_timeout >= diag_tickTime) then { true } else { false };
_regeneration = 1;
_check = true;

if (r_player_blood > 11999) exitWith {
                _check = false;
                };
while {true} do
{
.
.
.

Or is it doesnt matter if the loop is running the whole time? (FPS loss)

EDIT: Could get a step further :) Report the results soon
 
Last edited:
I don't actually understand what you're trying to accomplish.
You want blood regen over time but only if the player is not in combat?
There's no need to start another execVM or another while {true} loop for that matter.
You have all kinds of loops already running in the dayz_code. Use an existing one.
The most suitable one would be player_spawn_2.sqf
 
Thanks i will take take a look at it.
Fir now I just want to start the regeneration when the blood is under 12k and when it's 12k or above it should stop the loop till the amount of blood is again under 12k.
The Combat isn't that important for me I think I will leave it out on the release
 
I think that the better way is check in another way.
You are trying to check like if any of exceptions is true then blood = blood
it can be changed like this: if blood is less than 11999 and player is nor injured nor bleeding and so then do regeneration, else exit with or just blood = blood.
In this case we have no need to make a check wether the blood is full and exit the script, instead of it we check if blood is not full.
So here is what the structure shood be:
first we check if there is a need to regenerate and non of the exceprions like bleeding or in combat a true. If we pass this check then we make else for regeneratiin for each case, wether the player is running, in vehicle, staying and so on. If we do not pass the check then we exit the script at bottom.
I am using phone now so only can show the structure:
check if need to regenerate with exceptions
than if sleeping regeneration = 1000 points
if in vehicle = 10 points
case running (speed) = 2 points
case walking (speed) = 5 points
other cases
else
exit with blood = blood
sleep 2 sec

so anyway in this case we will have loop every 2 sec to check wether it is needed to regenerate.
Because i think if to cancel the loop at all, it will check the need of regeneration only once and then stop working
 
Last edited:
only thing doesnt work is the combat-check but i think it doesnt matter. I think i will release the new version now =)
 
here it is:
Code:
//////////////////////////////////////////////////////////////////////////
// Script written by Schwede                                             //
//    Thanks to ka3ant1p and cyrq for Support and Idea                  //
//                                                                      //
//    Version 1.1                                                       //
//////////////////////////////////////////////////////////////////////////

private ["_regeneration","_timeout","_inCombat"];
waituntil {!alive player ; !isnull (finddisplay 46)};
_regeneration = 1; //change to whatever you like


while {alive player} do
{
        if(r_player_blood > 11999 or r_player_unconscious  or r_player_injured  or r_player_infected  or r_fracture_legs  or r_fracture_arms  or r_player_inpain or r_player_loaded or dayz_hunger < 0.5 or dayz_thirst < 0.5) then {
        r_player_blood = r_player_blood;        
            
        } else {

            if (!(vehicle player == player)) then {
                r_player_blood = r_player_blood + (_regeneration * 10); //when in vehicle _regeneration = 10
                } else {
                    switch (true) do {
                    case (speed player >= 14):    {r_player_blood = r_player_blood + _regeneration;}; //when running _regeneration = 1
                    case (speed player >= 5) :    {r_player_blood = r_player_blood + (_regeneration * 2);}; //when walking _regeneration = 2
                    case (speed player >= 3) :    {r_player_blood = r_player_blood + (_regeneration * 3);}; //when sneaking _regeneration = 3
                    case (speed player >= 1) :    {r_player_blood = r_player_blood + (_regeneration * 4);}; //when crawling _regeneration = 4
                    case (speed player == 0) :    {r_player_blood = r_player_blood + (_regeneration * 5);}; //when seating or staying _regeneration = 5
                    };
                };
            };
sleep 2;
};
 
you should also add NoNameUnit to credits, he gave me lots of ideas.
Also I see you haven't changed speed, have you checked if it corresponds to each movement, I mean are you shure that walking is abot speed 5, crawling is about speed 1?
Cause I used this numbers randomly.
Also have you tried the structure I send in my previous message?
 
waituntil {!alive player ; !isnull (finddisplay 46)}; - what is this for?

Also this line:

Code:
            if (!(vehicle player == player)) then {
                r_player_blood = r_player_blood + (_regeneration * 10);
As I understood means that if vehicle player is not player then r_player_blood = r_player_blood + (_regeneration * 10)
So it means that while not in vehicle regeneration will be _regeneration * 10, I mean that this expression fits all cases except when in vehicle.
 
There's a lot of nonsense in this code.
I would do it like this:

Code:
while {alive player} do {
    if    ((r_player_blood < 12000) AND !(r_player_unconscious)
    AND !(r_player_injured) AND !(r_player_infected)
    AND !(r_fracture_legs) AND !(r_fracture_arms)
    AND !(r_player_inpain) AND !(r_player_loaded)
    AND ((dayz_statusArray select 0) > 0.5) AND ((dayz_statusArray select 1) > 0.5)) then {
        if (vehicle player != player) then {
            r_player_blood = r_player_blood + (1 * 10); //when in vehicle _regeneration = 10
        };
        if (vehicle player == player) then {
            switch (true) do {
                case (speed player >= 14): {
                    r_player_blood = r_player_blood + 1;  //when running _regeneration = 1
                };
                case (speed player >= 5) : {
                    r_player_blood = r_player_blood + (1 * 2);  //when walking _regeneration = 2
                };
                case (speed player >= 3) : {
                    r_player_blood = r_player_blood + (1 * 3);  //when sneaking _regeneration = 3
                };
                case (speed player >= 1) : {
                    r_player_blood = r_player_blood + (1 * 4); //when crawling _regeneration = 4
                };
                case (speed player == 0) : {
                    r_player_blood = r_player_blood + (1 * 5); //when seating or staying _regeneration = 5
                };
            };
        };
    };
sleep 2;
};
 
this part is the vehicle check.

waituntil {!alive player ; !isnull (finddisplay 46)};
This is necessary, because if the player is spawning he spawns with 12k in the debug-field and if its not in the code the whole thing doesnt work.
 
I'm still learning scripting ^^ so sry if its looking that bad.
just tested your version and works great.
Mind if i release it how your wrote it?
 
Back
Top