SCAR CDE manual 2.01 - by Kaitnieks


Home
Scar Scripts
Autobots & Cheats
Buy Gold

Author information
SCAR is created by Kaitnieks (Aivars Irmejs)
(C) 2003-2005 Aivars Irmejs
If you like SCAR, drop me a line: aispam@serveris.lv
Community website: http://www.kaitnieks.com/scr.
SCAR official webpage: http://www.kaitnieks.com/scar/

Introduction
SCAR is a scriptable color clicker which is meant to be used to automate tasks. The general purpose of SCAR is automating repetitive actions in online games by simulating human interaction, which in most cases is considered cheating. SCAR uses custom  version of Pascal language for scripts and includes a number of built in functions for mouse, keyboard interaction, text, color, bitmap searching etc. SCAR makes script developing easy by offering friendly IDE with syntax highlighting and script debugging features.

General
You should start with trying out sample scripts. The default shortcut keys are Ctrl+Alt+R to run script and Ctrl+Alt+S to stop.
To specify client window just drag the crosshair over the client (the game area itself).
If it can't find files or there are any other problems, make sure you have extracted all required files and directories from the archive.
If it doesn't run script because includes are missing, make sure you download the required includes and copy them to same folder your script is or "Includes" folder (from SCAR menu Tools > Explore Folder > Includes Folder).

Pascal basics
Some Pascal basics can be found here, but I must warn you that the site will scare you: http://www2.iicm.edu/hmcard/courseware/pascal/Pascal2.htm
Or you could try this site:
http://web.mit.edu/taoyue/www/tutorials/pascal/contents.html
You really should find and read a serious Pascal tutorial, this manual will give you an idea, not teach the Pascal language.
The simplest Pascal program:
begin
end.
As you see, it requires 2 lines - begin shows where the program starts, end with dot - where it ends. Everything after it gets ignored. A better program would be:

program MyFirst;
begin
Writeln ('Hello World!');
end.

It's a good style to specify program name at the beginning, also pay attention to spacing, small and capital letters, usage of semicolons.
Here is a thing about variables. I know most of you avoided them at all in AR script, but they are easier here (I hope). The variables have types. SCAR supports less types than Pascal and for those who are familiar with Pascal - it doesn't support arrays (ok it actually does, I just didn't want to explain it here :P). Here are types you will use:

string Text, string of characters 'a', 'some text', 'awaa'#13'bah'
Integer Whole numbers, positive and negative 0, 1, 2, 3, ..., -1, -2, -3, ...
Extended Real numbers, positive and negative 0, 1.5, -100.67, 100.3333
Boolean Have only 2 values - true or false True, False

There are other types too, but these are the main to operate with. A simple example:

program VarDemo;
var s: string;
begin
s:= 'Hello World!';
Writeln(s);
end.

As you see, we have to use var variable_name : type; to define the variable before using it.
You will sometimes want to print out Integer and Extended type variable values, so here is a sample to do it as only strings can be printed out. A sample of type conversion:

program PrintNumbers;
var i: Integer;
e: Extended;
begin
i:= 10;
e:= 3.5;
Writeln('i=' + IntToStr(i) + ', e=' + FloatToStr(e));
end.

(Copy and paste it in SCAR window to test)
What can you do with variables? It depends on variable type. You can concatenate string variables: s:= 'wo' + 'rd'; will result with 'word' in variable s. You can do a whole bunch of arithmetic operations with Integer and Extended: i:= 4 + 5 will result with 9 in i etc. Boolean are useful too. You can set it to true or false: b:= True; or to logical condition b:= (a = 1); will result with True in b is a is equal to 1 or False if a is equal to anything else.
Now about control types.
Conditional statement.

if( a = 1)or(a = 4)then
begin
a:= 0;
Writeln('a was 1 or 4 so we made it to zero');
end else
begin
Writeln('a was neither 1 nor 4');
end;

While loops.

i:= 0;
while(i < 10) do
begin
i:= i + 1;
Writeln(IntToStr(i));
end;

Repeat loop is very similar, except the condition is checked at the end of the loop and it's exit condition (if it's true, the loop ends), so it always go through repeat-until loop at least 1 time.

i:= 0;
repeat
i:= i + 1;
Writeln(IntToStr(i));
until(i >= 10);

For loops.

for i:= 1 to 10 do
begin
Writeln(i);
end;


That's all about control structures. You will understand more from the examples included with SCAR.

Standard functions

This is a list to functions you can use which do not requite THE CLIENT window. The most useful (for you) functions are underlined.
procedure Writeln(s: string); - outputs string to debug box
procedure Status(s: string);
- shows a message in status bar
function Readln(question: string): string;
- asks question to user and returns the answer
procedure Wait(ms: Integer);
- Waits ms milliseconds (Wait(1000) - wait 1 second). You should use this to avoid freezing.
function inttostr(i: Longint): string;
- converts integer to string.
function strtoint(s: string): Longint;
- converts string to integer.
function strtointdef(s: string; def: Longint): Longint;
function copy(s: string; ifrom, icount: Longint): string; - returns part of the string (Copy('abcde',2,3) would return 'bcd'.
function pos(substr, s: string): Longint;
- returns position of substring in string. Returns 0 if not found.
procedure delete(var s: string; ifrom, icount: Longint): string;
- delete part of string.
procedure insert(s: string; var s2: string; ipos: Longint): string;
- insert s into s2.
function Between(s1, s2, s: string): string; - returns part of string s between substrings s1 and s2.
function getarraylength: integer;
procedure setarraylength;
Function StrGet(var S : String; I : Integer) : Char;
procedure StrSet(c : Char; I : Integer; var s : String);
Function Uppercase(s : string) : string;
Function Lowercase(s : string) : string;
Function Trim(s : string) : string;
- removes spaces from start and end of string.
Function Length(s : String) : Longint;
- returns string length in characters.
procedure SetLength(var S: String; L: Longint);
function Random(Range: Integer): Integer;
Function Sin(e : Extended) : Extended;
Function Cos(e : Extended) : Extended;
Function Sqrt(e : Extended) : Extended; - square root.
function Pow(Base, Exponent: Extended) : Extended; - Returns the power of the Base with the given Exponent
function SameValue(A, B: Extended) : Boolean; - Checks if the given Extended numbers are equal
Function Round(e : Extended) : Longint; - rounds and converts floating point number to integer.
Function Trunc(e : Extended) : Longint; - rounds down and converts to integer.
Function Int(e : Extended) : Longint;
function Max(a, b: Integer): Integer; - Returns biggest of two integer values.
function MaxE(a, b: Extended): Extended; - Returns biggest of two extended values.
function Min(a, b: Integer): Integer; - Returns smallest of two integer values
function MinE(a, b: Extended): Extended; - Returns smallest of two extended values
Function Pi : Extended;
Function Abs(e : Extended) : Extended; - returns absolute value (converts negative number to pozitive).
function StrToFloat(s: string): Extended; - converts string to floating pointnumber.
Function FloatToStr(e : Extended) : String; - converts floating point number to string.
Function Padl(s : string;I : longInt) : string;
Function Padr(s : string;I : longInt) : string;
Function Padz(s : string;I : longInt) : string;
Function Replicate(c : char;I : longInt) : string;
Function StringOfChar(c : char;I : longInt) : string;
function VarGetType(x: Variant): TVarType;
function Null: Variant;
procedure RaiseLastException;
procedure RaiseException(Ex: TIFException; Param: string);
function ExceptionType: TIFException;
function ExceptionParam: string;
function ExceptionProc: Cardinal;
function ExceptionPos: Cardinal;
function ExceptionToString(er: TIFException; Param: string): string;
Function means that the function returns a value, procedure just does something and doesn't return anything. Parameters and their types are specified in brackets and as the last comes type of function return value.

Supported classes

This is only a list of some of classes that can be used in SCAR. For more help on properties and methods of individual classes consult Delphi help or internet search. Remember that only very limited functionality is implemented and many properties and methods that work in Delphi will not work in SCAR. Not all supported classes are listed here, only the main ones.

TGroupBox - The TGroupBox component represents a standard group box, used to group related controls on a form.

TLabel - Use TLabel to add text or a bitmap that the user canít edit to a form.

TEdit - Use a TEdit object to put a standard edit control on a form.

TMemo - Use TMemo to put a standard multiline edit control on a form.

TComboBox - A TComboBox component is an edit box with a scrollable drop-down list attached to it.

TButton - Use TButton to put a standard push button on a form.

TCheckBox - A TCheckBox component presents an option for the user.

TRadioButton - Use TRadioButton to add a radio button to a form.

TListBox - Use TListBox to display a scrollable list of items that users can select, add, or delete.

TScrollBar - Use TScrollBar to add a free-standing scroll bar to a form.

TImage - Use TImage to display a graphical image on a form.

TPanel - Use TPanel to put an empty panel on a form.

TTimer - TTimer is used to simplify calling the system timer functions.

TForm - form (window) component.

TApplication - TApplication encapsulates a windowed application.

TMenuItem - Use TMenuItem to specify the appearance and behavior of an item in a menu.

TMenu - Use TMenu as a base class when defining a component that represents a collection of menu items.

TMainMenu - Use TMainMenu to provide the main menu for a form.

TPopupMenu - Use TPopupMenu to define the pop-up menu that appears when the user clicks on a control with the right mouse button.

TCanvas - Use TCanvas as a drawing surface for objects that draw an image of themselves.

Mouse, keyboard functions

procedure GetMousePos(var x,y: integer); - read current mouse position into x,y.

procedure MoveMouse(x,y: integer); - simulate mouse movement, move cursor to x,y instantly.

procedure MoveMouseSmooth(x,y: integer) - simulate humanlike mouse movement to x,y from current mouse position.

procedure MoveMouseSmoothEx(x,y: integer; minsleeptime, maxsleeptime, maxdistance, gravity, forces: Integer) - simulate humanlike mouse movement with more customizable parameters. By default MinSleepTime = 1; MaxSleepTime = 3; MaxDistance = 45; Gravity = 20; Forces = 10. Minsleeptime and Maxsleeptime limit pause between mouse cursor jumps, MaxDistance is maximal allowed distance between mouse jumps, Gravity is how much mouse tends to reach destination, Forces are like random winds, hand shaking simulation.

procedure MoveMouseSmoothFrom(x1, y1, x2, y2: integer); - Works like MoveMouseSmooth but has starting position specified. Moves mouse cursor smoothly from x1, y1 to x2, y2.

procedure MoveMouseSmoothFromEx(x1, y1, x2, y2: integer; minsleeptime, maxsleeptime, maxdistance, gravity, forces: Integer); - Works like MoveMouseSmoothEx but has starting position specified.

procedure ClickMouse(x,y: integer; Left: boolean); - simulate mouse click at x,y.
Example:
ClickMouse(100, 30, True); //left click at coordinates 100,30

procedure HoldMouse(x,y: integer; Left: boolean); - Holds mouse button. Set parameter Left to true for left button, false for right.

procedure ReleaseMouse(x,y: integer; Left: boolean); Releases mouse button.

procedure SendKeys(S: String); - simulate key pressing to send a string to the active window.

procedure SendKeysSilent(S: String); - send string to Client's window, if this doesn't work, use SendKeys

procedure SendArrowSilent(a: Byte); - Sends arrow to Client's window. For a, 0 = up, 1 = right, 2 = down, 3 = left.

procedure SendArrowSilentWait(a: Byte; WaitTime: Integer) - Sends an arrow to Client's window like SendArrowSilent and holds it for a given wait time.
Example: SendArrowSilentWait(1, 10); //holds "Right" arrow for 10 milliseconds.

procedure SendKeysVB(S: string; Wait: Boolean); - Sends the keys analogically to Visual Basic SendKeys command. Wait parameter specifies if SCAR should wait for the command to complete.

procedure KeyDown(Key: Byte); - simulates pushing a key.

procedure KeyUp(Key: Byte); - simulates releasing a key.

procedure KeyDownSilent(Key: Byte); - simulates pushing a key in silent mode.

procedure KeyUpSilent(Key: Byte); - simulates releasing a key in silent mode.

function GetKeyCode(Key: Char): Byte; - get keyboard code of a character.

function IsMouseButtonDown(LeftButton: Boolean): Boolean; - If LeftButton is true, then it checks if the left mouse button is down; false, checks if the right mouse button is down

function IsFunctionKeyDown(Key: Byte): Boolean; - Checks if the given function key is down.
Meanings of Key:
0: SHIFT
1: CONTROL
2: ALT
3: LEFT SHIFT
4: LEFT CONTROL
5: LEFT ALT
6: RIGHT SHIFT
7: RIGHT CONTROL
8: RIGHT ALT

function IsFKeyDown(Num: Byte): Boolean; - Num = 1..12. Checks if F1, F2, ... F11 or F12 key is down corresponding to Num.

function IsArrowDown(Num: Byte): Boolean; - Checks if arrow key is down. Num corresponds to 0 = up, 1 = right, 2 = down, 3 = left.

function IsKeyDown(C: Char): Boolean; - Checks if the given key is down.
Example:
if(IsKeyDown('a'))then
  Writeln('You have pressed "a". Congratulations!');

Color, bitmap searching and related functions

function LoadBitmap(path: string): Integer; - Loads bitmap (*.bmp) in memory and returns handle to it. Path can be absolute or relative if starts with a dot. Example: somepic:= LoadBitmap('.\somepic.bmp');

procedure FreeBitmap(bitmap: Integer) - Releases a bitmap and frees the memory

function BitmapFromString(Width, Height: Integer; data: string): Integer; - Loads bitmap in memory from string data and returns handle to it. Data strings can be created by clicking menu Script > Picture To String.

function CreateBitmapMaskFromText(Text: string; Chars: Integer): Integer; - creates mask image from text that can be used for searching text. Chars specifies font number returned by LoadChars2 or LoadCharsFromFont2.

function CreateMirroredBitmap(bitmap: Integer): Integer; - creates mirror image from another bitmap.

function GetColor(x,y: Integer): Integer; - Return color number at x,y.

function FindColor(var x,y: Integer; color, xs, ys, xe, ye: Integer): Boolean; - find color in box specified by xs, ys, xe, ye starting from left to right. Returns True if color found, the coordinates of the color if found is put in x,y.

function FindColorTolerance(var x,y: Integer; color, xs, ys, xe, ye: Integer; Tolerance: Integer): Boolean - Works like the regular FindColor function but with a tolerance parameter for finding any similar color. Tolerance is used to find a color in range of the color you are looking for. The greater color range you want, the higher the tolerance parameter should be.

function FindColorSpiral(var x,y: Integer; color, xs, ys, xe, ye: Integer): Boolean; - find color in box specified by xs, ys, xe, ye but start from x,y.

function FindColorSpiralTolerance(var x,y: Integer; color, xs, ys, xe, ye: Integer; Tolerance: Integer): Boolean - Works like the regular FindColorSpiral but with a tolerance parameter for finding any similar color. Tolerance is used to find a color in range of the color you are looking for. The greater color range you want, the higher the tolerance parameter should be.

function FindColorSpiral2(var x,y: Integer; color, xs, ys, xe, ye: Integer): Boolean; - find color just like FindColorSpiral, and if there is a big spot of that color then it finds the center of it.

function FindColoredAreaTolerance(var x,y: Integer; color, xs, ys, xe, ye: Integer; MinArea, Tolerance: Integer): Boolean - Works similar to FindColorTolerance but instead of finding just 1 colored pixel and storing the coordinates into x and y, it finds an area where the colored pixel was found and stores a random coordinate according to the entered MinArea value into x,y. MinArea is specified by the count of pixels you it has in an area. To find area in size 10X10 you would enter 100 as MinArea.

function FindBitmap(bitmap: Integer; var x, y: Integer): Boolean; - search for the bitmap in client window. If found coordinates are returned in x,y. bitmap contains handle to bitmap generated by LoadBitmap.

function FindBitmapIn(bitmap: Integer; var x, y, x1, y1, x2, y2: Integer): Boolean; - search for the bitmap in coordinates specified by x1, y1, x2, y2. bitmap contains handle to bitmap generated by LoadBitmap.

function FindBitmapToleranceIn(bitmap: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; tolerance: Integer): Boolean - Works like FindBitmapIn but with a tolerance parameter for finding any similar colored bitmap. Tolerance is used to find a colored bitmap in range of the bitmap you are looking for. The greater color range you want, the higher the tolerance parameter should be.

function FindBitmapSpiral(bitmap: Integer; var x, y, x1, y1, x2, y2: Integer): Boolean; - search for the bitmap in coordinates specified by x1, y1, x2, y2 starting from x, y.  bitmap contains handle to bitmap generated by LoadBitmap.

function FindBitmapSpiralTolerance(bitmap: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; Tolerance: Integer): Boolean - Works like FindBitmapSpiral but with a tolerance parameter for finding any similar colored bitmap. Tolerance is used to find a colored bitmap in range of the bitmap you are looking for. The greater color range you want, the higher the tolerance parameter should be.

function FindBitmapMaskTolerance(mask: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; Tolerance, ContourTolerance: Integer): Boolean - Essentially it works like FindBitmapIn except it identifies using the masks/shape of an object in the bitmap. Masks are specified by the colors black and white. ContourTolerance is the minimal tolerance for color difference between shape of a mask and the background in a bitmap, It makes sure the shape differs from the background.
<-- sample mask for finding letter A in any color.

function FindDeformedBitmapToleranceIn(bitmap: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; tolerance: Integer; Range: Integer; AllowPartialAccuracy: Boolean; var accuracy: Extended): Boolean; - Works similar to FindBitmapToleranceIn but allows searching for partially covered or transformed bitmaps. If range is 0, it checks pixels at positions that match bitmap we are looking for; if Range ir 1, it checks neighbor pixels as well, if range is bigger, it checks further. AllowPartialAccuracy allows accuracy that is not 100% match. accuracy returns accuracy of found bitmap to bitmap we are looking for. accuracy = 1.0 means it was 100% perfect match.
Example: we are searching for .
1. Target bitmap:
FindDeformedBitmapToleranceIn(b, x, y, 0, 0, 100, 100, 70, 0, True, acc);
Results: acc = 0.825745682889
FindDeformedBitmapToleranceIn(b, x, y, 0, 0, 100, 100, 70, 1, True, acc);
Results: acc = 1.000000000000
2. Target bitmap:
FindDeformedBitmapToleranceIn(b, x, y, 0, 0, 100, 100, 70, 0, True, acc);
acc = 0.585557299843
FindDeformedBitmapToleranceIn(b, x, y, 0, 0, 100, 100, 70, 1, True, acc);
acc = 0.751962323391

function FindDeformedBitmapToleranceRotationIn(bitmap: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; tolerance: Integer; Range: Integer; var accuracy: Extended; AngleIntervals: Extended; StartAngle, MaxAngle: Extended; var angle: Extended): Boolean; - Works similar to FindDeformedBitmapToleranceIn but allows searching for rotated bitmaps as well. Basically it rotates bitmap, searches in target image, then rotates again, searches again. AngleIntervals specifies by how much it rotates every time, StartAndge specifies initial rotation angle, MaxAngle specifies how far it rotates and angle returns angle of found image. All angles are specified in radians (Pi = 180˚)
Example: FindDeformedBitmapToleranceRotationIn(minimaptree, x, y, 582, 37, 700, 117, 170, 0, acc, PI/10, 0, 2*PI, angle);

function RotateBitmap(bitmap: Integer; angle: Extended): Integer; - Rotates bitmap by specified angle in radians (Pi = 180˚)

function SimilarColors(col1, col2, tolerance: integer): Boolean - Function to test weather two colors are within tolerance range. If they are within range, it returns true, if not false.

procedure ColortoHSL(C: TColor; var H, S, L: Extended); - converts color to hue, saturation and luminance map.

procedure PickColor(var Color: TColor; var X, Y: Integer); - This command allows color to be picked directly from script. Color returns color picked and x, y returns coordinates the color was picked at.

procedure FindColorsSpiralTolerance(x, y: Integer; var Points: TPointArray; color, xs, ys, xe, ye: Integer; Tolerance: Integer); - finds all colors in area specified by xs, ys, xe, ye and returns their coordinates into Points.

Text finding and reading functions

function LoadChars2(path: string): Integer; - Load font from folder in memory.
Example: UpChars:= LoadChars2(AppPath + 'CharsRS22\');
If you are planning on creating your own character set, make sure bitmap images are named according to their ASCII codes.

function LoadCharsFromFont2(fontname: string; fontsize: Integer; fontbold, fontitalic, fontunderline, fontstrike: Boolean): Integer; - Load characters from Windows font in memory.
Example: c:= LoadCharsFromFont2('Courier New', 10, False, False, False, False);

procedure FreeChars2(i: Integer); - Unload font from memory.

function GetTextAtEx(x, y: Integer; Tolerance: Integer; Chars: Integer; CheckShadow, CheckOutline: Boolean; MinSpacing, MaxSpacing: Integer; TextColor: Integer; TextLength: Integer; Strict: Boolean; Range: TCharRange) : String; - reads text at position specified by x, y. Tolerance specifies acceptable color range in for characters that are not completely monochrome, Chars specifies font number returned by LoadChars2 or LoadCharsFromFont2, CheckShadow specifies whether function should look for shadow, CheckOutline specifies whether function should verify if character borders are correct, MinSpacing and MaxSpacing are RS1 and RS2 specific parameters for text with changing spacing between characters, in other cases use MinSpacing=0 and MaxSpacing=0,  TextColor specifies text color, if set to -1, will search for text in any color, TextLength - maximal text length to read, if Strict is set to true then it won't find characters that contain additional pixels of character's color in the same area as character is, Range can have following values:
tr_AllChars - read all characters;
tr_BigLetters - read capital Latin letters;
tr_SmallLetters - read lowercase Latin letters;
tr_Digits - read digits;
tr_BigSymbols - read symbols that are big in size, like "=", "%", "$", etc;
tr_SmallSymbols - read small symbols like ".", ",", "'", etc;
tr_SecondTableChars - read symbols with character code above 127;
tr_Letters = tr_BigLetters or tr_SmallLetters;
tr_AlphaNumericChars = tr_Letters or tr_Digits;
tr_Symbols = tr_BigSymbols or tr_SmallSymbols;
tr_NormalChars = tr_AlphaNumericChars or tr_Symbols;
Example:
GetTextAtEx(9, 9, 130, UpChars, True, False, 0, 1, $E0E0E0, 20, False, tr_AlphaNumericChars) - read RS2 upper text in this color.
GetTextAtEx(96, 387, 0, ChatChars, False, False, 0, 0, -1, 20, True, tr_NormalChars) - read RS2 chat text in any color.
UpChars and ChatChars are set up during script initialization like this:
UpChars:= LoadChars2(AppPath + 'CharsRS22\');
ChatChars:= LoadChars2(AppPath + 'CharsChat2\');

function IsTextAtEx(x, y: Integer; S: String; Tolerance: Integer; Chars: Integer; CheckShadow, CheckOutline: Boolean; MinSpacing, MaxSpacing: Integer; TextColor: Integer) : Boolean; - checks if text specified by S is at location specified by x, y. Tolerance specifies acceptable color range in case characters are not completely monochrome, Chars specifies font number returned by LoadChars2 or LoadCharsFromFont2, CheckShadow specifies whether function should look for shadow, CheckOutline specifies whether function should verify if character borders are correct, MinSpacing and MaxSpacing are RS1 and RS2 specific parameters for text with changing spacing between characters, in other cases use MinSpacing=0 and MaxSpacing=0,  TextColor specifies text color, if set to -1, will search for text in any color

function IsTextInAreaEx(x1, y1, x2, y2: Integer; var x, y: Integer; S: String; Tolerance: Integer; Chars: Integer; CheckShadow, CheckOutline: Boolean; MinSpacing, MaxSpacing: Integer; TextColor: Integer) : Boolean; - Searches for text in area specified by x1, y1, x2, y2. Other parameters match IsTextAtEx.

Deformable template model related functions

function LoadDTM(FileName: string): Integer; - Load deformable template model from file.

function DTMFromString(s: string): Integer; - Load deformable template model from string. Strings can be created in deformable template model editor in menu Tools > DTM editor.

procedure FreeDTM(DTM: Integer); - Unload deformable template editor.

function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer): Integer; - Use DTM to find object on client window. x1, y1, x2, y2 specifies box to search in, x, y returns coordinates if found.
Example:
if(FindDTM(rock, x, y, 100, 100, 500, 300)) then
  Writeln('I rock');

Output functions

procedure Writeln(s: string); - outputs text string to debug box.

procedure Status(s: string); - shows a message in status bar

procedure AddToReport(s: string) - Adds a message to the report box

procedure ClearReport - Clears all messages sent to the report box

procedure ChangeReportWidth(Width: Integer); - Changes the width of the report box to the given Width

procedure PlaySound(FileName: string); - play the specified WAV file.

procedure SaveScreenshot(FileName: string); - save screenshot of client window in bitmap file.

procedure SaveBitmap(bitmap: Integer; path: string) - Saves a bitmap as a file.

function GetStatus : string; - Returns SCAR window status bar text.

procedure ClearDebug; - clears debug box.

File functions

function OpenFile(Path: string; Shared: Boolean): Integer; - opens file for reading and returns file number if successful or negative number if failed. If shared = true then attempts to open files used by other applications as read-only.

function RewriteFile(Path: string; Shared: Boolean): Integer; - opens file for writing and truncates it. Returns file number if successful or negative number if error.

procedure CloseFile(FileNum: Integer); - closes file specified by FileNum.

function EndOfFile(FileNum: Integer): Boolean; - returns true if end of file specified by FileNum reached.

function FileSize(FileNum: Integer): LongInt; - returns file size in bytes.

function WriteFileByte(FileNum: Integer; b: Byte): Boolean; - writes a single byte to file.

function WriteFileInt(FileNum: Integer; i: Integer): Boolean; - writes a single integer to file.

function WriteFileString(FileNum: Integer; s: string): Boolean; - writes a string to file.

function ReadFileByte(FileNum: Integer; var b: Byte): Boolean; - reads a single byte from file.

function ReadFileInt(FileNum: Integer; var i: Integer): Boolean; - reads a single integer from file.

function ReadFileString(FileNum: Integer; var s: string; Length: Integer): Boolean; - reads Length number of bytes from file into string s.

Internet functions

function GetPage(URL: string): string; - Return HTTP webpage contents as string.
Example:
s:= GetPage('http://kaitnieks.com');
if(s = '')then
begin
  Writeln('Some kind of connection error');
end else
begin
  ..
end;

procedure OpenWebPage(URL: string); - Opens webpage in default internet browser.

function InitializeHTTPClient(HandleCookies, HandleRedirects: Boolean): Integer; - creates a new HTTP client in memory and returns handle of the client.

procedure FreeHTTPClient(i: Integer); - destroys HTTP client in memory.

function GetHTTPPage(Client: Integer; URL: string): string; - return HTTP page contents using specified client.

procedure SetHTTPUserAgent(Client: Integer; Agent: string); - change HTTP agent value of HTTP client.

function PostHTTPPage(Client: Integer; Url: string; PostData: string): string; - do POST request of page specified by Url, where POST variables are in string PostData.

function PostHTTPPageEx(Client: Integer; Url: string): string; - do POST request of page specified by Url, where POST variables are added prior using ClearPostData and AddPostVariable.

procedure ClearPostData(Client: Integer); - clears POST variables list (for PostHTTPPageEx).

procedure AddPostVariable(Client: Integer; VarName, VarValue: string); - adds new POST variable (for PostHTTPPageEx).

function GetRawHeaders(Client: Integer): string; - displays raw response headers of HTTP client.

function OpenConnection(Host: string; Port, TimeOut: Integer): Integer; - creates new socket connection to specified host and port. Returns connection handle if successful.

function ReadConnectionData(Connection: Integer; var s: string): Boolean; - reads data from connection into string s.

function SendConnectionData(Connection: Integer; s: string): Boolean; - sends data to connection.

procedure FreeConnection(i: Integer); - destroys socket connection.

function IsConnectionOpen(Connection: Integer): Boolean; - checks if connection is connected.
 

RS1 and RS2 specific non depreciated functions

procedure FixMouse(var x,y: integer; slot: Integer) - Fixmouse checks for screen shifting around x,y and changes x,y accordingly. Slots are used to stored the number for every spot you're following. example 0, 1, 2. If you're just checking one spot, then 0 as slot. x,y are the coords of the spot you're watching and lost is just the spot number. RS1 and RS2 only.

procedure FixMouseEx(var x,y: integer; slot, maxshift, squaresx, squaresy,squaresize: Integer; minaccuracy: Extended) - Like FixMouse with added detail. Maxshift is how far the max distance the square could have been shifted. Default 3. Squaresx is how many squares in row, default 13. Squaresy is how many squares in column, default 10. Squaresize is how big the squares are, Default 15. Minaccuracy is accuracy limit for a square, how much we allow it to change, default 0.7, 1 for 100%. RS1 and RS2 only.

function DetectRS2MinimapCompassAngle : Extended; - returns RS2 compass angle in radians (Pi = 180˚). Returns -1 if fails.

function DetectRS2MinimapAngle(var ByCompass: Boolean): Extended; - returns minimap angle in radians (Pi = 180˚) determined from minimap itself. If map didn't have anything to determine angle from, returns compass angle and sets ByCompass to true. Returns -1 if fails.

SCAR form control, form and object functions

function GetSelf : TForm;- get reference to SCAR main form.

function GetApplication : TApplication;- get reference to SCAR Application object.

function GetCanvas : TCanvas;- get reference to game client window's Canvas.

function GetBitmapCanvas(bitmap: Integer) : TCanvas;- get reference to bitmap's Canvas.

function GetDebugCanvas : TCanvas; - Returns a canvas of the debug image window.

procedure CopyCanvas(Source, Dest: TCanvas; sxs, sys, sxe, sye, dxs, dys, dxe, dye: Integer); - Copy image from Source canvas to Dest canvas. Area to be copied from is specified by sxs, sys, sxe, sye, area to be copied to is specified by dxs, dys, dxe, dye.

function CreateForm: TForm; - creates form. The difference from standard TForm.Create(Application); is that forms created with CreateForm will be destroyed after SCAR script finishes or crashes. Also this function is thread-safe.
Example:
F:= CreateForm;
FreeForm(F);

procedure FreeForm(Form: TForm); - destroys forms created with CreateForm.

procedure LoadDebugBitmap(path: string); - Loads bitmap and displays it in debug image window.

procedure DisplayDebugImgWindow(Width, Height: Integer) - Brings up the debug image window. This window can be used for drawing so you don't have to create your own.

procedure HideDebugImgWindow; - Hides the debug window

Client control functions

procedure FindWindow(Title: string);- finds Client window with specified title. Character case of Title must match that in window title exactly.

function FindWindowTitlePart(Title: string; CaseSensitive: Boolean): Boolean; - finds window that contains text specified by Title parameter in window caption.

function FindWindowBySize(Width, Height: Integer): Boolean; -- finds window with specified size.

procedure ActivateClient; - activate client window.

function GetClientWindowHandle : Integer; - Get Windows handle value of active client window.

procedure SetClientWindowHandle(H: Integer); - Set active client window to handle H.
Example:
H:= GetClientWindowHandle;
//specify another client window
FindWindow('Debug Image');
...
//return to previous client
SetClientWindowHandle(H);

procedure SetTargetBitmap(bitmap: Integer); - Sets bitmap as target for all color/bitmap searching functions. After calling SetTargetBitmap all functions won't be working with client but with specified bitmap.
Example:
SetTargetBitmap(flagstaff);
if(FindColor(x, y, $000066, 0, 0, 3, 2))then
 ...
The sample above will not search on client screen but in bitmap "flagstaff" instead.

procedure GetClientDimensions(var Width, Height: Integer); - Get client width and height.

procedure CopyClientToBitmap(bitmap: Integer; xs, ys, xe, ye: Integer); - Copy client screen part to bitmap specified.

Script control functions

procedure Wait(ms: Integer); - Waits ms milliseconds (Wait(1000) - wait 1 second).

procedure Sleep(ms: Integer); - alias of Wait

function SetTimeout(secs: Integer; procname: string): Integer; - set timed procedure. After secs seconds a procedure with name procname will be called. The procedure should have no parameters and it's only called once (you can SetTimeout again in the procedure).
Example:
SetTimeout(1,'StartPlaying'); will set procedure StartPlaying on timer and it will be called after 1 second.
Declaration:
procedure StartPlaying;
begin
  ...
end;

function ThreadSafeCall(ProcName: string; var V: TVariantArray): TVariant; - Calls function or procedure in thread-safe way. SCAR scripts operate in separate thread to prevent main form freezing and as a rule threads are not allowed to create, modify or even access forms or controls directly. That means scripts can't create or use forms or controls directly, operate with debug image directly etc. Most of SCAR functions that access forms (Writeln, Status, Readln, LoadDebugImg, ect) are thread-safe already. However if you're operating with debug window canvas directly for an example, you're risking to make SCAR unstable or crash it.
Example:
var
  Params: TVariantArray;

procedure ChangeTitle(s: string);
begin
  GetSelf.Caption:= s;
end;
....
setarraylength(Params, 1);
Params[0]:= 'Test';
ThreadSafeCall('ChangeTitle', Params);

procedure ClearTimeout(s: string) - Cancels a single timed procedure set with SetTimeout

procedure ClearTimeouts - Cancels all timed procedures set with SetTimeout

procedure TerminateScript; - Immediately terminates the currently running script

function IntPow(Base: Extended; Exponent: Integer): Extended; -  Returns the power of the Base with the given Exponent. Whole number exponents only.

function Max(a, b: Integer): Integer; - Returns biggest of two integer values.

function MaxE(a, b: Extended): Extended; - Returns biggest of two extended values.

function Min(a, b: Integer): Integer; - Returns smallest of two integer values

function MinE(a, b: Extended): Extended; - Returns smallest of two extended values

Mathematical, number and evaluation functions

function Random(Range: Integer): Integer; - returns random 0 <= number < Range. Random(5) will return any of values 0, 1, 2, 3, 4. Random(5) + 1 will return values 1..5.

function GetSystemTime : Integer; - Returns the current time in milliseconds

function Pow(Base, Exponent: Extended) : Extended; - Returns the power of the Base with the given Exponent

function SameValue(A, B: Extended) : Boolean; - Checks if the given Extended numbers are equal

function Sin(e : Extended) : Extended; - returns sine value of e.

function Cos(e : Extended) : Extended; - returns cosine value of e.

function Sqrt(e : Extended) : Extended; - square root.

function Sqr(X: Extended): Extended; - returns X*X.

Communication functions

procedure SendInterSCARMessage(id, message: string) - Sends a string to another script. The ID is used for both scripts to communicate with each other by sending and reading the string/messages. Example: SendInterScarMessage('control', 'Please stop taking my chips');

function ReadInterSCARMessage(id: string): string - Reads string/messages sent by another script by means of an ID.
Example:
if(ReadInterScarMessage('control') = 'Please stop taking my chips') then
  Writeln('But I already ate them!');

Fast drawing functions

procedure SetTransparentColor(bitmap, color: Integer); - set specified color in bitmap to be transparent for FastDraw functions

procedure SetTransparencyFromBitmap(Bitmap, AlphaMaskBitmap: Integer); - sets transparency from bitmap specified by AlphaMaskBitmap, which should be grayscale image, but currently only blue color channel is used. Supports halftones as well.

procedure FastDrawTransparent(x, y: Integer; SourceBitmap, TargetBitmap: Integer); - draws source bitmap to target bitmap at coordinates specified by x, y.

procedure FastDrawSizeTransparent(x1, y1, x2, y2: Integer; sourcebitmap, targetbitmap: Integer); - draws source bitmap to target bitmap and stretches to rectangle specified by x1, y1, x2, y2.

procedure FastDrawClear(bitmap: Integer; Color: TColor); - fills bitmap with a single color.

procedure SafeDrawBitmap(Source: Integer; Dest: TCanvas; x, y: Integer); - draws Source bitmap to Dest canvas thread-safely at coordinates specified by x, y.

procedure SafeCopyCanvas(Source, Dest: TCanvas; sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2: Integer); - acts like CopyCanvas, but is thread-safe.

function FastGetPixel(bitmap: Integer; x, y: Integer): TColor; - gets color at x, y on bitmap.

procedure FastSetPixel(bitmap: Integer; x, y: Integer; c : TColor); - puts pixel on bitmap at x, y.

Other functions

procedure SetMouseMode(Silent: boolean); - if SetMouseMode(True) then it will move and click without moving mouse cursor. If that doesn't work, use SetMouseMode(False);

function AppPath : string;- get SCAR folder path.

function ScriptPath : string;- get path of currently active script.

procedure ColorToleranceSpeed(x: integer) - Sets the speed of tolerance comparisons. ColorToleranceSpeed(1) is a little slower then 0 but more accurate. ColorToleranceSpeed(0) is faster but not as accurate as 1. ColorToleranceSpeed(2) uses Hue, Saturation and Lightness to determine color similarity.

procedure SetColorspeed2Modifiers(huemodifier, saturationmodifier: Extended); - these work when ColorToleranceSpeed(2) has been set. Normally Tolerance parameter in this mode applies to Luminance directly. For an example, SimilarColors(c1, c2, 10) would work if both colors differ by 10 max luminance. After calling SetColorspeed2Modifiers(0.2, 2) it would mean that SimilarColors(c1, c2, 10) would check for Hue in range of 2 and Saturation in range of 20. Default huemodifier and saturationmodifier is 0.2.

function IsFontSmoothingEnabled : Boolean; - Checks if Windows font smoothing is enabled

procedure SetFontSmoothing(Enable: Boolean); - Sets or unsets Windows font smoothing according to Enable parameter.

function GetSCARVersion: Integer; - returns current SCAR version.

Depreciated functions

function GetTextAt(x, y: Integer): string; - get text at the specified coordinates. Works with RS1 only. Depreciated.

function IsTextAt(x, y: Integer; S: string): Boolean; - works faster than GetTextAt - compares if there is specified text at x,y. Works with RS1 only. Depreciated.

function IsTextAt2(x, y: Integer; S: String; Tolerance: Integer): Boolean - Works like regular TextAt at but supports text spacing and changing colors. Works for RS2 only. Depreciated.

function IsTextInArea(x1, y1, x2, y2: Integer; var x, y: Integer; S: String): Boolean; - searches for text in S in box specified by x1, y1, x2, y2. Returns coordinates of the text in x, y if found. Works for RS1 only. Depreciated.

function GetFightMode: Integer; - Will return 0 is fight mode selection is invisible, 1 for controlled, 2 for str, 3 for att and 4 for def. For RS1 only. Depreciated.

function SpiralFindObj(var x,y: Integer; color, xs, ys, xe, ye: Integer; Step: Integer; Text: string; WaitTime, MaxTime: Integer): Boolean; - universal function for object finding x, y contain coordinates to start search from and return coordinates of spot if object found, color - object color or -1 if the color is ignored, xs, ys, xe, ye specify box to search in (set them to -1 to search the whole client screen), Step - how many pixels skip (as more as faster), text - text to look for that appears when mouse is over the object at 6,2, WaitTime - time in milliseconds to wait before reading the text after moving the mouse, MaxTime - maximum time to search (if not found during tha time, give up). RS1 only. Depreciated.

function SpiralFindObjs(var x,y: Integer; color, xs, ys, xe, ye: Integer; Step: Integer; CommaText: string; WaitTime, MaxTime: Integer): Boolean; - works like SpiralFindObj but looks for multiple objects. CommaText is objects to look for, seperated by commas. If object name contains comma, put it in quotes like this Text = 'Object1,Object2,"Object,contains comma","Contains ""quotes"" and, comma",Object999'; RS1 only. Depreciated.

function StartScreen: Boolean; - RS1 only. Depreciated, only left for compatibility

function LoginScreen: Boolean; - RS1 only. Depreciated, only left for compatibility

function CreateLandmark(W, H: Integer; Data: string): Integer; - creates landmark. Use Script > Create landmark from main menu to generate a correct landmark. RS1 only, depreciated.

function FindLandmark(LandMark: Integer; var x,y: Integer; var accuracy: Extended): Boolean; - searches for the landmark in map (Get map into memory with ProcessMap first). x and y returns top left corner of the landmark in map, r contains 1 if the place in map matches the landmark perfectly and 0 if it's totally different. RS1 only, depreciated.

procedure ProcessMap; - Analyzes image on client and creates map in memory. RS1 only, depreciated.

procedure ProcessMapNoCompass; - reads the map into memory. Processing does not fail if compass is not perfectly straight. RS1 only, depreciated.

procedure ClickMap(x,y: integer; Left: boolean); - click map coordinates. 18,18 are your coordinates. RS1 only, depreciated.

function CreatePath: Integer; - Create new path. RS1 only, depreciated.

procedure AddLandmarkToPath(path, landmark, x, y: Integer); - add landmark to path, x,y contain relative coordinates from the top left corner of the landmark that should be clicked. RS1 only, depreciated.

function ProcessPath(path: Integer;var x, y: Integer; var accuracy: Extended; Tolerance: Extended): Integer; - moves further by the path. Returns x, y - map coordinates that should be clicked, accuracy that we're on the path 0..1 and function value is number of the current landmark in the path. RS1 only, depreciated.

function ConvertColor(C: Integer): Integer; - converts Windows RGB color to Graphics32 color. Depreciated.

procedure LoadChars(path: string) - Loads rs2 chars. For default path: LoadChars(''). Depreciated.

Using forms.
Just follow this step by step tutorial and you will get the idea. Preconditions: you should know something about SCAR scripting.
1. Create new script and press SCAR menu Script > Form Editor
2. Drop a button on form somewhere.
3. Save the form and close form editor
4. Press SCAR menu Script > Load DFM form
5. You will get bunch of things in debug box. Copy variable declarations before begin.
6. Create new procedure before main begin
procedure InitForm;
begin
end;
7. Copy the rest form debug box into this procedure starting with frmDesign := CreateForm;
8. Declare new procedure
procedure SafeInitForm;
var
  v: TVariantArray;
begin
  setarraylength(V, 0);
  ThreadSafeCall('InitForm', v);
end;
9. Put call to SafeInitForm in main script
10. Run the script.
11. Ok, let's make it a bit more useful. Declare two procedures:
procedure ShowFormModal;
begin
  frmDesign.ShowModal;
end;

procedure SafeShowFormModal;
var
  v: TVariantArray;
begin
  setarraylength(V, 0);
  ThreadSafeCall('ShowFormModal', v);
end;

12. Put call to SafeShowFormModal in main script so it looks like this:
begin
  SafeInitForm;
  SafeShowFormModal;
end.
13. Remove form visibility. Find line frmDesign.Visible := True; and change True to False.
14. Run script. As you see form is modal and SCAR will freeze while form is open.
15. Let's make button do something. Declare procedure before InitForm declaration:
procedure buttonclick(sender: TObject);
begin
  Writeln('Button pressed!');
  frmDesign.Caption:= frmDesign.Caption + '.';
end;
16. Add line after Button1 := TButton.Create(frmDesign):
Button1.OnClick:= @buttonclick;
17. Run the script. Now when you press the button, it will Writeln and change window title.
18. If you want window to close when button is pressed, add line inside procedure buttonclick:
frmDesign.ModalResult:= mrOk;

Here is my final code:
program New;
var
  frmDesign : TForm;
  Button1 : TButton;

procedure buttonclick(sender: TObject);
begin
  Writeln('Button pressed!');
  frmDesign.Caption:= frmDesign.Caption + '.';
  frmDesign.ModalResult:= mrOk;
end;

procedure InitForm;
begin
  frmDesign := CreateForm;
  frmDesign.Left := 259;
  frmDesign.Top := 132;
  frmDesign.Width := 354;
  frmDesign.Height := 254;
  frmDesign.Caption := 'frmDesign';
  frmDesign.Color := clBtnFace;
  frmDesign.Font.Color := clWindowText;
  frmDesign.Font.Height := -11;
  frmDesign.Font.Name := 'MS Sans Serif';
  frmDesign.Font.Style := [];
  frmDesign.Visible := False;
  frmDesign.PixelsPerInch := 96;
  Button1 := TButton.Create(frmDesign);
  Button1.OnClick:= @buttonclick;
  Button1.Parent := frmDesign;
  Button1.Left := 69;
  Button1.Top := 61;
  Button1.Width := 75;
  Button1.Height := 25;
  Button1.Caption := 'Button1';
  Button1.TabOrder := 8;
end;

procedure SafeInitForm;
var
  v: TVariantArray;
begin
  setarraylength(V, 0);
  ThreadSafeCall('InitForm', v);
end;

procedure ShowFormModal;
begin
  frmDesign.ShowModal;
end;

procedure SafeShowFormModal;
var
  v: TVariantArray;
begin
  setarraylength(V, 0);
  ThreadSafeCall('ShowFormModal', v);
end;

begin
  SafeInitForm;
  SafeShowFormModal;
end.


 

(C) 2003-2005 Aivars Irmejs


Runescape 101 | Autobots & Cheats | Cheat Pack | Scar Scripts | Buy Gold