Jump to content
mattjb

Resolved: [ACE] Unconscious / Medic Cry Script

Recommended Posts

Wondering if anyone has any ideas to solve the issue with the script I have here...

Issue: If a player goes unconscious, wakes up, and goes down again during the sleep timer, two or more spawns are created (depending on how many times this happens during the sleep). It does clear up if the player stays alive until the sleep timer finishes due to the condition. I'm planning on increasing the sleep period to 60 seconds or so, so this could result in more spawns happening in the sleep duration for the unfortunate player. Another minor annoyance is that because of this, the two or more spawns may include voices from different voice pools due to me randomizing it, sounding a bit awkward. :)

Theory: Terminate the _handle on player wake-up; however, I'm not sure how to terminate the _handle for the player due to locality. Is it possible to store a handle via setVariable and retrieve it via getVariable to be terminated? I've also thought about generating a boolean variable stored in the player object and using that to determine if it should spawn another thread (i.e.   if (_unit getVariable "runningLoop" isEqualTo true) exitWith {};  ) but I'm having issues with that as well.

 

Quote

// initServer.sqf - executed on server only

["ace_unconscious", { // global event (runs on all machines)
    params ["_unit", "_isUnconscious"];

    _allHCs = entities "HeadlessClient_F";
    _allHPs = allPlayers - _allHCs;
    _aliveCount = 0;
    _allCount = count _allHPs;

    { 
        if (_x getVariable "ACE_isUnconscious" isEqualTo false) then { _aliveCount = _aliveCount + 1; }; 
    } foreach _allHPs;

    if ((_isUnconscious) && (_unit in _allHPs)) then { 
        (format ["%1 is down!  %2/%3 alive.", name _unit, _aliveCount, _allCount]) remoteExec ["systemChat", 0]; 
        _VoiceArr = ["Person0","Person1","Person2","Person3"];
        _randomVoice = selectRandom _VoiceArr;

        _handle = [_unit, _isUnconscious, _randomVoice] spawn {
            _unit = (_this select 0);
            _isUnconscious = (_this select 1);
            _randomVoice = (_this select 2);

            while { _unit getVariable "ACE_isUnconscious" isEqualTo true } do {
                // Create Marker at dead player position
                _downMarker = createMarker [name _unit, position _unit];
                _downMarker setMarkerShape "ICON";
                _downMarker setMarkerType "hd_dot";
                _downMarker setMarkerColor "ColorRed";
                _downMarker setMarkerText (name _unit);

                // Select associated player voice
                _P = switch _randomVoice do {
                    case "Person0" : { "P0" };
                    case "Person1" : { "P1" };
                    case "Person2" : { "P2" };
                    case "Person3" : { "P3" };
                };

                // Select random sound for the associated player voice
                _N = switch _P do {
                    case "P0" : { selectRandom [13,14,15,16,17,18,19,20] };
                    case "P1" : { selectRandom [19,20,21,22,23,24,25,26,27,28,29,30,31,32,33] };
                    case "P2" : { selectRandom [14,15,16,17,18,19,20,21] };
                    case "P3" : { selectRandom [10,11,12,13,14,15,16,17,18,19,20] };
                };

                // Play Sound at dead player position
                playSound3D ["A3\Sounds_F\Characters\human-sfx\" + _randomVoice + "\" + _P + "_moan_" + str(_N) + "_words.wss", _unit, false, getPosASL _unit, 5, 1, 30];

                // Sleep before next run
                sleep 15;

                // Delete marker in preparation for recreation
                deleteMarker (name _unit);
            };
        };
    };
    if ( (! _isUnconscious) && (_unit in _allHPs)) then { 
        (format ["%1 has woken up.  %2/%3 alive.", name _unit, _aliveCount, _allCount]) remoteExec ["systemChat", 0];
        deleteMarker (name _unit);
    };
    
}] call CBA_fnc_addEventHandler;

 

Share this post


Link to post
Share on other sites

I managed to hack up a solution leveraging "time" and setting it into a player variable  ("timeDown") to be compared.... so far it seems working. I'm still interested though if there's a way to terminate handles from other scripts.

 

Quote

// initServer.sqf - executed on server only

["ace_unconscious", { // global event (runs on all machines)
    params ["_unit", "_isUnconscious"];

    _allHCs = entities "HeadlessClient_F";
    _allHPs = allPlayers - _allHCs;
    _aliveCount = 0;
    _allCount = count _allHPs;

    { 
        if (_x getVariable "ACE_isUnconscious" isEqualTo false) then { _aliveCount = _aliveCount + 1; }; 
    } foreach _allHPs;

    if ((_isUnconscious) && (_unit in _allHPs)) then { 
        (format ["%1 is down!  %2/%3 alive.", name _unit, _aliveCount, _allCount]) remoteExec ["systemChat", 0]; 
        _VoiceArr = ["Person0","Person1","Person2","Person3"];
        _randomVoice = selectRandom _VoiceArr;

        _timeDown = time;
        _unit setVariable ["timeDown",_timeDown];

        _handle = [_unit, _isUnconscious, _randomVoice, _timeDown] spawn {
            _unit = (_this select 0);
            _isUnconscious = (_this select 1);
            _randomVoice = (_this select 2);
            _timeDown = (_this select 3);

            while { (_unit getVariable "ACE_isUnconscious" isEqualTo true) && (_unit getVariable "timeDown" isEqualTo _timeDown) } do {
                // Create Marker at dead player position
                _downMarker = createMarker [name _unit, position _unit];
                _downMarker setMarkerShape "ICON";
                _downMarker setMarkerType "hd_dot";
                _downMarker setMarkerColor "ColorRed";
                _downMarker setMarkerText (name _unit);

                // Select associated player voice
                _P = switch _randomVoice do {
                    case "Person0" : { "P0" };
                    case "Person1" : { "P1" };
                    case "Person2" : { "P2" };
                    case "Person3" : { "P3" };
                };

                // Select random sound for the associated player voice
                _N = switch _P do {
                    case "P0" : { selectRandom [13,14,15,16,17,18,19,20] };
                    case "P1" : { selectRandom [19,20,21,22,23,24,25,26,27,28,29,30,31,32,33] };
                    case "P2" : { selectRandom [14,15,16,17,18,19,20,21] };
                    case "P3" : { selectRandom [10,11,12,13,14,15,16,17,18,19,20] };
                };

                // Play Sound at dead player position
                playSound3D ["A3\Sounds_F\Characters\human-sfx\" + _randomVoice + "\" + _P + "_moan_" + str(_N) + "_words.wss", _unit, false, getPosASL _unit, 5, 1, 30];

                // Sleep before next run
                sleep 15;

                // Delete marker in preparation for recreation
                deleteMarker (name _unit);
            };
        };
    };
    if ( (! _isUnconscious) && (_unit in _allHPs)) then { 
        (format ["%1 has woken up.  %2/%3 alive.", name _unit, _aliveCount, _allCount]) remoteExec ["systemChat", 0];
        deleteMarker (name _unit);
        _unit setVariable ["timeDown", nil];
    };
    
}] call CBA_fnc_addEventHandler;
 

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×