marcon 0 Posted August 4, 2010 This is probably a repost but the search function hasen's given me any answers so here's my question: Is there any function or variable that stores the cause of death of a given unit, and more important for me, the killer/shooter of a unit? I've been looking through the COMREF and couldn't find anythink, I hope i haven't missed it. Thanks in advance! Share this post Link to post Share on other sites
TRexian 0 Posted August 4, 2010 I shot the sheriff... but I did not shoot the deputy.... :D You want the "killed" eventhandler which you can add to a unit with the addEventhandler command. This can be applied via the editor, but to make the best use of it, you are probably going to need to run a script. :) Share this post Link to post Share on other sites
marcon 0 Posted August 4, 2010 Thanks, I'm not common with eventhandlers but I will do my research :) Thanks TRexian! Share this post Link to post Share on other sites
-=bac=-gengiskhan 10 Posted August 4, 2010 This look like something i'm working on: Here an exemple to show the name of the killer: //Put this in the init field of an enemy //EVHDist = this addEventHandler ["killed", {_this execVM "ShowKiller.sqf"}]; //And this in an Script name ShowKiller, it will show the name of the player when an enemy die _target = _this select 0; _killer = _this select 1; hint format["Name_Of_The_Killer %1",_killer]; Share this post Link to post Share on other sites
marcon 0 Posted August 5, 2010 Thanks for the example, I do figured out how the eventHandlers work and they are really of a good use! Share this post Link to post Share on other sites
Clavicula_nox4817 0 Posted April 29, 2011 (edited) I was wondering if there was a way to show the name of the unit that was killed. In the mission I am building, there are several targets that have the killed eventhandler in use and, while it is great for showing the name of the killer, i don't know how to differentiate the names of the killed. It's important to know whether Targets 1-5 or random civilians were killed. *edit* I had a dull moment. I figured it out: this addEventHandler ["killed", "hint format['Sniper Killed by %1',_this select 1]"]; Edited April 29, 2011 by Clavicula_nox4817 Share this post Link to post Share on other sites
riouken 15 Posted April 29, 2011 _this select 0 Inside the eventhandler is the person killed Share this post Link to post Share on other sites
froggyluv 2136 Posted October 9, 2011 (edited) Hi, can someone point me int he right direction (just read Taurus guide) on how to isolate kill message to only one group _target = _this select (group e2); _killer = _this select (group redmist1); hint format["Name_Of_The_Killer %1",_killer]; Doesn't work :( I'm really trying to learn how to only get a response when Redmist1 kills a member of group e2. I get the concepts just am literally lost with proper syntax. Edited October 9, 2011 by froggyluv Share this post Link to post Share on other sites
AZCoder 921 Posted October 9, 2011 To filter for the killer in a certain group you could do this: _target = _this select 0; _killer = _this select 1; if (group _killer == group redmist1) then { player sideChat format["target: %1, killer: %2", _target, _killer]; }; You can filter the target in a similar fashion, however if you only assign the event handler to members of group e2, then you don't need to filter it of course. Share this post Link to post Share on other sites
froggyluv 2136 Posted October 9, 2011 Hmm, so I placed your code into Showkiller.sqf _target = _this select 0; _killer = _this select 1; if (group _killer == group redmist1) then { player sideChat format["target: %1, killer: %2", _target, _killer]; }; Have this is the enemy init line: e2 = group this;this addEventHandler ["killed", {_this execVM "ShowKiller.sqf"}]; And have Redmist1 kill him -but Im getting error message Error Group Type Group expected object in Line 3 I believe Share this post Link to post Share on other sites
AZCoder 921 Posted October 9, 2011 Well double hmm, I replicated what you have there and it works for me :D Maybe remove the if-then part but leave the "player sideChat format["target: %1, killer: %2", _target, _killer];" part to see what values they have. Oh, and is redmist1 a group name or unit name? I assumed the latter. If it's a group name, then remove "group" from "group redmist1". Share this post Link to post Share on other sites
froggyluv 2136 Posted October 10, 2011 (edited) Yes that did it! They are a group and I'm sorry I should have clarified that. You know scripting to me is a lot like when I first started playing drums, I could hear the rythmes in my head but had no idea how to make my hands speak the language. Here I know the concept and can pretty much follow the script reading it -but writing it Im just at a loss for syntax and proper structure :( Anyhow thanks alot! ---------- Post added at 01:32 AM ---------- Previous post was Yesterday at 11:40 PM ---------- Just a little continuation: So that part works great and I had a custom sound that I wanted played after that: _target = _this select 0; _killer = _this select 1; if (group _killer == redmist1) then playsound "sound1"; alpha sidechat "He's down"; Which worked swell except this trigger will fire quite a bit so wanted to add random choice of maybe 3 sounds. I took this from another post from Celery _target = _this select 0; _killer = _this select 1; _sounds = ["sound1","sound3","sound4"]; _sound = _sounds select floor random count _sounds; if (group _killer == redmist1) then _killer say _sound; alpha sidechat "He's down"; Which does not work -it seems _killer say _sound is not a viable candidate for the THEN statement. I could just put an empty sound in that statment and then run the _killer say _sound on next line that feels false and also I don't know if thats still part of the RedMist1 as killer argument. Man this is confusing :crazy_o: Edit: Aha! I got it! Needed to be if (group _killer == redmist1) then {_killer say _sound}; Freakin brackets, lol, well thanks Wiki :) Edited October 10, 2011 by froggyluv Share this post Link to post Share on other sites
froggyluv 2136 Posted October 14, 2011 (edited) Hi, I got the above working but need to get accoompanying text to correlate with proper audio. Im sure it's faulty syntax _target = _this select 0; _killer = _this select 1; _response1 = [_killer sidechat "He's down"; playsound "sound10"]; ///// Specifically what I'm asking here is do I need further punctuation in terms of brackets etc..? _response2 = [_killer sidechat "Eliminated"; playsound "sound11"]; _response3 = [_killer sidechat "Target down"; playsound "sound12"]; _sounds = [_response1,_response2,_response3]; /////// What I'm asking here is can I have theese variable placed as such in this array? _sound = _sounds select floor random count _sounds; if (group _killer == foxmist1) then {_killer exec _sound}; Edit: As of now, it plays all 3 texts and the first 2 sounds upon every kill....hmm. Edited October 14, 2011 by froggyluv Share this post Link to post Share on other sites
twirly 11 Posted October 14, 2011 (edited) Try something like this for the sound man....short and simple. playsound (["killconfirmed","heshistory","goodbye"] select floor (random 3)); Edited October 14, 2011 by twirly Clarity Share this post Link to post Share on other sites
froggyluv 2136 Posted October 14, 2011 But how will that match the proper text if only the sound is random? Share this post Link to post Share on other sites
twirly 11 Posted October 14, 2011 (edited) OK...do it this way maybe (I was working on it for you!). _responses = [[_response1,"He's down"],[_response2,"Eliminated"],[_response3,"Target down"]]; _indx = 0; if (group _killer == foxmist) then { _indx = floor random 3; playsound (_responses select _indx) select 0; _killer sidechat (_responses select _indx) select 1; }; You follow? ... not tested but should work. EDIT: I corrected the code lol! had a cut and paste nightmare going on there! Edited October 14, 2011 by twirly Corrected again. lol! Share this post Link to post Share on other sites
froggyluv 2136 Posted October 15, 2011 Hehe, thanks -sorry if I seemed impatient :o I pretty much follow your format except not sure why _index = 0 - Is that to set the start count of 0-2? Still having issues with 2 sounds playing together and I've lost the accompanying text _target = _this select 0; _killer = _this select 1; _response1 = [ playsound "sound10"]; _response2 = [ playsound "sound11"]; _response3 = [ playsound "sound12"]; _responses = [[_response1,"He's down"],[_response2,"Eliminated"], [_response3,"Target down"]]; _indx = 0; if (group _killer == foxmist) then { _indx = floor random 3; playsound (_responses select _indx) select 1; _killer sidechat (_responses select _indx) select 0; }; }; Share this post Link to post Share on other sites
twirly 11 Posted October 15, 2011 (edited) Hehe, thanks -sorry if I seemed impatient Nah mate....not you being impatient. I didn't really help you much with my post... so was trying to go the extra mile and give you something better. _indx = 0 is simply to initialize the variable _indx. To give it a value before we use it in the "if" statement. You can have problems if variables are not set before being used in "if's" and "while's" etc. Arrays certainly won't work unless being previously initialized outside the scope of these statements. OK...here your error is easy... _target = _this select 0; _killer = _this select 1; [s]_response1 = [ playsound "sound10"]; _response2 = [ playsound "sound11"]; _response3 = [ playsound "sound12"]; [/s] _responses = [[[color="Red"]"sound10"[/color],"He's down"],[[color="Red"]"sound11"[/color],"Eliminated"], [[color="Red"]"sound12"[/color],"Target down"]]; _indx = 0; if (group _killer == foxmist) then { _indx = floor random 3; playsound (_responses select _indx) select 1; _killer sidechat (_responses select _indx) select 0; }; }; You need to see why you made an error though!...do you? Edited October 15, 2011 by twirly Clarity Share this post Link to post Share on other sites
froggyluv 2136 Posted October 15, 2011 Actually no - it looks like it should work to me to be honest. So I placed your current code in _target = _this select 0; _killer = _this select 1; _responses = [["sound10","He's down"],["sound11","Eliminated"], ["sound12","Target down"]]; _indx = 0; if (group _killer == foxmist) then { _indx = floor random 3; playsound (_responses select _indx) select 1; _killer sidechat (_responses select _indx) select 0; }; }; and unfortunately neither text nor sound now. Ok so _indx = 0 is the intializer. Question: playsound (_responses select _indx) select 1; Wouldn't that play the 2nd element in the tuple since 0 is the first? That being the text rather then the sound? Thanks for helping me on this- this stuff is really fascintating tho a bit like learning algebra the first time :) Share this post Link to post Share on other sites
twirly 11 Posted October 15, 2011 Oh yes.... it will... stupid me. I just copied your post again. If you look at my orignal post above... I actually edited it after to be correct. Seems you grabbed the code before I had fixed it. So yes you are 100% correct. Share this post Link to post Share on other sites
froggyluv 2136 Posted October 15, 2011 (edited) Still no luck with either text or sound (Id actually already switched the 0 and 1) _target = _this select 0;_killer = _this select 1; responses = [[_response1,"He's down"],[_response2,"Eliminated"],[_response3,"Target down"]]; _indx = 0; if (group _killer == foxmist1) then { _indx = floor random 3; playsound (_responses select _indx) select 0; _killer sidechat (_responses select _indx) select 1; }; It's crazy, I understand more and more what your doing and don't see why it doesnt work. I even tried adding a 'playsound' to bottom of your argument just to make sure it was firing and it never played. The sounds do all work and are proper in the description...very strange. This is in the init of the target: this addEventHandler ["killed", {_this execVM "ShowKiller.sqf"}]; with showkiller.sqf being the name of this file. The original post I had the sounds and text playing together -but they were random and mismatched and all firing at the same time -lol. Edited October 15, 2011 by froggyluv Share this post Link to post Share on other sites
twirly 11 Posted October 15, 2011 (edited) You still have some errors.... You forgot the underscore in _responses.... and you didn't assign anything to _response1, _response2, _response3! _response1 = "sound10"; _response2 = "sound11"; _response3 = "sound12"; But then...hang on a second!. You don't need _response1, _response2 and _response3 at all if you just use the actual sound itself. _target = _this select 0; _killer = _this select 1; [color="SeaGreen"]_responses[/color] = [[[color="Red"]"sound10"[/color],"He's down"],[[color="Red"]"sound11"[/color],"Eliminated"],[[color="Red"]"sound12"[/color],"Target down"]]; _indx = 0; if (group _killer == foxmist1) then { _indx = floor random 3; playsound (_responses select _indx) select 0; _killer sidechat (_responses select _indx) select 1; }; EDIT: OK... I made a demo for you. Works sweet! There's another error that I missed above and that is... The Eventhandler passes an array [victim,killer] to your script.... so to get the killer and the victim you have to extract them from the passed array like this:- [color="Red"]_array = _this select 0[/color]; _target =[color="Red"] _array[/color] select 0; _killer = [color="Red"]_array[/color] select 1; I knew that all along but without testing I just did not see it. Edited October 15, 2011 by twirly Clarity Share this post Link to post Share on other sites
froggyluv 2136 Posted October 15, 2011 Ugh, somewhere in all this shuffling I lost that underscore So here it reads now: _target = _this select 0; _killer = _this select 1; _responses = [["sound10","He's down"],["sound11","Eliminated"],["sound12","Target down"]]; _indx = 0; if (group _killer == foxmist1) then { _indx = floor random 3; playsound (_responses select _indx) select 0; _killer sidechat (_responses select _indx) select 1; }; Still no luck :( Share this post Link to post Share on other sites
twirly 11 Posted October 15, 2011 Go back to my last post....I added stuff for you. You'll be OK now. Share this post Link to post Share on other sites
froggyluv 2136 Posted October 15, 2011 (edited) Doood - thats great man it works like a charm! Problem is, I'm not sure why it wasn't firing until I stole your EH.Sqf - apparently it wasn't from the init I had.... Speaking of which, any chance I can use those sounds in my mission :D They're freakin awesome and would fit perfectly. Of course Ill have to name a key character Twirly somehow :) Man thank you so much :) Edit: _group = _this select 0;//add the event handler to the units in the group for "_i" from 0 to (count units _group)-1 do { _unit = units _group select _i; _unit addeventhandler ["KILLED",{nul=[_this] execVM "ShowKiller.sqf"}]; sleep 0.01; }; this is tougher for me to follow and Ill have really study to understand fully. Edited October 15, 2011 by froggyluv Share this post Link to post Share on other sites