Jump to content
aie-boshell

Using Sleep with Mission Eventhandler Entitykilled on Dedicated Server

Recommended Posts

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

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>}  }];

  • Like 1

Share this post


Link to post
Share on other sites

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

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> };

  • Confused 1

Share this post


Link to post
Share on other sites

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
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" :don14:
 

 

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.

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, dedmen said:

You are missing a { before the "this" :don14:
 

 

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

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
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

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×