clock_x 2 Posted July 19, 2018 Hey, so I made this script were AI, which are alerted and close to the player, play sounds to simulate AI talk. it works pretty well but I have one problem. Often the script gets executed multiple times for a unit/group, which leads to too much and unimmersive (multiple speakers with only one AI) AI talk. The script gets fired by different other scripts, like if a flare or a shot is fired or a body is found. Here's the script: Spoiler //_shoutx = [leader (group _unit), player] execVM "scripts\ShoutSound.sqf"; _unit = _this select 0; _target = _this select 1; _unit_group = group _unit; while { ({alive _x} count units (_unit_group) > 0) && ((leader (_unit_group) distance _target < 120) OR (leader (_unit_group) distance player < 120)) } do //repeat cycles as long unitis not killed { sleep 1; _alivecount = ({alive _x} count units _unit_group); if (_alivecount == 1) then { if (50 > random 100) then { if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - group: %1 alive: %2 target: %3", _unit_group, _alivecount, _target]; }; _shouts = [ ["s1",10+(random 20)], ["s2",10+(random 20)], ["s3",10+(random 20)], ["s4",10+(random 20)], ["s5",10+(random 20)] ]; while {((count _shouts) > 0) && (_alivecount == 1)} do //internal loop - lasts as long as there is at least one not played yet shout in the playlist { _selection = floor (random (count _shouts));//random playlist position number _shout = _shouts select _selection;//pick random element from _shouts _sleep = _shout select 1;//length _shout = _shout select 0;//name _shouts set [_selection,"Delete"]; _shouts = _shouts - ["Delete"];//remove for now chosen shout from the playlist, so will be not repeated in this cycle _shouter = units _unit_group call BIS_fnc_selectRandom; if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - unit:%1 shout: %2 time: %3 shouter: %4 group: %5", _unit, _shout, _sleep, _shouter, _unit_group]; }; if ( ( _shouter == _unit ) && ( _unit hasWeapon "ItemRadio" ) && !(_shouter call ace_sys_wounds_fnc_isUncon)) then { _shouter say3d "s17"; _shouter say3d _shout; _shouter say3d "s16"; sleep _sleep; } else { if !(_shouter call ace_sys_wounds_fnc_isUncon) then { _shouter say3d _shout; sleep _sleep; } else { sleep 5; }; }; if (({alive _x} count units (_unit_group) < 1) && ((leader (_unit_group) distance _target < 120) OR (leader (_unit_group) distance player < 120))) exitWith {if (mein_debug>0) then {player globalChat format ["ShoutSound.sqf - end"];};}; }; } else { if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - group: %1 alive: %2 target: %3", _unit_group, _alivecount, _target]; }; _shouts = [ ["s9",5+(random 25)], ["s10",5+(random 25)], ["s11",5+(random 25)], ["s12",5+(random 25)], ["s13",5+(random 25)] ]; while {((count _shouts) > 0) && (_alivecount == 1)} do //internal loop - lasts as long as there is at least one not played yet shout in the playlist { _selection = floor (random (count _shouts));//random playlist position number _shout = _shouts select _selection;//pick random element from _shouts _sleep = _shout select 1;//length _shout = _shout select 0;//name _shouts set [_selection,"Delete"]; _shouts = _shouts - ["Delete"];//remove for now chosen shout from the playlist, so will be not repeated in this cycle _shouter = units _unit_group call BIS_fnc_selectRandom; if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - unit:%1 shout: %2 time: %3 shouter: %4 group: %5", _unit, _shout, _sleep, _shouter, _unit_group]; }; if ( ( _shouter == _unit ) && ( _unit hasWeapon "ItemRadio" ) && !(_shouter call ace_sys_wounds_fnc_isUncon) ) then { _shouter say3d "s17"; _shouter say3d _shout; _shouter say3d "s16"; sleep _sleep; } else { if !(_shouter call ace_sys_wounds_fnc_isUncon) then { _shouter say3d _shout; sleep _sleep; } else { sleep 5; }; }; if (({alive _x} count units (_unit_group) < 1) && ((leader (_unit_group) distance _target < 120) OR (leader (_unit_group) distance player < 120))) exitWith {if (mein_debug>0) then {player globalChat format ["ShoutSound.sqf - end"];};}; }; }; }; if (_alivecount == 2) then { if (50 > random 100) then { if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - group: %1 alive: %2 target: %3", _unit_group, _alivecount, _target]; }; _shouts = [ ["s1",2+(random 28)], ["s2",2+(random 28)], ["s3",2+(random 28)], ["s4",2+(random 28)], ["s5",2+(random 28)], ["s6",2+(random 28)], ["s14",2+(random 28)], ["s15",2+(random 28)] ]; while {((count _shouts) > 0) && (_alivecount == 2)} do //internal loop - lasts as long as there is at least one not played yet shout in the playlist { _selection = floor (random (count _shouts));//random playlist position number _shout = _shouts select _selection;//pick random element from _shouts _sleep = _shout select 1;//length _shout = _shout select 0;//name _shouts set [_selection,"Delete"]; _shouts = _shouts - ["Delete"];//remove for now chosen shout from the playlist, so will be not repeated in this cycle _shouter = units _unit_group call BIS_fnc_selectRandom; if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - unit:%1 shout: %2 time: %3 shouter: %4 group: %5", _unit, _shout, _sleep, _shouter, _unit_group]; }; if ( ( _shouter == _unit ) && ( _unit hasWeapon "ItemRadio" ) && !(_shouter call ace_sys_wounds_fnc_isUncon) ) then { _shouter say3d "s17"; _shouter say3d _shout; _shouter say3d "s16"; sleep _sleep; } else { if !(_shouter call ace_sys_wounds_fnc_isUncon) then { _shouter say3d _shout; sleep _sleep; } else { sleep 5; }; }; if (({alive _x} count units (_unit_group) < 1) && ((leader (_unit_group) distance _target < 120) OR (leader (_unit_group) distance player < 120))) exitWith {if (mein_debug>0) then {player globalChat format ["ShoutSound.sqf - end"];};}; }; } else { if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - group: %1 alive: %2 target: %3", _unit_group, _alivecount, _target]; }; _shouts = [ ["s9",2+(random 28)], ["s10",2+(random 28)], ["s11",2+(random 28)], ["s12",2+(random 28)], ["s13",2+(random 28)], ["s6",2+(random 28)], ["s14",2+(random 28)], ["s15",2+(random 28)] ]; while {((count _shouts) > 0) && (_alivecount == 2)} do //internal loop - lasts as long as there is at least one not played yet shout in the playlist { _selection = floor (random (count _shouts));//random playlist position number _shout = _shouts select _selection;//pick random element from _shouts _sleep = _shout select 1;//length _shout = _shout select 0;//name _shouts set [_selection,"Delete"]; _shouts = _shouts - ["Delete"]; //remove for now chosen shout from the playlist, so will be not repeated in this cycle _shouter = units _unit_group call BIS_fnc_selectRandom; if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - unit:%1 shout: %2 time: %3 shouter: %4 group: %5", _unit, _shout, _sleep, _shouter, _unit_group]; }; if ( ( _shouter == _unit ) && ( _unit hasWeapon "ItemRadio" ) && !(_shouter call ace_sys_wounds_fnc_isUncon) ) then { _shouter say3d "s17"; _shouter say3d _shout; _shouter say3d "s16"; sleep _sleep; } else { if !(_shouter call ace_sys_wounds_fnc_isUncon) then { _shouter say3d _shout; sleep _sleep; } else { sleep 5; }; }; if (({alive _x} count units (_unit_group) < 1) && ((leader (_unit_group) distance _target < 120) OR (leader (_unit_group) distance player < 120))) exitWith {if (mein_debug>0) then {player globalChat format ["ShoutSound.sqf - end"];};}; }; }; }; if (_alivecount > 2) then { if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - group: %1 alive: %2 target: %3", _unit_group, _alivecount, _target]; }; _shouts = [ ["s1",0+(random 30)], ["s2",0+(random 30)], ["s3",0+(random 30)], ["s4",0+(random 30)], ["s5",0+(random 30)], ["s6",0+(random 30)], ["s7",0+(random 30)], ["s8",0+(random 30)], ["s9",0+(random 30)], ["s10",0+(random 30)], ["s11",0+(random 30)], ["s12",0+(random 30)], ["s13",0+(random 30)], ["s14",0+(random 30)], ["s15",0+(random 30)] ]; while {((count _shouts) > 0) && (_alivecount > 2)} do //internal loop - lasts as long as there is at least one not played yet shout in the playlist { _selection = floor (random (count _shouts));//random playlist position number _shout = _shouts select _selection;//pick random element from _shouts _sleep = _shout select 1;//length _shout = _shout select 0;//name _shouts set [_selection,"Delete"]; _shouts = _shouts - ["Delete"];//remove for now chosen shout from the playlist, so will be not repeated in this cycle _shouter = units _unit_group call BIS_fnc_selectRandom; if (mein_debug>0) then { player globalChat format ["ShoutSound.sqf - unit:%1 shout: %2 time: %3 shouter: %4 group: %5", _unit, _shout, _sleep, _shouter, _unit_group]; }; if ( ( _shouter == _unit ) && ( _unit hasWeapon "ItemRadio" ) && !(_shouter call ace_sys_wounds_fnc_isUncon) ) then { _shouter say3d "s17"; _shouter say3d _shout; _shouter say3d "s16"; sleep _sleep; } else { if !(_shouter call ace_sys_wounds_fnc_isUncon) then { _shouter say3d _shout; sleep _sleep; } else { sleep 5; }; }; if (({alive _x} count units (_unit_group) < 1) && ((leader (_unit_group) distance _target < 120) OR (leader (_unit_group) distance player < 120))) exitWith {if (mein_debug>0) then {player globalChat format ["ShoutSound.sqf - end"];};}; }; }; } Anybody got an idea how to change it so it only fires once each group? Thanks in advance. Share this post Link to post Share on other sites