Before I start, Wouldn't it be more logical to have BuySell.scar in misc?
I don't see the logic in having it in Skill 
Added
- ShopItemCoords
- ExistsShopItem
Re-did/Modified
- BuyCoords
- BuyAmount
- BuyColor
- SellCoords
- Sell (Small edit).
Deleted
This will not outdated anything... afaik BuySell.scar was outdated.
New BuySell.scar
SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- Buying and Selling routines --//
//-----------------------------------------------------------------//
//
// * Function ShopItemCoords(I: Integer): TPoint; // * by N1ke!
// * Function ExistsShopItem(i: Integer): Boolean; // * by N1ke!
// * Function BuyCoords(x, y, Amount: Integer): Boolean; // * by RSN re-done by N1ke!
// * Function BuyAmount(i, Amount: Integer): Boolean; // * by RSN modified by N1ke!
// * Function BuyColor(UpText: String; Color, Tol, Amount: Integer): Boolean; // * by RSN Modified by N1ke!
// * Function SellCoords(x, y, Amount: Integer): boolean; // * by RSN redone by N1ke!
// * Function Sell(i, Amount: Integer): Boolean; // * RSN small edit by N1ke!
// * Function FindItems(color, tol: Integer; text: string; num: Integer): TPointArray; // * by RSN
// * Procedure SellItems(Color, Tol, Num, Amount: Integer; Text: string); // * by RSN
{*******************************************************************************
Function ShopItemCoords(I: Integer): TPoint;
By: N1ke!
Description: Results the coords for shop item. (Left to right).
*******************************************************************************}
Function ShopItemCoords(I: Integer): TPoint;
var
row, col: Integer;
begin
row := i div 10;
col := i - (row * 10) - 1;
if (col < 0) then
begin
col := 9;
row := row - 1;
end;
Result := Point(78+(col * 39), 107+(row * 55));
end;
{*******************************************************************************
Function ExistsShopItem(i: Integer): Boolean;
By: N1ke!
Description: Checks if the shop item exists. (Left to right).
*******************************************************************************}
function ExistsShopItem(i: Integer): Boolean;
var
Cords: TPoint;
X, Y: Integer;
begin
Result := False;
If Not ShopScreen then
Exit;
Cords := ShopItemCoords(I);
Result := FindColor(X, Y, 65536, Cords.X-20, Cords.Y-20, Cords.X+20, Cords.Y+20);
end;
{*******************************************************************************
Function BuyCoords(x, y, Amount: Integer): Boolean;
By: RSN re-done by N1ke!
Description: Buys the specified amout of the Item at x, y
*******************************************************************************}
Function BuyCoords(x, y, Amount: Integer): Boolean;
var
AmountLeft, xz, yz, iTime: Integer;
S: String;
begin
Result := False;
If Not ShopScreen then Exit;
If Amount < 1 then
begin
srl_Warn('BuyCoords', 'Invalid amount parameter', warn_Warning);
Exit;
end;
AmountLeft := Amount;
While AmountLeft > 0 do
begin
MMouse(x, y, 5, 5);
If Not WaitUpText('alue', 300)then
Exit;
GetMousePos(xz, yz);
Mouse(xz, yz, 0, 0, False);
Case AmountLeft of
1: S := '1';
5: S := '5';
10: S := '10';
else S := 'Buy X';
end;
If Not WaitOption(S, 400)then
Exit;
If (S = 'Buy X') then
begin
iTime := GetSystemTime + 7000;
While Not (CountColor(0, 211, 392, 307, 410) > 200) do
Wait(150+Random(100));
If AmountLeft > 49999 then
S := '50000' else S := IntToStr(AmountLeft);
TypeSend(S);
end;
AmountLeft := AmountLeft - StrToInt(S);
end;
Result := True;
end;
{*******************************************************************************
Function BuyAmount(i, Amount: Integer): Boolean;
By: RSN modified by N1ke!
Description: Buys the specified amount of the Item at assigned row and column
*******************************************************************************}
Function BuyAmount(i, Amount: Integer): Boolean;
var
Cords: TPoint;
begin
Result := False;
If Not ExistsShopItem(i) then
Exit;
Cords := ShopItemCoords(I);
Result := BuyCoords(Cords.X, Cords.Y, Amount);
end;
{*******************************************************************************
Function BuyColor(UpText: String; Color, Amount: Integer): Boolean;
By: RSN Modified by N1ke!
Description: Buys all items with that color
*******************************************************************************}
Function BuyColor(UpText: String; Color, Tol, Amount: Integer): Boolean;
var
x, y: Integer;
begin
Result := False;
If Not(FindItem(x, y, 'color', Color, 19, 27, 499, 325, [Tol, 4]))then
Exit;
Result := BuyCoords(X, Y, Amount);
end;
{*******************************************************************************
Function SellCoords(x, y, Amount: Integer): boolean;
By: RSN redone by N1ke!
Description: Sells Item at x, y
*******************************************************************************}
Function SellCoords(x, y, Amount: Integer): boolean;
var
AmountLeft, xz, yz: Integer;
S: String;
begin
Result := False;
If Not ShopScreen then Exit;
If Amount < 1 then
begin
srl_Warn('SellCoords', 'Invalid amount parameter', warn_Warning);
Exit;
end;
AmountLeft := Amount;
While AmountLeft > 0 do
begin
MMouse(x, y, 5, 5);
If Not WaitUpText('alue', 300)then
Exit;
GetMousePos(xz, yz);
Mouse(xz, yz, 0, 0, False);
Case AmountLeft of
1..4: S := '1';
5..9: S := '5';
10..49: S := '10';
else
If (Random(20) = 0)then
S := '10' else
S := '50';
end;
If Not WaitOption(S, 400)then
Exit;
AmountLeft := AmountLeft - StrToInt(S);
end;
Result := True;
end;
{*******************************************************************************
Function Sell(i, Amount: Integer): Boolean;
By: RSN small edit by N1ke!
Description: Sells Items at specified Inv Slot
*******************************************************************************}
Function Sell(i, Amount: Integer): Boolean;
var
ItemPoint: TPoint;
begin
Result := False;
if Not (ExistsItem(i)) then
Exit;
ItemPoint := ItemCoords(i);
Result := SellCoords(ItemPoint.x, ItemPoint.y, Amount);
end;
{*******************************************************************************
function FindItemsArray(color, tol: Integer; Text: String; num: Integer): TPointArray;
By: RSN
Description: Returns Array of all Coords of that Item
*******************************************************************************}
function FindItemsArray(color, tol: Integer; Text: string; num: Integer)
: TPointArray;
var
xi, yi, tx, ty, Used: Integer;
x, y: Integer;
begin
GameTab(4);
SetArrayLength(Result, 0);
if (num = 0) then
num := -1;
ty := 190;
tx := 548;
repeat
yi := yi + 1;
ty := ty + 37;
xi := 0;
repeat
xi := xi + 1;
tx := tx + 41;
if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
tol) and (Text <> '')) then
begin
MMouse(tx, ty, 2, 2)
Wait(250);
if (IsUpText(Text)) then
begin
Used := Used + 1;
SetArrayLength(Result, Used);
GetMousePos(Result[Used - 1].x, Result[Used - 1].y);
Wait(150);
end;
end
else
if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
tol)) then
begin
Used := Used + 1;
SetArrayLength(Result, Used);
Result[Used - 1].x := tx;
Result[Used - 1].y := ty;
end;
until (xi = 4) or (Used = num);
tx := 544;
until (yi = 7) or (Used = num);
end;
{*******************************************************************************
function FindItems(color, tol: Integer; text: String; num: Integer): TPointArray;
By: Mutant Squirrle
Description: Finds Items with color and up text.
*******************************************************************************}
function FindItems(color, tol: Integer; text: string; num: Integer):
TPointArray;
var
xi, yi, tx, ty, Used: Integer;
x, y: Integer;
begin
GameTab(4);
SetArrayLength(Result, 0);
if (num = 0) then
num := -1;
ty := 190;
tx := 548;
repeat
yi := yi + 1;
ty := ty + 37;
xi := 0;
repeat
xi := xi + 1;
tx := tx + 41;
if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
tol)) then
begin
MMouse(tx, ty, 2, 2);
Wait(250);
if (IsUpText(text)) then
begin
Used := Used + 1;
SetArrayLength(Result, Used);
GetMousePos(Result[Used - 1].x, Result[Used - 1].y)
Wait(150);
end;
end;
until ((xi = 4) or (Used = num));
tx := 544;
until ((yi = 7) or (Used = num));
end;
{*******************************************************************************
procedure SellItems(Color, Tol, Num, Amount: Integer; Text: String);
By: RSN
Description: Sells items with that color, UpText and Tolerance by
Amount Specified
*******************************************************************************}
procedure SellItems(Color, tol, Num, Amount: Integer; Text: string);
var
TP: TPointArray;
i: Integer;
begin
TP := FindItems(Color, tol, Text, Num);
for i := 0 to GetArrayLength(TP) - 1 do
SellCoords(TP[i].x, TP[i].y, Amount);
end;
Old BuySell.scar
SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- Buying and Selling routines --//
//-----------------------------------------------------------------//
// * procedure BuyCoords(x, y, amount: Integer); // * by RSN
// * procedure Buy(i, amount: Integer); // * by RSN
// * procedure BuyColor(Color,Amount: Integer); // * by RSN
// * procedure SellCoords(x, y, amount: Integer); // * by RSN
// * procedure Sell(i, amount: Integer); // * by RSN
// * function FindItems(color, tol: Integer; text: string; num: Integer): TPointArray; // * by RSN
// * procedure SellItems(Color, Tol, Num, Amount: Integer; Text: string); // * by RSN
{*******************************************************************************
procedure BuyCoords(x, y, amount: Integer);
By: RSN
Description: Buys the specified amout of the Item at x, y
*******************************************************************************}
procedure BuyCoords(x, y, Amount: Integer); // By RSN
var
ix, iy: Integer;
ToBuy: array[1..3] of Integer;
Done: array[1..3] of Integer;
begin
ix := x;
iy := y;
ToBuy[1] := Amount div 10;
ToBuy[2] := (Amount mod 10) div 5;
ToBuy[3] := (Amount mod 10) mod 5;
while (done[1] < tobuy[1]) do
begin
Mouse(ix, iy, 3, 3, False);
Wait(450);
if (ChooseOption('Buy 10')) then
Done[1] := done[1] + 1
else
Exit;
Wait(300);
end;
while (done[2] < tobuy[2]) do
begin
Mouse(ix, iy, 3, 3, False);
Wait(450);
if (ChooseOption('Buy 5')) then
Done[2] := done[2] + 1
else
Exit;
Wait(300);
end;
while (done[3] < tobuy[3]) do
begin
Mouse(ix, iy, 3, 3, False);
Wait(450);
if (ChooseOption('Buy 1')) then
Done[3] := done[3] + 1
else
Exit;
Wait(300);
end;
end;
{*******************************************************************************
procedure BuyAmount(i, amount: Integer);
By: RSN
Description: Buys the specified amount of the Item at assigned row and column
*******************************************************************************}
procedure BuyAmount(i, Amount: Integer);
var
ix, iy, row, col: Integer;
begin
row := i div 8;
col := i - (row * 8) - 1;
if (col < 0) then
begin
col := 7;
row := row - 1;
end;
ix := 88 + (col * 47) + Random(7);
iy := 76 + (row * 47) + Random(7);
BuyCoords(ix, iy, Amount);
end;
{*******************************************************************************
procedure BuyColor(Color, Amount: Integer);
By: RSN
Description: Buys all items with that color
*******************************************************************************}
procedure BuyColor(Color, Amount: Integer); // by RSN
var
x, y: Integer;
begin
while (FindColorSpiral(x, y, Color, 16, 53, 501, 321)) do
BuyCoords(x, y, Amount);
end;
{*******************************************************************************
procedure SellCoords(x, y, amount: Integer);
By: RSN
Description: Sells Item at x, y
*******************************************************************************}
procedure SellCoords(x, y, Amount: Integer);
var
ix, iy: Integer;
ToSell: array[1..3] of Integer;
Done: array[1..3] of Integer;
begin
ix := x;
iy := y;
ToSell[1] := Amount div 10;
ToSell[2] := (Amount mod 10) div 5;
ToSell[3] := (Amount mod 10) mod 5;
while (done[1] < toSell[1]) do
begin
Mouse(ix, iy, 3, 3, False);
Wait(450);
if (ChooseOption('Sell 10')) then
Done[1] := done[1] + 1
else
Exit;
Wait(300);
end;
while (done[2] < toSell[2]) do
begin
Mouse(ix, iy, 3, 3, False);
Wait(450);
if (ChooseOption('Sell 5')) then
Done[2] := done[2] + 1
else
Exit;
Wait(300);
end;
while (done[3] < toSell[3]) do
begin
Mouse(ix, iy, 3, 3, False);
Wait(450);
if (ChooseOption('Sell 1')) then
Done[3] := done[3] + 1
else
Exit;
end;
end;
{*******************************************************************************
procedure Sell(i, amount: Integer);
By: RSN
Description: Sells Items at specified Inv Slot
*******************************************************************************}
procedure Sell(i, Amount: Integer); // by RSN
var
ItemPoint: TPoint;
begin
if (ExistsItem(i)) then
begin
ItemPoint := ItemCoords(i);
SellCoords(ItemPoint.x, ItemPoint.y, Amount);
end;
end;
{*******************************************************************************
function FindItemsArray(color, tol: Integer; Text: String; num: Integer): TPointArray;
By: RSN
Description: Returns Array of all Coords of that Item
*******************************************************************************}
function FindItemsArray(color, tol: Integer; Text: string; num: Integer)
: TPointArray;
var
xi, yi, tx, ty, Used: Integer;
x, y: Integer;
begin
GameTab(4);
SetArrayLength(Result, 0);
if (num = 0) then
num := -1;
ty := 190;
tx := 548;
repeat
yi := yi + 1;
ty := ty + 37;
xi := 0;
repeat
xi := xi + 1;
tx := tx + 41;
if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
tol) and (Text <> '')) then
begin
MMouse(tx, ty, 2, 2)
Wait(250);
if (IsUpText(Text)) then
begin
Used := Used + 1;
SetArrayLength(Result, Used);
GetMousePos(Result[Used - 1].x, Result[Used - 1].y);
Wait(150);
end;
end
else
if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
tol)) then
begin
Used := Used + 1;
SetArrayLength(Result, Used);
Result[Used - 1].x := tx;
Result[Used - 1].y := ty;
end;
until (xi = 4) or (Used = num);
tx := 544;
until (yi = 7) or (Used = num);
end;
{*******************************************************************************
function FindItems(color, tol: Integer; text: String; num: Integer): TPointArray;
By: Mutant Squirrle
Description: Finds Items with color and up text.
*******************************************************************************}
function FindItems(color, tol: Integer; text: string; num: Integer):
TPointArray;
var
xi, yi, tx, ty, Used: Integer;
x, y: Integer;
begin
GameTab(4);
SetArrayLength(Result, 0);
if (num = 0) then
num := -1;
ty := 190;
tx := 548;
repeat
yi := yi + 1;
ty := ty + 37;
xi := 0;
repeat
xi := xi + 1;
tx := tx + 41;
if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
tol)) then
begin
MMouse(tx, ty, 2, 2);
Wait(250);
if (IsUpText(text)) then
begin
Used := Used + 1;
SetArrayLength(Result, Used);
GetMousePos(Result[Used - 1].x, Result[Used - 1].y)
Wait(150);
end;
end;
until ((xi = 4) or (Used = num));
tx := 544;
until ((yi = 7) or (Used = num));
end;
{*******************************************************************************
procedure SellItems(Color, Tol, Num, Amount: Integer; Text: String);
By: RSN
Description: Sells items with that color, UpText and Tolerance by
Amount Specified
*******************************************************************************}
procedure SellItems(Color, tol, Num, Amount: Integer; Text: string);
var
TP: TPointArray;
i: Integer;
begin
TP := FindItems(Color, tol, Text, Num);
for i := 0 to GetArrayLength(TP) - 1 do
SellCoords(TP[i].x, TP[i].y, Amount);
end;