SRL Archive - OSR Help

[reflection] Detecting other players


jhildy

2014-04-26 16:28:18

I've been looking through the reflection includes, and I was wondering if there were any specific functions made for finding other players withing your sight. If not, are there any good ways to accomplish this. What I am trying to do is figure out the number of players in the immediate area near me in order to determine the best world to chop magics in. I want to release a script that cycles through the worlds and stores the number of other players in each in order to narrow down the worlds that would be good for cutting in. Also, what happened to the DTM string generator, I can't seem to find it in Simba. DTMs would probably be the other way I would go about this, but I would prefer to do it with reflection just to make it more accurate. Thanks for the help!

Frement

2014-04-26 16:32:35

http://villavu.com/forum/showthread.php?t=108592&p=1290751#post1290751

Let me get you the new hooks, sec.

EDIT: Here
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}

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

TPlayerArray = Array of TPlayer;

function CreatePlayer(Name: String; Level: Integer): TPlayer;
begin
Result.Name := Name;
Result.Level := Level;
end;

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);
_Name := SmartGetFieldObject(SmartCurrentTarget, _Player, 'e');
_Level := SmartGetFieldInt(SmartCurrentTarget, _Player, 'j') * 1106596591;
Result[J - 1] := CreatePlayer(R_GetJavaString(_Name, 512), _Level);
SmartFreeObject(SmartCurrentTarget, _Name);
SmartFreeObject(SmartCurrentTarget, _Player);
end;
end;

begin
SetupSRL;
SetupReflection;
Writeln(R_GetPlayers);
end.

jhildy

2014-04-26 16:36:59

Thanks, this is exactly what I was looking for. Now is this just limited to players on the currently loaded screen? I know I could filter them out after the fact by checking their tile position, but I am just wondering how far away this detects other players. Also, is there a field for the location of each player?

Frement

2014-04-26 16:49:20

From: jhildy
Thanks, this is exactly what I was looking for. Now is this just limited to players on the currently loaded screen? I know I could filter them out after the fact by checking their tile position, but I am just wondering how far away this detects other players. Also, is there a field for the location of each player?


Heres with the location of the player, and it gets all the players from currently loaded region, which is 104x104.

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}

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

TPlayerArray = Array of TPlayer;

function CreatePlayer(Name: String; Level: Integer; Tile: TPoint): TPlayer;
begin
Result.Name := Name;
Result.Level := Level;
Result.Tile := Tile;
end;

function R_GetPlayers: TPlayerArray;
var
I, J, _Count, _Player, _Name, _Level, _X, _Y: 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);
_Name := SmartGetFieldObject(SmartCurrentTarget, _Player, 'e');
_Level := SmartGetFieldInt(SmartCurrentTarget, _Player, 'j') * 1106596591;
_X := (SmartGetFieldInt(SmartCurrentTarget, 0, client_baseX) * client_baseX_Multiplier) + (SmartGetFieldInt(SmartCurrentTarget, _Player, 's') * -806469611) div 128;
_Y := (SmartGetFieldInt(SmartCurrentTarget, 0, client_baseY) * client_baseY_Multiplier) + (SmartGetFieldInt(SmartCurrentTarget, _Player, 'y') * -54698801) div 128;
Result[J - 1] := CreatePlayer(R_GetJavaString(_Name, 512), _Level, Point(_X, _Y));
SmartFreeObject(SmartCurrentTarget, _Name);
SmartFreeObject(SmartCurrentTarget, _Player);
end;
end;

begin
SetupSRL;
SetupReflection;
Writeln(R_GetPlayers);
end.

jhildy

2014-04-27 08:53:56

Thanks! This is awesome.