Jump to content
Sign in to follow this  
stingfish74

Scripting Trigger - Play Effect when Unit Kills

Recommended Posts

Can't seem to figure this out and need assistance.

Goal: To play a specific effect sound when my team AI or player kills an enemy. I have a list of 6 unique sounds, and would like them to be dynamic per AI unit if possible.

Issue: I can't seem to determine if the trigger events can support this. If so, how and if not, do you have alternative solutions?

Additional Notes: Remember GhostRecon, when a member of your team kills a enemy unit and the radio chatter... "Kill Confirmed" or "Nailed Him"

That is what I'm looking to accomplish.

Share this post


Link to post
Share on other sites

thanks mate. was afraid i needed to use eventhandlers. i weak in those, even after trying to play around with them for a while. im not sure what it would look like creating one for what i wanted to accomplish.

---------- Post added at 08:36 PM ---------- Previous post was at 08:06 PM ----------

hey Demonized.

can you help me with this? i can do some scripting but never figured out the EH's. What would this look like?

i have 3 bluefor units. one player, and two AI. When I, or my AI kill an opfor i want to play a specific .ogg file.

Share this post


Link to post
Share on other sites

I think you'll need something like this placed in all OPFOR units

this addEventHandler ["killed", "{if (_this select 1 ==  _x) then {_x say ['ahh',0];hint 'dead'}  } count units  player "]

you can remove the hint it was just in for testing and you'll need to replace 'ahh' with the name of your sound file.

Share this post


Link to post
Share on other sites

If you new help with scripting in general, look at Demonized's signature.

Download the Mr.Murray Guide and take a look at it! It has everything you could imagine for scripting, anything from creating an object to extremely complicated scripts.

Share this post


Link to post
Share on other sites

@F2k Sel, it's a start in the right direction for me. i just tested it and it seems its one solution to what im looking for. i dont know where to stick the sound file, i referenced it in your snippet but when i kill an opfor it errors "killed.ogg" not found.

also, im wondering if there is something i can add to the bluefor unit/s that when they kill someone they say something.

@bigshotking, many thanks for the reference. I've trolled Murray's guide in the past and found it to be useful for some of the other scripting i do. for some reason, i cant get a grip on EH's.

Share this post


Link to post
Share on other sites

Common practice is to place your sounds in a folder called sound which is inside the mission folder.

You will also need a description.ext file

example.

class CfgSounds
{

sounds[] = {ahh};

// Definition for each sound
class ahh
{
	name = "ahh"; // Name for mission editor
	sound[] = {\sound\ahh.ogg, db +0, 1.0};
	titles[] = {0, ""};
};
};

be careful with description files, every time you edit them you need to reload the mission not just run it or it won't be updated.

Share this post


Link to post
Share on other sites

Follow F2k Sel´s instructions with description.ext and use the eventhandler example below.

But here is how you auto assign the eventhandlers to all opfor by simply placing this code in 1 unit init or init.sqf, so you dont have to manually paste the code in all units.

Though i wonder if its correct syntax used? differs from wiki and what i know.

{
if (side _x == east) then {
	_x addEventHandler ["killed", "{if (_this select 1 ==  _x) then {_x say ['ahh',0]}  } count units group player "];
};
} foreach allUnits;

Basically what code does:

Its same code as F2K Sel posted (hint removed), it goes over all units in mission, if unit is a east unit it will get the eventhandler.

make sure to alter the 'ahh' to whatever sound file you use.

Also:

You mention you want the 6 sounds to be dynamic, i asume you mean a random sound is played each time.

If so, this is how you do instead of above code.

What the 1 number in the say command wiki example is i have no idea, also it seems say uses 3 params??? typo in wiki maybe? or optional...

Anywho, you see code goes through all units once, if side is east then eventhandler is assigned to unit.

eventhandker checks if the killer is in player group, then if so it selects 1 soundname from the _sounds array(these are the sounds you have in description.ext and then it plays that sound, it will be a random sound every time.

{
if (side _x == east) then {
	_x addEventHandler ["killed", {
		_killer = _this select 1;
		if ( _killer in (units (group player)) ) then {
			_sounds = ["ahh","got_him","boojaa","u_rock",suck_it_biatch","whos_next"];
			_sound = _sounds select (floor(random(count _sounds)));
			_killer say [_sound,1,5];
		};
	];
};
} foreach allUnits;

Share this post


Link to post
Share on other sites

@Demonized and F2k Sel, thanks so much for your help.

i just tested the first code Demonized wrote and used the description F2K Sel provided, just modified the Ahh to my sound name and it worked like a charm.

many many thanks! going to try the dynamic EH Demonized wrote now. Thanks again for your help!

---------- Post added at 12:18 PM ---------- Previous post was at 11:21 AM ----------

ok, i just tried the dynamic code, but when i insert it into the int line of my player i get the error pop when i preview, but there is no specific error message referenced. not sure what may be wrong. here is the int code im using. i double checked my description code as well.

int.

{
if (side _x == east) then {
	_x addEventHandler ["killed", {
		_killer = _this select 1;
		if ( _killer in (units (group player)) ) then {
			_sounds = ["kill1","kill2","kill3","kill4","kill5","kill6"];
			_sound = _sounds select (floor(random(count _sounds)));
			_killer say [_sound,1,6];
		};
	];
};
} foreach allUnits;

description

class CfgSounds
{

sounds[] = {kill1};

// Definition for each sound
class kill1
{
	name = "kill1"; // Name for mission editor
	sound[] = {\sound\kill1.ogg, db +0, 1.0};
	titles[] = {0, ""};
};

// Definition for each sound
class kill2
{
	name = "kill2"; // Name for mission editor
	sound[] = {\sound\kill2.ogg, db +0, 1.0};
	titles[] = {0, ""};
};

// Definition for each sound
class kill3
{
	name = "kill3"; // Name for mission editor
	sound[] = {\sound\kill3.ogg, db +0, 1.0};
	titles[] = {0, ""};
};

// Definition for each sound
class kill4
{
	name = "kill4"; // Name for mission editor
	sound[] = {\sound\kill4.ogg, db +0, 1.0};
	titles[] = {0, ""};
};

// Definition for each sound
class kill5
{
	name = "kill5"; // Name for mission editor
	sound[] = {\sound\kill5.ogg, db +0, 1.0};
	titles[] = {0, ""};
};

// Definition for each sound
class kill6
{
	name = "kill6"; // Name for mission editor
	sound[] = {\sound\kill6.ogg, db +0, 1.0};
	titles[] = {0, ""};
};

};

---------- Post added at 12:33 PM ---------- Previous post was at 12:18 PM ----------

Scope Change:

How would this work if I wanted each BlueFor to say a specific sound each time they killed an Opfor?

One on my units will say kill1 for every opfor he kills. The other unit says kill2 for each opfor he kills etc?

Share this post


Link to post
Share on other sites

The problem is in the evh it's missing a bracket

{ 
     if (side _x == east) then { 
          _x addEventHandler ["killed", {    
             _killer = _this select 1;
              if ( _killer in (units (group player)) ) then {   
                     _sounds = ["ahh","ahh2","barrel1"]; 
                     _sound = _sounds select (floor(random(count _sounds)));    
                     _killer say [_sound,1,6];   
                  };    
                }   
              ]; 
       }; 
} foreach allUnits;

Edited by F2k Sel

Share this post


Link to post
Share on other sites

@F2k Sel. Thanks, it works now.

Jeez, just like Ghost Recon! when I or my group AI kill an enemy, you hear a "killed confirmed", or "nailed him!", or "hes history" etc :)

One more question.

How can we make this work do that each member is assigned one sound to make when killing an opfor?

example, when i kill someone i say kill confirmed. when one specific unit in my group kills someone he says something else?

Share this post


Link to post
Share on other sites

If your placing it in an init I'd swap to a proper script as it's going to get quite long.

You will also need to name your units.

Save the script as Shout_out.sqf

and call with null=[] execvm "Shout_out.sqf "

placed in an init

Example for two units not including the player

{   

if (side _x == east) then {  
 _x addEventHandler ["killed", { 
     _killer = _this select 1;   

       if ( _killer in (units (group player)) ) then { 

            switch (_killer) do {

            case bill : 
            {
            _bill_sounds = ["ahh1","ahh2","ahh3"];
              _bill_sound = _bill_sounds select (floor(random(count _bill_sounds)));  
                    _killer say [_bill_sound,1,6];   
             };  

            case ted  : 
            { 	 
                  _ted_sounds = ["barrel1","barrel2","barrel3"];
              _ted_sound = _ted_sounds select (floor(random(count _ted_sounds)));  
                    _killer say [_ted_sound,1,6];   
             };

            };  
          };    

         }  

       ];  
    }; 
} foreach allUnits;

You'll need to replace the sounds and set up the units names.

You can add more units by adding more case codes.

Share this post


Link to post
Share on other sites

thanks F2k Sel. This works. :)

the only thing is when bill, or ted kills an opfor they will shout the sound twice. i'm not sure why tho. here is what i'm using. any idea?

int code line, this is what i stick in the int line of each unit.

null=[] execvm "Shout_out.sqf"

There is the shout.sqs

{   

if (side _x == east) then {  
 _x addEventHandler ["killed", { 
     _killer = _this select 1;   

       if ( _killer in (units (group player)) ) then { 

            switch (_killer) do {

            case bill : 
            {
            _bill_sounds = ["kill1"];
              _bill_sound = _bill_sounds select (floor(random(count _bill_sounds)));  
                    _killer say [_bill_sound,1,6];   
             };  

            case ted  : 
            { 	 
                  _ted_sounds = ["kill4"];
              _ted_sound = _ted_sounds select (floor(random(count _ted_sounds)));  
                    _killer say [_ted_sound,1,6];   
             };

            };  
          };    

         }  

       ];  
    }; 
} foreach allUnits;

Share this post


Link to post
Share on other sites

int code line, this is what i stick in the int line of each unit.

null=[] execvm "Shout_out.sqf"

it only needs to be in one unit or objects init or you'll get multiple eventhandlers created fore each unit

Share this post


Link to post
Share on other sites

@F2k Sel. Thanks for your support in this one. Thanks to everyone. It works and is pretty cool IMO. Love the "kill confirmed" when one of my AI units kills someone.

thanks again. brings back the old Ghost Recon 1 days.

Share this post


Link to post
Share on other sites

Hey F2k Sel.

If you're still around will you please help me with one more thing. I wanted to play a specific sound when one of my units is killed.

IE, i'm the player and if one of my units is killed i hear a specific sound. would this look like the EH you set?

thanks for your help as always.

Share this post


Link to post
Share on other sites

Hi, I think this may be quite easy just place this in the init of the unit with the sound you want.

this addEventHandler ["killed", "(_this select 1)  say ['ahh',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  

×