Jump to content
Sign in to follow this  
dmarkwick

On kill

Recommended Posts

As part of my education in ArmA scripting I'm making a simple addon. For it to be effective I need it to do something first before I can get into the easy (relatively) scripting part of it. That thing is this:

I need it to execute some code each time something dies. Whether that's a vehicle, aircraft or soldier. I can separate out what the thing is in code but how do I get ArmA to execute my code each time something dies without having to edit all the init fields in the editor?

Basically an addon that will work without having to add it as a script to a mission, just drop it in the Addons folder & have it work. I'm guessing some sort of eventhandler, but that's a phrase I plucked out of the air really, can there be a common eventhandler for any type of death?

Share this post


Link to post
Share on other sites

I don't think you need any kind of mod.  The killed eventhantler will tell a called script who was killed, and who did the killing.  Biki link:

http://community.bistudio.com/wiki/Armed_Assault:_EventHandlers_List

Add an eventhandler to a unit via AddEventHandler command (search biki for AddEventHandler).

And to add an eventhandler to every unit on the map, you could:

1. Create a trigger whose radius covers the whole map

2. Activated by "Anybody Present", Once

3. And in the action field put this code:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addeventhandler addEventHandler ["killed", {[_this select 0, _this select 1] exec "myHandler.sqs"}]} foreach thislist

The above trigger code will assign the killed eventhandler to every living unit. (Not every object, won't work for cars, trees, choppers, etc.)

4. Write your script that is executed by the event handler.  In my example I named it myHandler.sqs, you can name it anything you want.  This script would start by reading the first two parameters, which are who was killed, and killer:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; myHandler.sqs

_victim = _this select 0;

_killer = _this select 1;

...here you code whatever you want...

Every time a unit is killed, myHandler.sqs will be called.

This would work for all living units. Not cars, trucks, houses, etc. Hope that helps some.

Share this post


Link to post
Share on other sites

What you try to achieve is not trivial but it can be done. The same principle has been applied in CENT's tracer script addon for example. It has to do with catching creation events of each object on the map. If you decompile and fully understand those scripts you have done a good deal for your education in Arma. xmas_o.gif

Regards,

Victor

Share this post


Link to post
Share on other sites

@JohnnyBoy - this method works thanks smile_o.gif

@VictorFarbau - I will check out the scripts thanks smile_o.gif

Share this post


Link to post
Share on other sites

Just a note, this addeventhandler killed is great for alot of things.

and in your code snippet (thank you! ) you made a mistake

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addeventhandler addEventHandler ["killed", {[_this select 0, _this select 1] exec "myHandler.sqs"}]} foreach thislist

should be

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addeventhandler ["killed", {[_this select 0, _this select 1] exec "myHandler.sqs"}]} foreach thislist

...you had an extra "addeventhandler" in there.  wink_o.gif  Right now I was searching for this to execute a speech script. While limited to being killed, this when set for "Blufor" in "Activated By" field, will call a speech script that makes a soldier yell "Sh%! mandown! MEDIC!"  biggrin_o.gif  So using two triggers, one activated by OPFOR, you can customize voices and speech depending on which side you belong...woo hoo

Thanks a bunch!

pistols.gif

ARMAVIDZ

Share this post


Link to post
Share on other sites
Quote[/b] ]...you had an extra "addeventhandler" in there. Right now I was searching for this to execute a speech script. While limited to being killed, this when set for "Blufor" in "Activated By" field, will call a speech script that makes a soldier yell "Sh%! mandown! MEDIC!" So using two triggers, one activated by OPFOR, you can customize voices and speech depending on which side you belong...woo hoo

Oops...extra "addeventhandler"! The "man down" idea is good. Like you, I'm using these eventhandlers to add voice for immersion. In my case, if the victim killed is an enemy within 5 meters of player, and someone other than player killed him, the player says "That was close! Thanks!", and the killer says "You owe me one!". Have a few variations of each to keep it different.

Share this post


Link to post
Share on other sites
Quote[/b] ]...you had an extra "addeventhandler" in there.    Right now I was searching for this to execute a speech script. While limited to being killed, this when set for "Blufor" in "Activated By" field, will call a speech script that makes a soldier yell "Sh%! mandown! MEDIC!"    So using two triggers, one activated by OPFOR, you can customize voices and speech depending on which side you belong...woo hoo

Oops...extra "addeventhandler"!  The "man down" idea is good.  Like you, I'm using these eventhandlers to add voice for immersion.  In my case, if the victim killed is an enemy within 5 meters of player, and someone other than player killed him, the player says "That was close!  Thanks!", and the killer says "You owe me one!".  Have a few variations of each to keep it different.

I think the whole community would d/l the crap outta that if it were polished. I can tell ya, seeing a soldier go down in front of me (I put in a unitsetpos "middle" to the script) and having the whole team react by crouching down and the "man down, MEDIC!" remakes how you think about games and ArmA. Actually, the soldiers says: "F&@$! Contact. Shit, Mandown. MEDIC!" hehehe

What I've done (b/c I'm just a newb) is unPBO'd the sounds PBO and used the voices from there...Ryan...Howard...etc... Created a simple batch file to change all the names of the files to more "user" friendly names then did the description.ext / .csv thing. Pretty good effect for now. Maybe later I'll get into bringing in outside voices for ARMA.

Awesome. smile_o.gif

Share this post


Link to post
Share on other sites
Quote[/b] ]...you had an extra "addeventhandler" in there.    Right now I was searching for this to execute a speech script. While limited to being killed, this when set for "Blufor" in "Activated By" field, will call a speech script that makes a soldier yell "Sh%! mandown! MEDIC!"    So using two triggers, one activated by OPFOR, you can customize voices and speech depending on which side you belong...woo hoo

Oops...extra "addeventhandler"!  The "man down" idea is good.  Like you, I'm using these eventhandlers to add voice for immersion.  In my case, if the victim killed is an enemy within 5 meters of player, and someone other than player killed him, the player says "That was close!  Thanks!", and the killer says "You owe me one!".  Have a few variations of each to keep it different.

Hi again JohnnBoy, I am very curious how you are throwing in the randomness of the voices. Any chance you could share the randomness script?

I think the footwork for the actual sounds needs to customized and done for each person, but I don't know how to put multiple sounds and have the soldiers choose random ones.

Very cool idea you got there. smile_o.gif

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  

×