Twinki
2015-01-25 00:48:44
{------------------------------------------------------------------------------)
Function: FindTheTwinki
Description: Custom FindObject. Anyone is welcome to use this, I just ask you provide credits where it's due!
Credits: Twinki (Thank you TheMayor, hoodz, Ross, and BMWxi for the help!)
(------------------------------------------------------------------------------}
function FindTheTwinki(Hue, Sat: extended; Color, Tolerance, Filter, clickType: Integer; mouseOverText, chooseOptions: array of string;
MouseMove: boolean = true; FindRelativeObject: boolean = false; rHue, rSat: extended = 0; rColor, rTolerance: Integer = 0; excludePointsDist: Integer = 150): boolean;
Label
retry;
Var
attempts, X, Y, i: integer;
rTPA, TPA: TPointArray;
ATPA: T2DPointArray;
rPoint: TPoint;
isPlayerMovingTimer: TTimeMarker;
begin
if not isLoggedIn() then exit;
if scriptSMARTDebug then smartImage.clear();
//minimap.waitPlayerMoving();
//if (waitForLoading(2500, 2500)) then Wait(randomRange(750, 1500));
repeat
if scriptSMARTDebug then smartImage.clear();
if FindRelativeObject = true then
begin
findColorsSpiralTolerance(X, Y, rTPA, rColor, mainScreen.getBounds(), rTolerance, colorSetting(2, rHue, rSat));
if length(rTPA) < 1 then exit;
if scriptSMARTDebug then smartImage.debugTPA(rTPA, false);
rPoint := middleTPA(rTPA);
end;
findColorsSpiralTolerance(X, Y, TPA, Color, mainScreen.getBounds(), Tolerance, colorSetting(2, Hue, Sat));
if length(TPA) < 1 then exit(false);
if FindRelativeObject = true then TPA.excludePointsDist(0, excludePointsDist, rPoint.x, rPoint.y);
ATPA := TPA.toATPA(30, 30);
ATPA.filterBetween(1, Filter);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
if scriptSMARTDebug then smartImage.debugATPA(ATPA);
for i := 0 to high(ATPA) do
begin
if scriptSMARTDebug then smartImage.drawText('ATPA Length: '+IntToStr(length(ATPA[i])), point(ATPA[i][0].x+10, ATPA[i][0].y+10), clLime);
if (length(ATPA[i]) <= 10) then Continue; //*Will go to the next indext if the current TPA length (in the ATPA) is less than 10
if MouseMove = true then Mouse(ATPA[i].getBounds().getRandomPoint(), MOUSE_MOVE);
if MouseMove = false then Mouse(ATPA[i].getBounds().getRandomPoint(), MOUSE_NONE);
if isMouseOverText(mouseOverText, 150) then
begin
if clickType = MOUSE_NONE then exit(true);
fastClick(clickType);
if clickType = MOUSE_LEFT then SmallRandomMouse();
Wait(randomRange(250, 750));
if chooseOption.optionsExist(chooseOptions) then
chooseOption.select(chooseOptions, 1000);
exit(true);
end
else Continue;
end;
WriteLn('Failed FindTheTwinki, re-trying');
Wait(randomRange(1000, 2000));
inc(attempts);
WriteLn('attempts: '+toStr(attempts));
until attempts >= 5;
//if scriptSMARTDebug then smartImage.clear();
end;
I've been trying to implement a failsafe using attempts, however everytime it goes back to the top to repeat, it crashes Simba. No error message or log, it just closes it.
I was able to open Simba via Command Prompt to grab the error code:
formWriteln: Failed FindTheTwinki, re-trying
formWriteln: attempts: 1
formWriteln: Error: Access violation
formWriteln: Execution failed.
formWriteln: Exception TLPThread.Destroy: Access violation
[FORMS.PP] ExceptionOccurred
Sender=EAccessViolation
Exception=Access violation
Stack trace:
$0040FF31
$0076F21D
$0040C0B2
$0040C0B2
TApplication.HandleException Access violation
Stack trace:
$0040FF31
$0076F21D
$0040C0B2
$0040C0B2
[FORMS.PP] ExceptionOccurred
TApplication.HandleException: there was another exception during showing the fir
st exception
Stack trace:
$0040FF31
$0041B098
$00419637
$00419661
$0040C0B2
$004164CD
$0040EEC9
$0040CEE4
$0040D159
$0040CEE4
$0040D159
$0040C0B2
TApplication.HandleException: there was another exception during showing the fir
st exception
Stack trace:
$070C81FB
$0041B098
$00419637
$00419661
$0045B12F
$0040C0B2
$004159B8
$0040ED68
$0041B3A5
$0041B0CA
$00419637
$00419661
$0040C0B2
$004164CD
$0040EEC9
$0040CEE4
$0040D159
I'm not sure what I've done wrong. This only happens after I added a repeat loop. Any help is appreciated