Jump to content
Sign in to follow this  
civiciam

Trying to make enemies play sound when they die

Recommended Posts

I get it to work when I change "_killed say3D [_sound,10000,1];" to _killer instead. Then my player says those reactions when the enemy dies. But I want it to be coming from "_killed". I get no errors when doing so but there is NO SOUND at all. This is the code I'm running in my death_sounds.sqf. I would be so happy to get this working!
 

{ 
     if (side _x == east) then { 
          _x addEventHandler ["Killed", {    
             _killer = _this select 1;
             _killed = _this select 0;
              if ( _killer in (units (group player)) ) then {   
                     _sounds = ["death1","death2","death3","death4"]; 
                     _sound = _sounds select (floor(random(count _sounds)));    
                     _killed say3D [_sound,10000,1];   
                  };    
                }   
              ]; 
       }; 
} foreach allUnits;

 

EDIT: I tried stripping the code trying to make it work but no success. No errors but also no sound:

{ 
     if (side _x == east) then { 
          _x addEventHandler ["Killed", {    
             _downed = _this select 0;
              _sounds = ["death1","death2","death3","death4"]; 
              _sound = _sounds select (floor(random(count _sounds)));    
              _downed say3D [_sound,10000,1];   
              }   
              ]; 
       }; 
} foreach allUnits;

 

Share this post


Link to post
Share on other sites

I'm pretty sure say3D immediately stops when an object dies, so since it was already dead it probably never played. In the wiki page for say3D there is an example (#2) showing how to fake a dead person playing a sound, alternatively use playSound3D

Share this post


Link to post
Share on other sites
2 hours ago, dreadedentity said:

I'm pretty sure say3D immediately stops when an object dies, so since it was already dead it probably never played. In the wiki page for say3D there is an example (#2) showing how to fake a dead person playing a sound, alternatively use playSound3D

 

Thank you, got it working. Leaving it here for people who need it:

{ 
     if (side _x == east) then { 
          _x addEventHandler ["Killed", {    
               params ["_corpse"];
               private _dummy = "#particlesource" createVehicleLocal [0,0,0];
               _dummy setPosWorld getPosWorld _corpse;
               _sounds = ["death1","death2","death3","death4"]; 
               _sound = _sounds select (floor(random(count _sounds)));    
               _dummy say3D [_sound,100,1];   
          }]; 
       }; 
} foreach allUnits;

 

  • Like 1

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
Sign in to follow this  

×