Gah, someone could at least tell me about this :p
//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- » Reflection Routines --||
//------------------------------------------------------------------//
// * Function GetLevel(index: integer): integer; // * by BenLand100
// * Function StringFromBytes(jbytearray: integer): string; // * by BenLand100
// * Function GetMyName: string; // * by BenLand100
// * Function GetAnimation: integer; // * by BenLand100
// * Function GetSpeed: integer; // * by Widget
// * Function CharacterMoving: boolean; // * by BenLand100
// * Procedure GetMyPos(var x, y: Integer); // * by BenLand100
// * Function GetBoxAnswer: integer; // * by BenLand100
// * Function GetMinimapAngleDeg: extended; // * by BenLand100
// * Function GetMinimapAngleRad: extended; // * by BenLand100
// * Procedure TileToMinimap(tileX, tileY: integer; var screenX, // * by BenLand100
// screenY: integer); //
// * Procedure MinimapToTile(screenX, screenY: integer; var tileX, // * by BenLand100
// tileY: integer); //
// * Procedure TileToMS(tileX, tileY, height: integer; // * by BenLand100
// var screenX, screenY: integer); //
// * Function TileOnMM(TileX, TileY : Integer) : Boolean; // * by ss23
// * Function TileOnMS(TileX, TileY, Height : Integer) : Boolean; // * by ss23
// * Function DistanceFrom(TileX, TileY: Integer) : Integer; // * by Widget
// * Function GetNPCs: array of TNPC; // * by Widget
// * Function GetNPCsByName: array of TNPC; // * by Widget
// * Function GetNPCsByID: array of TNPC; // * by Widget
// * Function SortNPCs(NPCs: array of TNPC): array of TNPC; // * by Widget
// * Function FindNPC(Name: string; height: integer; // * by Widget
// * var x,y:integer): Boolean; //
// * Function FindNPCTile(Name: string; var x,y:integer): Boolean; // * by Widget
// * Function ClickTile(TileX, TileY, Height : Integer; // * by ss23 and Widget
// Left : Boolean) : Boolean; //
// * Procedure WalkToTile(Tilex, Tiley : Integer); // * by ss23
// * Function MMtoMS(x, y: Integer; left: Boolean): Boolean; // * by LeeLokHin
// * Function OpenBankReflection(Bank : String): Boolean; // * by ss23
//------------------------------------------------------------------//
// NPC stuff completely re-written
//
// Added TNPC type, will use later; Improved TileOn functions - ss23
//
// Thanks to Speljohan and Quaters for making hooks that we can steal =)
//------------------------------------------------------------------//
type
TNPC = record
x, y, NPCType, height : integer;
TheName : string;
InFight, IsMoving: boolean;
end;
TPlayer = record
x, y:integer;
animation, speed: integer;
HPRatio, height, level: integer;
Name: string;
Levels, Experiences: array[1..24]{or whatever} of integer;
end;
const
// Global Static Hooks
BaseLayer = 'bc.f';
BaseX = 'pa.e';
BaseY = 'rb.D';
CamX = 'ph.j';
CamY = 'bb.y';
CamZ = 'bi.w';
CamPitch = 'sh.N';
CamYaw = 'pi.E';
CompassAngle = 'oj.p';
CurrentLevels = 'fd.eb';
Experiences = 'e.n';
FlagX = 'sc.Y';
FlagY = 'le.f';
GroundHeights = 'lh.N';
GroundSettings = 'ad.P';
LoopCycle = 'lg.a';
MapOffsetAngle = 'fa.m';
MaxLevels = 'hk.e';
MyPlayer = 'th.u';
NPCArray = 'gj.o';
NPCCount = 'qi.h';
NPCIndexArray = 'cf.c';
PlayerArray = 'fg.h';
PlayerCount = 'li.h';
PlayerIndArray = 'sf.K';
SettingsArray = 'ki.c';
// Character Hooks
CharAnim = 'cb';
CharMotion = 'pb';
CurrentX = 'Q';
CurrentY = 'Bb';
CharHeight = 'y';
LoopCycleStatus= 'qb';
// Player Hooks
CharName = 'uc';
// NPC Hooks
NPCDef = 'Nb';
// NPCDef Hooks
GetNPCName = 'V';
GetNPCType = 'j';
// RSString Hooks
StringBytes = 'B';
//----------------------------------------------------------------------//
function GetLevel(index: integer): integer;
{*******************************************************************
Function - GetLevel(index: integer): integer;
By: BenLand100
Description: Returns the current level of your player (its a funny array)
********************************************************************}
begin
result:= SmartGetFieldArrayInt(0,CurrentLevels,index);
end;
function StringFromBytes(jbytearray: integer): string;
{*******************************************************************
Function - StringFromBytes(jbytearray: integer): string;
By: BenLand100
Description: Converts a byte[] from StringWrap to a DelphiString
(max length 256)
********************************************************************}
begin
SetLength(result, 256);
SetLength(result, SmartStringFromBytes(jbytearray,result));
end;
function GetMyName: string;
{*******************************************************************
Function - GetMyName: string;
By: BenLand100
Description: Returns last logged in player's name
********************************************************************}
var
bytes: Integer;
begin
bytes:= SmartGetFieldObject(0,MyPlayer+'.'+CharName+'.'+StringBytes);
result:= StringFromBytes(bytes);
SmartFreeObject(bytes);
end;
function GetAnimation: integer;
{*******************************************************************
Function - GetAnimation: integer;
By: BenLand100
Description: Returns your animation
********************************************************************}
begin
result:= SmartGetFieldInt(0,MyPlayer+'.'+CharAnim);
end;
function GetSpeed: integer; // :)
{*******************************************************************
Function - GetSpeed: integer;
By: Widget
Description: Gets character speed (squares per second)
********************************************************************}
begin
result:= SmartGetFieldInt(0,MyPlayer+'.'+CharMotion);
end;
function CharacterMoving: boolean; //:)
{*******************************************************************
Function - CharacterMoving: boolean;
By: BenLand100
Description: True if you are moving
********************************************************************}
begin
result:= (GetSpeed > 0);
end;
procedure GetMyPos(var x, y: Integer); // :)
{*******************************************************************
procedure - GetMyPos(var x, y: Integer);
By: BenLand100
Description: Calculates your x,y position or [somehugenumber] if not
logged in
********************************************************************}
var
me: Integer;
begin
me:= SmartGetFieldObject(0,MyPlayer);
x:= SmartGetFieldInt(0,BaseX) + SmartGetFieldInt(me,CurrentX) shr 7;
y:= SmartGetFieldInt(0,BaseY) + SmartGetFieldInt(me,CurrentY) shr 7;
SmartFreeObject(me);
end;
function DumpSettingArray: array[0..1999] of integer;
{*******************************************************************
function - DumpSettingArray: array[0..1999] of integer;
By: BenLand100
Description: Dumps the settings array to an integer array
********************************************************************}
var
i: integer;
begin
for i:= 0 to 1999 do
Result[i]:= SmartGetFieldArrayInt(0,SettingsArray,i);
end;
function GetBoxAnswer: integer;
{*******************************************************************
function - GetBoxAnswer: integer;
By: BenLand100
Description: Returns -1 if no box open or 0..2 for the correct
answer to the box
Comments: Yet another reason reflection is leet =) [-Widget]
********************************************************************}
var
boxIndex: Integer;
begin
boxIndex:= SmartGetFieldArrayInt(0,SettingsArray,312);
if boxIndex = 0 then
result:= -1
else
result:= (boxIndex shr 24) and $FF;
end;
function GetMinimapAngleDeg: extended;
{*******************************************************************
function - GetMinimapAngleDeg: extended;
By: BenLand100
Description: Returns the current Map angle in degrees
********************************************************************}
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * 180 / 1024;
end;
function GetMinimapAngleRad: extended;
{*******************************************************************
function - GetMinimapAngleRad: extended;
By: BenLand100
Description: Returns the current map angle in radians
********************************************************************}
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * Pi / 1024;
end;
procedure TileToMinimap(tileX, tileY: integer; var screenX, screenY: integer);
{*******************************************************************
procedure - TileToMinimap(tileX, tileY: integer; var screenX, screenY: integer);
By: BenLand100
Description: Converts the tile position tileX,tileY to a minimap location
********************************************************************}
var
angle: extended;
tempX, tempY: integer;
begin
angle:= getMinimapAngleRad;
GetMyPos(tempX, tempY);
tempX:= (tileX - tempX) * 4 - 2;
tempY:= (tempY - tileY) * 4 - 2;
screenX:= round(tempX*cos(angle) - tempY*sin(angle)) + 629;
screenY:= round(tempX*sin(angle) + tempY*cos(angle)) + 85;
end;
procedure MinimapToTile(screenX, screenY: integer; var tileX, tileY: integer);
{*******************************************************************
procedure - MinimapToTile(screenX, screenY: integer; var tileX, tileY: integer);
By: BenLand100
Description: converts the screen position screenX,screenY from the minimap
to a tile
********************************************************************}
var
angle: extended;
tempX, tempY: integer;
begin
angle:= getMinimapAngleRad;
tempX:= (screenX - 643);
tempY:= (84 - screenY);
tileX:= round(tempX*cos(angle) - tempY*sin(angle)) / 4;
tileY:= round(tempX*sin(angle) + tempY*cos(angle)) / 4;
GetMyPos(tempX, tempY);
tileX:= tileX + tempX;
tileY:= tileY + tempY;
end;
procedure TileToMS(tileX, tileY, height: integer; var screenX, screenY: integer);
{*******************************************************************
procedure - TileToMS(tileX, tileY, height: integer; var screenX, screenY: integer);
By: BenLand100
Description: Converts the tile position tileX,tileY to a mainscreen location
Height is the distance (in px) above the ground
********************************************************************}
var
cx, cy, cz, dx, dy, dz, locX, locY, layer: Integer;
pitch, yaw, sinYaw, cosYaw, sinPitch, cosPitch, rotation: extended;
begin
locX:= tileX - SmartGetFieldInt(0,BaseX);
locY:= tileY - SmartGetFieldInt(0,BaseY);
if (locX < 0) or (locY < 0) or (locX > 103) or (locY > 103) then
Exit;
layer:= SmartGetFieldInt(0,BaseLayer);
if (layer < 3) and ((2 and SmartGetFieldArray3DByte(0,GroundSettings,1,locX,locY)) = 2) then
Inc(layer);
cz:= SmartGetFieldArray3DInt(0,GroundHeights,layer,locX,locY) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX+1,locY) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX,locY+1) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX+1,locY+1);
cx:= locX * 128 + 64 - SmartGetFieldInt(0,CamX);
cy:= locY * 128 + 64 - SmartGetFieldInt(0,CamY);
cz:= (cz / 4) - height - SmartGetFieldInt(0,CamZ);
pitch:= SmartGetFieldInt(0,CamPitch) * Pi / 1024;
yaw:= SmartGetFieldInt(0,CamYaw) * Pi / 1024;
sinYaw:= sin(yaw);
cosYaw:= cos(yaw);
sinPitch:= sin(pitch);
cosPitch:= cos(pitch);
rotation:= cosYaw*cy-sinYaw*cx;
dx:= Round(sinYaw*cy+cosYaw*cx);
dy:= Round(sinPitch*cz+cosPitch*rotation);
dz:= Round(cosPitch*cz-sinPitch*rotation);
screenX:= (dx * 512) / dy + 256;
screenY:= (dz * 512) / dy + 167;
end;
Function TileOnMM(TileX, TileY : Integer) : Boolean;
{*******************************************************************
Function TileOnMM(TileX, TileY : Integer) : Boolean;
By: ss23
Description: True = Tile on MM
********************************************************************}
Var
PointEx : TPoint;
BoxEx : TBox;
Begin
BoxEx := IntToBox(MMX1, MMY1, MMX2, MMY2);
TileToMinimap(TileX, TileY, PointEx.x, PointEx.y);
Result := PointInBox(PointEx, BoxEx);
end;
Function TileOnMS(TileX, TileY, Height : Integer) : Boolean;
{*******************************************************************
Function TileOnMS(TileX, TileY, Height : Integer) : Boolean;
By: ss23
Description: True = Tile on MS
********************************************************************}
Var
PointEx : TPoint;
BoxEx : TBox;
Begin
BoxEx := IntToBox(MSX1, MSY1, MSX2, MSY2);
TileToMS(Tilex, Tiley, Height, pointex.x, pointex.y);
Result := PointInBox(PointEx, BoxEx);
end;
Function DistanceFrom(TileX, TileY: Integer) : Integer;
{*******************************************************************
Function DistanceFrom(TileX, TileY: Integer) : Integer;
By: Widget
Description: Returns the distance between your player and the tile
********************************************************************}
Var
MyX,MyY : integer;
Begin
GetMyPos(MyX, MyY);
result := Distance(TileX, TileY, MyX, MyY);
end;
function GetNPCs:array of TNPC;
{*******************************************************************
function GetNPCs:array of TNPC;
By: Widget
Description: Returns all the currently loaded NPCs
********************************************************************}
var
i,NumNPCs,Index,TheNPC,TheNPCDef,TheBytes: integer;
begin
end;
function GetNPCsByName(name:string):array of TNPC;
{*******************************************************************
Function GetNPCsByName(name:string):array of TNPC;
By: Widget
Description: Returns NPCs matching the name.
********************************************************************}
var
i: integer;
NPCs: array of TNPC;
begin
end;
function GetNPCsByID(TheType:integer):array of TNPC;
{*******************************************************************
Function GetNPCsByID(TheType:integer):array of TNPC;
By: Widget
Description: Returns NPCs matching the ID.
********************************************************************}
var
i: integer;
NPCs: array of TNPC;
begin
end;
function SortNPCs(NPCs:array of TNPC):array of TNPC;
{*******************************************************************
Function SortNPCs(NPCs:array of TNPC):array of TNPC;
By: Widget
Description: Sorts NPCs by distance from you.
********************************************************************}
var
i,i2,ix,iy: integer;
tpa: TPointArray;
begin
end;
Function FindNPCTile(Name: string; var TileX,TileY:integer):boolean;
{*******************************************************************
Function GetNPCTile(Name: string; var x,y:integer):boolean;
By: Widget
Description: Finds the tile of the named NPC, returns tile (useful for banking)
********************************************************************}
var
NPCs: array of TNPC;
begin
end;
Function FindNPC(Name: string; var x,y:integer):boolean;
{*******************************************************************
function FindNPC(Name: string; var x,y:integer):boolean;
By: Widget
Description: Finds the tile of the named NPCand fills x and y.
Returns true if found, false if not. (Try checking for tiles if
it's not on the mainscreen.)
********************************************************************}
var
NPCs: array of TNPC;
begin
end;
Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
{*******************************************************************
Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
By: ss23 and Widget
Description: Clicks a tile. Height is the approximate heigh in pixels
Height doesnt matter if HighestAngle;
********************************************************************}
Var
x, y : Integer;
Begin
TileToMS(TileX, TileY, Height, x, y);
result := TileOnMs(x,y,height);
if not result then
Exit;
Mouse(x, y, 5, 5, False);
end;
Function WalkToTile(TileX, TileY : Integer): Boolean;
{*******************************************************************
Function - WalkToTile(TileX, TileY : Integer): Boolean;
By: ss23 and Widget
Description: Walks to the tile using minimap.
********************************************************************}
Var
x, y : Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if not TileOnMM(TileX, TileY) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, 3, 3, True);
Result := True;
end;
procedure MMtoMS(MMX,MMY:integer; var MSX,MSY:integer);
{*******************************************************************
Function MMtoMS(x, y: Integer; left: Boolean): Boolean;
By: LeeLokHin
Description: Converts Coordinates x and y on the minimap
to equivilants on the MainScreen and clicks right or left according
to boolean left.
********************************************************************}
var
tx,ty:integer;
begin
MinimapToTile(MMX, MMY, tx, ty);
TileToMS(tx, ty, 5, MSX, MSY);
end;
Function OpenBankReflection(Bank : String): Boolean;
{*******************************************************************
Function OpenBankReflection(Bank : String): Boolean;
By: ss23
Description: Opens the bank. Opens nearest slot
********************************************************************}
Var
x, y : Integer;
Me : TPoint;
Tiles : TPointArray;
Begin
Case Bank of
'veb': Tiles := [Point(3251,3419), Point(3252,3419), Point(3253,3419),
Point(3254,3419), Point(3255,3419), Point(3256,3419)];
'vwb': Tiles := [Point(3190,3435), Point(3190,3437), Point(3190,3439),
Point(3190,3441), Point(3190,3443), Point(3181,3444), Point(3181,3442),
Point(3181,3440), Point(3181,3438), Point(3181,3436)];
'fwb': Tiles := [Point(2945,3367), Point(2946,3367), Point(2947,3367),
Point(2948,3367)];
'feb': Tiles := [Point(3010,3354), Point(3011,3354), Point(3012,3354),
Point(3013,3354), Point(3014,3354), Point(3015,3354)];
'lum': Tiles := [Point(3208,3221)];
'dra': Tiles := [Point(3091,3419), Point(3091,3245), Point(3091,3244),
Point(3091,3243), Point(3091,3242)];
'alk': Tiles := [Point(3268,3168), Point(3268,3167), Point(3268,3166),
Point(3268,3165), Point(3268,3164)];
end;
GetMyPos(Me.x, Me.y);
SortTPAFrom(Tiles, Me);
If (DistanceFrom(Tiles[0].x, Tiles[0].y) > 3) then
Begin
If not(TileOnMM(Tiles[0].x, Tiles[0].y)) then
Begin
Writeln('Couldn''t find bank');
Result := False;
Exit;
end;
WalkToTile(Tiles[0].x, Tiles[0].y);
Wait(10);
Flag;
Wait(100 + Random(100));
end;
If not(TileOnMS(Tiles[0].x, Tiles[0].y, 15)) then
Begin
SetAngle(True);
MakeCompass('n');
If not(TileOnMS(Tiles[0].x, Tiles[0].y, 20)) then
Begin
Writeln('Couldnt'' find bank booth');
Result := False;
Exit;
end;
end;
TileToMS(Tiles[0].x, Tiles[0].y, 20, x, y);
Mouse(x, y, 5, 5, False);
// Make choose option work here
// Wait(100 + Random(100));
// ChooseOption('uic');
Result := True;
end;
function GetPlayers: array of TPlayer;
{*******************************************************************
function - GetPlayers: array of TPlayer;
By: Widget
Description: Returns all the players on the minimap
********************************************************************}
var
i, IndexPos, Count, Player, Name: integer;
begin
Count := SmartGetFieldInt(0, PlayerCount);
writeln('Number of players: '+inttostr(Count));
SetArrayLength(result, Count);
for i := 0 to (count-1) do
begin
IndexPos := SmartGetFieldArrayInt(0, PlayerIndArray, i);
writeln('Index position: '+inttostr(count));
Player := SmartGetFieldArrayObject(0, PlayerArray, IndexPos);
writeln('Player placement: '+inttostr(Player));
Name := SmartGetFieldObject(Player, CharName);
writeln(inttostr(name));
writeln(StringFromBytes(Name));
Result[indexpos].Name := StringFromBytes(Name);
SmartFreeObject(Name);
Writeln(Result[indexpos].Name);
end;
end;
function GetPlayer(name: string): TPlayer;
{*******************************************************************
function - GetPlayer(name: string): TPlayer;
By: Widget
Description: Gets available stats for a player (Levels only work on you).
********************************************************************}
begin
end;
Don't bother trying to use player finding yet ;)
Btw, I took out NPC finding from this one since it probably won't be in the next srl :)