Adding interrupt to script

Doppelganger

Well-Known Member
Hello,

so the self blood script has a way to interrupt if you need to by moving. I currently have a suicide script on my server and would like to add the interrupt ability to it, but im not sure i can figure it out.

anyone mind giving it a shot?

Interrupt Code
Code:
    ////////////////////////////////////////////////
    // Fancy cancel if interrupted addition start //
    ////////////////////////////////////////////////
    r_interrupt = false; // public interuppt variable
    _animState = animationState player; // get the animation state of the player
    r_doLoop = true; // while true sets whether to continue self bloodbagging
    _started = false; // this starts as false as a check
    _finished = false; // this starts as false and when true later sets players blood
    while {r_doLoop} do {
        _animState = animationState player; // keep checking to make sure player is in correct animation
        _isMedic = ["medic",_animState] call fnc_inString; // checking to make sure the animstate is the medic animation still
        if (_isMedic) then {
            _started = true; // this is a check to make sure everything is still ok
        };
        if(!_isMedic && !r_interrupt && (time - _bloodbagUsageTime) < _bloodbagUseTime) then {
            player playActionNow "Medic"; //play bloodbag animation
            _isMedic = true;
        };
        if (_started && !_isMedic && (time - _bloodbagUsageTime) > _bloodbagUseTime) then {
            r_doLoop = false; // turns off the loop
            _finished = true; // set finished to true to finish the self bloodbag and give player health/humanity
            lastBloodbag = time; // the last self bloodbag time
        };
        if (r_interrupt) then {
            r_doLoop = false; // if interuppted turns loop off early so _finished is never true
        };
        sleep 0.1;
    };
    r_doLoop = false; // make sure loop is off on successful self bloodbag
    ///////////////////////////////////////////////
    // Fancy cancel if interrupted addition end //
    //////////////////////////////////////////////

Suicide Code
Code:
//designed by WTF-Kaysio
//www.WTF-Gaming.co.uk


private ["_Secondary"];
canAbort = true;
_Secondary = currentWeapon player;
player addEventHandler ["fired", {if (alive player) then { player SetDamage 1.1;};}];
cutText [format["You think about your family... 10 Seconds"], "PLAIN DOWN"];
sleep 4;
cutText [format["Your little daughter, and what happened to her... 6 Seconds"], "PLAIN DOWN"];
sleep 4;
cutText [format["You cant take this shit any longer... 2 Seconds"], "PLAIN DOWN"];
sleep 2;
cutText [format["Goodbye cruel world!"], "PLAIN DOWN"];
canAbort = false;
player playmove "ActsPercMstpSnonWpstDnon_suicide1B";
sleep 8.4;
player fire _Secondary;

Code for selfaction
Code:
private ["_handGun"];
_handGun = currentWeapon player;
if ((_handGun in ["glock17_EP1","M9","M9SD","Makarov","MakarovSD","revolver_EP1","UZI_EP1","Sa61_EP1","Colt1911"]) && (player ammo _handGun > 0)) then {
    hasSecondary = true;
} else {
    hasSecondary = false;
};
if((speed player <= 1) && hasSecondary && _canDo) then {
    if (s_player_suicide < 0) then {
        s_player_suicide = player addaction[("<t color=""#ff0000"">" + ("Commit Suicide like a boss") +"</t>"),"custom\suicide.sqf",_handGun,0,false,true,"", ""];
    };
} else {
    player removeAction s_player_suicide;
    s_player_suicide = -1;
};
 
anyone? i feel the community help on the forum is very small, I have yet to ever get a response to any of my threads for issues ive had. even contacting the makers of addons is a hit or miss and mainly miss.
 
Hey I've been looking to do the same but have not been able to get it working. I'm just a rookie in scripts and thought it'd be as simple as changing some commands but hmm nope :(. There really should be an interrupt technique tho!
 
Code:
player playActionNow "Medic"
 
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 {
 
your code goes here...
 
} else { //player moved
 
r_interrupt = false;
[objNull, player, rSwitchMove,""] call RE;
player playActionNow "stop";
cutText ["You moved","PLAIN DOWN"];
};
 
Doppelganger, in case you still need it, i figured out how it could be done:

this should be in suicide.sqf

PHP:
private ["_Secondary","_suicideTime","_startTime","_interrupt","_Timeleft"];
canAbort = true;
_Secondary = currentWeapon player;
_startTime = time;
_suicideTime = 10;
_Timeleft = ((_startTime + _suicideTime) - time);
_interrupt = false;
while {(!_interrupt) && (_Timeleft > 0)} do {
    _Timeleft = ((_startTime + _suicideTime) - time);
    if (speed player > 1) then {
        _interrupt = true;
    };
    if (_Timeleft > 6) then {
        cutText [format["You think about your family... 10 Seconds (move to cancel)"], "PLAIN DOWN"];
        sleep 2;
    };
    if ((_Timeleft  <= 6) && (_Timeleft > 2)) then {
        cutText [format["Save me Jesus!... 6 Seconds (move to cancel)"], "PLAIN DOWN"];
        sleep 1;
    };
    if ((_Timeleft <= 2) && (_Timeleft > 0)) then {
        cutText [format["You can't take this shit any longer... 2 Seconds (move to cancel)"], "PLAIN DOWN"];
        sleep .5;
    };
};
if (_interrupt) then {
    cutText [format["Phew, that was a close call!"], "PLAIN DOWN"];
};
if (!_interrupt && (_Timeleft <= 0)) then {
    cutText [format["I see the light, Goodbye cruel world!"], "PLAIN DOWN"];
    canAbort = false;
    player addEventHandler ["fired", {if (alive player) then { player SetDamage 1.1;};}];
    player playmove "ActsPercMstpSnonWpstDnon_suicide1B";
    sleep 8.4;
    player fire _Secondary;
};
 
My dayz community died out and i let my server expire so i sometimes just come to the forums to try and answer questions i can. but thanks, this should help others im sure!
 
Back
Top