SRL Archive - Reflection Development

[suggestion] R_GetInteractingNPCs


superuser

2011-08-25 14:15:19

I think this is necessary, as R_GetInteractingNPC only returns first interacting NPC. This is highly inconvenient, as for example if the player has summoned familiar and fights a monter, it only returns the familiar. The following returns all NPCs interacting.

function R_GetInteractingNPCs(Null: Boolean): TNPCArray;
var
MyPlayer, InteractingPlayer: TPlayer;
NPCs: TNPCArray;
I, H, PlayerIndex: Integer;
begin
MyPlayer := R_GetMe;
NPCs := R_GetAllNPCs(Null);

H := High(NPCs);
for I := 0 to H do
begin
PlayerIndex := NPCs[I].Interacting - 32768;
if(PlayerIndex < 0)then
Continue;
InteractingPlayer := R_GetPlayer(PlayerIndex);
if(InteractingPlayer.Name = MyPlayer.Name)then
begin
SetLength(result, Length(result) + 1);

result[High(result)] := NPCs[I];
end;
end;
end;

Nava2

2011-08-25 16:18:55

I like the idea, the code could be much more efficient, but I like the idea. Perhaps just grab the Player name information (aka the strong objects, vs. all the player information), as well the resulting npcs could be more efficiently taken out of the loop.

Just some things. :)

superuser

2011-08-25 16:53:52

From: Nava2
I like the idea, the code could be much more efficient, but I like the idea. Perhaps just grab the Player name information (aka the strong objects, vs. all the player information), as well the resulting npcs could be more efficiently taken out of the loop.

Just some things. :)


I agree, the code is copy-paste from actual ref.2 with just a minor changes, but the idea is clear :)

Drakan

2011-08-26 10:54:48

It's a good suggestion and i'll be sure to implement it in the coming days! Thanks for pointing it out :)

mormonman

2011-09-02 05:43:33

I cut the time down a ton using some minimalistic(made up word) functions.
Went from 48-50ms down to 12-13ms per call.
http://villavu.com/forum/showthread.php?p=829944#post829944