Jump to content
Sign in to follow this  
Treelor

EHKilled not working properly

Recommended Posts

a31bb7e07b5faab96a806fcb3dd603f7.png

^ This is what I get when attempting to simply return who killed the enemy.

I add the event handler by using a refresh script to check for new opfor, which is here:

{ if (side _x == east) then {_x addEventHandler ["killed",{_nul = [] ExecVM "Functions\eventHandlerKilled.sqf"}];};} forEach list CenterMap;
sleep 4;
{_x removeAllEventHandlers "killed"} forEach list CenterMap;
_nul = [] ExecVM "Functions\eventHandlerKilledRefresh.sqf";

and then I execute this one simple line to report it in a hint:

hint format ["%1 killed something",_this select 1];

I remember doing this the last time I got into ArmA, so I have ABSOLUTELY no idea why its suddenly not working now. Help!

Relevant spew from arma.rpt:

Error in expression <int format ["%1 killed something",_this select 1];>
 Error position: <select 1];>
 Error Zero divisor
File C:\Documents and Settings\Treelor\My Documents\ArmA 2\missions\TheSandbox.GNT_Sands\Functions\eventHandlerKilled.sqf, line 1

Share this post


Link to post
Share on other sites

Maybe like this:

_x addEventHandler ["killed", {nul = [(_this select 1)] execVM "Functions\eventHandlerKilled.sqf"}];

hint format ["%1 killed something",(_this select 0)];

btw you can do the loop like this:

while {true} do {
// code
sleep 4;
// code
};

No need to exec the file again and again.

Edited by sxp2high

Share this post


Link to post
Share on other sites

you are passing a empty array to the evnthandler script, [], so a _this select 0 would be generic error or out of bounds as there is no object in the array:

it should be like this:

_nul = [b][i]_this[/i][/b] execVM "Functions\eventHandlerKilled.sqf"

more info on eventhandlers, and you find a link to list there of all types of eventhandlers and what they return:

they all return

_this

_this contains various info based on type eventhandler.

in case of killed eventhandler:

_this is the same as : [unit, killer]

you can also add code directly into eventhandler, with some limitations, wich i do not know fully yet, though it is not fan of delays of any kind afaik:

example:

_x addEventHandler ["killed", {
_dead = _this select 0;
_killer = _this select 1;
_str = format["%1 killed by %2",_dead,(name _killer)];
_null = [nil,nil,rHINT,_str] call RE;
}];

you would need the function module placed on map for the hint to work, as the killed eventhandlers fire locally.

more info in the links above.

Share this post


Link to post
Share on other sites

Oh, right! I knew I must've been forgetting something. For some reason I figured since it was a script attached to the EH it would magic up the array out of thin air.

Anyway, the reason I have that script loop is that the second script, the hint, was actually a script based on adding money to the player unit (or in the case of NPC, the high command leading player unit). I didn't think to use a while true loop, and in fact I had always thought the engine would flip out at an infinite loop like that. I'll give that a shot too.

Thanks for the help guys C:

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  

×