aie-boshell 22 Posted November 16, 2017 Hello, I I am using an entitykilled mission eventhandler how to run a custom radio message each time a certain unit gets a Kill. Everything is working fantastic accepted that I would like to have a delay before the radio message gets played. I've been trying to use sleep and it is not working. Does anyone know how to get sleep to work with entitykilled or perhaps a viable alternative to achieve the results of getting a delay before a radio message after a certain unit gets a Kill? Any help is very much appreciated, as always :-) Share this post Link to post Share on other sites
pierremgi 4862 Posted November 16, 2017 You need to spawn your code then suspend what you want in it: addMissionEventHandler ["entityKilled", _this spawn { params ["_killed", "_killer", "_instigator"]; <lines of code>; sleep 2; <other lines of code>} }]; 1 Share this post Link to post Share on other sites
aie-boshell 22 Posted November 16, 2017 Thank you very much for the response, Pierremgi. I do get one error when I use this. "Error Undefined variable in expression: this". Might you be be able to help me with that? Share this post Link to post Share on other sites
phronk 898 Posted November 17, 2017 Replace this with _this select 0 It's probably better to do this though: [_this select 0, _this select 1, _this select 2] spawn { params ["_killed", "_killer", "_instigator"]; <lines of code>; sleep 2; <other lines of code> }; 1 Share this post Link to post Share on other sites
M1ke_SK 230 Posted November 17, 2017 I think eventHandler run unscheduled code, so sleep will probably give error. You should use spawn inside eventhandler to have delay ( usage of sleep ) like pierremgi explained Share this post Link to post Share on other sites
Dedmen 2703 Posted November 17, 2017 18 hours ago, pierremgi said: You need to spawn your code then suspend what you want in it: addMissionEventHandler ["entityKilled", this spawn { params ["_killed", "_killer", "_instigator"]; <lines of code>; sleep 2; <other lines of code>} }]; You are missing a { before the "this" 5 minutes ago, M1ke_SK said: I think eventHandler run unscheduled code, so sleep will probably give error. You should use spawn inside eventhandler to have delay ( usage of sleep ) like pierremgi explained Which is what was already answered in the first answer to the question ;) Even OP said that sleep doesn't work. 1 Share this post Link to post Share on other sites
pierremgi 4862 Posted November 17, 2017 5 hours ago, dedmen said: You are missing a { before the "this" Yes, thanks. I was not able to answer. Apart : I don't know why my forum access is totally jammed everyday. I had the bad gateway (last weeks), then the blank firefox page, now the endless access before it expires. On BI forums only... Share this post Link to post Share on other sites
aie-boshell 22 Posted November 17, 2017 I appreciate all of your help very much. I'm still having no luck with this and am getting multiple errors. My code is fine without the additions. Here's what I'm doing. addMissionEventHandler ["entityKilled", [_this select 0, _this select 1, _this select 2] spawn { params ["_killed", "_killer", "_instigator"]; <lines of code>; sleep 2; <other lines of code>}; Share this post Link to post Share on other sites
pierremgi 4862 Posted November 17, 2017 1 hour ago, aie-boshell said: I appreciate all of your help very much. I'm still having no luck with this and am getting multiple errors. My code is fine without the additions. Here's what I'm doing. addMissionEventHandler ["entityKilled", [_this select 0, _this select 1, _this select 2] spawn { params ["_killed", "_killer", "_instigator"]; <lines of code>; sleep 2; <other lines of code>}; addMissionEventHandler ["entityKilled", { _this spawn { params ["_killed", "_killer", "_instigator"]; <lines of code>; sleep 2; <other lines of code>} } ]; Then depending on what you're writing in your lines of code. Share this post Link to post Share on other sites
aie-boshell 22 Posted November 17, 2017 Still no luck :-( It says it got string while expecting array. I don't think I've given you enough information. Here is the full script. addMissionEventHandler ["entityKilled", { _this spawn { params ["_killed", "_killer", "_instigator"]; //If we don not have an instigator, where we controlling a UAV if (isNull _instigator) then {_instigator = UAVControl vehicle _killer select 0}; //If we still do not have an instigator use killer instead if (isNull _instigator) then {_instigator = _killer}; if (vehiclevarname _killer isEqualTo "plane_1" and _killed isKindOf "CAManBase" and side group _killed isEqualTo east) then {p_1 addscore 1}; if (vehiclevarname _killer isEqualTo "plane_1" and _killed isKindOf "CAManBase" and side group _killed isEqualTo independent and [west, independent] call BIS_fnc_sideIsenemy) then {p_1 addscore 1}; }]; Share this post Link to post Share on other sites
aie-boshell 22 Posted November 17, 2017 I stand corrected. This works for sleep. Thanks so much guys :-) addMissionEventHandler ["entityKilled", { _this spawn { params ["_killed", "_killer", "_instigator"]; //If we don not have an instigator, where we controlling a UAV if (isNull _instigator) then {_instigator = UAVControl vehicle _killer select 0}; //If we still do not have an instigator use killer instead if (isNull _instigator) then {_instigator = _killer}; if (vehiclevarname _killer isEqualTo "plane_1" and _killed isKindOf "CAManBase" and side group _killed isEqualTo east) then {p_1 addscore 1}; if (vehiclevarname _killer isEqualTo "plane_1" and _killed isKindOf "CAManBase" and side group _killed isEqualTo independent and [west, independent] call BIS_fnc_sideIsenemy) then {p_1 addscore 1}; }]; Share this post Link to post Share on other sites