SRL Archive - OSR Help

Custom Dropping Proc.


Valithor

2013-01-11 17:27:17

haha. So, I feel like you guys are starting to hate me, because I don't ever really post unless it's because I'm having scripting issues. :( Though, I promise I'm trying to figure out how to be a decent scripter! Don't hate! :redface:

EDIT: Ok, so I'm back with another question… This time in regards to "ActionBarSlotToBox();". This part of the script I'm trying to search the Action Bar for an object. I want to use "FindObjTPA();" and if it's found, it should return the number of the box. If not, it should Result:= 0;. The issue? If the object isn't found I always get "Error: Out of Range". What am I doing wrong?

function SearchActionBar(color, tol: Integer; hue, sat: Extended; StartBox, EndBox: Integer; UpText: TStringArray): Integer;
var
actionSlot: TBox;
invPattern: TIntegerArray;
tmpCTS, x, y, I: Integer;

begin
invPattern := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; //Sets array length, and what boxes to search.
tmpCTS:= GetColorToleranceSpeed; //grabs current CTS
ColorToleranceSpeed(2); //sets the CTS to CTS2
SetColorSpeed2Modifiers(hue, sat); //changes the modifiers

for I:= (StartBox) to (EndBox) do //Using a "for..to..do.." loop to search (Duh!)
begin
actionSlot:= ActionBarSlotToBox(invPattern[I]); // "ERROR: Out of Range" happens here
x:= actionSlot.x1+5; //Adjusting the coordinates
y:= actionSlot.y1+5; //just to help FindObjTPA

MMouse(actionSlot.x1, actionSlot.y1, 20, 20); //Just using this to visually see how it searches the box
Writeln('Searching Box '+IntToStr(invPattern[I])); //Debugging Evidence
if FindObjTPA(x, y, color, tol, 2, 4, 4, 12, UpText) then //IF we find the object then...
begin
Writeln('FindObjTPA resulted "True"; Object is in actionSlot['+IntToStr(invPattern[I])+'].');
result:= invPattern[I]; //Should result the number of the box, right?
Exit;
end;
end;

//if we failed to find it then...
SetColorSpeed2Modifiers(0.2, 0.2); //reset the CTS2 modifiers
ColorToleranceSpeed(tmpCTS); //reset the CTS
Result:= 0;
end;

My Original Issue (note: read my edit post to see the fix)
Ok, I'm sure this will be a quick fix... I just can't get my head around how to solve it though. I've tried a couple different ways, but nothing seems to work.  The idea is that it would use SearchInvColor(); to double check the inventory to make sure it's full.  Then I wanted to use a custom TPA to find the Crayfish in an Action bar box.  I suppose that I could just do coordinates, but what's the fun in that, right? 

The problem is that, it seems to search the box for the color, but the TPA length always turns out to be 0 points long. I have no idea why. I've checked my coordinates, so they should be okay. The problem seems to around FindColorsSpiralTolerance();, but I don't know what I'm doing wrong.

Any thoughts?

P.S. All this is to update my Lumbridge Crayfisher, if that wasn't clear.

My Code:
[SIMBA]program new;
{$DEFINE SMART}
{$i srl/srl.simba}

function SearchInvColor(Color, Tol: Integer; Hue, Sat: Extended; StartInvBox, EndInvBox: Integer): Boolean;
var
I, x, y, tmpCTS: integer;
invPattern: TIntegerArray;
slotBox:TBox;

begin
tmpCTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2); //searches using CTS 2
SetColorSpeed2Modifiers(Hue, Sat); //Hue and Sat modifiers

invPattern := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]; //the pattern it searches in

Writeln('Checking for the object in your Inventory.');
for I:= (StartInvBox) to (EndInvBox) do
begin
slotBox:= InvBox(invPattern[I]);
{Writeln('Checking item colors in InvBox['+IntToStr(invPattern[I])+']'); }
if (not FindColorTolerance(x, y, Color, slotBox.x1, slotBox.y1, slotBox.x2, slotBox.y2, Tol)) then
begin
Writeln('Could not find the color in InvBox['+IntToStr(invPattern[I])+']!');
Result:= false;
Exit;
end;
end;

SetColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Writeln('We have confirmed that your inventory is full.');
Result:= true;
end;

procedure DropInventory;
var
Points: TPointArray;
aPoints: T2DPointArray;
myPoint: TPoint;
barBox: TBox;
I, tmpCTS, a, b: Integer;

begin
barBox:= IntToBox(370, 346, 402, 377); //the box the Crayfish will be in
a:= 383; //middle "x" for the box
b:= 364; //middle "y"

if SearchInvColor(1914720, 12, 0.03, 0.11, 0, 27) then //Made to double check inv
begin
tmpCTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);

SetColorSpeed2Modifiers(0.03, 0.11);
Writeln('Beginning to search the Action Bar for the Crayfish.');
FindColorsSpiralTolerance(a, b, Points, 1914720, barBox.x1, barBox.y1, barBox.x2, barBox.y2, 12);
ColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);

if Length(Points) = 0 then //Points will always return "0"
begin //Issue with FindColorsSpiralTolerance?
Writeln('TPA Length is "0".');
Writeln('Object was not found.');
Exit;
end;

Writeln('Object found.');
aPoints:= TPAtoATPAEX(Points, 7, 7);
SetLength(Points, 0);
for I := 0 to High(aPoints) do
begin
if Length(aPoints[i]) < 3 then
Continue;
myPoint := MiddleTPA(aPoints[i]);
MMouse(myPoint.X, myPoint.Y, 3, 3);
end;
end;

ColorToleranceSpeed(tmpCTS);
end;


begin
SetupSRL;
DropInventory;
end.[/SIMBA]

Awkwardsaw

2013-01-12 12:24:22

Try out DTMs. Also, what does it print out for your debugging?

doxin

2013-01-13 01:17:08

for
FindColorsSpiralTolerance(a, b, ...
isn't A and B the coordinates for where the spiraling starts?

EDIT: sorry did not notice you set coordinates for those variables

Valithor

2013-02-04 02:16:54

@Awkwardsaw - I would try DTMs, but I always have issues with them. Weird how TPAs make more sense. O.o

Having an "Out of Range" issue, so I updated my orginal post, as to avoid making another thread. I'm pretty sure you guys don't want to see another "Help" thread from me. ;) Anyway, I really appreciate the help that was given earlier. I kinda dropped the whole idea of using a custom TPA, and from here on out will use a "unique color" to find my object.

End result was…
function CheckInvColors(Color, Tol: Integer; Hue, Sat: Extended; StartInvBox, EndInvBox: Integer): Boolean;
var
I, x, y, tmpCTS: integer;
invPattern: TIntegerArray;
slotBox:TBox;

begin
tmpCTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2); //searches using CTS 2
SetColorSpeed2Modifiers(Hue, Sat); //Hue and Sat modifiers

invPattern := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]; //the pattern it searches in

Writeln('Checking for colors in your Inventory.');
for I:= (StartInvBox) to (EndInvBox) do
begin
slotBox:= InvBox(invPattern[I]);
//Writeln('Checking item colors in InvBox['+IntToStr(invPattern[I])+']');
if (not FindColorTolerance(x, y, Color, slotBox.x1, slotBox.y1, slotBox.x2, slotBox.y2, Tol)) then
begin
Writeln('Could not find the color in InvBox['+IntToStr(invPattern[I])+']!');
Result:= false; // Could not find color
Exit;
end;
//MMouse(x, y, 10, 10);
end;

SetColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Result:= true;
end;

i luffs yeww

2013-02-04 04:28:07

From: Valithor
EDIT: Ok, so I'm back with another question… This time in regards to "ActionBarSlotToBox();". This part of the script I'm trying to search the Action Bar for an object. I want to use "FindObjTPA();" and if it's found, it should return the number of the box. If not, it should Result:= 0;. The issue? If the object isn't found I always get "Error: Out of Range". What am I doing wrong?

function SearchActionBar(color, tol: Integer; hue, sat: Extended; StartBox, EndBox: Integer; UpText: TStringArray): Integer;
var
actionSlot: TBox;
invPattern: TIntegerArray;
tmpCTS, x, y, I: Integer;

begin
invPattern := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; //Sets array length, and what boxes to search.
tmpCTS:= GetColorToleranceSpeed; //grabs current CTS
ColorToleranceSpeed(2); //sets the CTS to CTS2
SetColorSpeed2Modifiers(hue, sat); //changes the modifiers

for I:= (StartBox) to (EndBox) do //Using a "for..to..do.." loop to search (Duh!)
begin
actionSlot:= ActionBarSlotToBox(invPattern[I]); // "ERROR: Out of Range" happens here
x:= actionSlot.x1+5; //Adjusting the coordinates
y:= actionSlot.y1+5; //just to help FindObjTPA

MMouse(actionSlot.x1, actionSlot.y1, 20, 20); //Just using this to visually see how it searches the box
Writeln('Searching Box '+IntToStr(invPattern[I])); //Debugging Evidence
if FindObjTPA(x, y, color, tol, 2, 4, 4, 12, UpText) then //IF we find the object then...
begin
Writeln('FindObjTPA resulted "True"; Object is in actionSlot['+IntToStr(invPattern[I])+'].');
result:= invPattern[I]; //Should result the number of the box, right?
Exit;
end;
end;

//if we failed to find it then...
SetColorSpeed2Modifiers(0.2, 0.2); //reset the CTS2 modifiers
ColorToleranceSpeed(tmpCTS); //reset the CTS
Result:= 0;
end;


You're getting an out of range error if it's not found because you're trying to search from 1 (this part actually doesn't matter as long as it's not 12) to 12, and the highest index of your invPattern array is actually 11 (remember that indexing starts at 0!). So if you pass 12 to EndBox, it will try to access the 12th index of invPattern, which doesn't exist. You could search up to EndBox - 1, and it should work. You should also add some error checking before the loop by adding something like


if StartBox < 1 or EndBox > 12 then
Exit;

Hope that helps.

Valithor

2013-02-04 10:18:39

Thanks i luff yews! That made total sense! I really can't believe I didn't think about that sooner. :facepalm:
I added the error check that you suggested at the very beginning of the procedure, and I receive a type mismatch error.
Otherwise when I remove it… it runs well now.
Thanks again.

Edit: I removed the error-check to avoid a "type mismatch" error (which I would like to conquer later), but now if the object is in the action bar at all, the script will search the first box, and the instantly jump to the object and results:= 1;.

but… Why?

if the object isn't in the first box shouldn't loop through each box until it finds it?
My debug reads…
Searching Box 1
FindObjTPA resulted "True"; Object is in actionSlot[1].
My Box is: 1.

Edit 2: The issue seems to revolve around the height, width, and mincount of FindObjTPA();. If either one of them are too low… it tends to jump to the object. If they are too high sometimes they totally skip it…

Edit 3: Decided to temporarily resolve the issue by using WaitUptextMulti();. Would prefer to use some color-finding first.

Valithor

2013-03-20 00:03:10

Let's assume for a second that you want to add a TList to a Form that you are making. For complexity's sake we are going to say that you only want to have two(2) items in your TList. The trick is when one item is choosen certain information will appear, while the other item shows different information.

Some Psuedo-code coming at you to help clarify the idea.
if Item1 then
Show(Info_1);

if Item2 then
Show(Info_2);

My best attempt at producing the results using an Event;
the issue is the moment you choose an option ".ONCLICK" Simba crashes.
procedure OnSelect(Sender: TObject);
var
I: Integer;

begin
for I:= 0 to 2 do
begin
case lstMyItems.ITEMS.Strings[I] of
0:
begin
Item1.CAPTION:= 'help';
end;
1:
begin
Item2.Caption:= 'no help';
end;
end;
end;

edtWinnerHP.Visible:= True;
end;