SRL Archive - Research & Development Lounge

SPAMS2 location detectiony stuff


mixster

2010-02-07 12:07:14

Currently working on producing a second version of SPAMS. At the moment I'm working on refining the location detection - just need to work on perfecting the ratio.

Note: you will have to download a ~12MB file that has a local world map saved in it. They should be placed in a folder named 'tiles' in Scar's directory, so it would be 'SCAR 3.xx\tiles\tile.1000.1500.bmp' as an example).
Link to the tiles (it does also have a readme, but you can ignore it as it was for Heavenguard who awesomely decided to help me do a tedious bit).
Or http://www.mediafire.com/?zytnzu0i0oe

Second note: Some of the functions are Zyt3x's or based upon Zyt3x's and credit will be given to him in the script when I'm finished, but until then it is here instead :)

{.include srl/srl.scar}
const
MOX1 = 609;
MOY1 = 311;
MOX2 = 757;
MOY2 = 560;
RATX = 31.1;
RATY = 30.5;

function IsMapUp : Boolean;
var
tmp: string;
begin
Result := GetMMLevels('hp', tmp) = -1;
end;

function OpenWorldmap : Boolean;
var
T : Integer;
begin
if IsMapUp then
begin
Result := True;
exit;
end;

MouseOval(542, 140, 15, 15, 1);

Wait(1500);
T := GetSystemTime + 15000;
while (GetColor(230, 196) = 1118604) and (GetSystemTime < T) do
Wait(200);

Result := IsMapUp;
end;

procedure CloseMap;
begin
MouseBox(741, 11, 754, 24, 1);
Wait(1500);
if not IsMapUp then
Wait(1000);
end;

function IsOverviewUp: Boolean;
begin
Result := (CountColor(0, MOX1, MOY1, MOX2, MOY2) >= 500) and (CountColor(255, MOX1, MOY1, MOX2, MOY2) >= 10);
end;

function SetMapOverview(open: Boolean): Boolean;
begin
if open <> IsOverviewUp then
begin
MouseBox(667, 470, 697, 490, 1);
Wait(250);
Result := open <> IsOverviewUp;
end
else
Result := True;
end;

function ChangeZoom(zoomin: Boolean): Boolean;
begin
Result := IsMapUp;

if not Result then
exit;

MouseBox(743, 465 + (Integer(not zoomin) * 14), 756, 480 + (Integer(not zoomin) * 14), 1);
end;

function GetWorldPos: TPoint;
var
tpa: TPointArray;
atpa: T2DPointArray;
box: TBox;
i: Integer;
begin
Result := Point(-1, -1);

if not OpenWorldMap then
exit;

if not SetMapOverview(true) then
if not SetMapOverview(true) then
exit;

FindColorsTolerance(tpa, 255, MOX1, MOY1, MOX2, MOY2, 5);

if (Length(tpa) <= 15) then
exit;

atpa := SplitTPA(tpa, 3);
for i := 0 to High(atpa) do
if (Length(atpa[i]) >= 15) then
begin
box := GetTPABounds(atpa[i]);
break;
end;

if (i = Length(atpa)) then
exit;

Result := Point((box.x1 + box.x2) div 2, (box.y1 + box.y2) div 2);
end;

var
t: TPoint;
o: TPoint;
b: Integer;
i: Integer;
begin
ActivateClient;
SetupSRL;
Wait(2500);

t := GetWorldPos;
Writeln(IntToStr(t.x) + ',' + IntToStr(t.y));
MMouse(t.x, t.y, 1, 1);

t.x := Round((t.x - 617) * RATX);
t.y := Round((t.y - 333) * RATY);

o := Point(t.x mod 500, t.y mod 500);
b := LoadBitmap(AppPath + 'tiles\tile.' + IntToStr(t.x - o.x) + '.' + IntToStr(t.y - o.y) + '.bmp');

DisplayDebugImgWindow(500, 500);
Wait(250);
SafeDrawBitmap(b, GetDebugCanvas, 0, 0);

GetDebugCanvas.Pen.Color := clRed;
GetDebugCanvas.Brush.Color := clYellow;
GetDebugCanvas.Brush.Style := bsBox;

GetDebugCanvas.Rectangle(o.x - 16, o.y - 15, o.x + 16, o.y + 15);

SafeCopyCanvas(GetDebugCanvas, GetBitmapCanvas(b), 0, 0, 500, 500, 0, 0, 500, 500);

for i := 1 to 50 do
if not FileExists(AppPath + 'SPAMS' + IntToStr(i) + '.bmp') then
break;

if i = 51 then
begin
Writeln('50 already exist, so you kind of need to clear some first');
end
else
begin
SaveBitmap(b, AppPath + 'SPAMS' + IntToStr(i) + '.bmp');
end;

Writeln(IntToStr(t.x) + ',' + IntToStr(t.y));
end.

Just run it when your character is logged in and it should do the rest. After it runs, open up the bitmap (it will be in the form SPAMSxx.bmp where xx is a number saved in your Scar's directory) and check out how accurate it is (preferably mark on the bitmap where you actually were). I just need this to refine the numbers I'm using - I know they're roughly right at the moment, but I only have 1 char and it's quite annoying having to run around to different places to test it :(

Edit: Already improved it slightly thanks to sexy RM
Edit2: Another little change and made the ratios a constant for more sexy changing.

Sir R. M8gic1an

2010-02-07 12:21:15

PMing you my chars for you to use them to test :)

~RM

mixster

2010-02-07 13:15:36

So far it's looking accurate for F2P RS - I don't suppose any members want to try it in the extremities of the desert as those should be the most inaccurate of places, though anywhere member-related would be nice :)

Gu3st...

2010-02-07 14:00:12

Hey, cool :)
I'll test right away!

Timer

2010-02-07 15:16:09

oh noes, I think this might replace yours Zyt3x. :p

Home

2010-02-07 16:02:54

Can't DL Map :S

mixster

2010-02-07 16:08:03

From: Home
Can't DL Map :S


Please elaborate as the download link is still up :(

Gu3st...

2010-02-07 16:12:07

From: Timer
oh noes, I think this might replace yours Zyt3x. :p
Mine was based on SPAMS ;)
Without it I wouldn't make my own. The only reason why I made my own instead of using SPAMS was because of the plugin and the time it took to calculate the path

EDIT: Yeah, Chrome stopped downloading for me.. I'll try again

Timer

2010-02-07 16:20:12

Can't download… :(


Gu3st...

2010-02-07 16:26:31

Same here. Can't find the page

mixster

2010-02-07 17:20:56

I've added a mediafire link now - should hopefully work (http://www.mediafire.com/?zytnzu0i0oe if you don't want to look at first post)