More efficient way to detect if theres a player nearby?
Posted: 18.06.2016 9:47
by nyce
I need to detect if theres a player nearby me.
This should be done as fast as possible and the range of the search should be as big as possible as well.
Im using this bool function below. It does the job.
However it takes long to run, i think because of multiple Findtypes and TStringList.Create. Since is crucial for me to react fast when a played is detected, theres a better aproach?
function playercheck : Boolean;
var n : integer; l : TStringList;
begin
FindDistance := 40;
l := TStringList.Create();
Result := False;
FindType($190,ground); //m_human
GetFindedList(l);
if (l.count > 0) then
begin
Result := true;
ClientPrint(l[0]);
end;
l.free;
l := TStringList.Create();
FindType($191,ground); //f_human
GetFindedList(l);
if (l.count > 1) then // 1 cause my char is f
begin
Result := true;
ClientPrint(l[0]);
end;
l.free;
l := TStringList.Create();
FindType($25E,ground); //f_elf
GetFindedList(l);
if (l.count > 0) then
begin
Result := true;
ClientPrint(l[0]);
end;
l.free;
l := TStringList.Create();
FindType($25D,ground); //m_elf
GetFindedList(l);
if (l.count > 0) then
begin
Result := true;
ClientPrint(l[0]);
end;
l.free;
end;
function playercheck : Boolean;
var n : integer; l : TStringList;
begin
FindDistance := 40;
l := TStringList.Create();
Result := False;
FindType($190,ground); //m_human
GetFindedList(l);
if (l.count > 0) then
begin
Result := true;
ClientPrint(l[0]);
l.free;
exit;
end
else begin l.free; end;
l := TStringList.Create();
FindType($191,ground); //f_human
GetFindedList(l);
if (l.count > 1) then // 1 cause my char is f
begin
Result := true;
ClientPrint(l[0]);
l.free;
exit;
end
else begin l.free; end;
l := TStringList.Create();
FindType($25E,ground); //f_elf
GetFindedList(l);
if (l.count > 0) then
begin
Result := true;
ClientPrint(l[0]);
l.free;
exit;
end
else begin l.free; end;
l := TStringList.Create();
FindType($25D,ground); //m_elf
GetFindedList(l);
if (l.count > 0) then
begin
Result := true;
ClientPrint(l[0]);
l.free;
exit;
end
else begin l.free; end;
end;
Re: More efficient way to detect if theres a player nearby?
l := TStringList.Create();
FindType($191,ground); //f_human
GetFindedList(l);
if (l.count > 1) then // 1 cause my char is f
begin
Result := true;
ClientPrint(l[0]);
l.free;
exit;
end
else begin l.free; end;
function playercheck : Boolean;
begin
Result := FindTypesArrayEx([$190, $191, $25E, $25D],[$FFFF],[Ground],false) > 0;
If Result then
ClientPrint('$' + IntToHex(FindItem,8);
end;
Re: More efficient way to detect if theres a player nearby?
Posted: 18.06.2016 18:10
by nyce
Solved! I would like to thank Vizit0r for the tremendous support. Hes a code magician who can transform 40 lines in 4