R_GetAllNPCs returns a length 0 array time to time. From what it looks like, the first time it is called it works, but the second time it doesn't, and then the third works. It looks like it flips like that.
I assume it's because of the switch to LocalIndex? I don't have the reflection technical know-how to fix, but I'm currently dabbling; I might be able to help.
EDIT:
Looks like for the first call, a -1 gets into the result for R_GetIndices() for this part of the code:
Simba Code:
for i:=0 to 99 do
begin
Result[i] := SmartGetFieldArrayint(SmartCurrentTarget, 0, client_npcIndices, i);
end;
Result:= RemoveDeadTIA(Result);
Resulting in LocalIndex not being used until the second call, when the -1 doesn't appear anymore. I guess catching the -1 would be a good call? I don't know if that ever appears when NPCIndex is working properly, so it would be a quick bugfix.
Replacing the above with this fixes the issue.
Simba Code:
for i:=0 to 99 do
begin
Result[i] := SmartGetFieldArrayint(SmartCurrentTarget, 0, client_npcIndices, i);
if result[ i ] = -1 then // Hack-fix for 6/26/14 OSRS update.
result[ i ] := 0; // To be caught under RemoveDeadTIA.
end;
Result:= RemoveDeadTIA(Result);