SRL Archive - OSR Help

[Reflection] Detecting other players


neeger

2014-12-07 21:30:42

Looked through the reflection functions didn't find anything that could help me.
How can I detect other players near me? say 10 tile radius?

Frement

2014-12-07 21:46:16

As always, hooks needs updating, have a read here: https://villavu.com/forum/showthread.php?t=108798

Fitta

2014-12-08 07:15:15

From: Frement
As always, hooks needs updating, have a read here: https://villavu.com/forum/showthread.php?t=108798


I love you right now. Thank you for that link!

neeger

2014-12-08 16:14:25

Thank you, got it to work, now how can I add a tile radius to filter only those who are for example 10 tiles away from me?

program R_GetPlayers_TEST;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/Misc/SmartGraphics.Simba}
{$I SRL-OSR/SRL/reflection/Reflection.simba}

var
amount: Integer;

type
TPlayer = record
Name: String;
Level: Integer;
end;

TPlayerArray = Array of TPlayer;

function R_GetPlayers: TPlayerArray;
var
I, J, _Count, _Player, _Name, _Level: Integer;
begin
_Count := SmartGetFieldArraySize(SmartCurrentTarget, 0, 'client.ga', 0);
SetLength(Result, J);
for I := 0 to _Count - 1 do begin
_Player := SmartGetFieldArrayObject(SmartCurrentTarget, 0, 'client.ga', I);
if (_Player <= 0) then
Continue;
Inc(J);
SetLength(Result, J);
end;
amount := J-1; // subtract yourslef
end;

begin
SetupSRL;
SetupReflection;
repeat
R_GetPlayers();
Writeln('There are currently '+tostr(amount)+' players');
wait(1000);
until(false);
end.

Hoodz

2014-12-08 16:49:13

From: neeger
Thank you, got it to work, now how can I add a tile radius to filter only those who are for example 10 tiles away from me?


you need to get their location, then you just use distance(your loc, their loc)

Frement

2014-12-08 16:57:50

I'm surprised the class is the same after all these revisions.

neeger

2014-12-08 20:02:53

Oke, something like this?
 
if R_DistanceFromTile(PlayerLocation) > 5 then
....
How can I get "PlayerLocation"?

Frement

2014-12-08 20:09:46

From a quick glance I didn't see the hooks for player position in the updater logs when I looked, and I don't have an OSR account to test any values.

You can test these like shown in the thread I linked:
v * -207467453
f * 708620417

neeger

2014-12-08 20:53:16

Hmm I'm lost now :/

Frement

2014-12-08 21:18:21

From: neeger
Hmm I'm lost now :/


You can PM me an account and I can then confirm the new hooks.