Using BIS ModulesI think using them requires the Functions Module to be placed in the editor.
That's why I don't want to use it.And from what you've said, it is checking the objects on the entire map.
I wanted to check the object only if there are within a specified distance.
------------------------
-showscripterrorsI've been using that thing from the day that I've started to script in ArmA 2
(And sometimes it won't show errors like : '{' is missing )
I compiled the function using :
H_Check_Dis=compile preprocessFile "script.sqf"
What's the difference between preprocessFile and preprocessFileLineNumbers? --------------
sleep commandThe function is at the bottom of this post.
Note that I've not added any sleep commands in it.
-------------
Testing the function :The array contained about 46 us soldiers(
listed using trigger, and yes,I've put a delay of 2 secs in the trigger which calls the script) and the object was a civilian put in the middle of those us men.
The zombie man (civilian) was taking a while before he got the nearest victim.
And sometimes he act like he's stuck(turning around standing at the same position)
The function is to be called
every 2 seconds via my extra long main zombie script.
(that main script was run by ALL the zombies)
And I've got a problem :
The problem is that it is taking a bit long for the zombies to check the nearest victim.
And what should I do to fix that prob?
The syntax i use for calling the function is :
_h_victim=[_h_zom,_h_victimarray] call H_Check_Dis;
Note : h_victim is the current victim for _h_zom while _h_victimarray being the array of victims
here is the actual function One can define the radius for the check with my Function. //Pass an object and an array of objects and the checking radius, the result is the
//object in the array which is nearest to the object.
//
//eg : [man1,[car1,truck1,plane1],400] CALL H_Func_NearestToObject
// If car1 is nearest to man1 and is in the radius, result will be car1.
private ["_i"];
_i=0;
_output="";
_loop=0;
_radius=0;
_min=0;
_dist=0;
_filtered=0;
_unit = _this select 0;
_array = _this select 1;
_radius = _this select 2;
if (isNil "_array") then {_array=nearestObjects [_unit,["MAN"],50];
if (isNil "_radius") then {_radius=60};
//For Loop until _i matches the _array's element count/room count
for [{_i=0},{_i < count _array},{_i=_i+1}] do
{
_cur_element_dis=(_array select _i) distance _unit;
if (_cur_element_dis < _radius) then
{
_min=_radius min _cur_element_dis;
if (_min < _radius) then
{
_radius=_cur_element_dis;
_filtered=_i;
}
};
//Debugging...
//hintSilent format ["Min : %1\nMax : %2\nCur_Element_Dis : %3\nVictim : %4\nElement: %5(Name: %6)\nLoop %7",_min,_radius,_cur_element_dis,_output,_i,_array select _i,_loop];
};
if (not (isNull (_array select _filtered))) then
{
_output= _array select _filtered;
};
_output;
What i am concerned about is:
is my script written in the proper way?
Can i make a change to the script so that it's gives out performance?
I found no errors with the isnull,but I was curious if it is written correctly...,is it?