PDA

View Full Version : isMapOpen();



Shield
11-07-2015, 03:37 PM
I have recently been having some trouble with SPS where it would sometime click the map button while trying to click on a point. I found that it occurs fairly rarely but when it happened my bot would stop as there is no built in function in the SRL Include to exit the map (at least there was none that I could find).

This is why I put together this guy:


function isMapOpen(): boolean;
var
mapOpenDTM, x, y: integer;
begin
mapOpenDTM := DTMFromString('mrAAAAHic42BgYLBkZWAwhGI3KDZhhYiDcD tQzSQgroViEBsk1gPETUB8czkvA4eoDAMbvwgYg9gv9xozHF9m zLCpQ4SBiQETMCFhRgIYBgCeYw1g');
result := false;
if (findDTM(mapOpenDTM, x, y, getClientBounds())) then
begin
writeln('Map Is Open.');
result := true;
end else
writeln('Map is not open.');
freeDTM(mapOpenDTM);
end;


This function will let you know if the map is opened on the screen.

I have gone further and wrote an override of the TSPSArea.walkPath function where you can implement the above function to use if the script accidentally clicks on the map while walking.


function TSPSArea.walkPath(path: TPointArray; waitMoving: Boolean = True; shiftInterval: Integer = 500): boolean; override
var
p, lastPos, mmPoint: TPoint;
t, fails, h, l, i, dx, dy, mapOpenDTM: integer;
dtmTimer: TTimeMarker;
begin
mapOpenDTM := DTMFromString('mrAAAAHic42BgYLBkZWAwhGI3KDZhhYiDcD tQzSQgroViEBsk1gPETUB8czkvA4eoDAMbvwgYg9gv9xozHF9m zLCpQ4SBiQETMCFhRgIYBgCeYw1g');
result := false;

h := high(path);
l := low(path);

t := (getSystemTime() + randomRange(15000, 20000));

repeat
if (not isLoggedIn()) then
exit(false);

p := self.getPlayerPos();

for i := h downto l do
if (SPS_PosToMM(path[i], p, mmPoint)) then
begin
if (distance(minimap.getCenterPoint(), mmPoint) >= 10) then
begin
if (spsMultiMouse) then
multiClick(mmPoint, 25, 3)
else
mouse(mmPoint, MOUSE_LEFT);

if (minimap.isFlagPresent(2500 + random(500))) then
minimap.waitFlag(10 + random(25));
end;

t := (getSystemTime() + randomRange(15000, 20000));

result := (i = h) or (distance(path[i], path[h]) < 10);

if (result) then
break(2)
else
break();

end;

if (p.x = lastPos.x) and (p.y = lastPos.y) then
inc(fails);

lastPos := p;

dtmTimer.start;
if (findDTM(mapOpenDTM, dx, dy, getClientBounds())) then
begin
repeat
writeln('Map Is Open. We will try to close it.');
wait(randomrange(250, 750));
moveMouse(dx, dy);
fastClick(MOUSE_LEFT);
until(not (findDTM(mapOpenDTM, dx, dy, getClientBounds())) or dtmTimer.getTime > 15000);
end;

until (getSystemTime() > t) or (fails > 5);

if waitMoving then
if (minimap.isFlagPresent() or minimap.isPlayerMoving()) then
minimap.waitPlayerMoving(shiftInterval);

print(self.getName()+'.walkPath(): result = '+boolToStr(result));
freeDTM(mapOpenDTM);
end;


I know that you could make is simpler by having that little section as its own procedure, but this is just something I quickly whipped up.

I seemed to notice that this problem could be seen as human error, which I find kind of useful in making sure you dont get banned. :D

Incurable
11-08-2015, 03:10 PM
I tried repping you buuuuut...

http://i.imgur.com/yiKBoHw.png

I've never had SPS click on the map button before, does this happen to you often? I also notice that the loop you use to close the map in the override function basically won't end unless the map is closed. What if something goes wrong and it never closes?

Shield
11-08-2015, 05:02 PM
I tried repping you buuuuut...

http://i.imgur.com/yiKBoHw.png

I've never had SPS click on the map button before, does this happen to you often? I also notice that the loop you use to close the map in the override function basically won't end unless the map is closed. What if something goes wrong and it never closes?

Ha ha. Thanks! It happens only when the next 'visible' point is close to the map button. I could always use a timer (which I totally forgot to add) but the DtM is fairly unique. The DtM is the exit button on the map, which I don't think is used anywhere else in the game (I could be wrong) but even if it is used somewhere else it would most likely be another exit button on some sort of other interface, therefore I can't see it ever finding the DTM without there being some sort of interface loaded.

But I definitely should add a timer.

Incurable
11-08-2015, 05:57 PM
But I definitely should add a timer.

It's basically just a case of covering the "what if?" scenarios. It's probably never going to be necessary, but what if it was? :p

Shield
11-08-2015, 06:14 PM
It's basically just a case of covering the "what if?" scenarios. It's probably never going to be necessary, but what if it was? :p

Yea man! Better to be safe than sorry. Plus it couldn't hurt to add another failsafe.

I'll add one when I get to my computer. :D

Man16
06-10-2016, 10:12 PM
Thanks, using this now and will see how it works out.

Edit: Sometimes it will randomly say the map is open but it is not. I guess I will find a workaround. I adjusted the break timer to 10 seconds instead.