Greetings.
I am breaking my head here, and have tried a million variations, but can't seem to get simple variable addition and testing to work. Can someone help me please.
The Idea.
A soldier is unarmed, and gets a task to move to a location. Working 100%
A Trigger on the way assigns a gun to the soldier and new task. Working 100%
The new task is to kill 3 people. Not working
Now I have tried so many flavours I am almost crying. The 3 people he has to kill is not in a group, nor are they the only 3 people in a area. So what I have done is to add on there init box
this addEventHandler ["killed", {_this exec "kill_task2.sqf"}];
in my kill_task2.sqf file I have
_this removeAllEventHandlers "killed";
_bodies = player getVariable "num_task2";
if ( _bodies > 2) then
{
hint format['Guards Killed %1',_bodies];
task2 setTaskState "SUCCEEDED";
[task2] call mk_fTaskHint;
} else
{
_bodies = _bodies + 1;
player setVariable ["num_task2", _bodies];
hint format['Guards Killed %1',_bodies];
};
The idea is to simply call the script on the kill, incrament the kill count, and when all 3 guards are dead, finish the task...
Right now The scripts is called twice for every kill, resulting in double numbers on the hint, and both the if and else is executing???
What am I doing wrong here...
---------- Post added at 03:35 PM ---------- Previous post was at 02:00 PM ----------
So I have simpliefied the script even more...
_obj = _this select 0;
_obj removeEventHandler ["killed", 0];
num_task2 = num_task2 + 1;
hint format['Guards Killed %1',num_task2];
but still get 2 Guards killed if I kill only 1
another version
_obj = _this select 0;
_obj removeEventHandler ["killed", 0];
sleep 10;
num_task2 = num_task2+1;
hint format['Guards Killed %1',num_task2];
sleep 10;
if (num_task2==3) then
{
task2 setTaskState "SUCCEEDED";
[task2] call mk_fTaskHint;
}
This one starts to count better, but sometime I get a 2 count and sometime a 1 ???