SRL Archive - SRL Suggestions

Chat.simba addition: Crafting options


Runaway

2012-09-11 16:03:23

I've been working on some functions lately to handle the crafting menu. It's very similar to ChooseOption in that it grabs the option text and parses through it for the desired string. I put it through some testing and everything seems to be working fast and efficient :)


function CraftingScreen: Boolean;
begin
Result := CountColorTolerance(1131144, MCX1, MCY1, MCX2, MCY2, 3) >= 100;
end;

function ScrollCraftingMenu(Left: Boolean): Boolean;
var
Box: TBox;
P: TPoint;
t: Integer;
begin
Result := False;
if not CraftingScreen then
Exit;
case Left of
True: P := Point(12, 394);
False: P := Point(493, 394);
end;
Box := IntToBox(P.x, P.y, P.x + 12, P.y + 69);
Result := WaitColor(P.x, P.y, 791065, 1, 100);
if not Result then
Exit;
MouseTBox(Box, mouse_move);
MarkTime(t);
while not SimilarColors(GetColor(P.x, P.y), 1446924, 1) and (TimeFromMark(t) < 2000) do
Wait(100+Random(50));
end;

function GetCraftingOptions(var Options: TStringArray; var Points: TPointArray): Integer;
var
aTPA: T2DPointArray;
TPA: TPointArray;
Bounds: TBox;
P: TPoint;
lTPA, i: Integer;
begin
Result := 0;
if not CraftingScreen then
Exit;
SetLength(Options, 0);
SetLength(Points, 0);
FindColorsTolerance(TPA, 2070783, MCX1, MCY1 + 40, MCX2, MCY2, 0);
if (Length(TPA) < 1) then
Exit;
aTPA := SplitTPAEx(TPA, 15, 10);
SortATPAFromMidPoint(aTPA, Point(MCX1, MCCY));
lTPA := Length(aTPA);
SetLength(Options, lTPA);
SetLength(Points, lTPA);
for i := 0 to (lTPA - 1) do
begin
Bounds := GetTPABounds(aTPA[i]);
P := MiddleTPA(aTPA[i]);
Options[i] := GetTextAtExWrap(Bounds.x1, Bounds.y1, Bounds.x2, Bounds.y2, 0, 4, 2, 2070783, 0, statChars);
Points[i] := Point(P.x, P.y - 15);
if (Options[i] <> '') then
Inc(Result);
end;
end;

function CraftingOptionMulti(Text: TStringArray; Scroll: Boolean): Boolean;
var
Options: TStringArray;
Points: TPointArray;
Box: TBox;
M: TPoint;
hOption, hText, t, i, ii: Integer;
Left: Boolean;
begin
Result := False;
if not CraftingScreen then
Exit;
hText := High(Text);
t := 0;
repeat
if InRange(t, 1, 2) and Scroll then
begin
case t of
1: Left := True;
2: Left := False;
end;
ScrollCraftingMenu(Left);
end;
GetCraftingOptions(Options, Points);
if (Length(Options) < 1) then
Exit;
hOption := High(Options);
for i := 0 to hText do
begin
for ii := 0 to hOption do
begin
if (Pos(Text[i], Options[ii]) <> 0) then
begin
Result := True;
Box := IntToBox(Points[ii].x - 15, Points[ii].y - 15, Points[ii].x + 15, Points[ii].y + 15);
GetMousePos(M.x, M.y);
if PointInBox(M, Box) then
ClickMouse2(mouse_left)
else
MouseTBox(Box, mouse_left);
Wait(500+Random(250));
Exit;
end;
end;
end;
if not Scroll then
Exit;
Inc(t);
until(t > 2);
end;

function CraftingOption(Text: String; Scroll: Boolean): Boolean;
begin
Result := CraftingOptionMulti([Text], Scroll);
end;

function WaitCraftingOptionMulti(Time: Integer; Text: TStringArray; Scroll: Boolean): Boolean;
var
t: Integer;
begin
Result := False;
MarkTime(t);
while not Result and (TimeFromMark(t) < Time) do
Result := CraftingOptionMulti(Text, Scroll);
end;

function WaitCraftingOption(Time: Integer; Text: String; Scroll: Boolean): Boolean;
begin
Result := WaitCraftingOptionMulti(Time, [Text], Scroll);
end;

euphemism

2012-09-11 16:31:15

Looks neat, you should check out kanah's "The Pot Maker" I believe he wrote many of the same functions already.

Le Jingle

2012-09-11 17:02:55

I believe the crafting chat options could possibly be renamed, since so many other skills use the same interface (at least I think they all matched up). I.E. using clay to make urns, you get a lot of options, as well as fletching, firemaking, and some other skills too I believe.

Nonetheless, nice work on these additions!

Runaway

2012-09-11 17:25:38

From: euphemism
Looks neat, you should check out kanah's "The Pot Maker" I believe he wrote many of the same functions already.


I was unaware someone had already attempted this! Although his is rather… messy :pinch:

From: Le Jingle
I believe the crafting chat options could possibly be renamed, since so many other skills use the same interface (at least I think they all matched up). I.E. using clay to make urns, you get a lot of options, as well as fletching, firemaking, and some other skills too I believe.

Nonetheless, nice work on these additions!


Thanks! I've been trying to figure out what it's name is, but I've checked everywhere and there's nothing on the main site or wiki about it. Although I believe it's referred to as the "Crafting interface" since the right-click menu option to enter the interface is "Craft" (Like logs, gems, etc).

Flight

2012-09-11 21:51:49

Perhaps you might suggest these being added to SRL's crafting.simba branch; those poor skill files never receive any attention.

Very good job, Runaway. :)

Runaway

2012-09-13 11:34:39

From: Flight
Perhaps you might suggest these being added to SRL's crafting.simba branch; those poor skill files never receive any attention.

Very good job, Runaway. :)


Thanks!

I was thinking crafting.simba at first, but I ended up with chat.simba because the crafting interface is used in 8 (I think?) different skills and utilizes the chat box globals. I was trying to find something for it in Misc but nothing in there worked :pinch: Although, I've never organized an official include so I'm not the one to make the decision anyways. Whatever works for the SRL team works for me; I just think these functions are useful enough to be included somewhere :p